#C9039. Taco Card Scoring
Taco Card Scoring
Taco Card Scoring
You are given a sequence of card values. In this problem, your task is to compute the total score of the sequence by summing the values of the cards, while considering consecutive duplicate cards as a single instance. That is, if the same card value appears consecutively, only its first occurrence is counted towards the total score.
Formally, let \(n\) be the number of cards and let \(a_1, a_2, \dots, a_n\) be the card values. You need to calculate the sum:
[ S = \sum_{i=1}^{n} b_i \quad \text{ where } \quad b_1 = a_1 \text{ and } b_i = a_i ;\text{if}; a_i \neq a_{i-1}, ; ; \text{for } i \ge 2. ]
If the list is empty, the score is 0.
inputFormat
The input is given via standard input and consists of two lines:
- The first line contains an integer \(n\) (\(0 \le n \le 10^5\)), representing the number of cards.
- The second line contains \(n\) space-separated integers representing the card values. Each card value is an integer.
If \(n = 0\), the second line may be omitted.
outputFormat
Output via standard output a single integer, which is the total score computed by summing the card values after ignoring consecutive duplicates.
## sample8
5 5 9 1 1 1 6 7
28
</p>