#include #define rep(i,n) for(int (i)=0;(i)<(n);(i)++) using namespace std; typedef long long ll; int main(void){ cin.tie(0); ios::sync_with_stdio(false); ll a,b,x,n; cin >> a >> b >> x >> n; ll taka_w=0,taka_b=0; ll aoki_w=0,aoki_b=0; while(n--){ int num = 2; while(num--){ x = (a*x + b) % (ll)(pow(2,32)); if((x%6)%2==0){ taka_b++; }else{ taka_w++; } x = (a*x + b) % (ll)pow(2,32); if((x%6)%2==0){ aoki_b++; }else{ aoki_w++; } } } printf("%d %d",min(taka_w,taka_b),min(aoki_b,aoki_w)); return 0; }