"""
문제 :알파벳 소문자로 이루어진 N개의 단어가 들어오면 아래와 같은 조건에 따라 정렬하는 프로그램을 작성하시오.
길이가 짧은 것부터
길이가 같으면 사전 순으로
입력 :13
but
i
wont
hesitate
no
more
no
more
it
cannot
wait
im
yours
출력 :
13
but
i
wont
hesitate
no
more
no
more
it
cannot
wait
im
yours
아이디어:
1. for문을 돌면서 최종 결과 리스트에 입력 받은 문자와 문자의 길이를 넣어놓는다.
2. 중복을 제거하기 위하여 그 리스트를 set -> list 형태로 다시 돌려놓는다
3. lambda를 활용하여 길이, 단어순으로 sort 한다.
"""
import sys
words_num = int(input())
words_list = []
for i in range(words_num):
word = str(input())
word_count = len(word)
words_list.append((word, word_count))
words_list = list(set(words_list))
words_list.sort(key= lambda word: (word[1],word[0]))
for word in words_list:
print(word[0])