a, b, x0, N = map(int, input().split()) t_black = 0 t_white = 0 a_black = 0 a_white = 0 t_pos = 0 a_pos = 0 x_current = x0 for i in range(N): x_current = (a * x_current + b) % (2 ** 32) d = (x_current % 6) + 1 if (i + 1) % 2 == 1: # Takahashi's turn t_pos += d if t_pos % 2 == 1: t_black += 1 else: t_white += 1 else: # Aoki's turn a_pos += d if a_pos % 2 == 1: a_black += 1 else: a_white += 1 t_score = min(t_black, t_white) a_score = min(a_black, a_white) print(t_score, a_score)