Codeforces Round 325 (Div. 2)
A
Alena's Schedule
Codeforces
900
原题
←B →
翻译中…

Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.

翻译中…

One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).

翻译中…

The University works in such a way that every day it holds exactly $*n*$ lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).

翻译中…

The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the $*n*$ pairs she knows if there will be a class at that time or not.

翻译中…

Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.

翻译中…

Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.

翻译中…

Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.

翻译中…

Input

翻译中…

The first line of the input contains a positive integer $*n*$ ($1 ≤ *n* ≤ 100$) — the number of lessons at the university.

翻译中…

The second line contains $*n*$ numbers $*a*_{*i*}$ ($0 ≤ *a*_{*i*} ≤ 1$). Number $*a*_{*i*}$ equals $0$, if Alena doesn't have the $*i*$-th pairs, otherwise it is equal to $1$. Numbers $*a*_{1}, *a*_{2}, ..., *a*_{*n*}$ are separated by spaces.

翻译中…

Output

翻译中…

Print a single number — the number of pairs during which Alena stays at the university.

翻译中…

Note

翻译中…

In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair.

翻译中…

In the last sample Alena doesn't have a single pair, so she spends all the time at home.

翻译中…

样例

Input #1
5
0 1 0 1 1
Output #1
4
InputCopy OutputCopy
Input #2
7
1 0 1 0 0 1 0
Output #2
4
InputCopy OutputCopy
Input #3
1
0
Output #3
0
InputCopy OutputCopy
题目信息
题号
586A
时间限制
1 s
内存限制
256 MB
标签
模拟

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。