#ABC473B. 抽鬼牌 / Old Maid
抽鬼牌 / Old Maid
Problem Statement
Takahashi currently has cards. The -th card has the integer 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
- All input values are integers.
Input
The input is given from Standard Input in the following format:
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.
- The fourth card and sixth card both have written on them, so he chooses them and eats them.
- The first card and fifth card both have written on them, so he chooses them and eats them.
- The third card and seventh card both have 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 .
Note that there are three cards with 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
- Source: AtCoder ABC 473 B
相关
在下列比赛中: