GlobeX Cup '19 J4 - Winni's Lonely Card Game

View as PDF

Points: 5 (partial)
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

Winni is playing a card game with herself since she lost all of her friends when travelling to outer space. Winni lays cards face up on the table. Each card has a non-unique number on it from to . Winni proceeds to pick up cards from the table one at a time. Whenever Winni picks up a card, she receives dollars where is the number of cards with the same number that she has already picked up. Can you help Winni determine the maximum amount of money she can obtain?

Input Specification

The first line of input contains integers, , , .

The next line of input contains integers between to , representing the number of the cards on the table.

Output Specification

Output the maximum amount of money she can obtain.

Sample Input

7 10 5
10 8 9 10 9 9 10

Sample Output

4

Explanation For Sample

1. She can initially pick up 10 gaining dollars.
2. She picks up 9, gaining dollars.
3. She then picks up 10, gaining dollar.
4. She picks up 10 again, gaining dollars.
5. She picks up 9 again, gaining dollar.

In total, she gains dollars, which is the maximum amount of money Winni can obtain.