class Player: def __init__(self, name): self.name = name self.black = 0 self.white = 0 self.pos = 0 def forward(self, x): self.pos += x if self.pos % 2: self.black += 1 else: self.white += 1 def getpoint(self): return min(self.black, self.white) def main(): a, b, x0, n = map(int, input().split()) ans = solve(a, b, x0, n) print(*ans) def solve(a, b, x, n): m = 2 ** 32 - 1 takahashi, aoki = Player('takahashi'), Player('aoki') for _ in range(n): x = rand(a, b, x, m) takahashi.forward(saikoro(x)) x = rand(a, b, x, m) aoki.forward(saikoro(x)) return takahashi.getpoint(), aoki.getpoint() def rand(a, b, x, m): return (a * x + b) & m def saikoro(x): return x % 6 + 1 def test(): n = 4 a, b, x0, m= map(int, input('a b x0 m\n').split()) x = [x0 for _ in range(n * 2 + 1)] for i in range(n * 2): x[i + 1] = rand(a, b, x[i], m) print(*['x{}:{}'.format(i, x) for i, x in enumerate(x)], sep = '\n') if __name__ == '__main__': main()