#K56472. Organize Books

    ID: 30206 Type: Default 1000ms 256MiB

Organize Books

Organize Books

You are given \(n\) book titles. Your task is to remove duplicate titles and then output the unique book titles sorted in lexicographical (dictionary) order.

In other words, given a list of \(n\) titles \(T = [t_1, t_2, \dots, t_n]\), find the unique set \(U\) of titles and output them in sorted order. Recall that a string \(s_1\) is said to be lexicographically smaller than string \(s_2\) if \(s_1\) comes before \(s_2\) in dictionary order. Formally, if \(s_1 = t_1t_2\dots t_k\) and \(s_2 = u_1u_2\dots u_m\), then \(s_1 < s_2\) if there exists an index \(i\) such that \(t_j = u_j\) for all \(1 \le j < i\) and \(t_i < u_i\), or if \(s_1\) is a prefix of \(s_2\) and \(k < m\).

For example, if the titles are ["thegreatgatsby", "mobydick", "thegreatgatsby", "animalfarm", "mobydick"], then the unique titles sorted lexicographically are:

animalfarm
mobydick
thegreatgatsby

inputFormat

The input is read from standard input (stdin) and has the following format:

  • The first line contains an integer \(n\) representing the number of books.
  • The next \(n\) lines each contain a single book title (a string without spaces).

outputFormat

Output the sorted unique book titles to standard output (stdout), with each title printed on a separate line.

## sample
5
thegreatgatsby
mobydick
thegreatgatsby
animalfarm
mobydick
animalfarm

mobydick thegreatgatsby

</p>