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 = saikoro(a, b, x, m) takahashi.forward(x) x = saikoro(a, b, x, m) aoki.forward(x) return takahashi.getpoint(), aoki.getpoint() def rand(a, b, x, m): return (a * x + b) and m def saikoro(a, b, x, m): return rand(a, b, x, m) % 6 + 1 if __name__ == '__main__': main()