n = gets.to_i ss = n.times.map { gets.chomp } l = ss.inject(0){|s,v| s + v.size} puts l.times.inject("") {|r,i| ss.sort! c = ss[0][0] ss[0] = ss[0].slice(1,1000) + "~" r + c }