#C3335. Rearrange List: Limit Occurrence of Each Integer to At Most Two

    ID: 46751 Type: Default 1000ms 256MiB

Rearrange List: Limit Occurrence of Each Integer to At Most Two

Rearrange List: Limit Occurrence of Each Integer to At Most Two

You are given a list of integers. Your task is to rearrange the list so that every distinct integer appears at most twice, while preserving the order of their first appearances. In other words, when traversing the list from left to right, include each integer only if it has appeared less than two times earlier in the output.

The input will consist of an integer n (possibly zero) followed by n integers. You need to output the modified list in which every integer appears no more than twice. This problem tests your ability to process sequences, maintain counts, and output results in the required format.

The solution must read from standard input and write to standard output.

inputFormat

The first line contains a single integer n, representing the number of elements in the list.

The second line contains n space-separated integers.

outputFormat

Output the rearranged list as space-separated integers in a single line. If the list is empty, output nothing.

## sample
8
1 1 1 2 2 3 4 4
1 1 2 2 3 4 4