B. 抽鬼牌 / Old Maid

    传统题 1000ms 256MiB

抽鬼牌 / Old Maid

该比赛已结束,您无法在比赛模式下递交该题目。您可以点击“在题库中打开”以普通模式查看和递交本题。

Problem Statement

Takahashi currently has NN cards. The ii-th (1≤i≤N)(1\le i\le N) card has the integer AiA_i written on it.

He repeats the following operation as many times as possible.

  • Choose two different cards with the same integer written on them, and eat those two cards. The eaten cards are permanently removed and cannot be chosen in subsequent operations.

Find the sum of the integers written on the cards that remain when the operation can no longer be performed.

Constraints

  • 1≤N≤1001\le N\le100
  • 1≤Ai≤100 (1≤i≤N)1\le A_i\le100\ (1\le i\le N)
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

  • NN
  • A1A_1 A2A_2 …\dots ANA_N

Output

Output the sum of the integers written on the remaining cards.

8
2 7 1 8 2 8 1 8
15

For example, Takahashi operates as follows.

  1. The fourth card and sixth card both have 88 written on them, so he chooses them and eats them.
  2. The first card and fifth card both have 22 written on them, so he chooses them and eats them.
  3. The third card and seventh card both have 11 written on them, so he chooses them and eats them.

(Original image: https://img.atcoder.jp/abc473/839dc9d3f8c77f88619fee1b74e6428d.png)

Thus, the sum of the integers written on the remaining cards is 7+8=157+8=15.

Note that there are three cards with 88 written on them, so once two of them are eaten, the remaining one cannot be eaten.

5
1 2 3 4 5
15

It is possible that Takahashi cannot perform the operation even once.

15
58 97 74 16 97 74 97 16 51 52 58 52 74 32 43
297

ABC473 赛后模拟赛 ✅

未参加
状态
已结束
规则
IOI
题目
7
开始于
2026-8-29 21:40
结束于
2026-9-12 21:40
持续时间
336 小时
主持人
参赛人数
45