a, b, x, N = map(int,input().split()) MOD = 2**32 L = [] for k in range(2): x = a*x + b x %= MOD L.append(1+x%6) s, t = 0, 0 if L[0]%2 == 1: s = N//2 if L[1]%2 == 1: t = N//2 print(s,t)