#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define repd(i,a,b) for (int i=(a);i<(b);++i) #define rep(i,n) repd(i,0,n) typedef long long ll; typedef pair P; int main(int argc, const char * argv[]) { unsigned int n; unsigned int m; int a, b, x; cin >> a >> b >> x >> n; int a1 = 0; int a2 = 0; int b1 = 0; int b2 = 0; int c1 = 0; m = x; rep(i, n){ m = a * m + b; c1 += m % 6 + 1; if(i % 2 == 0){ if(c1%2 == 1){ ++a1; }else{ ++a2; } }else{ if(c1%2 == 1){ ++b1; }else{ ++b2; } } } cout << min(a1, a2) << ' ' << min(b1, b2) << endl; return 0; }