def lscan; gets.split.map(&:to_i); end n = gets.to_i ww = n.times.map{lscan[1..-1]} ans = [] while !ww.empty? ww = ww.map{|w| ans << w.shift; w.empty? ? nil : w}.compact end puts ans.compact*' '