public class boj_1181 {
public static void main(String[] args) throws IOException {
BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));
int count = Integer.parseInt(r.readLine());
Set<String> words = new HashSet<>();
for(int i=0;i<count;i++){
words.add(r.readLine());
}
List<String> collect = words.stream()
.sorted(Comparator.comparingInt(String::length).thenComparing(Comparator.naturalOrder()))
.collect(Collectors.toList());
for(String index : collect){
w.write(index);
w.newLine();
}
w.flush();
}
}