def lscan; gets.split.map(&:to_i); end n, h = lscan div = (1..(n-1)).filter{|x| n/x*x == n}.to_a div.each do |w| h2 = 0 stk = 0 ok = true div.each do |x| if x/w*w != x stk += x if stk > w ok = false break end if stk == w h2 += 1 stk = 0 end next end h2 += x/w end next unless ok # p h2 if h2 == h stk = [] div.each do |x| if x/w*w != x stk += [x]*x if stk.size == w puts stk*' ' stk = [] end next end (x/w).times {puts [x]*w*' '} end end end p -1