line1 = gets.chomp! abort "line 1 format error" unless line1=~/^\d+ \d+$/ line2 = gets.chomp! abort "line 2 format error" unless line2=~/^\d+(?: \d+)*$/ line3 = gets.chomp! abort "line 3 format error" unless line3=~/^\d+(?: \d+)*$/ abort "end of line error" unless !gets n,cap = line1.split.map(&:to_i) len = line2.split.map(&:to_i) price = line3.split.map(&:to_i) abort "N == sizeof len" unless n == len.size abort "N == sizeof price" unless n == price.size abort "1 <= n <= 50" unless 1 <= n && n <= 50 abort "1 <= cap <= 50" unless 1 <= cap && cap <= 50 len.each{|l| abort "1 <= l <= 50" unless 1 <= l && l <= 50 } price.each{|w| abort "1 <= w <= 50" unless 1 <= w && w <= 50 } # ======================================================= # format check ここまで # ======================================================= def kadomatu?(a,b,c) (a!=c)&&((ac)||(a>b&&b