a, b, x0, n = map(int, input().split())
m = pow(2, 32)

x = x0
stones = [[0, 0], [0, 0]]
now = [0, 0]
for i in range(2 * n):
    turn = i % 2
    x = (a * x + b) % m
    dice = x % 6 + 1
    now[turn] += dice
    now[turn] %= 2
    stones[turn][now[turn]] += 1

print(*list(map(min, stones)))