n = gets raise unless n =~ /^[0-9]+$/ n = n.to_i raise unless 1 <= n && n <= 500000 a = gets raise unless a =~ /^([0-9]+ )+[0-9]+$/ a = a.split.map(&:to_i) raise unless a.size == n a.each do |x| raise unless 1 <= x && x <= 1_000_000_000 end