#K89212. Arrange Pottery Categories

    ID: 37481 Type: Default 1000ms 256MiB

Arrange Pottery Categories

Arrange Pottery Categories

You are given a list of pottery items, each associated with a category. Your task is to rearrange the list such that items belonging to the same category are grouped together while preserving the order of the first appearance of each category. In other words, the group order is determined by the order in which a category appears for the first time in the input.

For example, if the input list is Historical Artistic Historical Ceremonial Artistic, the grouped output should be Historical Historical Artistic Artistic Ceremonial.

The problem tests your ability to manipulate arrays and maintain stable ordering of groups.

inputFormat

The first line of input contains an integer n denoting the number of pottery items. The second line contains n space-separated strings, where each string represents the category of a pottery item.

Constraints:

  • 1 \(\leq n \leq 10^5\)
  • Each category is a non-empty string of letters.

outputFormat

Output a single line containing the categories arranged such that all items of the same category are grouped together. The categories must be printed in the order determined by their first appearance in the input and should be separated by a space.

## sample
5
Historical Artistic Historical Ceremonial Artistic
Historical Historical Artistic Artistic Ceremonial

</p>