#include <cstdio>

int solve(int n, long long k, int cnt[], int m[]);

int main() {
    FILE *fin = fopen("cadouri.in", "r"), *fout = fopen("cadouri.out", "w");
    int n; /// first parameter for solve()
    long long k; /// second parameter for solve()
    int M1, C1; /// 0 <= cnt[i] < M1
    int M2, C2; /// 0 <= cnt[i] < M2
    fscanf(fin, "%d%d%d%d%d%lld", &n, &M1, &C1, &M2, &C2, &k);
    int *cnt = new int[n], *m = new int[n]; /// last parameters for solve()
    long long m1 = M1, m2 = M2;
    unsigned int c1 = C1, c2 = C2;
    for (int i = 0; i < n; i++) {
        c1 = 5 * c1 + 1;
        c2 = 5 * c2 + 3;
        cnt[i] = ((m1 * c1) >> 32) + 1;
        m[i] = ((m2 * c2) >> 32) + 1;
    }

    fprintf(fout, "%d\n", solve(n, k, cnt, m));

    delete[] cnt;
    delete[] m;
    fclose(fin);
    fclose(fout);
    return 0;
}
