class XORShift def initialize(x) @x = x @y = 1 @z = 2 @w = 3 end def generate t = (@x ^ (@x << 11)) @x, @y, @z = @y, @z, @w @w = (@w ^ (@w >> 19)) ^ (t ^ (t >> 8)) end end seed = gets.to_i a = 1000001 puts (2000000000..2300000000).bsearch { |x| xor = XORShift.new(seed) (1..a).count { xor.generate <= x } >= (a / 2 + 1) }