a, b, x0, N = map(int, input().split(' ')) MOD=2**32 x=[x0] for n in range(N*2): x.append(x[n]*a+b) x=[(n%6)+1 for n in x] x.pop(0) if N==0: print('0 0') exit() turn = 0 score=[[0,0],[0,0]] position=[0,0] for value in x: position[turn]+=value if position[turn]%2==1: score[turn][0]+=1 else: score[turn][1]+=1 turn = (turn+1) % 2 #print(score) #print(position) a_score = min(score[0]) b_score = min(score[1]) print(str(a_score)+' '+str(b_score))