#include <stdlib.h>
#include <stdio.h>

#define long long long

const long inf = 1000000000000000000L;

const int n = 1000000;

long key[n + 1];
int idx[n + 1];
int hidx[n + 1];

int size;

inline void swap(int i, int j) {
    int t = idx[i]; idx[i] = idx[j]; idx[j] = t;
    hidx[idx[i]] = i;
    hidx[idx[j]] = j;
}

void siftUp(int i) {
    while (i != 1 && key[idx[i / 2]] > key[idx[i]]) {
        swap(i / 2, i);
        i /= 2;
    }
}

void siftDown(int i) {
    int j = i;
    if (2 * i + 0 <= size && key[idx[2 * i + 0]] < key[idx[j]]) j = 2 * i + 0;
    if (2 * i + 1 <= size && key[idx[2 * i + 1]] < key[idx[j]]) j = 2 * i + 1;
    if (i != j) {
        swap(i, j);
        siftDown(j);
    }
}

int extractMin() {
    swap(1, size);
    size--;
    siftDown(1);
    return idx[size + 1];
}

int main() {

    long h;
    long a, b, c;
    scanf("%d%d%d%d", &h, &a, &b, &c);

    for (int i = 0; i < c; i++) {
        key[i] = inf;
        idx[i + 1] = i;
        hidx[i] = i + 1;
    }
    size = c;

    key[0] = 0;
    siftUp(hidx[0]);
    while (size != 0) {
        int i = extractMin();
        if (key[i] == inf) break;
        if (key[(i + a) % c] > key[i] + a) {
            key[(i + a) % c] = key[i] + a;
            siftUp(hidx[(i + a) % c]);
        }
        if (key[(i + b) % c] > key[i] + b) {
            key[(i + b) % c] = key[i] + b;
            siftUp(hidx[(i + b) % c]);
        }
    }

    long ok = 0;
    for (int i = 0; i < c; i++) {
        if (key[i] < h) {
            ok += ((h - 1) - key[i]) / c + 1;
        }
    }

    printf("%d\n", ok);
}
