import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.*;
public class WordSort {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int N = Integer.parseInt(br.readLine()); // 단어의 개수 N 입력받기
// 단어를 저장할 리스트
List<String> list = new ArrayList<>();
// N개의 단어를 입력받아 리스트에 저장
for (int i = 0; i < N; i++) {
list.add(br.readLine());
}
// 중복 제거 및 사전 순 정렬
Set<String> set = new HashSet<>(list); // 중복 제거
List<String> sortedList = new ArrayList<>(set); // 중복 제거된 단어를 리스트로 변환
Collections.sort(sortedList); // 사전 순 정렬
// 길이순 정렬
Collections.sort(sortedList, new Comparator<String>() {
@Override
public int compare(String o1, String o2) {
if (o1.length() == o2.length()) { // 길이가 같은 경우
return o1.compareTo(o2); // 사전 순 정렬
}
else { // 길이가 다른 경우
return o1.length() - o2.length(); // 길이 오름차순 정렬
}
}
});
for (String word : sortedList) {
System.out.println(word);
}
}
}