Score Calculation

Interview

Time limit1sMemory limit128 MB

Summary
Compute a total score from a 0/1 sequence where consecutive correct answers score an increasing running count.
Level

Easy2 of 10

Topics
Array, Simulation, Implementation
Solved
No attempts yet

Problem

An OX problem has only two possible results: correct or incorrect. In a test made of several OX problems, consecutive correct answers receive bonus points as follows. If problem 1 is correct, it is worth 1 point. After one or more incorrect answers, the first correct answer is also worth 1 point. In a consecutive run of correct answers, the second correct answer is worth 2 points, the third is worth 3 points, and so on, so the K-th correct answer in that run is worth K points. An incorrect answer is worth 0 points.

For example, suppose 10 OX problems are marked with 1 for a correct answer and 0 for an incorrect answer. The scores are calculated as shown below, and the total score is 1+1+2+3+1+2=10.

Result1011100110
Score1012300120

Given the grading results of the test, write a program that calculates the total score after applying the bonus rule.

Input

The first line contains the number of problems N (1 <= N <= 100). The second line contains N grading results, each either 0 or 1, separated by spaces. A 0 means the answer was incorrect, and a 1 means the answer was correct.

Output

Print the total score after applying the bonus rule to the grading results from the input.

Examples1

  1. Example 1

    Input
    10
    1 0 1 1 1 0 0 1 1 0
    
    Expected output
    10