// No.2707 Bag of Words Encryption import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); Map wordCount = new HashMap<>(); for (int i = 0; i < n; i++) { String word = sc.next(); wordCount.put(word, wordCount.getOrDefault(word, 0) + 1); } List words = new ArrayList<>(wordCount.keySet()); words.sort(Comparator.comparingInt(wordCount::get)); StringBuilder encrypted = new StringBuilder(); for (String word : words) { int count = wordCount.get(word); for (int j = 0; j < count; j++) { encrypted.append(word); encrypted.append(" "); } } System.out.println(encrypted.toString().trim()); } }