There is a new mobile game that starts with consecutively numbered clouds.  Some of the clouds are thunderheads and others are cumulus.  The player can jump on any cumulus cloud having a number that is equal to the number of the current cloud plus $\mbox{1}$ or $2$.  The player must avoid the thunderheads.  Determine the minimum number of jumps it will take to jump from the starting postion to the last cloud.  It is always possible to win the game.  

For each game, you will get an array of clouds numbered $\mbox{0}$ if they are safe or $\mbox{1}$ if they must be avoided.  

Example 

$c=[0,1,0,0,0,1,0]$  

Index the array from $\boldsymbol{0\ldots6}$.  The number on each cloud is its index in the list so the player must avoid the clouds at indices $\mbox{I}$ and $5$.  They could follow these two paths: $0\rightarrow2\rightarrow4\rightarrow6$ or $0\to2\to3\to4\to6$.  The first path takes $3$ jumps while the second takes $\begin{array}{c}4\end{array}$.  Return $3$.

Function Description  

Complete the jumpingOnClouds function in the editor below.  

jumpingOnClouds has the following parameter(s):  

int c[n]: an array of binary integers  

Returns  

int: the minimum number of jumps required

Input Format

The first line contains an integer $n$, the total number of clouds. 
The second line contains $n$ space-separated binary integers describing clouds $c[i]$ where $0\leq i<n$.

Constraints

$2\leq n\leq100$
$c[i]\in\{0,1\}$
$c[0]=c[n-1]=0$

Output Format

Print the minimum number of jumps needed to win the game.

Sample Input 0

7
0 0 1 0 0 1 0

Sample Output 0

4

Explanation 0: 

The player must avoid $c[2]$ and $c\left[5\right]$. The game can be won with a minimum of $\begin{array}{c}4\end{array}$ jumps:

Sample Input 1

6
0 0 0 0 1 0

Sample Output 1

3

Explanation 1: 

The only thundercloud to avoid is $c\left[4\right]$. The game can be won in $3$ jumps:

Source: hackerrank | Difficulty: EASY
Tags: Implementation


Solutions:
import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
res = 0
i = 0
while i < n - 1:
	if i + 2 < n and c[i + 2] == 0:
		i = i + 2
		res += 1
	else:
		i = i + 1
		res += 1
print(res)


n = int(input())
c = list(map(int, input().split()))
d = [n] * n
d[0] = 0
if c[1] == 0:
	d[1] = 1
for i in range(2, n):
	if c[i] == 0:
		d[i] = min(d[i - 1], d[i - 2]) + 1
print(d[n - 1])


n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
steps = 0
current = 0
while current < n - 1:
	if current + 2 < n and c[current + 2] == 0:
		steps += 1
		current += 2
	else:
		steps += 1
		current += 1
