#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int cmp(const string& a, const string& b)
{
if (a.length() == b.length()) //길이가 같다면
return a < b; //사전순으로 올림차순
else
return a.length() < b.length(); //길이순으로 올림차순
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
string* word = new string[n];
for (int i = 0; i < n; i++)
cin >> word[i];
sort(word, word + n, cmp);
for (int i = 0; i < n; i++)
{
cout << word[i] << '\n';
while (word[i] == word[i + 1]) i++; //현재 문장과 다음 문자이 같다면 다음 문장으로 접근(중복 방지)
}
delete[] word;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8c3RyaW5nPgojaW5jbHVkZSA8YWxnb3JpdGhtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCmludCBjbXAoY29uc3Qgc3RyaW5nJiBhLCBjb25zdCBzdHJpbmcmIGIpCnsKCWlmIChhLmxlbmd0aCgpID09IGIubGVuZ3RoKCkpCQkJLy/quLjsnbTqsIAg6rCZ64uk66m0CgkJcmV0dXJuIGEgPCBiOwkJCQkJCS8v7IKs7KCE7Iic7Jy866GcIOyYrOumvOywqOyInAoJZWxzZQoJCXJldHVybiBhLmxlbmd0aCgpIDwgYi5sZW5ndGgoKTsJCS8v6ri47J207Iic7Jy866GcIOyYrOumvOywqOyInAp9CgppbnQgbWFpbih2b2lkKQp7Cglpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CgljaW4udGllKE5VTEwpOwoKCWludCBuOwoJY2luID4+IG47CgoJc3RyaW5nKiB3b3JkID0gbmV3IHN0cmluZ1tuXTsKCglmb3IgKGludCBpID0gMDsgaSA8IG47IGkrKykKCQljaW4gPj4gd29yZFtpXTsKCglzb3J0KHdvcmQsIHdvcmQgKyBuLCBjbXApOwoKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKQoJewoJCWNvdXQgPDwgd29yZFtpXSA8PCAnXG4nOwoJCXdoaWxlICh3b3JkW2ldID09IHdvcmRbaSArIDFdKSBpKys7CQkvL+2YhOyerCDrrLjsnqXqs7wg64uk7J2MIOusuOyekOydtCDqsJnri6TrqbQg64uk7J2MIOusuOyepeycvOuhnCDsoJHqt7wo7KSR67O1IOuwqeyngCkKCX0KCglkZWxldGVbXSB3b3JkOwoJcmV0dXJuIDA7Cn0=