题目描述
Problem Background
Recently, Y School has undergone comprehensive reforms to its cafeteria and a complete overhaul of its convenience store (mismanagement), resulting in the ban of snacks sold at the convenience store and the disappearance of the fried chicken window in the cafeteria.
Moreover, Director Q of the Student Affairs Office strictly prohibits students from ordering takeout and monitors them day and night.
As the saying goes, food is the paramount necessity of the people. Due to constant hunger, all students are in dire straits.
Problem Description
Xiao Z, a friend of zhouwc (who is also himself), is so hungry that he risks ordering takeout.
However, Director Q has set up a surveillance network to catch students ordering takeout.
Due to limited funding from the school, these surveillance cameras cannot work continuously; they operate for one second and then pause for one second, repeating this cycle.
Also, due to limited funding, these cameras are arranged in a straight line, which is on the必经之路 for students to reach the takeout pickup point—Gate 2 (without a guard).
Since Xiao Z has mastered the skill of sprinting, the time it takes for him to pass through any number of inactive cameras is $1$ (i.e., one action can pass through several inactive cameras).
As Xiao Z wants to eat takeout without getting caught by Director Q who is watching the surveillance, please tell him the minimum time required to safely reach the takeout pickup point.
Input and Output Formats
Input Format
There are 2 lines in total.
The first line contains a positive integer $n$, indicating that there are $n$ surveillance cameras on this road.
The second line contains $n$ numbers, representing the on/off status of the cameras at the 0th second, where $0$ means the camera is off, and $1$ means the camera is on, ensuring that the first camera is always off.
Output Format
There is one line in total, indicating the time Xiao Z needs to safely reach the takeout pickup point.
Sample Input and Output
Sample Input #1
6
0 0 1 1 0 1
Sample Output #1
4
Sample Input #2
6
0 0 0 0 0 0
Sample Output #2
1
Notes
Data Range:
For $10\%$ of the data, $1 \leq n \leq 10$
For $30\%$ of the data, $1 \leq n \leq 100$
For $50\%$ of the data, $1 \leq n \leq 10^3$
For $70\%$ of the data, $1 \leq n \leq 10^5$
For $100\%$ of the data, $1 \leq n \leq 10^6$
The status of the cameras is represented by $0$ and $1$.
Sample Explanation #1:
Xiao Z sprints to the second camera at the first second, taking $1$ second, for a total of $1$ second.
At the second second, the status of the cameras changes to $1 1 0 0 1 0$.
At this time, Xiao Z quickly sprints from the second camera to the fourth camera, taking $1$ second, for a total of $2$ seconds.
At the third second, the status of the cameras changes to $0 0 1 1 0 1$.
At this time, Xiao Z quickly sprints from the fourth camera to the fifth camera, taking $1$ second, for a total of $3$ seconds.
At the fourth second, the status of the cameras changes to $1 1 0 0 1 0$.
At this time, Xiao Z quickly sprints out of the surveillance area from the fifth camera, taking $1$ second, for a total of $4$ seconds.
Sample Explanation #2:
Xiao Z sprints out of the surveillance area directly at the first second.
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分