Codeforces Round 265 (Div. 2)
B
Inbox (100500)
Codeforces
1000
原题
← AC →
翻译中…

Over time, Alexey's mail box got littered with too many letters. Some of them are read, while others are unread.

翻译中…

Alexey's mail program can either show a list of all letters or show the content of a single letter. As soon as the program shows the content of an unread letter, it becomes read letter (if the program shows the content of a read letter nothing happens). In one click he can do any of the following operations:

翻译中…
  • Move from the list of letters to the content of any single letter.
  • Return to the list of letters from single letter viewing mode.
  • In single letter viewing mode, move to the next or to the previous letter in the list. You cannot move from the first letter to the previous one or from the last letter to the next one.
翻译中…

The program cannot delete the letters from the list or rearrange them.

翻译中…

Alexey wants to read all the unread letters and go watch football. Now he is viewing the list of all letters and for each letter he can see if it is read or unread. What minimum number of operations does Alexey need to perform to read all unread letters?

翻译中…

Input

翻译中…

The first line contains a single integer $*n*$ ($1 ≤ *n* ≤ 1000$) — the number of letters in the mailbox.

翻译中…

The second line contains $*n*$ space-separated integers (zeros and ones) — the state of the letter list. The $*i*$-th number equals either $1$, if the $*i*$-th number is unread, or $0$, if the $*i*$-th letter is read.

翻译中…

Output

翻译中…

Print a single number — the minimum number of operations needed to make all the letters read.

翻译中…

Note

翻译中…

In the first sample Alexey needs three operations to cope with the task: open the second letter, move to the third one, move to the fourth one.

翻译中…

In the second sample the action plan: open the first letter, move to the second letter, return to the list, open the fifth letter.

翻译中…

In the third sample all letters are already read.

翻译中…

样例

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

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