#include #define rep(i, n) for(int i = 0; i < n; ++i) #define rrep(i, n) for(int i = n-1; i >= 0; --i) #define fi first #define se second using namespace std; using lint = long long; using uint = unsigned int; using ulint = unsigned long long; using ldouble = long double; using pii = pair; using pli = pair; using pdd = pair; using pld = pair; using v1i = vector; using v1li = vector; using v2i = vector>; using v2li = vector>; using v3i = vector>>; using v3li = vector>>; using v1b = vector; using v2b = vector>; using v3b = vector>>; using v1c = vector; using v2c = vector>; using v3c = vector>>; constexpr lint mod1 = 1e9+7; int main() { lint pb = 0, pw = 0, qb = 0, qw = 0, xp = 0, xq = 0; uint a, b, x, n; cin >> a >> b >> x >> n; rep(i, 2*n){ x *= a; x += b; if(i % 2 == 0){ xp += (x % 6 + 1); if(xp % 2 == 0) pw++; else pb++; } else{ xq += (x % 6 + 1); if(xq % 2 == 0) qw++; else qb++; } } cout << min(pb, pw) << " " << min(qb, qw) << endl; return 0; }