A,B,X,N = map(int,input().split()) m = [X%6] while 1: x = A*m[-1] + B x %= 6 if x in m: break m.append(x) m = [1-n%2 for n in m] m += m tm,am = m[::2], m[1::2] to,ao,te,ae = [0],[0],[0],[0] ct = ca = 0 for t,a in zip(tm,am): ct += t ca += a to.append(to[-1] + int(ct%2==1)) te.append(te[-1] + int(ct%2==0)) ao.append(ao[-1] + int(ca%2==1)) ae.append(ae[-1] + int(ca%2==0)) d,m = divmod(N,len(tm)) t_odd = to[-1]*d + to[m] t_ev = te[-1]*d + te[m] a_odd = ao[-1]*d + ao[m] a_ev = ae[-1]*d + ae[m] print(min(t_odd,t_ev), min(a_odd,a_ev))