print(steps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
dp = []
dp.append(0)
dp.append(n + 1 if c[1] else 1)
for i in range(2, n):
	dp.append(n + 1 if c[i] else min(dp[-1] + 1, dp[-2] + 1))
print(dp[-1])


n = int(input())
clouds = [int(c) for c in input().split(' ')]
i = 0
counter = 0
while i < n:
	counter += 1
	if i + 1 == n - 1 or i + 2 == n - 1:
		break
	elif clouds[i + 2] == 0:
		i += 2
	else:
		i += 1
print(counter)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
i = count = 0
while i < n - 1:
	if i + 2 < n and c[i + 2] == 0:
		i += 2
		count += 1
	elif i + 1 < n and c[i + 1] == 0:
		i += 1
		count += 1
print(count)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
x = [0, 1000 if c[1] else 1]
for i in range(2, n):
	if c[i]:
		x.append(1000)
	else:
		x.append(min(x[i - 1], x[i - 2]) + 1)
print(x[n - 1])


import sys
n = int(input().strip())
clouds = [int(c_temp) for c_temp in input().strip().split(' ')]
currcloud = 0
jumps = 0
while currcloud < n - 1:
	if currcloud + 2 < n and clouds[currcloud + 2] == 0:
		currcloud += 2
		jumps += 1
	else:
		currcloud += 1
		jumps += 1
print(jumps)


n = int(input())
a = list(map(int, input().split()))
ans = 0
i = 0
while i < n - 1:
	i = min(i + 2, n - 1)
	if a[i] == 1:
		i -= 1
	ans += 1
print(ans)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
done = False
i = 0
count = 0
while not done:
	if i + 2 < n and c[i + 2] == 0:
		i += 2
	else:
		i += 1
	count += 1
	if i >= n - 1:
		done = True
print(count)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
d = [0 for i in range(n)]
d[0] = 0
for i in range(1, n):
	if c[i - 1] == 1:
		d[i] = d[i - 2] + 1
	if c[i - 2] != 1:
		d[i] = d[i - 2] + 1
	else:
		d[i] = d[i - 1] + 1
print(d[-1])


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
i = 0
s = 0
while i < n - 1:
	if i + 2 < n and c[i + 2] == 0:
		i += 2
	else:
		i += 1
	s += 1
print(s)


n = int(input())
a = list(map(int, input().split()))
i = 0
c = 0
while i != n - 1:
	if i + 2 <= n - 1:
		if a[i + 2] != 1:
			i = i + 2
		else:
			i = i + 1
	else:
		i = i + 1
	c = c + 1
print(c)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
ct = []
x = 0
for i in c:
	if i:
		ct.append(x - 1)
		ct.append(2)
		x = 0
	else:
		x += 1
ct.append(x - 1)
print(sum((x // 2 + x % 2 for x in ct)))


nn = int(input())
case = [int(x) for x in input().split()]

def add2(nn):
	return nn + 2
cont = 0
temp = 0
while cont < nn - 1:
	if cont == nn - 2:
		temp += 1
		cont = cont + 2
	else:
		if case[add2(cont)] == 0:
			cont = cont + 2
		else:
			cont += 1
		temp += 1
print(temp)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
curr = 0
pathLength = 0
while curr != n - 1:
	if curr < n - 2 and c[curr + 2] == 0:
		curr += 2
	else:
		curr += 1
	pathLength += 1
print(pathLength)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jumps = 0
i = 0
while i < n - 1:
	if i + 2 < n:
		if c[i + 2] == 0:
			i += 1
	i += 1
	jumps += 1
print(jumps)


n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
cnt = 0
index = 0
while True:
	if index + 2 < n:
		if c[index + 2] == 0:
			index += 2
			cnt += 1
		else:
			index += 1
			cnt += 1
	elif index + 1 < n:
		if c[index + 1] == 1:
			if index + 2 < n:
				index += 2
				cnt += 1
	if index >= n - 1:
		break
	if index == n - 2:
		cnt += 1
		break
print(cnt)


n = int(input())
l = list(map(int, input().split()))
(jump, i) = (-1, 0)
while i <= n - 1:
	if i + 2 < n and l[i + 2] == 0:
		i += 2
		jump += 1
	else:
		i += 1
		jump += 1
print(jump)


def n_jumps(l):
	n = len(l)
	i = 0
	count = 0
	while i < n - 1:
		if i == n - 2 or l[i + 2] == '1':
			i += 1
		else:
			i += 2
		count += 1
	return count

def test():
	l = [0, 0, 1, 0, 0, 0, 0]
	assert n_jumps(l) == 4
	l = [0, 0, 0, 0, 1, 0]
	assert n_jumps(l) == 3

def hackerrank():
	_ = input()
	clouds = input().split()
	print(n_jumps(clouds))
hackerrank()


n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
i = 0
jump = -1
while i < n:
	if i + 2 < n and c[i + 2] == 0:
		i += 2
	else:
		i += 1
	jump += 1
print(jump)


import sys
n = int(input().strip())
clouds = [int(c_temp) for c_temp in input().strip().split(' ')]
jumps = 0
cloud = 0
while cloud < len(clouds) - 1:
	if cloud + 2 < len(clouds):
		if clouds[cloud + 2] == 0:
			cloud += 2
		else:
			cloud += 1
	else:
		cloud = len(clouds)
	jumps += 1
print(jumps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jumps = 0
i = 0
while i < n - 2:
	if c[i + 2] == 0:
		i += 2
		jumps += 1
	elif c[i + 1] == 0:
		i += 1
		jumps += 1
if i + 2 == len(c):
	jumps += 1
print(jumps)


n = int(input())
a = [int(_) for _ in input().split()]
dp = [101 for i in range(n + 1)]
dp[n - 1] = 0
for i in reversed(range(n - 1)):
	dp[i] = 101 if a[i] else min(dp[i], 1 + dp[i + 1], 1 + dp[i + 2])
print(dp[0])


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
x = 0
i = 0
while i + 3 < n:
	if c[i + 2] == 0:
		i += 2
	else:
		i += 1
	x += 1
print(x + 1)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
j = 0
i = 0
while i != len(c) - 1:
	try:
		if c[i + 2] != 1:
			i += 2
			j += 1
		else:
			i += 1
			j += 1
	except:
		i += 1
		j += 1
print(j)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
ans = [n] * n
ans[0] = 0
ans[1] = 1
for i in range(2, n):
	if c[i] == 0:
		ans[i] = min(ans[i - 1], ans[i - 2]) + 1
print(ans[n - 1])


def jump(n, clouds):
	steps = 0
	i = 0
	while i < n - 1:
		try:
			two_ahead = clouds[i + 2]
		except IndexError:
			steps += 1
			break
		if two_ahead:
			i += 1
		else:
			i += 2
		steps += 1
	return steps
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
print(jump(n, c))


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
c.append(1)
jumper = 0
count = 0
while jumper < n - 1:
	if c[jumper + 2] == 0:
		jumper += 2
	else:
		jumper += 1
	count += 1
print(count)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
count = 0
i = 0
while i < n - 1:
	count += 1
	if i + 2 < n and c[i + 2] == 1:
		i += 1
	else:
		i += 2
print(count)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
i = 0
steps = 0
while i < n - 1:
	if i >= n - 2:
		i = i + 1
	else:
		i = i + 2 if c[i + 2] == 0 else i + 1
	steps += 1
print(steps)


import sys
n = int(input().strip())
jumps = 0
c = [int(c_temp) for c_temp in input().strip().split(' ')]
i = 0
while i < n - 1:
	if i < n - 2 and c[i + 2] == 0:
		i = i + 2
	else:
		i += 1
	jumps += 1
print(jumps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jumps = 0
i = 0
while i + 2 < n - 1:
	jumps += 1
	if c[i + 2]:
		i = i + 1
	else:
		i = i + 2
if n - 1 > i:
	jumps += 1
print(jumps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
curr_cloud = 0
jumps = 0
while curr_cloud < n - 1:
	if curr_cloud == n - 3 or curr_cloud == n - 2:
		curr_cloud = n - 1
		jumps += 1
	elif c[curr_cloud + 2] == 0:
		curr_cloud += 2
		jumps += 1
	else:
		curr_cloud += 1
		jumps += 1
print(jumps)


n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jumps = 0
if n in range(2, 101):
	if c[0] == 0 and c[n - 1] == 0:
		i = 0
		while i <= n - 1:
			if i + 2 < n and c[i + 2] == 0:
				jumps += 1
				i += 2
			elif i + 1 < n and c[i + 1] == 0:
				jumps += 1
				i += 1
			else:
				break
		if jumps != 0:
			print(jumps)


n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
i = 0
count = 0
while i < n - 1:
	if i == n - 2 or c[i + 2] == 1:
		i += 1
	else:
		i += 2
	count += 1
print(count)


def solve(arr, i, res):
	if i >= n:
		return 999999
	if i == n - 1:
		return res
	if arr[i] == 1:
		return 999999
	return min(solve(arr, i + 1, res + 1), solve(arr, i + 2, res + 1))
n = int(input())
arr = list(map(int, input().split()))
print(solve(arr, 0, 0))


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
step = 0
counter = 0
while step < n - 1:
	if step + 2 <= len(c) - 1 and c[step + 2] != 1:
		step += 2
		counter += 1
	else:
		step += 1
		counter += 1
print(counter)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
cpt = 0
act = 0
while act < n - 2:
	if c[act + 2] == 0:
		act += 2
	else:
		act += 1
	cpt += 1
if act == n - 1:
	print(cpt)
else:
	print(cpt + 1)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jump = 0
i = 0
while i < n - 1:
	if i < n - 2:
		if c[i + 2] == 0:
			jump += 1
			i += 2
		else:
			jump += 1
			i += 1
	else:
		jump += 1
		i += 1
print(jump)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]

def Function(a):
	n = len(a)
	left = 0
	right = n - 1
	count = 0
	while left != right:
		if right == left + 1:
			return count + 1
		if a[left + 2] == 0:
			left = left + 2
			count = count + 1
		elif a[left + 1] == 0:
			left = left + 1
			count = count + 1
	return count
print(Function(c))


import sys
from math import ceil, floor

def jumps(n):
	if n == 1:
		return 0
	if n % 2 == 1:
		return floor(n / 2)
	if n % 2 == 0:
		return n / 2
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
g_c = 0
j = 0
s = 0
for i in range(0, n):
	if c[i] == 0:
		g_c += 1
	else:
		d = jumps(g_c)
		g_c = 0
		s += d + 1
print(int(jumps(g_c) + s))


import sys
n = int(input().strip())
c = [str(c_temp) for c_temp in input().strip().split(' ')]
S = ''.join(c).split('1')
result = 0
for i in S:
	result += len(i) // 2 + 1
print(result - 1)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
i = s = 0
while i < n - 2:
	if c[i + 2] == 0:
		i += 2
	else:
		i += 1
	s += 1
if i == n - 2:
	s += 1
print(s)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
p = 0
m = 0
while p < n - 2:
	if c[p + 2] == 0:
		p += 2
	elif c[p + 1] == 0:
		p += 1
	m += 1
if p < n - 1:
	m += 1
print(m)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
n = len(c)
if n >= 2 and n <= 100 and (c[0] == c[-1]) and (c[0] == 0):
	total = 0
	i = 0
	while i < n:
		if i + 2 < n and c[i + 2] == 0:
			i += 1
			total += 1
		elif i + 1 < n:
			total += 1
		i += 1
print(total)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')] + [1]
res = 0
curr = 0
for i in range(n + 1):
	if c[i] == 1:
		res += (i - curr - 1) % 2 + (i - curr - 1) // 2 + 1
		curr = i + 1
print(res - 1)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
turns = 0
pos = 0
while pos < n - 1:
	if pos + 2 > n - 1 or c[pos + 2] == 0:
		pos = pos + 2
	else:
		pos = pos + 1
	turns += 1
print(turns)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
c.append(-1)
present = 0
count = 0
while present != n - 1:
	if c[present + 2] != -1 and c[present + 2] != 1:
		present += 2
		count += 1
	elif c[present + 1] == 0:
		present += 1
		count += 1
print(count)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
i = 0
pas = 1
while i < n - 2:
	if c[i + 1] == 0 and c[i + 2] == 1:
		i = i + 1
		if i == n - 1:
			break
	elif c[i + 2] == 0:
		i = i + 2
		if i == n - 1:
			break
	pas = pas + 1
print(pas)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jumps = -1
cl = 0
while cl < n:
	if cl + 2 < n and c[cl + 2] == 0:
		cl = cl + 2
		jumps += 1
	else:
		cl = cl + 1
		jumps += 1
print(jumps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
pos = 0
steps = 0
while pos < n - 1:
	pos = pos + 2 if pos + 2 < n and c[pos + 2] != 1 else pos + 1
	steps = steps + 1
print(steps)


import sys
input()
l = list(map(int, input().split()))
cur = 0
total = 0
while True:
	if cur + 2 < len(l) and l[cur + 2] == 0:
		total += 1
		cur += 2
	elif cur + 1 < len(l) and l[cur + 1] == 0:
		total += 1
		cur += 1
	else:
		break
print(total)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jumps = [0] * n
for (i, e) in enumerate(c):
	if e == 1:
		jumps[i] = float('inf')
for i in range(1, n):
	if i != n and jumps[i] == float('inf'):
		continue
	if i == 1:
		jumps[i] = 1
	else:
		jumps[i] = 1 + min(jumps[i - 1], jumps[i - 2])
print(jumps[n - 1])


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
nb_moves = 0
i = 0
while i < n - 1:
	if i == n - 2 or c[i + 2] == 1:
		i += 1
	else:
		i += 2
	nb_moves += 1
print(nb_moves)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]

def walk(i, jumps):
	if i == n - 1:
		return jumps
	if i > n - 1:
		return sys.maxsize
	if c[i] == 1:
		return sys.maxsize
	return min(walk(i + 1, jumps + 1), walk(i + 2, jumps + 1))
print(walk(0, 0))


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
moves = 0
i = 0
while i < len(c) - 2:
	if c[i + 2] != 1:
		moves += 1
		i += 2
	elif c[i + 1] != 1:
		moves += 1
		i += 1
if i != len(c) - 1:
	moves += 1
print(moves)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
count = 0
pos = 0
while pos < len(c):
	if pos + 2 <= len(c) - 1 and c[pos + 2] is 0:
		pos += 2
		count += 1
	else:
		pos += 1
		count += 1
print(count - 1)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
s = 0
i = 0
fin = False
while not fin:
	if i == n - 1:
		fin = True
		break
	if i == n - 2:
		s += 1
		i += 1
	else:
		if c[i + 1] == 1:
			s += 1
			ind = 2
		elif c[i + 1] == 0 and c[i + 2] == 0:
			s += 1
			ind = 2
		else:
			s += 1
			ind = 1
		i += ind
print(s)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jumps = i = 0
while i < n - 3:
	jumps += 1
	if c[i + 2] == 0:
		i += 2
	else:
		i += 1
print(jumps + 1)


case = int(input())
clouds = input().rstrip().split(' ')
clouds.append('1')
counter = 0
i = 0
while i != case - 1:
	if clouds[i + 2] != '1':
		i += 2
	else:
		i += 1
	counter += 1
print(counter)


import sys
import math
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
sum_of_zeros = 0
sum_of_move = 0
sum_of_ones = 0
zero_moves = 0
one_jumps = 0

def calculate_zero_moves(sum_of_zeros):
	return math.floor(sum_of_zeros / 2) + sum_of_zeros % 2
for number in c:
	if number == 0:
		sum_of_zeros += 1
	else:
		zero_moves += calculate_zero_moves(sum_of_zeros - 1)
		sum_of_zeros = 0
		one_jumps += 1
if sum_of_zeros > 1:
	zero_moves += calculate_zero_moves(sum_of_zeros - 1)
print(zero_moves + one_jumps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
current_pos = len(c) - 1
count = 0
while current_pos > 0:
	if current_pos - 2 >= 0:
		if c[current_pos - 2] == 0:
			count += 1
			current_pos -= 2
			continue
	if current_pos - 1 >= 0:
		if c[current_pos - 1] == 0:
			count += 1
			current_pos -= 1
print(count)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
(x, ans) = (0, 0)
while True:
	x += 2
	if x == n:
		x -= 1
		ans += 1
		break
	if x == n - 1:
		ans += 1
		break
	if c[x] == 1:
		x -= 1
	ans += 1
print(ans)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
current_cloud = 0
moves = 0
while current_cloud < n - 1:
	if current_cloud + 2 < len(c):
		if c[current_cloud + 2] != 1:
			current_cloud += 1
	current_cloud += 1
	moves += 1
print(moves)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
currLoc = 0
numJumps = 0
while currLoc != n - 1:
	next1 = currLoc + 1
	next2 = currLoc + 2
	if next2 < n:
		if c[next2] == 0:
			currLoc += 2
		else:
			currLoc += 1
	else:
		currLoc += 1
	numJumps += 1
print(numJumps)


n = int(input().strip())
s = map(int, input().split())
co = 0
st = 0
s = list(s)
while st != n - 1:
	if st + 2 < n:
		if s[st + 2] == 0:
			st += 2
			co += 1
		else:
			st += 1
			co += 1
	if st == n - 2:
		st += 1
		co += 1
print(co)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
currentPosition = 0
numberJumps = 0
while True:
	if currentPosition + 2 <= n - 1 and c[currentPosition + 2] == 0:
		currentPosition += 2
	else:
		currentPosition += 1
	numberJumps += 1
	if currentPosition == n - 1:
		break
print(numberJumps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
step = 0
cur = 0
loop = 0
while cur < n and loop < n:
	loop += 1
	if cur + 2 < n:
		if c[cur + 2] == 0:
			cur += 2
			step += 1
		elif c[cur + 1] == 0:
			cur += 1
			step += 1
	elif cur + 1 < n:
		if c[cur + 1] == 0:
			cur += 1
			step += 1
print(step)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
count = 0
i = 0
while i < len(c):
	if i + 2 < len(c) and c[i + 2] == 0:
		count += 1
		i = i + 2
	elif i + 1 < len(c) and c[i + 1] == 0:
		count += 1
		i = i + 1
	else:
		i = i + 1
print(count)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
location = [i for i in range(len(c)) if c[i] == 0]
i = count = 0
n = len(c)
while i < n - 1:
	if i + 2 < n and c[i + 2] == 0:
		i += 2
	else:
		i += 1
	count += 1
print(count)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
i = 0
cnt = 0
while i < n:
	if i + 2 < n and c[i + 2] != 1:
		i += 2
		cnt += 1
	elif i + 1 < n and c[i + 1] != 1:
		i += 1
		cnt += 1
	else:
		i = n
print(cnt)


n = int(input().strip())
arr = list(map(int, input().rstrip().split()))
c = 0
o = 0
while True:
	if c >= n - 1:
		break
	if arr[c + 1] == 1:
		c += 2
		o += 1
	elif c < n - 2 and arr[c + 2] == 1:
		c += 1
		o += 1
	else:
		c += 2
		o += 1
print(o)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jumps = 0
current = 0
while current < n - 1:
	if current + 2 <= n - 1:
		if c[current + 2] == 0:
			current = current + 2
			jumps += 1
		else:
			current = current + 1
			jumps += 1
	else:
		current = current + 1
		jumps += 1
print(jumps)


n = int(input()) - 1
l = [int(i) for i in input().split()]
(c, i) = (0, 0)
while i != n:
	if i < n - 1 and l[i + 2] == 0:
		c += 1
		i += 2
	elif l[i + 1] == 0:
		c += 1
		i += 1
print(c)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jumps = 0
i = 0
len_c = len(c)
while i < len_c - 1:
	i_2 = i + 2
	if i_2 < len_c and (not c[i_2]):
		i += 2
	else:
		i += 1
	jumps += 1
print(jumps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
currentCloud = 0
numJumps = 0
while currentCloud < n - 3:
	if c[currentCloud + 2] == 0:
		currentCloud += 2
		numJumps += 1
	else:
		currentCloud += 1
		numJumps += 1
numJumps += 1
print(numJumps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
count = 0
i = 0
while i < len(c):
	if i + 2 <= len(c) - 1 and c[i + 2] == 0:
		i = i + 2
		count += 1
	elif i + 1 <= len(c) - 1 and c[i + 1] == 0:
		i = i + 1
		count += 1
	elif i == len(c) - 1 and c[i] == 0:
		break
print(count)


import sys
n = int(input().strip())
run_lengths = list(map(len, input().strip().replace(' ', '').split('1')))

def n_jumps(run_length):
	return run_length // 2 + 1
answer = sum(map(n_jumps, run_lengths)) - 1
print(answer)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
i = 0
cnt = 0
while len(c) > 1:
	if len(c) > 2 and c[i + 2] == 0:
		c = c[i + 2:]
		cnt += 1
	else:
		c = c[i + 1:]
		cnt += 1
	if len(c) == 0:
		break
print(cnt)


INFINITY = float('inf')

def get_minimum_hops(n, cloud_is_ordinary):
	clouds = range(n + 1)
	cloud_hops = {0: 0}
	for cloud in clouds[1:]:
		if not cloud_is_ordinary[cloud]:
			cloud_hops[cloud] = INFINITY
		else:
			previous_cloud = cloud - 1
			previous_hop = cloud_hops[previous_cloud] if cloud_is_ordinary[previous_cloud] else INFINITY
			if cloud > 1:
				second_previous_cloud = cloud - 2
				second_previous_hop = cloud_hops[second_previous_cloud] if cloud_is_ordinary[second_previous_cloud] else INFINITY
				current_hop = min(previous_hop, second_previous_hop) + 1
			else:
				current_hop = previous_hop + 1
			cloud_hops[cloud] = current_hop
	return cloud_hops[n]
number_of_clouds = int(input().strip())
clouds = [int(i) for i in input().strip().split()]
cloud_map = {k: v for (k, v) in zip(range(number_of_clouds + 1), [not bool(i) for i in clouds])}
print(get_minimum_hops(number_of_clouds - 1, cloud_map))


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jumps = 0
i = 0
while i < n - 1:
	if i + 2 < n and c[i + 2] == 0:
		i += 2
	else:
		i += 1
	jumps += 1
print(jumps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
minJumps = 0
i = 0
while i <= n - 2:
	if c[i + 1] == 1:
		minJumps += 1
		i += 2
		continue
	elif c[i + 1] == 0:
		if i + 2 < n and c[i + 2] == 0:
			minJumps += 1
			i += 2
		else:
			minJumps += 1
			i += 1
		continue
	minJumps += 1
	i += 1
print(minJumps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
steps = 0
while len(c) > 1:
	if len(c) > 2 and c[2] == 0:
		c = c[2:]
	else:
		c = c[1:]
	steps += 1
print(steps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
route = 0
ttl = 0
while route < n - 1:
	if route + 2 < n and c[route + 2] == 0:
		route += 2
		ttl += 1
	elif route + 1 < n and c[route + 1] == 0:
		route += 1
		ttl += 1
print(ttl)


n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
jump = 0
idx = 0
while idx < n - 1:
	jump += 1
	idx += 2
	if idx == n:
		break
	if c[idx] == 1:
		idx -= 1
print(jump)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
length = 0
current = len(c) - 1
while current > 0:
	if current == 1 or c[current - 2] == 0:
		current = current - 2
	else:
		current = current - 1
	length = length + 1
print(length)


import sys
n = int(input().strip())
clouds = [int(c_temp) for c_temp in input().strip().split(' ')]
clouds += [2, 2]
target = n - 1
current = 0
steps = 0
while current != target:
	steps += 1
	if not clouds[current + 2]:
		current += 2
		continue
	current += 1
print(steps)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
count = 0
start = 0
while start != n - 1:
	start = start + 2
	if start == n or c[start] == 1:
		start = start - 1
	count += 1
print(count)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
nb = 0
i = 0
while i + 1 < n:
	if i + 2 < n and c[i + 2] == 0:
		i += 2
	else:
		i += 1
	nb += 1
print(nb)


import sys
n_value = int(input())
array = []
count = 0
array = [int(c_temp) for c_temp in input().strip().split(' ')]
array[0] = 0
array[-1] = 0
h_value = 0
loop = range(h_value, n_value)
for i_value in loop:
	if h_value == n_value - 2:
		count += 1
		break
	elif h_value != n_value - 1 and array[h_value + 1] == 0 and (array[h_value + 2] == 0):
		h_value += 2
		loop = range(h_value, n_value)
		count += 1
	elif h_value != n_value - 1 and (array[h_value + 1] == 0 and array[h_value + 2] == 1 or (array[h_value + 1] == 1 and array[h_value + 2] == 0)):
		if array[h_value + 1] == 0:
			loop = range(h_value, n_value)
			h_value += 1
			count += 1
		else:
			h_value += 2
			loop = range(h_value, n_value)
			count += 1
print(count)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
c.append(None)
steps = 0
curr = 0
while curr < n - 1:
	if c[curr + 2] != None and c[curr + 2] == 0:
		curr = curr + 2
	else:
		curr = curr + 1
	steps = steps + 1
print(steps)


number_clouds = int(input())
count_step = 0
clouds_cursor = 0
clouds = list(map(int, input().split()))
amount_clouds = len(clouds)
potential_step = clouds_cursor + 2
while clouds_cursor < amount_clouds:
	if potential_step < amount_clouds and clouds[potential_step] != 1:
		clouds_cursor = potential_step
		count_step += 1
		potential_step = clouds_cursor + 2
	elif potential_step < amount_clouds and clouds[potential_step] == 1:
		clouds_cursor += 1
		count_step += 1
		potential_step = clouds_cursor + 2
	elif potential_step >= amount_clouds:
		clouds_cursor += 1
		count_step += 1
	if clouds_cursor == amount_clouds - 1:
		break
print(count_step)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]
i = 0
n_jumps = 0
while i < n - 1:
	n_jumps = n_jumps + 1
	longjump = i + 2
	if longjump >= n:
		break
	if c[longjump] == 0:
		i = longjump
		continue
	else:
		i = i + 1
print(n_jumps)


n = int(input())
l = [int(x) for x in input().split()]
s = 0
p = 0
while p != n - 1:
	if p + 1 == n - 1:
		s += 1
		break
	if l[p + 2] == 1:
		s += 1
		p += 1
	else:
		s += 1
		p += 2
print(s)


import sys
n = int(input().strip())
c = [int(c_temp) for c_temp in input().strip().split(' ')]

def jump(n, array, count, here):
	if here == n - 1:
		return count
	return jump(n, array, count + 1, here + 2) if here + 2 < n and array[here + 2] == 0 else jump(n, array, count + 1, here + 1)
print(jump(n, c, 0, 0))


def rindex(lst, e):
	return len(lst) - 1 - lst[::-1].index(e)

def next_jump(clouds, current_cloud_index):
	win = False
	try:
		next_cloud_index = current_cloud_index + rindex([clouds[current_cloud_index + i] for i in [1, 2]], 0) + 1
	except IndexError:
		next_cloud_index = len(clouds) - 1
		win = True
	else:
		if next_cloud_index == len(clouds) - 1:
			win = True
	return (next_cloud_index, win)

def min_number_of_jumps(clouds):
	win = False
	current_cloud_index = 0
	nr_of_jumps = 0
	while not win:
		(current_cloud_index, win) = next_jump(clouds, current_cloud_index)
		nr_of_jumps += 1
	return nr_of_jumps

def main():
	input()
	clouds = [int(cloud) for cloud in input().strip().split()]
	print(min_number_of_jumps(clouds))
main()


input()
clouds = [c for c in input().split()]
counter = -1
pos = 0
while pos < len(clouds):
	counter += 1
	if len(clouds) > pos + 2 and clouds[pos + 2] == '0':
		pos += 2
	else:
		pos += 1
print(counter)