import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): A, B, X, N = [int(x) for x in input().split()] M = 6 prev = X prev = X t = 0 a = 0 tw = 0 tb = 0 aw = 0 ab = 0 for i in range(N * 2): prev = (prev * A + B) % M + 1 if i % 2 == 0: t += prev if t % 2 == 0: tb += 1 else: tw += 1 else: a += prev if a % 2 == 0: ab += 1 else: aw += 1 print(min(tw, tb), min(aw, ab)) if __name__ == '__main__': main()