Hide

Problem B
No Thanks!

In the card game “No Thanks,” the deck of cards consists of $36$ cards numbered $1$$36$, and players collect cards to their score pile as the game is played. A player’s final score is the sum of the numbers on their collected cards, with one exception: if a player has collected any cards with two or more consecutive numbers, only the smallest number of that group counts toward the score. Your job is to compute the score for a single player’s pile of cards, though here we allow play with a deck much larger than $36$ cards.

Input

The first line contains one integer, $n$, representing the number of cards collected. The second line contains $n$ integers representing the numbers on the collected cards. You may assume that $1 \leq n \leq 90\ 000$, all card values are in the range $1\ldots 90\ 000$ inclusive, and no card value is repeated.

Output

Output a single line containing the score for the given set of cards.

Sample Input 1 Sample Output 1
5
1 7 5 3 4
11
Sample Input 2 Sample Output 2
6
2 1 3 8 4 5
9

Please log in to submit a solution to this problem

Log in