def main(): import sys a, b, x0, N = map(int, sys.stdin.readline().split()) mod6 = 6 # Generate the cycle for x_i mod 6 current = x0 % mod6 cycle = [current] prev_states = {current: 0} start = None while True: current = (a * current + b) % mod6 if current in prev_states: start = prev_states[current] break else: prev_states[current] = len(cycle) cycle.append(current) # Extract the cyclic part cyclic_part = cycle[start:] T = len(cyclic_part) # Simulate the dice rolls and players' moves takahashi_pos = 0 takahashi_black = 0 takahashi_white = 0 aoki_pos = 0 aoki_black = 0 aoki_white = 0 total_rolls = 2 * N for i in range(1, total_rolls + 1): idx = (i - 1) % T current_mod6 = cyclic_part[idx] % mod6 d = current_mod6 + 1 if i % 2 == 1: takahashi_pos += d if takahashi_pos % 2 == 1: takahashi_black += 1 else: takahashi_white += 1 else: aoki_pos += d if aoki_pos % 2 == 1: aoki_black += 1 else: aoki_white += 1 score_t = min(takahashi_black, takahashi_white) score_a = min(aoki_black, aoki_white) print(score_t, score_a) if __name__ == "__main__": main()