a, b, x, N = map(int, input().split()) X = [x] while True: nxt = (X[-1]*a+b)%6 if nxt in X: break X.append(nxt) nowT = 0 nowA = 0 cntT = [0, 0] cntA = [0, 0] seenT = set() seenA = set() cnt = -1 si = 0 for i in range(N): saiT = X[si%len(X)]+1 if (nowT, saiT) in seenT: cnt = i+1 break seenT.add((nowT, saiT)) nowT += saiT nowT %= 2 cntT[nowT]+=1 si += 1 saiA = X[si%len(X)]+1 if (nowA, saiA) in seenA: assert() break seenA.add((nowA, saiA)) nowA += saiA nowA %= 2 cntA[nowA]+=1 si+=1 if cnt==-1: scoT = min(cntT) scoA = min(cntA) print(scoT, scoA) exit() c = N//cnt m = N%cnt cntT = [cntT[0]*c, cntT[1]*c] cntA = [cntA[0]*c, cntA[1]*c] for i in range(m): saiT = X[si%len(X)]+1 nowT += saiT nowT %= 2 cntT[nowT]+=1 si += 1 seenA.add((nowA, saiA)) nowA += saiA nowA %= 2 cntA[nowA]+=1 si+=1 scoT = min(cntT) scoA = min(cntA) print(scoT, scoA)