This page is still under construction.

Parts of this page are still being built. What you see may change.

Remove the Duplicates

Time limit1sMemory limit128 MB

Summary
For each test case, collapse every run of consecutive equal numbers into a single value and print the result.
Level

Easy2 of 10

Topics
Array, Implementation
Solved
No attempts yet

Problem

Al's Chocolate Mango Company runs a website where visitors can guess how many chocolate mangoes are inside a 2d jar. A visitor picks a number from 11 to 9999 and presses the "Submit" button. Because the server often responds slowly, impatient visitors mash the "Submit" button several times, which causes the same number to be submitted many times in a row.

Help the ACM staff collapse each run of consecutive duplicate submissions into a single value, recovering the original intended sequence.

Input

The input consists of several test cases. Each line begins with an integer NN (0<N≤250 < N \le 25), followed by NN integers, each between 11 and 9999 inclusive. These NN numbers are the submitted values, in the order the visitor pressed them.

The last line contains a single 00, marking the end of the input.

Output

For each test case, print one line containing the submissions after collapsing every run of consecutive equal numbers into one, separated by single spaces. At the end of each line, print a single space followed by a $ character.

Examples1

  1. Example 1

    Input
    5 1 22 22 22 3
    4 98 76 20 76
    6 19 19 35 86 86 86
    1 7
    0
    
    Expected output
    1 22 3 $
    98 76 20 76 $
    19 35 86 $
    7 $