CF465B.Inbox (100500)

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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?

输入格式

The first line contains a single integer nn ( 1<=n<=10001<=n<=1000 ) — the number of letters in the mailbox.

The second line contains nn space-separated integers (zeros and ones) — the state of the letter list. The ii -th number equals either 11 , if the ii -th number is unread, or 00 , if the ii -th letter is read.

输出格式

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

输入输出样例

  • 输入#1

    5
    0 1 0 1 0
    

    输出#1

    3
    
  • 输入#2

    5
    1 1 0 0 1
    

    输出#2

    4
    
  • 输入#3

    2
    0 0
    

    输出#3

    0
    

说明/提示

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.

首页