

Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 200 点
問題文
N + 1 個の部屋が一列に並んでおり、順に 0, 1, \ldots, N の番号が付けられています。
部屋の間には N 個のドアがあり、1, 2, \ldots, N の番号が付けられています。ドア i は部屋 i - 1 と部屋 i の間にあります。
各ドアについて鍵の状態を表す値 L_i が与えられ、L_i = 0 のときドア i の鍵は開いており、L_i = 1 のときドア i の鍵は閉まっています。
2 人の人がおり、1 人は部屋 0 に、もう 1 人は部屋 N にいます。それぞれの人は、ドア i の鍵が開いているときに限り、部屋 i - 1 と部屋 i の間を移動することができます。
このとき、2 人のいずれも到達できない部屋の個数を求めてください。
制約
- 2 \leq N \leq 100
- L_i \in \lbrace 0, 1 \rbrace
- 入力される値はすべて整数
入力
入力は以下の形式で標準入力から与えられる。
N L_1 L_2 \ldots L_N
出力
答えを出力せよ。
入力例 1
5 0 1 0 0 1
出力例 1
3
2 人のいずれも到達できない部屋は部屋 2, 3, 4 の 3 つです。
入力例 2
3 1 0 1
出力例 2
2
入力例 3
8 0 0 1 1 0 1 0 0
出力例 3
3
Score : 200 points
Problem Statement
There are N + 1 rooms arranged in a line, numbered 0, 1, \ldots, N in order.
Between the rooms, there are N doors numbered 1, 2, \ldots, N. Door i is between rooms i - 1 and i.
For each door, a value L_i representing the lock state is given. When L_i = 0, door i is unlocked, and when L_i = 1, door i is locked.
There are two people, one in room 0 and the other in room N. Each person can move between rooms i - 1 and i only when door i is unlocked.
Find the number of rooms that neither of the two people can reach.
Constraints
- 2 \leq N \leq 100
- L_i \in \lbrace 0, 1 \rbrace
- All input values are integers.
Input
The input is given from Standard Input in the following format:
N L_1 L_2 \ldots L_N
Output
Output the answer.
Sample Input 1
5 0 1 0 0 1
Sample Output 1
3
The rooms that neither of the two people can reach are rooms 2, 3, 4, which is 3 rooms.
Sample Input 2
3 1 0 1
Sample Output 2
2
Sample Input 3
8 0 0 1 1 0 1 0 0
Sample Output 3
3