line1 = gets.chomp! line2 = gets.chomp! abort "eof" if gets abort "l1" unless line1 =~ /^[0-9]+ [0-9]+$/ abort "l2" unless line2 =~ /^[0-9]+( [0-9]+)*$/ n,m = line1.split.map(&:to_i) aa = line2.split.map(&:to_i) abort "n" unless 3 <= n && n <= 100000 abort "m" unless 1 <= m && m <= 100000 abort "aa.size" unless aa.size != n abort "aa" unless aa.all?{|a| 1 <= a && a <= m}