#include #include #include #include #include using namespace std; typedef long long ll; #define rep(i,n) for (int i=0;i < (int)(n);i++) const ll INF = 1LL << 60; int main(){ unsigned int a,b,x,n; cin >> a >> b >> x >> n; unsigned int d; ll tb=0,tw=0; ll ab=0,aw=0; int tnow=0; int anow=0; for (int i=0;i < 2*n;i++){ x=x*a+b; d=(x)%6+1; if (i%2==0){ tnow+=d; tnow%=2; if (tnow ==1) tb++; else tw++; } else{ anow+=d; anow%=2; if (anow==1) ab++; else aw++; } } cout << min(tb,tw) << " " << min(ab,aw) << endl; return 0; }