using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; int itemCount = int.Parse(Reader.ReadLine()); List inputList = new List(); for(int i=0; ia.Length) > 0) { int idx = this.SelectFirstByDic(inputList); sb.Append(inputList[idx][0]); if(inputList[idx].Length == 1) { inputList.RemoveAt(idx); } else { inputList[idx] = inputList[idx].Substring(1); } if(inputList.Count == 0) { break; } } Console.WriteLine(sb.ToString()); } private int SelectFirstByDic(List target) { Dictionary dic = new Dictionary(); target.ForEach(a=>dic.Add(dic.Count, a)); List> list = new List>(dic.ToList()); list.Sort((a,b)=>{ if(a.Value.Equals(b.Value)) { return 0; } if(a.Value.Length == 0) { return 1; } if(b.Value.Length == 0) { return -1; } int len = Math.Min(a.Value.Length ,b.Value.Length); for(int i=0; i b.Value[i]) { return 1; } } KeyValuePair sht = (a.Value.Length < b.Value.Length)?a:b; KeyValuePair lng = (a.Key == sht.Key)?b:a; foreach (KeyValuePair item in dic) { if(item.Key != sht.Key && item.Key != lng.Key) { if((sht.Value + item.Value).CompareTo(lng.Value) < 0) { if(sht.Key == a.Key) { return - 1; } else { return 1; } } } } return (lng.Key == a.Key)?-1:1; }); return list[0].Key; } public class Reader { public static bool IsDebug = true; private static String PlainInput = @" "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } public static int[] GetInt(char delimiter = ' ', bool trim = false) { string inptStr = ReadLine(); if (trim) { inptStr = inptStr.Trim(); } string[] inpt = inptStr.Split(delimiter); int[] ret = new int[inpt.Length]; for (int i = 0; i < inpt.Length; i++) { ret[i] = int.Parse(inpt[i]); } return ret; } } static void Main() { Program prg = new Program(); prg.Proc(); } }