LogiQuest

352. Bowling Score

HardSimulation

Given the pins knocked down by each roll of a complete ten-pin bowling game, print the total score (strikes add the next two rolls, spares add the next roll; the 10th frame may have bonus rolls).

Input format

Line 1: number of rolls Line 2: the rolls

Output format

The score.

Example 1

Input

12
10 10 10 10 10 10 10 10 10 10 10 10

Output

300

Example 2

Input

20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

Output

0

Constraints

A valid complete game.

Read input from standard input and print the answer to standard output. Your code is judged against 4 test cases, most of them hidden.

Loading the MyLoginn IDE…