A - 重複除去ログ 解説 /

実行時間制限: 2 sec / メモリ制限: 1024 MiB

配点 : 233

問題文

高橋君はサーバーの監視システムを管理しています。サーバーからは N 件のイベントログが時系列順に送られてきます。i 番目に送られてくるログのイベントコードは A_i です。

高橋君は、これらのログを A_1, A_2, \ldots, A_N の順に確認し、記録リストに追加していきます。ただし、記録リストが空でないとき、記録リストの末尾の要素と同じイベントコードのログが来た場合は重複とみなし、記録リストには追加せず読み飛ばします。記録リストが空の場合、または記録リストの末尾の要素と異なるイベントコードの場合は、そのイベントコードを記録リストの末尾に追加します。

N 件のイベントコードが時系列順に与えられるので、全てのログを確認し終えた後の記録リストの内容を出力してください。

制約

  • 1 \leq N \leq 5 \times 10^5
  • 1 \leq A_i \leq 10^91 \leq i \leq N
  • 入力はすべて整数である。

入力

N
A_1 A_2 \ldots A_N
  • 1 行目には、イベントログの件数 N が与えられる。
  • 2 行目には、イベントコード A_1, A_2, \ldots, A_N が空白区切りで与えられる。

出力

全てのログを確認し終えた後の記録リストの各要素を、先頭から順に空白区切りで出力せよ。


入力例 1

7
1 1 2 2 2 3 2

出力例 1

1
2
3
2

入力例 2

6
1 2 1 2 1 2

出力例 2

1
2
1
2
1
2

入力例 3

15
8 8 8 1 1 2 3 3 2 2 2 5 5 5 1

出力例 3

8
1
2
3
2
5
1

入力例 4

30
10 10 9 9 8 7 7 7 8 8 8 1000000000 1000000000 1 2 2 3 3 3 2 2 4 4 4 4 5 1 1 6 6

出力例 4

10
9
8
7
8
1000000000
1
2
3
2
4
5
1
6

入力例 5

1
1000000000

出力例 5

1000000000

Score : 233 pts

Problem Statement

Takahashi manages a server monitoring system. The server sends N event logs in chronological order. The event code of the i-th log sent is A_i.

Takahashi checks these logs in the order A_1, A_2, \ldots, A_N and appends them to a record list. However, if the record list is not empty and a log has the same event code as the last element of the record list, it is considered a duplicate and skipped without being added to the list. If the record list is empty, or if the log's event code is different from the last element of the record list, he appends that event code to the end of the record list.

Given the N event codes in chronological order, print the contents of the record list after all logs have been checked.

Constraints

  • 1 \leq N \leq 5 \times 10^5
  • 1 \leq A_i \leq 10^9 (1 \leq i \leq N)
  • All input values are integers.

Input

N
A_1 A_2 \ldots A_N
  • The first line contains the number of event logs, N.
  • The second line contains the event codes A_1, A_2, \ldots, A_N separated by spaces.

Output

Print the elements of the record list after all logs have been checked, in order from first to last, separated by spaces.


Sample Input 1

7
1 1 2 2 2 3 2

Sample Output 1

1
2
3
2

Sample Input 2

6
1 2 1 2 1 2

Sample Output 2

1
2
1
2
1
2

Sample Input 3

15
8 8 8 1 1 2 3 3 2 2 2 5 5 5 1

Sample Output 3

8
1
2
3
2
5
1

Sample Input 4

30
10 10 9 9 8 7 7 7 8 8 8 1000000000 1000000000 1 2 2 3 3 3 2 2 4 4 4 4 5 1 1 6 6

Sample Output 4

10
9
8
7
8
1000000000
1
2
3
2
4
5
1
6

Sample Input 5

1
1000000000

Sample Output 5

1000000000