1 type
2 arr=record
3 y,next,w:longint;
4 end;
5 var
6 n,ans:int64;
7 nm,xx,yy,zz:longint;
8 a:array [0..200001] of arr;
9 ls,list,v:array [0..100001] of longint;
10 d:array [0..100001] of int64;
11 procedure add(x,y,z:longint);
12 begin
13 inc(nm);
14 a[nm].y:=y; a[nm].w:=z;
15 a[nm].next:=ls[x]; ls[x]:=nm;
16 end;
17
18 procedure init;
19 var
20 i,t:longint;
21 begin
22 fillchar(ls,sizeof(ls),255);
23 readln(n);
24 readln(xx,yy,zz);
25 if xx<yy then
26 begin
27 t:=xx; xx:=yy; yy:=t;
28 end;
29 if xx<zz then
30 begin
31 t:=xx; xx:=zz; zz:=t;
32 end;
33 nm:=0;
34 for i:=0 to xx-1 do
35 begin
36 add(i,(i+yy) mod xx,yy);
37 add(i,(i+zz) mod xx,zz);
38 end;
39 end;
40
41 procedure spfa;
42 var
43 i,tail,head,x:longint;
44 begin
45 for i:=0 to 100001 do
46 d[i]:=9223372036854675807;
47 fillchar(v,sizeof(v),0);
48 head:=0; tail:=1;
49 list[1]:=1; d[1]:=1; v[1]:=1;
50 repeat
51 inc(head); x:=list[head];
52 i:=ls[x];
53 while i<>-1 do
54 with a[i] do
55 begin
56 if d[x]+w<d[y] then
57 begin
58 d[y]:=d[x]+w;
59 if v[y]=0 then
60 begin
61 inc(tail);
62 list[tail]:=y;
63 v[y]:=1;
64 end;
65 end;
66 i:=next;
67 end;
68 v[list[head]]:=0;
69 until head>tail;
70 end;
71
72 procedure print;
73 var
74 i:longint;
75 begin
76 ans:=0;
77 for i:=0 to xx-1 do
78 if n-d[i]>=0 then
79 ans:=ans+(n-d[i]) div xx+1;
80 writeln(ans);
81 end;
82
83 begin
84 init;
85 spfa;
86 print;
87 end.