#pragma GCC optimize("O3") #pragma GCC target("avx") #include #define rep(i ,n) for(int i=0;i<(int)(n);++i) #define repr(i ,n) for(int i=n;i>(int)(n);--i) #define rep1(i ,n) for(int i=1;i<=(int)(n);++i) #define ALL(a) a.begin(), a.end() #define SORT(a) sort(ALL(a)) #define bit_check(bit, i) ((bit>>(i)) & 1) #define PRINT(x) printf("%d\n",(x)); using namespace std; typedef long long int int64; typedef unsigned long long uint64; template using V = vector; using I = int; using VI = V; const int INF = 2e9; const int64 MOD = 1e9 + 7; template inline bool chmin(T& a, T b){if(a>b){a=b; return true;} return false;} template inline bool chmax(T& a, T b){if(a x; vector ta , ao; int main(){ uint64 a , b , x0 ,n; cin >> a >> b >> x0 >> n; if( n == 0) { cout << 0 << " " << 0 << endl; return 0; } x.resize(n*2+100,0); ta.resize(n,0); ao.resize(n,0); x[0] = x0; for(int i = 1; i <= n*2+100 ; ++i){ x[i]=(a*x[i-1]+b)%(uint64)pow(2,32); } uint64 t_[2]={0}; uint64 a_[2]={0}; uint64 i , j; ta[0]=x[1]%6+1; ao[0]=x[2]%6+1; for(i=3 , j=1; j < n ; i+=2 , ++j){ ta[i]=ta[i-1]+x[i]%6+1; } for(i=4 , j=1; j < n ; i+=2 , ++j){ ao[i]=ao[i-1]+x[i]%6+1; } for(int i = 0 ; i <=n ; ++i){ if(ta[i]%2 == 0) ++t_[0]; else ++t_[0]; } for(int i = 0 ; i <= n ; ++i){ if(ao[i]%2 == 0) ++a_[0]; else ++a_[1]; } //cout << "takahashi black:" << t_[0] << " takahashi white:" << t_[1] << endl; //cout << "Aoki black:" << a_[0] << " Aoki white:" << a_[1] << endl; chmin(t_[0] , t_[1]); chmin(a_[0] , a_[1]); cout << t_[0] << " " << a_[0] << endl; }