def max(a,b);a>=b ? a : b;end def min(a,b);a<=b ? a : b;end @height,@width,@n = gets.split.map(&:to_i) field = Array.new(@width,0) @height.times{ x = 0 gets.chomp!.chars{|c| field[x]+=1 if c=='#' x+=1 } } command = Array.new(@n,0) pack = Array.new(@n){Array.new(3,0)} command_bucket = Array.new(@width){[]} @n.times{|i| x = gets.to_i command[i] = x command_bucket[x] << i } cursor = 0 @width.times{|x| cursor = max(x,cursor) command_bucket[x].each{|idx| while (field[cursor] == 0) ; cursor += 1 ; end pack[idx][cursor-x] += 1 field[cursor] -= 1 } } @width.times{|x| command_bucket[x].each{|idx| 3.times{|ofs| fil = max(0,min(3-pack[idx][ofs],field[x+ofs])) pack[idx][ofs] += fil field[x+ofs] -= fil } } } pack.each{|v| 3.downto(1){|y| 0.upto(2){|x| print (y <= v[x]) ? '#' : '.' } puts "" } }