A, B, X0, N = gets.split.map(&:to_i) M = 2 ** 32 def rnd(x) (A * x + B) % M end x = X0 stones = Array.new(2) { Array.new(2, 0) } (2 * N).times do |i| x = rnd(x) v = (x % 6) + 1 t = i % 2 stones[i % 2][v % 2] += 1 end s1 = [stones[0][0], stones[0][1]].min s2 = [stones[1][0], stones[1][1]].min puts [s1, s2].join(' ')