A. Remove Duplicates

Codeforces
IDCF978A
Time1000ms
Memory256MB
Difficulty
implementation
English · Original
Chinese · Translation
Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relative order of the remaining unique elements should not be changed. ## Input The first line contains a single integer $n$ ($1 \le n \le 50$) — the number of elements in Petya's array. The following line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 1\,000$) — the Petya's array. ## Output In the first line print integer $x$ — the number of elements which will be left in Petya's array after he removed the duplicates. In the second line print $x$ integers separated with a space — Petya's array after he removed the duplicates. For each unique element only the rightmost entry should be left. [samples] ## Note In the first example you should remove two integers $1$, which are in the positions $1$ and $4$. Also you should remove the integer $5$, which is in the position $2$. In the second example you should remove integer $2$, which is in the position $1$, and two integers $4$, which are in the positions $2$ and $4$. In the third example you should remove four integers $6$, which are in the positions $1$, $2$, $3$ and $4$.
Petya 有一个由 $n$ 个整数组成的数组 $a$。他希望移除重复(相等)的元素。 Petya 希望为数组中的每个元素只保留最右侧的出现(出现位置)。剩余唯一元素的相对顺序不应改变。 第一行包含一个整数 $n$($1 lt.eq n lt.eq 50$)——Petya 数组中元素的个数。 接下来的一行包含一个序列 $a_1, a_2, dots.h, a_n$($1 lt.eq a_i lt.eq 1 thin 000$)——Petya 的数组。 在第一行输出整数 $x$ —— Petya 移除重复元素后数组中剩余的元素个数。 在第二行输出 $x$ 个用空格分隔的整数 —— Petya 移除重复元素后的数组。对于每个唯一元素,只保留其最右侧的出现。 在第一个例子中,你应该移除位置 $1$ 和 $4$ 上的两个整数 $1$。你还应该移除位置 $2$ 上的整数 $5$。 在第二个例子中,你应该移除位置 $1$ 上的整数 $2$,以及位置 $2$ 和 $4$ 上的两个整数 $4$。 在第三个例子中,你应该移除位置 $1$、$2$、$3$ 和 $4$ 上的四个整数 $6$。 ## Input 第一行包含一个整数 $n$($1 lt.eq n lt.eq 50$)——Petya 数组中元素的个数。接下来的一行包含一个序列 $a_1, a_2, dots.h, a_n$($1 lt.eq a_i lt.eq 1 thin 000$)——Petya 的数组。 ## Output 在第一行输出整数 $x$ —— Petya 移除重复元素后数组中剩余的元素个数。在第二行输出 $x$ 个用空格分隔的整数 —— Petya 移除重复元素后的数组。对于每个唯一元素,只保留其最右侧的出现。 [samples] ## Note 在第一个例子中,你应该移除位置 $1$ 和 $4$ 上的两个整数 $1$。你还应该移除位置 $2$ 上的整数 $5$。在第二个例子中,你应该移除位置 $1$ 上的整数 $2$,以及位置 $2$ 和 $4$ 上的两个整数 $4$。在第三个例子中,你应该移除位置 $1$、$2$、$3$ 和 $4$ 上的四个整数 $6$。
Samples
Input #1
6
1 5 5 1 6 1
Output #1
3
5 6 1
Input #2
5
2 4 2 4 4
Output #2
2
2 4
Input #3
5
6 6 6 6 6
Output #3
1
6
API Response (JSON)
{
  "problem": {
    "name": "A. Remove Duplicates",
    "description": {
      "content": "Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements. Petya wants to leave only the rightmost entry (occurrence) for each element of the array. The relativ",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF978A"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "Petya has an array $a$ consisting of $n$ integers. He wants to remove duplicate (equal) elements.\n\nPetya wants to leave only the rightmost entry (occurrence) for each element of the array. The relativ...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "Petya 有一个由 $n$ 个整数组成的数组 $a$。他希望移除重复(相等)的元素。\n\nPetya 希望为数组中的每个元素只保留最右侧的出现(出现位置)。剩余唯一元素的相对顺序不应改变。\n\n第一行包含一个整数 $n$($1 lt.eq n lt.eq 50$)——Petya 数组中元素的个数。\n\n接下来的一行包含一个序列 $a_1, a_2, dots.h, a_n$($1 lt.eq a_i ...",
      "is_translate": true,
      "language": "Chinese"
    }
  ]
}
Full JSON Raw Segments