Question
Festival Lamp Subarrays

During a night festival, there are n lamps placed in a straight line.

Each lamp is either off or on. An off lamp is represented by 0, and an on lamp is represented by 1.

A continuous segment of lamps is called bright if it contains at least one on lamp.

Your task is to count the number of bright continuous segments.

Input

The first line contains a single integer KaTeX can only parse string typed expression — the number of lamps.

The second line contains KaTeX can only parse string typed expression integers KaTeX can only parse string typed expression, where each value is either KaTeX can only parse string typed expression or KaTeX can only parse string typed expression.

Output

Print a single integer — the number of continuous segments that contain at least one on lamp.

Example
Input
5

0 1 0 0 1
Output
11
Explanation

There are KaTeX can only parse string typed expression total subarrays. The subarrays that contain only off lamps are KaTeX can only parse string typed expression, KaTeX can only parse string typed expression, KaTeX can only parse string typed expression, and KaTeX can only parse string typed expression. So the number of bright segments is KaTeX can only parse string typed expression.

Online