#include<iostream> #include<cstdio> #include<queue> #include<climits> #define INF LLONG_MAX usingnamespace std; constint N = 1e5 + 10, M = N << 1; longlong h, x, y, z, ans, dis[N]; bool vis[N]; int idx, hd[N], nxt[M], edg[M], wt[M];
voidadd(int x, int y, int z) { nxt[++idx] = hd[x]; hd[x] = idx; edg[idx] = y; wt[idx] = z; } voidspfa() { for (int i = 0; i < x; i++) dis[i] = INF; queue<int> q; q.push(0); vis[0] = true; dis[0] = 1; while (!q.empty()) { int x = q.front(); q.pop(); vis[x] = false; for (int i = hd[x]; i; i = nxt[i]) { int y = edg[i]; if (dis[y] > dis[x] + wt[i]) { dis[y] = dis[x] + wt[i]; if (!vis[y]) { q.push(y); vis[y] = true; } } } } }
intmain() { cin >> h >> x >> y >> z; for (int i = 0; i < x; i++) { add(i, (i + y) % x, y); add(i, (i + z) % x, z); } spfa(); for (int i = 0; i < x; i++) if (dis[i] <= h) ans += (h - dis[i]) / x + 1; cout << ans; return0; }