MOD = 2 ** 32 A, B, x0, N = gets.split.map(&:to_i) @temp = x0 def randin @temp = (A * @temp + B) % MOD return @temp % 6 + 1 end tk = [0,0] aok = [0,0] (N * 2).times do |i| if i.even? if randin.even? tk[0] += 1 else tk[1] += 1 end else if randin.even? aok[0] += 1 else aok[1] += 1 end end end puts "#{tk.min} #{aok.min}"