a,b,x,n=map(int,input().split()) b1,b2,w1,w2=0,0,0,0 cnt1,cnt2=0,0 for i in range(2*n): x=(a*x+b)%6 y=x%6+1 if i%2==0: cnt1+=y if cnt1%2==0: w1+=1 else: b1+=1 else: cnt2+=y if cnt2%2==0: w2+=1 else: b2+=1 print(min(b1,w1),min(b2,w2))