def ascan; gets.split.map(&:to_i); end def scan; gets.to_i; end a,b = ascan z = [] 0.upto(a){|x| z << x 1.upto(b){|y| z << (x + y*5) } } z.sort! z.uniq! z.shift puts z