Alena has successfully passed the entrance exams to the university and is now looking forward to start studying.

One two-hour lesson at the Russian university is traditionally called a pair, it lasts for two academic hours (an academic hour is equal to 45 minutes).

The University works in such a way that every day it holds exactly n lessons. Depending on the schedule of a particular group of students, on a given day, some pairs may actually contain classes, but some may be empty (such pairs are called breaks).

The official website of the university has already published the schedule for tomorrow for Alena's group. Thus, for each of the n pairs she knows if there will be a class at that time or not.

Alena's House is far from the university, so if there are breaks, she doesn't always go home. Alena has time to go home only if the break consists of at least two free pairs in a row, otherwise she waits for the next pair at the university.

Of course, Alena does not want to be sleepy during pairs, so she will sleep as long as possible, and will only come to the first pair that is presented in her schedule. Similarly, if there are no more pairs, then Alena immediately goes home.

Alena appreciates the time spent at home, so she always goes home when it is possible, and returns to the university only at the beginning of the next pair. Help Alena determine for how many pairs she will stay at the university. Note that during some pairs Alena may be at the university waiting for the upcoming pair.


-----Input-----

The first line of the input contains a positive integer n (1 ≤ n ≤ 100) — the number of lessons at the university. 

The second line contains n numbers a_{i} (0 ≤ a_{i} ≤ 1). Number a_{i} equals 0, if Alena doesn't have the i-th pairs, otherwise it is equal to 1. Numbers a_1, a_2, ..., a_{n} are separated by spaces.


-----Output-----

Print a single number — the number of pairs during which Alena stays at the university.


-----Examples-----
Input
5
0 1 0 1 1

Output
4

Input
7
1 0 1 0 0 1 0

Output
4

Input
1
0

Output
0



-----Note-----

In the first sample Alena stays at the university from the second to the fifth pair, inclusive, during the third pair she will be it the university waiting for the next pair. 

In the last sample Alena doesn't have a single pair, so she spends all the time at home.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
n = int(input())
m = list(map(int, input().split()))
N = -1
K = -1
i = 0
k = 0
o = 0
I = 0
while N == -1 and i < n:
	if m[i] == 1:
		N = i
	i += 1
i = n - 1
while K == -1 and i > -1:
	if m[i] == 1:
		K = i
	i -= 1
i = 0
k = K - N + 1
for i in range(N, K - 1):
	if m[i] == 0 and m[i + 1] == 0:
		if i != N and m[i - 1] == 1:
			o += 1
		o += 1
if N == -1:
	k = 0
elif o > 1:
	k = k - o
print(k)


import re
input()
print(len(''.join(re.split('00+', input().replace(' ', '').strip('0')))))


n = int(input())
a = [int(i) for i in input().split()]
count = 0
k = 0
if sum(a) != 1:
	if len(a) > 1 and sum(a) != 0:
		for i in range(len(a)):
			if a[i] != 0:
				a = a[i:]
				break
		while k < len(a) - 1:
			if a[k] == 1:
				count += 1
				k += 1
			elif a[k] == 0 and a[k + 1] == 0:
				k += 2
			elif a[k] == 0 and a[k + 1] == 1:
				if a[k - 1] == 0:
					k += 1
				else:
					count += 1
					k += 1
		if a[len(a) - 1] > 0:
			count += 1
	else:
		count = a[0]
else:
	count += 1
print(count)


import sys
import math
import itertools
import functools
import collections
import operator

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def lcm(a, b):
	return abs(a * b) // math.gcd(a, b)

def revn(n):
	return str(n)[::-1]

def dd():
	return collections.defaultdict(int)

def ddl():
	return collections.defaultdict(list)

def sieve(n):
	if n < 2:
		return list()
	prime = [True for _ in range(n + 1)]
	p = 3
	while p * p <= n:
		if prime[p]:
			for i in range(p * 2, n + 1, p):
				prime[i] = False
		p += 2
	r = [2]
	for p in range(3, n + 1, 2):
		if prime[p]:
			r.append(p)
	return r

def divs(n, start=2):
	r = []
	for i in range(start, int(math.sqrt(n) + 1)):
		if n % i == 0:
			if n / i == i:
				r.append(i)
			else:
				r.extend([i, n // i])
	return r

def divn(n, primes):
	divs_number = 1
	for i in primes:
		if n == 1:
			return divs_number
		t = 1
		while n % i == 0:
			t += 1
			n //= i
		divs_number *= t

def prime(n):
	if n == 2:
		return True
	if n % 2 == 0 or n <= 1:
		return False
	sqr = int(math.sqrt(n)) + 1
	for d in range(3, sqr, 2):
		if n % d == 0:
			return False
	return True

def convn(number, base):
	newnumber = 0
	while number > 0:
		newnumber += number % base
		number //= base
	return newnumber

def cdiv(n, k):
	return n // k + (n % k != 0)
n = ii()
a = li()
z = 0
for pos in range(1, n - 1):
	if a[pos - 1] == 1 and a[pos] == 0 and (a[pos + 1] == 1):
		z += 1
print(z + a.count(1))


n = int(input())
ans = 0
a = [0]
a.extend([int(v) for v in input().split(' ')])
for i in range(1, n + 1):
	if a[i] == 1:
		ans = ans + 1
		if i <= n - 2 and a[i + 1] == 0 and (a[i + 2] == 1):
			ans = ans + 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
u = 0
for i in range(1, n - 1):
	u += a[i] == 1 or a[i - 1] & a[i + 1]
u += a[0]
if n > 1:
	u += a[-1]
print(u)


n = int(input())
a = input()
a = a.replace(' ', '')
a = a + '00'
c = 2
h = 0
for i in a:
	if i == '0':
		c += 1
	else:
		if c == 1:
			h += 2
		else:
			h += 1
		c = 0
print(h)


from sys import stdin
x = [int(i) for i in stdin.read().rstrip().split()]
n = x[0]
sch = x[1:]
count = 0
for i in range(n):
	if sch[i] == 1:
		count += 1
	if sch[i] == 0 and i > 0 and (i < n - 1) and (sch[i - 1] == 1 and sch[i + 1] == 1):
		count += 1
print(count)


n = int(input())
if n == 1:
	st = input()
	if st == '1':
		print(1)
	else:
		print(0)
else:
	st = input()
	ans = n - 2
	n = n * 2
	if st[0] == '1':
		ans += 1
	if st[n - 2] == '1':
		ans += 1
	for a in range(2, n - 3, 2):
		if st[a] == '0' and (st[a - 2] == '0' or st[a + 2] == '0'):
			ans -= 1
	print(ans)


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


n = int(input())
a = [0] + list(map(int, input().split())) + [0]
print(sum((a[i - 1] + a[i + 1] + a[i] * 9 > 1 for i in range(1, n + 1))))


n = int(input())
a = list(map(int, input().split()))
p = 0
i = 0
t = 0
c = 0
while i < n and a[i] == 0:
	i += 1
for j in range(i, n):
	if a[j] == 0:
		t += 1
	if a[j] == 1:
		c += 1
		if t == 1:
			c += 1
			t = 0
		else:
			t = 0
print(c)


n = int(input())
l = list(map(int, input().split()))
t = 0
for i in range(len(l)):
	if l[i] == 0 and i > 0 and (i < n - 1):
		if l[i - 1] == 1 and l[i + 1] == 1:
			t = t + 1
	if l[i] == 1:
		t = t + 1
print(t)


n = int(input())
classes = list(map(int, input().split(' ')))
pair = 0
cont = 0
for j in range(len(classes)):
	if classes[j] == 1:
		break
for i in range(j, len(classes)):
	if classes[i] == 1 and cont == 1:
		pair += 2
		cont = 0
	elif classes[i] == 1 and cont == 0:
		pair += 1
	elif classes[i] == 1 and cont > 1:
		pair += 1
		cont = 0
	elif classes[i] == 0:
		cont += 1
print(pair)


input()
a = input().split()
n = 0
i = 0
b = False
while i < len(a):
	if a[i] == '1':
		n += 1
	elif i + 1 < len(a) and a[i + 1] == '1' and (i != 0) and (a[i - 1] == '1'):
		n += 1
	i += 1
print(n)


from itertools import groupby
N = int(input())
A = list(map(int, input().split()))
if N == 1 and A[0] == 0:
	print(0)
	exit()
groups = groupby(A)
ans = 0
for (i, (key, vals)) in enumerate(groups):
	vals = list(vals)
	if key == 1:
		ans += len(vals)
	elif len(vals) == 1 and i != 0:
		ans += 1
if A[-1] == 0:
	groups = groupby(A)
	n_groups = len(list(groups))
	groups = groupby(A)
	for (i, (key, vals)) in enumerate(groups):
		vals = list(vals)
		if i == n_groups - 1:
			if len(vals) == 1:
				ans -= 1
print(ans)


n = int(input())
P = list(map(int, input().split()))
kol = 0
if P[0] == 1:
	kol += 1
for i in range(1, n - 1):
	if P[i] != 0:
		kol += 1
	elif P[i - 1] != 0 and P[i] == 0 and (P[i + 1] != 0):
		kol += 1
if P[n - 1] != 0 and n != 1:
	kol += 1
print(kol)


n = int(input())
q = [int(x) for x in input().split()]
go = 0
np = 0
ans = 0
for i in range(n):
	if not go:
		if q[i] == 1:
			go = 1
		else:
			continue
	t = q[i]
	if t == 0:
		if i + 1 < n and t == q[i + 1] or (i - 1 >= 0 and t == q[i - 1]) or i == n - 1:
			go = 0
			continue
	ans += 1
print(ans)


n = int(input())
cnt = list(map(int, input().split()))
ans = 0
if cnt.count(1) != 0:
	sost = 1
	for i in range(cnt.index(1), n):
		if cnt[i] and sost == 2:
			sost = 1
			ans += 2
		elif cnt[i]:
			ans += 1
			sost = 1
		elif not cnt[i] and sost == 1:
			sost = 2
		elif not cnt[i] and sost == 2:
			sost = 0
		if i != n - 1 and (not cnt[i + 1:].count(1)):
			break
print(ans)


n = int(input())
l = [0] + list(map(int, input().split())) + [0]
res = 0
for i in range(1, n + 1):
	if l[i] == 1:
		res += 1
	if l[i] == 0 and l[i - 1] == 1 and l[i + 1]:
		res += 1
print(res)


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


input()
a = list(map(int, input().split()))
for i in range(1, len(a) - 1):
	if a[i - 1] and a[i + 1]:
		a[i] = 1
print(sum(a))


a = int(input())
s = list(map(int, input().split()))
c = s.count(1)
v = 0
im = 0
for i in range(a):
	if s[i] == 1:
		im = i
		break
for i in range(1, a):
	if s[i] == 0:
		v += 1
	elif v == 1 and i > im:
		c += 1
		v = 0
	else:
		v = 0
print(c)


n = int(input())
l = list(map(int, input().split()))
tot = l.count(1)
for i in range(1, n):
	if i == n - 1:
		break
	if l[i] == 0 and l[i + 1] == 1 and (l[i - 1] == 1):
		tot += 1
print(tot)


n = int(input())
s = input().split()
s = [int(x) for x in s]
i = 0
while len(s) and s[-1] == 0:
	s.pop()
while len(s) and s[0] == 0:
	s.remove(0)
ans = len(s)
while i < len(s):
	counter = 0
	while s[i] == 0 and i < len(s):
		counter += 1
		i += 1
	if counter >= 2:
		ans -= counter
	i += 1
print(ans)


n = int(input())
array = list(map(int, input().split()))
if array[0] == 0:
	array[0] = -1
if array[n - 1] == 0:
	array[n - 1] = -1
answer = 0
for i in range(0, n):
	if array[i] == 1:
		answer += 1
	if array[i - 1] == 1 and array[i] == 0 and (array[i + 1] == 1):
		answer += 1
print(answer)


n = int(input())
x = input().split()
counter = 0
for i in range(n):
	if x[i] == '0':
		if i == 0 or i == n - 1:
			counter += 1
		else:
			try:
				if x[i - 1] == x[i] or x[i + 1] == x[i]:
					counter += 1
			except IndexError:
				pass
print(n - counter)


n = int(input())
l = [int(i) for i in input().split()]
if n == 1:
	if l[0] == 0:
		print(0)
	else:
		print(1)
else:
	ans = 0
	for i in range(n):
		if l[i] == 1:
			ans += 1
		else:
			f1 = 0
			f2 = 0
			try:
				if l[i + 1] == 1:
					f1 = 1
			except:
				pass
			if i - 1 >= 0:
				if l[i - 1] == 1:
					f2 = 1
			if f1 == 1 and f2 == 1:
				ans += 1
	print(ans)


n = int(input())
l = list(map(int, input().split()))
for i in range(1, n - 1):
	if l[i - 1] and l[i + 1]:
		l[i] = 1
print(sum(l))


n = int(input())
arr = list(map(int, input().split()))
cnt = sum(arr)
for i in range(1, n - 1):
	if arr[i] == 0 and arr[i + 1] == arr[i - 1] == 1:
		cnt += 1
print(cnt)


n = int(input())
a = list(map(int, input().split()))
ans = sum(a)
for i in range(1, n - 1):
	if a[i] == 0 and a[i + 1] == 1 and (a[i - 1] == 1):
		ans += 1
print(ans)


n = int(input())
a = list(input().split(' '))
a = list((int(x) for x in a))
res = 0
begin = 0
while a[begin] == 0:
	begin += 1
	if begin == n:
		break
for i in range(begin, n):
	if a[i] == 1:
		res += 1
	elif i < n - 1 and i > 0:
		if a[i] == 0 and a[i + 1] == 1 and (a[i - 1] == 1):
			res += 1
print(res)


n = int(input())
l = input().replace('1 0', '1 x').replace('x 1', '1 1')
print(l.count('1'))


n = int(input())
a = list(map(int, input().split(' ')[:n]))
res = 0
state = 0
for x in a:
	if state == 0:
		if x == 0:
			pass
		else:
			state = 1
			res += 1
	elif state == 1:
		if x == 0:
			state = 2
		else:
			res += 1
	elif state == 2:
		if x == 0:
			state = 0
		else:
			state = 1
			res += 2
print(res)


n = int(input())
a = input().split()
zeroth = 0
ind = 0
for i in range(n):
	if a[i] == '1':
		if i == 1 and zeroth != 0:
			ind -= zeroth
		if zeroth > 1:
			ind -= zeroth
		ind += 1
		zeroth = 0
	else:
		zeroth += 1
		ind += 1
ind -= zeroth
print(ind)


n = int(input())
a = list(map(int, input().split()))
i = 0
d = 0
if any(a) == 0:
	print(0)
else:
	while a[0] == 0:
		del a[0]
	while a[len(a) - 1] == 0:
		del a[len(a) - 1]
	if len(a) > 0:
		if a[len(a) - 1] == 0:
			del a[len(a) - 1]
		while 0 in a:
			i = a.index(0)
			if a[i + 1] == 0:
				d = 1
				while a[i + d] == 0:
					d += 1
				del a[i:i + d]
			else:
				a[i] = 1
	print(len(a))


def main():
	n = int(input())
	arr = [int(x) for x in input().split()]
	ans = n
	(l, r) = (0, 0)
	if n == 1 and arr[0] == 0:
		print(0)
		return
	elif arr == [0] * n:
		print(0)
		return
	for i in range(n):
		if arr[i] == 0:
			l += 1
		else:
			break
	for i in range(n - 1, -1, -1):
		if arr[i] == 0:
			r += 1
		else:
			break
	i = 0 + l
	ans -= l
	ans -= r
	while 0 + l <= i < n - r:
		if arr[i] == 0:
			c = 0
			for j in range(i, n - r):
				if arr[j] == 0:
					c += 1
				else:
					break
			if c >= 2:
				ans -= c
			i += c
		else:
			i += 1
	print(ans)
main()


n = int(input())
string = input()
numbers = string.split()
for x in range(n):
	numbers[x] = int(numbers[x])
streaks = []
streak = 0
for x in numbers:
	if x == 0:
		streak += 1
	else:
		streaks.append(streak)
		streak = 0
if len(streaks) > 0:
	del streaks[0]
print(numbers.count(1) + sum(list(filter(lambda x: x < 2, streaks))))


n = int(input())
b = list(map(int, input().split()))
b = [0] + b + [0]
for i in range(1, len(b) - 3):
	if b[i:i + 3] == [1, 0, 1]:
		b = b[:i] + [1, 1, 1] + b[i + 3:]
print(sum(b))


from sys import stdin
n = int(stdin.readline())
a = stdin.readline().split()
lk = 0
for i in range(0, n):
	if a[i] == '1':
		lk = i
		break
rk = 0
for i in range(n - 1, -1, -1):
	if a[i] == '1':
		rk = i
		break
if lk == rk and a[rk] == '0':
	print('0')
	exit()
i = lk
res = 0
while i < rk:
	if a[i] == '0':
		j = i
		while a[j] == '0':
			j += 1
		if j - i > 1:
			res += j - i
		i = j
	i += 1
print(rk - lk + 1 - res)


n = int(input())
arr = list(map(int, input().split()))
ans = 0
if arr[0] == 0:
	arr[0] = -1
if arr[n - 1] == 0:
	arr[n - 1] = -1
for i in range(0, n):
	if arr[i] == 1:
		ans += 1
	if arr[i] == 0:
		if arr[i - 1] == 1 and arr[i + 1] == 1:
			ans += 1
print(ans)


n = int(input())
numbers = [int(x) for x in input().split()]
count = 0
for i in range(0, n - 1):
	if numbers[i] == 1:
		count += 1
	elif numbers[i] == 0 and i > 0 and (numbers[i + 1] == 1) and (numbers[i - 1] == 1):
		count += 1
if numbers[n - 1] == 1:
	count += 1
print(count)


n = int(input())
v = [int(e) for e in input().split()]
first = last = -1
for i in range(n):
	if v[i] == 1:
		last = i + 1
		if first == -1:
			first = i
ans = last - first
cnt = 0
for i in range(first, last):
	if v[i] == 1:
		if cnt >= 2:
			ans -= cnt
		cnt = 0
	else:
		cnt += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
if 1 in a:
	x = a.index(1)
	a = a[::-1]
	y = a.index(1)
	a = a[::-1]
	a = a[x:n - y]
	n = len(a)
else:
	n = 0
	a = []
b = 0
for i in range(n):
	if a[i] == 0 and a[i + 1] == 0 or (a[i] == 0 and a[i - 1] == 0):
		b = b + 1
if b > 0:
	print(len(a) - b)
elif len(a) == 0:
	print(0)
else:
	print(len(a))


from sys import stdin, stdout
input = stdin.readline
n = int(input())
a = list(map(int, input().split()))
ans = 0
uni = False
ind = 0
while ind < n - 1:
	if a[ind] == 1:
		ans += 1
		ind += 1
		uni = True
	elif a[ind + 1] == 0:
		while ind < n and a[ind] == 0:
			ind += 1
		uni = False
	else:
		if uni:
			ans += 1
		ind += 1
if a[n - 1] == 1:
	ans += 1
stdout.write(str(ans))


n = int(input())
k = 0
f = 0
curr = 0
numero = input().split()
for i in numero:
	if int(i) == 1:
		k += 1
		f = 1
		if curr < 2:
			k += curr
		curr = 0
	elif int(i) == 0:
		if f == 1:
			curr += 1
print(k)


from itertools import dropwhile
from operator import not_
n = int(input())
a = list(map(int, input().split()))
result = 0
prev1 = prev2 = -1
for x in dropwhile(not_, a):
	if x:
		result += 1
		if ~prev2 and (not prev1) and prev2:
			result += 1
	(prev1, prev2) = (x, prev1)
print(result)


i = int(input())
mas = list(input())
flag = 3
for j in range(len(mas)):
	if flag == 1 and j == len(mas) - 1 and (mas[j] == '0'):
		i -= 1
	elif flag == 1 and mas[j] == '0':
		flag = 2
	elif flag == 2 and mas[j] == '0':
		i -= 2
		flag = 3
	elif flag == 3 and mas[j] == '0':
		i -= 1
	elif (flag == 2 or flag == 3) and mas[j] == '1':
		flag = 1
print(i)


n = int(input().strip())
x = input().strip().split()
x = [int(y) for y in x]
count = 0
(i, itmp) = (0, 0)
c0 = 0
while i < n and x[i] == 0:
	i = i + 1
while i < n:
	while i < n and x[i] == 1:
		count = count + 1
		i = i + 1
	c0 = 0
	while i < n and x[i] == 0:
		c0 = c0 + 1
		i = i + 1
	if c0 == 1 and i != n:
		count = count + 1
print(count)


n = int(input())
l = list(map(int, input().split()))
cnt = 0
stop = -1
for i in range(n):
	if l[i] == 1:
		break
	else:
		stop = i
while l and l[-1] == 0:
	l.pop(-1)
for i in range(stop + 1, len(l)):
	if i <= len(l) - 2:
		if i < len(l) - 1 and l[i] == 0 and (l[i + 1] == 0) or (i > 0 and l[i] == 0 and (l[i - 1] == 0)):
			pass
		elif l[i] == 1 or l[i + 1] == 1 or l[i + 2] == 1:
			cnt += 1
	elif i <= len(l) - 2:
		if l[i + 1] == 1:
			cnt += 1
	elif l[i] == 1:
		cnt += 1
print(cnt)


n = int(input())
a = [int(x) for x in input().split()]
time = 0
try:
	start = a.index(1)
except:
	print(0)
	exit()
current = a[start]
zero_in_row = 0
f = lambda x: 1 if x == 1 else 0
for i in range(start, n):
	if a[i] == 1:
		time += f(zero_in_row)
		zero_in_row = 0
		time += 1
	else:
		zero_in_row += 1
print(time)


n = int(input())
P = list(map(int, input().split()))
c = 0
i = 0
j = 0
while c != 1 and i < n:
	if P[i] == 0:
		j = i + 1
	else:
		c += 1
	i += 1
c = 0
for i in range(j, n - 1):
	if P[i] == 1:
		c += 1
	if P[i] == 0 and P[i - 1] == 1 and (P[i + 1] == 1):
		c += 1
if P[n - 1] == 1:
	c += 1
print(c)


n = int(input())
l_p = list(map(int, input().split()))
t = 0
c_s = 2
for p in l_p:
	if p == 0:
		c_s += 1
	if p == 1:
		if c_s < 2:
			t += c_s
		c_s = 0
		t += 1
print(t)


n = int(input())
a = [int(x) for x in input().split()]
k = 0
while k < n and a[k] != 1:
	k += 1
m = n - 1
while m >= 0 and a[m] != 1:
	m -= 1
ans = m - k + 1
for i in range(k + 1, m):
	if a[i] == 0 and (a[i - 1] == 0 or a[i + 1] == 0):
		ans -= 1
print(max(0, ans))


n = int(input())
l = list(map(int, input().split()))
while len(l) > 0 and l[0] == 0:
	l.pop(0)
while len(l) > 0 and l[-1] == 0:
	l.pop()
cont = 1
res = 0
for i in range(len(l)):
	if l[i] == 0 and l[i + 1] == 0:
		cont += 1
	elif cont > 1:
		res = res + cont
		cont = 1
print(len(l) - res)


n = int(input())
a = [int(x) for x in input().split()]
ptr = 0
while ptr < n and a[ptr] == 0:
	ptr += 1
if ptr == n:
	print(0)
	exit()
a = a[ptr:]
ptr = len(a) - 1
while a[ptr] == 0:
	ptr -= 1
a = a[:ptr + 1]
n = len(a)
ptr = 0
res = 0
while ptr < n:
	if a[ptr]:
		res += 1
		ptr += 1
		continue
	j = 0
	while a[ptr + j] == 0:
		j += 1
	if j == 1:
		res += 1
	ptr += j
print(res)


n = int(input())
ai = input().replace(' ', '')
num = ai.count('1')
print(num + ai.replace('101', '11011').count('101'))


import sys
import math
import bisect

def solve(A):
	n = len(A)
	ans = 0
	for i in range(n):
		if A[i] == 1:
			ans += 1
		elif i - 1 >= 0 and A[i - 1] and (i + 1 < n) and A[i + 1]:
			ans += 1
	return ans

def main():
	n = int(input())
	A = list(map(int, input().split()))
	print(solve(A))
main()


input()
(pprev, prev) = (None, None)
ans = 0
for i in input().split():
	if i == '1':
		ans += 1
		if prev == '0' and pprev == '1':
			ans += 1
	(pprev, prev) = (prev, i)
print(ans)


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


n = int(input())
l = list(input().split())
s = ''.join(l)
s = s.lstrip('0')
s = s.rstrip('0')
if s == '':
	print(0)
else:
	c = '0'
	new = ''
	l = []
	a = 0
	for i in range(len(s) - 1):
		if s[i] == s[i + 1] == '0' or s[i] == s[i - 1] == '0':
			pass
		else:
			a += 1
	print(a + 1)


n = int(input())
mat = list(map(int, input().split()))
try:
	mat = mat[mat.index(1):]
	for i in range(1, len(mat) - 1):
		if mat[i] == 0 and mat[i - 1] == 1 and (mat[i + 1] == 1):
			mat[i] = 1
	print(sum(mat))
except:
	print(0)


n = int(input())
s = str(input())
s = s.replace(' ', '')
s = s.strip('0')
temp = ''
i = 0
while i < len(s) - 1:
	if s[i] == s[i + 1] and s[i] == '0':
		temp = s[i:]
		temp = temp.lstrip('0')
		s = s[:i] + temp
	i = i + 1
print(len(s))


input()
Pairs = input().replace(' ', '').strip('0')
(i, Count) = (0, 0)
while i < len(Pairs):
	if Pairs[i] == Pairs[i - 1] == '0':
		while Pairs[i - 1] == '0':
			Count += 1
			i += 1
	else:
		i += 1
print(len(Pairs) - Count)


R = lambda : map(int, input().split())
(n,) = R()
s = ''.join(input().split())
while '101' in s:
	s = s.replace('101', '111')
print(sum(map(int, s)))


n = int(input())
a = list(map(int, input().split()))
for i in range(1, n - 1):
	if a[i - 1] and a[i + 1]:
		a[i] = 1
print(a.count(1))


import sys
n = int(input())
v = list(map(int, input().split()))
for i in range(2, n):
	if v[i] + v[i - 2] == 2:
		v[i - 1] = 1
print(sum(v))


import sys
import re
sys.stdin.readline()
s = sys.stdin.readline()
s = re.sub('[^01]', '', s)
s = s.strip('0')
s = re.sub('0{2,}', '', s)
print(len(s))


import time
n = int(input())
a = [int(i) for i in input().split()]
start = time.time()
ans = 0
i = 0
while i < len(a):
	if a[i] == 1:
		break
	i += 1
while i < len(a) - 1:
	if a[i] == 0 and a[i + 1] == 1 and (a[i - 1] == 1):
		a[i] = 1
		i
	i += 1
print(sum(a))
finish = time.time()


def input_ints():
	return list(map(int, input().split()))

def solve():
	n = int(input())
	a = input_ints()
	for i in range(1, n - 1):
		if a[i - 1] and a[i + 1]:
			a[i] = 1
	print(a.count(1))
solve()


n = int(input())
lst = [int(x) for x in input().split()]
atuniversity = False
break_length = 0
time = 0
for lesson in lst:
	if lesson == 1:
		atuniversity = True
		break_length = 0
	elif lesson == 0:
		break_length += 1
		if break_length >= 2:
			if atuniversity:
				time -= 1
			atuniversity = False
	if atuniversity:
		time += 1
try:
	if lst[-1] == 0 and lst[-2] == 1:
		time -= 1
except IndexError:
	pass
print(time)


n = int(input())
a = [int(v) for v in input().split()]
for i in range(1, len(a) - 1):
	if a[i - 1] == 1 and a[i + 1] == 1:
		a[i] = 1
print(sum(a))


count = int(input())
in_str = input()
timetable = [int(i) for i in in_str.split()]
home = False
windows = 0
end_windows = 0
for i in timetable:
	if i == 0:
		count -= 1
	else:
		break
if len(timetable) != count:
	timetable = timetable[len(timetable) - count:]
for i in range(len(timetable) - 1, 0, -1):
	if timetable[i] == 0:
		end_windows += 1
	else:
		break
timetable = timetable[:len(timetable) - end_windows]
count -= end_windows
for i in timetable:
	if i == 0:
		windows += 1
		if windows >= 2 and (not home):
			home = True
			count -= 2
			continue
	else:
		home = False
		windows = 0
	if home:
		count -= 1
print(count)


n = int(input())
a = list(map(int, input().split()))
while len(a) > 0 and a[0] == 0:
	a.pop(0)
while len(a) > 0 and a[-1] == 0:
	a.pop(-1)
l = 0
r = 0
breaktime = 0
for i in range(1, len(a)):
	if a[i - 1] == 1 and a[i] == 0:
		l = i
	if a[i - 1] == 0 and a[i] == 1:
		if i - l > 1:
			breaktime += i - l
print(len(a) - breaktime)


n = int(input())
s = input()
s = s.lstrip('0 ')
s = s.rstrip(' 0')
s = s[::2]
while '00' in s:
	x = s.replace('00', '*')
	while x != s:
		s = x
		x = s.replace('*0', '*')
print(len(s) - s.count('*'))


def read_numbers():
	return list(map(int, input().split()))

def f(pairs):
	while pairs and pairs[0] == 0:
		pairs.pop(0)
	while pairs and pairs[-1] == 0:
		pairs.pop()
	count = 0
	parity = False
	tmp_count = 0
	for i in pairs:
		if i:
			if parity:
				tmp_count += 1
			parity = False
			tmp_count += 1
		else:
			if not parity:
				parity = True
			else:
				count += tmp_count
				tmp_count = 0
			if tmp_count == 0:
				parity = False
	count += tmp_count
	return count
n = int(input())
numbers = read_numbers()
print(f(numbers))


n = int(input())
pairs = ''.join(input().split())
pairs = pairs.strip('0')
if len(pairs) == 0:
	print('0')
	exit()
ans = int(pairs[0] == '1')
if len(pairs) > 1:
	ans += int(pairs[-1] == '1')
for i in range(1, len(pairs) - 1):
	if pairs[i] == '1':
		ans += 1
	elif pairs[i - 1] == '1' and pairs[i] == '0' and (pairs[i + 1] == '1'):
		ans += 1
print(ans)


def main():
	input()
	s = input()
	s = s[s.find('1'):s.rfind('1') + 1:2]
	s1 = s.replace('10', '1')
	print(len(s) - s1.count('0') - s1.count('10'))
main()


n = input()
lessons = input().split()
prev = '0'
home = True
cnt = 0
for l in lessons:
	if l == '0' and prev == '0':
		home = True
	elif l == '1':
		cnt += 1
		if prev == '0' and (not home):
			cnt += 1
		home = False
	prev = l
print(cnt)


n = int(input().strip())
arr = list(input().strip().split())
arr = list(''.join(arr).strip('0'))
for i in range(len(arr)):
	if arr[i] == '0' and arr[i - 1] == '1' and (arr[i + 1] == '1'):
		arr[i] = '1'
print(arr.count('1'))


num = int(input())
arr = list(map(int, input().split()))
ans = 0
started = False
for i in range(num):
	if arr[i] == 1 and (not started):
		started = True
		ans += 1
	elif arr[i] == 1:
		ans += 1
	elif arr[i] == 0 and started:
		if i == num - 1:
			continue
		elif arr[i - 1] == arr[i + 1] == 1:
			ans += 1
print(ans)


def arr_inp():
	return [int(x) for x in input().split()]
(n, a) = (int(input()), arr_inp())
(count, tem, ix1, ix2) = (0, 0, -1, -1)
for i in range(n):
	if a[i]:
		ix1 = i
		break
for i in range(n - 1, -1, -1):
	if a[i]:
		ix2 = i
		break
if ix1 == -1 or ix2 == -1:
	exit(print(0))
for i in range(ix1, ix2 + 1):
	if a[i]:
		if tem > 1:
			count -= tem
		tem = 0
	else:
		tem += 1
	count += 1
print(count)


n = int(input())
a = input()
ans = a.count('1')
z = a.find('0')
a = a.split('1')
if z == 0:
	z = 1
else:
	z = 0
for i in range(z, len(a)):
	if len(a[i].strip()) == 1 and a[i] != ' 0':
		ans += 1
print(ans)


__author__ = 'artyom'

def main():
	n = read()
	a = read(3)
	s = a[0]
	if n > 1:
		for i in range(1, n - 1):
			if a[i] or (a[i - 1] and a[i + 1]):
				s += 1
		s += a[n - 1]
	return s

def read(mode=1, size=None):
	if mode == 0:
		return input().strip()
	if mode == 1:
		return int(input().strip())
	if mode == 2:
		return input().strip().split()
	if mode == 3:
		return list(map(int, input().strip().split()))
	a = []
	for _ in range(size):
		a.append(read(3))
	return a

def write(s='\n'):
	if s is None:
		s = ''
	if isinstance(s, tuple) or isinstance(s, list):
		s = ' '.join(map(str, s))
	s = str(s)
	print(s, end='\n')
write(main())


n = int(input())
s = input()
a = s.split(' ')
d = 0
k = 0
for i in a:
	if i == '0':
		k += 1
	if i == '1':
		if k == 1 and d > 0:
			d += 2
			k = 0
		else:
			d += 1
			k = 0
print(d)


s = 0
z = int(input())
x = input().split()
for a in range(1, z - 1):
	if x[a] == '0' and x[a - 1] == '1' and (x[a + 1] == '1'):
		s += 1
print(s + x.count('1'))


import re
n = int(input())
l = input().split()
s = ''.join(l).strip('0')
if len(s) == 0:
	print(0)
else:
	c = len(s)
	xl = re.findall('00+', s)
	for i in xl:
		c -= len(i)
	print(c)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	cnt = 0
	ans = 0
	i = 0
	while i < n:
		if a[i] == 1:
			break
		i += 1
	while i < n:
		cnt = 0
		if a[i] == 0:
			while i < n and a[i] == 0:
				cnt += 1
				i += 1
			i -= 1
		else:
			ans += 1
		if cnt < 2 and i != n - 1:
			ans += cnt
		i += 1
	print(ans)
main()


import re
n = int(input())
s = re.sub('\\s+', '', input())
groups = re.findall('1(?:1|01)*', s)
print(sum(map(len, groups)))


n = int(input())
k = 0
i = 0
li = list(map(int, input().split()))
if len(li) > 1:
	while li[-1] == 0:
		if len(li) > 0:
			li = li[:-1]
			if len(li) == 0:
				break
	if len(li) > 1:
		while li[0] == 0:
			if len(li) > 0:
				li = li[1:]
				if len(li) == 0:
					break
if len(li) != 1 or li[0] != 0:
	while i < len(li):
		if li[i] == 1:
			k += 1
			i += 1
		elif li[i] == 0 and li[i + 1] != 0:
			k += 1
			i += 1
		elif li[i] == 0 and li[i + 1] == 0:
			j = i
			while li[j] == 0:
				j += 1
			i = j
print(k)


n = int(input())
a = [int(s) for s in input().split()]
sum = a[0]
if n > 1:
	sum = sum + a[n - 1]
for i in range(1, n - 1):
	if a[i] == 1:
		sum = sum + 1
	elif a[i] == 0 and a[i - 1] + a[i + 1] == 2:
		sum = sum + 1
print(sum)


n = int(input())
As = list(map(int, input().split()))
stay = 0
atuniv = False
for i in range(n):
	if As[i] == 1:
		atuniv = True
		stay += 1
	elif atuniv == False:
		continue
	elif i == n - 1:
		continue
	elif As[i + 1] == 0:
		atuniv = False
	else:
		stay += 1
print(stay)


n = int(input())
a = list(map(int, input().split()))
k = 0
for i in range(n):
	if a[i] == 1:
		k += 1
	elif k > 0:
		if i - 1 >= 0 and a[i - 1] != 0:
			if i + 1 < n and a[i + 1] == 1:
				k += 1
print(k)


def solve(s):
	k = 0
	j = 0
	while s[j] == '0' and j < len(s) - 1:
		j += 2
	for i in range(j, len(s), 2):
		if s[i] == '1':
			k += 1
		if i > 1 and i < len(s) - 1 and (s[i - 2] == '1') and (s[i] == '0') and (s[i + 2] == '1'):
			k += 1
	return k
inp0 = input()
inp = input()
print(solve(inp))


num = int(input())
arr = ''.join(list(input().split())).replace('101', '111')
while '101' in arr:
	arr = arr.replace('101', '111')
ans = arr.count('1')
print(ans)


n = int(input())
s = input()
a = s.split(' ')
a = [int(i) for i in a]
c = 0
r = 0
for i in range(n):
	if i == n - 1:
		if a[i] == 1:
			c += 1
	elif r > 0:
		if a[i] == 0 and a[i + 1] == 0:
			r = 0
		else:
			c += 1
	elif a[i] == 1:
		c += 1
		r = 1
print(c)


n = int(input())
a = [int(i) for i in input().split()]
i = 0
answ = n
c = 0
while i < n and a[i] == 0:
	i += 1
	answ -= 1
if i == n:
	print(0)
	exit()
while i < n:
	if a[i] == 0:
		c += 1
	else:
		if c > 1:
			answ -= c
		c = 0
	i += 1
answ -= c
print(answ)


n = int(input())
li1 = list(map(int, input().split()))
li3 = []
baal_falan = 0
if n == 1:
	if li1[0] == 0:
		print(0)
		exit(0)
	else:
		print(1)
		exit(0)
for i in range(n):
	if li1[i] == 1:
		li3.append(1)
	elif i == 0:
		baal_falan = 1
	elif i == n - 1:
		baal_falan = 1
	elif li1[i + 1] == 0 or li1[i - 1] == 0:
		baal_falan = 1
	else:
		li3.append(1)
print(len(li3))


n = int(input())
tmp = input().split()
lessons = list()
for i in tmp:
	lessons.append(bool(int(i)))
counter = 0
while lessons[0] == False and len(lessons) > 1:
	lessons.remove(False)
if len(lessons) > 0:
	lessons.append(False)
	lessons.append(False)
else:
	print(0)
	quit()
inUniv = True
size = len(lessons) - 2
i = 0
while i < size:
	if lessons[i] == True:
		counter += 1
	elif lessons[i + 1] == False:
		while lessons[i + 1] == False and i < size:
			i += 1
	else:
		counter += 1
	i += 1
print(counter)


n = int(input())
a = list(map(int, input().split()))
c = 0
l = 0
b = 0
while c < len(a) and a[c] == 0:
	c += 1
	b += 1
if c == len(a):
	print(0)
	return
d = len(a) - 1
while a[d] != 1:
	d -= 1
	b += 1
while c <= d:
	if a[c] == 0:
		l += 1
	else:
		if l > 1:
			b += l
		l = 0
	c += 1
print(n - b)


n = int(input())
b = input().split()
i = 0
a = list(str(int(''.join(b))))
while i < len(a):
	if a[-1] == '0':
		del a[-1]
	else:
		i = i + 1
count = 0
for i in range(1, len(a) - 1):
	if a[i] == '0':
		if a[i - 1] == '0' or a[i + 1] == '0':
			count = count + 1
print(len(a) - count)


__author__ = 'suvasish'
classes = int(input())
arr = list(map(int, input().split(' ')))
pos = []
count = 0
for i in range(0, len(arr)):
	if arr[i] == 1:
		pos.append(i)
for i in range(0, len(pos)):
	if i == 0:
		count += 1
	if i > 0:
		diff = pos[i] - pos[i - 1]
		if diff > 2:
			count += 1
		else:
			count += diff
print(count)


n = int(input())
A = list(map(int, input().split()))
x = n
i = 0
while A[i] == 0:
	x -= 1
	i += 1
	if i >= n:
		break
if i < n:
	j = -1
	while A[j] == 0:
		x -= 1
		j -= 1
	for k in range(i + 1, n + j):
		if A[k] == 0 and A[k + 1] == 0 and (A[k - 1] == 1):
			i = k
			while A[i] == 0:
				x -= 1
				i += 1
print(x)


a = int(input())
l = 0
b = list(map(int, input().split()))
for i in range(1, a - 1):
	if b[i] == 1:
		l += 1
	elif b[i] == 0 and b[i - 1] == b[i + 1] == 1:
		l += 1
if b[0] == 1:
	l += 1
if b[-1] == 1 and a != 1:
	l += 1
print(l)


n = int(input())
a = list(map(int, input().split()))
if a.count(0) == len(a):
	print(0)
	quit()
while a[0] == 0:
	a.pop(0)
while a[-1] == 0:
	a.pop(-1)
x = len(a)
for i in range(x):
	if a[i] == 0:
		if a[i - 1] == 1 and a[i + 1] == 1:
			a[i] = 1
print(sum(a))


def timetable(lst):
	(flag, count) = (True, 0)
	result = 0
	for elem in lst:
		if elem == 1:
			if count >= 2 and (not flag):
				result += count
			count = 0
			flag = False
		else:
			count += 1
		if flag is True:
			result += 1
	if not flag:
		result += count
	return len(lst) - result
n = int(input())
a = [int(j) for j in input().split()]
print(timetable(a))


n = int(input())
list = [int(i) for i in input().split()]
dem = 0
dem2 = 0
check = -1
for i in range(0, n):
	if list[i] == 0:
		dem2 += 1
	elif list[i] == 1:
		dem += 1
		check += 1
		if dem2 == 1 and check > 0:
			dem += 1
			dem2 = 0
		dem2 = 0
print(dem)


input()
A = list(map(int, input().split()))
if 1 not in A:
	print(0)
else:
	id = A.index(1)
	de = 0
	c0 = 0
	for i in A[id:]:
		if i == 0:
			c0 += 1
		else:
			if c0 > 1:
				de += c0
			c0 = 0
	de += c0
	print(len(A) - id - de)


n = int(input())
a = list(map(int, input().split()))
cnt0 = 0
for i in range(1, n - 1):
	if a[i - 1:i + 2] == [1, 0, 1]:
		cnt0 += 1
print(a.count(1) + cnt0)


import sys
n = int(input())
a = list(map(int, sys.stdin.readline().split()))
ans = 0
for i in range(1, n - 1):
	if a[i] == 0:
		if a[i - 1] == 1 and a[i + 1] == 1:
			a[i] = 1
print(sum(a))


def func(s):
	if len(s) < 3:
		return sum(s)
	k = 0
	for i in range(1, len(s) - 1):
		if s[i] == 0:
			if s[i - 1] == s[i + 1] == 1:
				k += 1
	return sum(s) + k
n = int(input())
s = list(map(int, input().split()))
print(func(s))


import itertools as it
import functools
import operator
import collections
import math
import sys

def solve(xs):
	ys = it.dropwhile(lambda x: x == 0, reversed(list(it.dropwhile(lambda x: x == 0, reversed(xs)))))
	zs = [(x, sum((1 for _ in iterable))) for (x, iterable) in it.groupby(ys)]
	print('zs =', zs, file=sys.stderr)
	return sum((cnt for (x, cnt) in zs if not (x == 0 and cnt > 1)))

def main():
	n = int(input())
	xs = [int(i) for i in input().strip().split()]
	assert len(xs) == n
	result = solve(xs)
	print(result)
main()


n = input()
s = input().replace(' ', '')
while s.find('101') != -1:
	s = s.replace('101', '111')
s = s.replace('0', '')
print(len(s))


n = int(input())
a = input().split()
tmp_count = 0
prev_sum = 0
for i in a:
	i = int(i)
	if i == 0:
		if tmp_count == 0:
			continue
		else:
			prev_sum += 1
	elif prev_sum == 1:
		tmp_count += 2
		prev_sum = 0
	else:
		prev_sum = 0
		tmp_count += 1
print(str(tmp_count))


def readProblem():
	n = int(input())
	A = [int(x) for x in input().strip().split()]
	return (n, A)

def indexOf00(A):
	for i in range(len(A) - 1):
		if A[i] == 0 and A[i + 1] == 0:
			return i
	return -1

def rem00AndTrail(A):
	i = indexOf00(A)
	if i == -1:
		return A
	j = i + 2
	while j < len(A) and A[j] == 0:
		j += 1
	A = A[0:i] + A[j:]
	return A

def solve(p):
	(n, A) = p
	while len(A) > 0 and A[0] == 0:
		A = A[1:]
	while len(A) > 0 and A[-1] == 0:
		A = A[:-1]
	while True:
		l = len(A)
		A = rem00AndTrail(A)
		if l == len(A):
			break
	return len(A)
r = solve(readProblem())
print(r)


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
for i in range(n):
	if i > 0 and i < n - 1 and (a[i] == 0) and (a[i - 1] == 1) and (a[i + 1] == 1):
		ans += 1
	if a[i] == 1:
		ans += 1
print(ans)


n = int(input())
list = [int(i) for i in input().split()]
list.insert(0, 0)
list.append(0)
dem = 0
for i in range(0, n + 1):
	if list[i] == 1:
		dem += 1
	elif list[i - 1] == 1 and list[i + 1] == 1:
		dem += 1
print(dem)


n = int(input())
a = list(map(int, input().split()))
ans = 0
for (i, e) in enumerate(a):
	if e == 1:
		ans += 1
	elif i < len(a) - 1 and i > 0 and (a[i + 1] == 1) and (a[i - 1] == 1):
		ans += 1
print(ans)


n = int(input())
array = list(map(int, input().split()))
count = sum(array)
for i in range(1, n - 1):
	if array[i] == 0 and array[i - 1] == 1 and (array[i + 1] == 1):
		count += 1
print(count)


n = int(input())
a = [int(i) for i in input().split()]
for i in range(1, n - 1):
	if a[i] == 0 and a[i - 1] == 1 and (a[i + 1] == 1):
		a[i] = 1
print(sum(a))


n = int(input())
l = list(map(int, input().split()))
ans = 0
for i in range(n):
	if l[i] == 1:
		ans += 1
	elif 0 < i < n - 1 and l[i - 1] == 1 and (l[i + 1] == 1):
		ans += 1
print(ans)


n = int(input())
line = str(input())
line = line.replace(' ', '')
line = line.replace('101', '111')
line = line.replace('101', '111')
line = line.replace('0', '')
print(len(line))


n = int(input())
c = list(map(int, input().split()))
l = 0
if c.count(1) > 0:
	x = c.index(1)
	k = 0
	for i in range(x, n):
		if c[i] == 1:
			l += 1
			if k == 1:
				l += 1
			k = 0
		else:
			k += 1
print(l)


n = int(input())
arr = [int(x) for x in input().split()]

def calc():
	count = 0
	(first, last) = [-1, -1]
	for j in range(n):
		if arr[j] == 1:
			first = j
			break
	for j in range(n - 1, -1, -1):
		if arr[j] == 1:
			last = j
			break
	if first == -1:
		print(0)
		return
	if last == -1:
		print(0)
		return
	i = first
	while i <= last:
		if arr[i] == 1:
			count += 1
		if arr[i] == 0:
			j = i
			count2 = 0
			while arr[j] == 0:
				count2 += 1
				j += 1
			if count2 == 1:
				count += 1
			else:
				i += count2 - 1
		i += 1
	print(count)
calc()


import re
N = int(input())
S = input()
S = S.replace(' ', '')
S = S.strip('0')
ret = 0
for seg in re.split('00+', S):
	ret += len(seg)
print(ret)


n = int(input())
x = [int(q) for q in input().split()]
for i in range(2, n):
	if x[i] == 1 and x[i - 1] == 0 and (x[i - 2] == 1):
		x[i - 1] = 1
print(x.count(1))


input()
A = input().replace(' ', '').strip('0')
while '000' in A:
	A = A.replace('000', '00')
print(len(A.replace('00', '')))


n = int(input())
arr = list(map(int, input().split()))
start = end = -1
for i in range(n):
	if arr[i] == 1:
		start = i
		break
for i in range(n - 1, -1, -1):
	if arr[i] == 1:
		end = i
		break
if start == end == -1:
	print(0)
elif start == end:
	print(1)
else:
	i = start + 1
	counter = 0
	while i < end:
		count = 0
		if arr[i] == 0:
			while arr[i] == 0:
				count += 1
				i += 1
		else:
			i += 1
		if count >= 2:
			counter += count
	print(end - start + 1 - counter)


from sys import stdin, stdout
n = int(stdin.readline())
nulls = float('inf')
result = 0
for a in map(int, stdin.readline().split()):
	if a:
		result += 2 if 0 < nulls < 2 else 1
		nulls = 0
	else:
		nulls += 1
print(result)


input()
a = ''.join(input().split())
while '101' in a:
	a = a.replace('101', '111')
print(sum(map(int, a)))


n = int(input())
x = list(map(int, input().split()))
ans = x.count(1)
for i in range(1, n):
	if i == n - 1:
		break
	if x[i] == 0 and x[i - 1] == 1 and (x[i + 1] == 1):
		ans += 1
print(ans)


n = int(input())
s = [int(x) for x in input().split()]
(p, o) = (0, 0)
for i in range(n):
	if s[i]:
		p += 1
		o = 1
	elif not o:
		continue
	elif i < n - 1:
		if s[i + 1] and s[i - 1]:
			p += 1
print(p)


import sys
from sys import stdin, stdout
n = int(input())
ll = [int(x) for x in stdin.readline().rstrip().split()]
count = 0
idx = -1
for i in ll:
	idx = idx + 1
	if i == 1:
		count += 1
	if idx > 0 and idx < len(ll) - 1:
		if ll[idx - 1] == 1 and ll[idx] == 0 and (ll[idx + 1] == 1):
			count += 1
stdout.write(str(count) + '\n')


from sys import stdin
n = int(stdin.readline().strip())
s = list(map(int, stdin.readline().strip().split()))
s1 = []
ans = 0
for i in range(n):
	if s[i] == 1:
		s1.append(i)
ans = 0
if len(s1) >= 1:
	ans += 1
for i in range(1, len(s1)):
	if s1[i] - s1[i - 1] >= 3:
		ans += 1
	else:
		ans += s1[i] - s1[i - 1]
print(ans)


def dvoiki(a, b):
	global d
	d = [1] + d + [1]
	f = 0
	i = a + 1
	while i < b + 1:
		if d[i] == 0 and d[i + 1] == d[i - 1] == 1:
			f += 1
		i += 1
	return f
n = int(input())
d = list(map(int, input().split()))
if set(d) == {0}:
	print(0)
	exit()
a = d.index(1)
d = d[::-1]
b = n - 1 - d.index(1)
d = d[::-1]
print(b - a + 1 + dvoiki(a, b) - d[a + 1:b + 2].count(0))


n = int(input())
l = list(map(int, input().split()))
if 1 not in l:
	print(0)
	exit()
ind = l.index(1)
ind2 = l[::-1].index(1)
co = 0
ans = 0
for i in range(ind, n - ind2):
	if l[i] == 1:
		ans += 1
		if co < 2:
			ans += co
		co = 0
	else:
		co += 1
print(ans)


N = int(input())
A = list(map(int, input().split()))
total = 0
for i in range(N):
	if A[i] == 1:
		total += 1
	elif total > 0:
		if (i - 1 >= 0 and A[i - 1] == 1) and (i + 1 < N and A[i + 1] == 1):
			total += 1
print(total)


n = int(input())
s = list(map(int, input().split()))
if n == 1:
	if 0 in s:
		print(0)
	else:
		print(1)
else:
	i = 0
	while i < len(s) and s[i] == 0:
		i += 1
	s = s[i:]
	if len(s) == 0:
		print(0)
	else:
		i = len(s) - 1
		while i >= 0 and s[i] == 0:
			i -= 1
		s = s[:i + 1]
		x = len(s)
		if x == 0:
			print(0)
		else:
			s = [str(i) for i in s]
			s = ''.join(s)
			s = s.split('1')
			count = 0
			for i in s:
				if len(i) > 1:
					count += len(i)
			print(x - count)


n = int(input())
list = [int(item) for item in input().split()]
count = 0
i = 0
if list.__contains__(1):
	i = list.index(1)
while i < len(list):
	if list[i] == 1:
		count += 1
		i += 1
	elif i < len(list) - 1 and list[i + 1] == 0 or i == len(list) - 1:
		if list[i:].__contains__(1):
			i = list.index(1, i, len(list))
		else:
			i = len(list)
	else:
		count += 1
		i += 1
print(count)


input()
l = list(map(int, input().split()))
while l and l[0] == 0:
	l = l[1:]
while l and l[-1] == 0:
	l = l[:-1]
for i in range(1, len(l) - 1):
	if l[i - 1] == 1 and l[i] == 0 and (l[i + 1] == 1):
		l[i] = 1
print(l.count(1))


n = int(input())
a = input().replace(' ', '')
a += '00'
result = 0
start = 0
count = 0
count0 = 0
for i in range(n + 2):
	if a[i] == '1':
		start = 1
		count += 1
		count0 = 0
	if a[i] == '0' and start == 1:
		count += 1
		count0 += 1
		if count0 == 2:
			result += count - 2
			count0 = 0
			count = 0
			start = 0
result += count
print(result)


def getData():
	line = input()
	line = line.split()
	for i in range(len(line)):
		line[i] = int(line[i])
	return line
n = int(input())
sc = getData()
time = 0
i = 0
while i < len(sc):
	if i == 0:
		while sc[i] == 0 and i < len(sc) - 1:
			i += 1
	if sc[i] == 1:
		time += 1
		i += 1
	elif sc[i] == 0 and i < len(sc) - 1:
		if sc[i + 1] == 1:
			time += 1
			i += 1
		else:
			while sc[i] == 0 and i < len(sc) - 1:
				i += 1
	else:
		break
print(time)


from collections import deque as de
import math
from collections import Counter as cnt
from functools import reduce
from typing import MutableMapping

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))
n = int(input())
a = list(map(int, input().split()))
ans = a.count(1)
for i in range(n - 2):
	if a[i] == 1:
		if a[i + 1] == 0 and a[i + 2] == 1:
			ans += 1
print(ans)


input()
x = list(map(int, input().split()))
for i in range(200):
	for j in range(1, len(x) - 1):
		if x[j - 1] == x[j + 1] == 1:
			x[j] = 1
print(sum(x))


import re
n = int(input())
l = input().replace(' ', '').strip('0')
l = re.sub('0{2,}', '', l)
print(len(l))


def days(schedule):
	if len(schedule) == 0:
		return 0
	if len(schedule) == 1:
		if schedule[0] == 0:
			return 0
		else:
			return 1
	elif schedule[0] == 0:
		if schedule[1] == 1:
			return 1 + days(schedule[1:])
		elif 1 in schedule:
			return days(schedule[schedule.index(1):])
		else:
			return days([])
	else:
		return 1 + days(schedule[1:])
n = int(input())
schedule = [int(i) for i in input().split()]
if 1 in schedule:
	print(days(schedule[schedule.index(1):]))
else:
	print(0)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	a = LI()
	s = -1
	t = -1
	r = 0
	for i in range(n):
		if a[i] == 1:
			if s < 0:
				s = i
				t = i
			elif i - t > 2:
				r += t - s + 1
				s = i
				t = i
			else:
				t = i
	if s >= 0:
		r += t - s + 1
	return r
print(main())


(n, count) = (int(input()), 0)
a = []
a = input().split()
for i in range(0, n):
	a[i] = int(a[i])
for i in range(0, n):
	if a[i] == 1:
		count += 1
	elif a[i] == 0 and i - 1 >= 0 and (a[i - 1] == 1) and (i + 1 < n) and (a[i + 1] == 1):
		count += 1
print(count)


n = int(input())
a = list(map(int, input().split())) + [0]
home = True
ans = 0
for i in range(n):
	if a[i]:
		ans += 1
		home = False
	elif not a[i + 1] and (not home):
		home = True
	elif not home:
		ans += 1
print(ans)


import time
n = int(input())
fp = True
np = 0
b = 0
for p in input().split():
	p = int(p)
	if p == 0:
		if fp:
			continue
		b += 1
	else:
		if fp:
			fp = False
			np += 1
			continue
		if b == 1:
			np += 2
		else:
			np += 1
		b = 0
print(np)


n = int(input())
a = list(map(int, input().split()))
(x, y) = (0, 0)
z = 0
for i in range(n):
	if a[i] == 1:
		z = i
		break
a = a[i:]
for i in range(len(a)):
	if a[i] == 1:
		if x == 1:
			y += 2
		else:
			y += 1
		x = 0
	else:
		x += 1
print(y)


n = int(input())
s = [int(x) for x in input().split(' ')]
for i in range(1, n - 1):
	if s[i - 1:i + 2] == [1, 0, 1]:
		s[i] = 1
print(sum(s))


n = int(input().strip())
ans = 0
pairs = list(map(int, input().split()))
curr_old = 10000000000
for i in range(n):
	if pairs[i] == 1:
		ans += 1
		if i - curr_old == 2:
			ans += 1
		curr_old = i
print(ans)


n = int(input())
schdl = list(map(int, input().split()))
for i in range(1, n - 1):
	if schdl[i - 1] == 1 and schdl[i + 1] == 1:
		schdl[i] = 1
u = 0
for i in schdl:
	if i == 1:
		u += 1
print(u)


n = int(input(''))
classes = input('').split(' ')
count = 0
for j in range(n - 2):
	if classes[j] == '1' and classes[j + 1] == '0' and (classes[j + 2] == '1'):
		count = count + 1
print(count + classes.count('1'))


n = int(input())
l = list(map(str, input().split()))
k = ''.join(l)
k = k.lstrip('0')
k = k.rstrip('0')
for i in range(n, 1, -1):
	k = k.replace('0' * i, '')
print(len(k))


from collections import Counter

def mp():
	return map(int, input().split())

def lt():
	return list(map(int, input().split()))

def pt(x):
	print(x)

def ip():
	return input()

def it():
	return int(input())

def sl(x):
	return [t for t in x]

def spl(x):
	return x.split()

def aj(liste, item):
	liste.append(item)

def bin(x):
	return '{0:b}'.format(x)
n = it()
s = input()
print(s.count('1') + sum([s[i:i + 5] == '1 0 1' for i in range(len(s))]))


n = int(input())
s = ''.join(input().split())
s = s.replace('00', ' ')
while s and s[0] == '0':
	s = s[1:]
while s and s[-1] == '0':
	s = s[:-1]
l = 0
for x in s.split():
	while x[0] == '0':
		x = x[1:]
	l += len(x)
print(l)


n = int(input())
pairs = list(map(int, input().split()))
if 1 in pairs:
	first = pairs.index(1)
	last = pairs[::-1].index(1)
	pairs = pairs[first:n - last]
	total = 0
	for i in range(len(pairs) - 1):
		if pairs[i] == 0 and pairs[i + 1] == 1 and (pairs[i - 1] == 1):
			total += 1
	total += pairs.count(1)
	print(total)
else:
	print(0)


n = int(input())
L = list(map(int, input().split()))
r = 0
d = 0
for k in range(n):
	if L[k] == 1:
		r += 1
		d = 1
	elif k < n - 1:
		if L[k + 1] == 1 and d == 1:
			r += 1
		else:
			d = 0
print(r)


n = int(input())
ps = input().split()
i = 0
while i < n and ps[i] == '0':
	i += 1
j = -1
while -j <= n and ps[j] == '0':
	j -= 1
free = 0
r = 0
for p in ps[i:n + j + 1]:
	if p == '0':
		if free == 0:
			r += 1
		elif free == 1:
			r -= 1
		else:
			pass
		free += 1
	else:
		free = 0
		r += 1
print(r)


n = int(input())
l = list(map(int, input().split()))
k = 0
if l[0] == 0:
	k = 1
for i in range(1, n - 1):
	if l[i] == 0 and l[i - 1] == 0 or (l[i] == 0 and l[i + 1] == 0):
		k = k + 1
if l[n - 1] == 0 and n >= 2:
	k = k + 1
print(n - k)


n = int(input())
l = ''.join(input().split()).replace('101', '111')
l = l.replace('101', '111')
print(len(l.replace('0', '')))


n = int(input())
a = list(map(int, input().split(' ')))
while len(a) > 0 and a[0] == 0:
	a.pop(0)
while len(a) > 0 and a[len(a) - 1] == 0:
	a.pop(len(a) - 1)
c = 0
skip = False
for i in range(len(a)):
	if a[i] == 1:
		skip = False
	if a[i] == 0 and a[i + 1] == 0:
		skip = True
	if not skip:
		c += 1
print(c)


n = int(input())
mas = list(map(int, input().split(' ')))
p = 0
res = 0
for i in range(n):
	if mas[i] == 0:
		if i > 0 and i < n - 1:
			if mas[i - 1] == 1 and mas[i + 1] == 1:
				mas[i] = 1
print(sum(mas))


n = input()
s = input()
ans = s.count('1') + sum((s[i:i + 5] == '1 0 1' for i in range(len(s))))
print(ans)


n = int(input())
arr = list(map(int, input().split()))
for i in range(200):
	for j in range(1, len(arr) - 1):
		if arr[j - 1] == arr[j + 1] == 1:
			arr[j] = 1
print(sum(arr))


import sys

def solve(v, n):
	start = n
	for i in range(n):
		if v[i] == 1:
			start = i
			break
	end = -1
	for i in range(n - 1, -1, -1):
		if v[i] == 1:
			end = i + 1
			break
	resp = end - start
	if resp > 1:
		zeros = 0
		maximum = 0
		for i in range(start, end):
			if v[i] == 0:
				zeros += 1
			else:
				if zeros >= 2:
					resp -= zeros
				zeros = 0
	return max(resp, 0)
n = int(input())
line = input()
v = [int(x) for x in line.split()]
print(solve(v, n))


n = int(input())
a = list(map(int, input().split()))
cnt = n
z = 0
for i in range(n):
	if a[i] == 0:
		z += 1
	else:
		if z >= 2:
			cnt -= z
		z = 0
cnt -= z
if len(a) > 1 and a[0] == 0 and (a[1] == 1):
	cnt -= 1
print(cnt)


n = int(input())
less = input().split()
jum = 0
if less[0] == '1':
	jum += 1
if n > 1:
	if less[n - 1] == '1':
		jum += 1
	for i in range(1, n - 1):
		if less[i] == '1':
			jum += 1
		elif less[i] == '0' and less[i + 1] == '1' and (less[i - 1] == '1'):
			jum += 1
print(jum)


__author__ = 'pxy'
n = int(input())
g = [int(j) for j in input().split()]
b = 0
t = 0
for z in g:
	if z == 1:
		if b >= 2 and t > 0:
			t += 1 - b
		else:
			t += 1
		b = 0
	else:
		b += 1
		if t > 0:
			t += 1
if t == 0:
	print(0)
else:
	print(t - b)


from sys import stdin
live = True
if not live:
	stdin = open('data.in', 'r')
n = int(stdin.readline())
numbers = list(map(int, stdin.readline().strip().split()))
numbers += [0]
ans = 0
isToHome = True
for it in range(n):
	if isToHome:
		if numbers[it] != 0:
			isToHome = False
			ans += 1
	elif numbers[it] == 1:
		ans += 1
	elif numbers[it + 1] == 0:
		isToHome = True
	else:
		ans += 1
print(ans)
if not live:
	stdin.close()


n = int(input())
a = [int(i) for i in input().split(' ')]
was_one = False
res = sum(a)
zeros = 0
for i in a:
	if i == 1:
		was_one = True
		if zeros == 1:
			res += 1
		zeros = 0
	if was_one and i == 0:
		zeros += 1
print(res)


n = int(input())
pairs = [int(pair) for pair in input().split()]
i = 0
while i < len(pairs) and pairs[i] == 0:
	i += 1
pairs = pairs[i:]
i = len(pairs) - 1
if 0 <= i < len(pairs):
	while pairs[i] == 0:
		i -= 1
	pairs = pairs[:i + 1]
zero_count = 0
ans = 0
for i in range(len(pairs)):
	if pairs[i] == 1:
		ans += 1
		zero_count = 0
	elif pairs[i] == 0:
		zero_count += 1
		if zero_count == 1:
			ans += 1
		if zero_count == 2:
			ans -= 1
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
ans = l.count(1)
seen = 0
for i in range(n):
	if l[i] == 0 and seen:
		c += 1
	elif l[i] == 1:
		if seen == 0:
			seen = 1
			c = 0
		else:
			if c == 1:
				ans += 1
			c = 0
print(ans)


n = int(input())
x = input().replace(' ', '').strip('0')
(i, count) = (0, 0)
while i < len(x):
	if x[i] == '0' and x[i - 1] == '0':
		while x[i - 1] == '0':
			count += 1
			i += 1
	else:
		i += 1
print(len(x) - count)


n = int(input())
lession = [int(x) for x in input().split()]
l = -1
r = -1
for i in range(n):
	if lession[i] == 1:
		l = i
		break
for i in range(n - 1, -1, -1):
	if lession[i] == 1:
		r = i
		break
if l == -1 and r == -1:
	print(0)
	exit()
res = r + 1 - l
i = l
tmp = 0
while i <= r:
	if lession[i] == 0:
		tmp += 1
	else:
		if tmp >= 2:
			res -= tmp
		tmp = 0
	i += 1
print(res)


__author__ = 'yarsanich'
n = int(input(''))
a = list(map(int, input('').split()))
ans = 0
for i in range(n):
	if a[i] == 1:
		ans += 1
a.append(1)
start = a.index(1)
if start != n:
	for i in range(start, n - 1):
		if a[i] == 0 and a[i + 1] != 0 and (a[i - 1] != 0):
			ans += 1
	print(ans)
else:
	print(0)


n = int(input())
l = input().split()
s = l.count('1')
i = 0
while i < n:
	if l[i] == '0':
		if i + 1 < n and l[i + 1] == '1':
			if i > 0 and l[i - 1] == '1':
				s += 1
	i += 1
print(s)


n = int(input())
lst = list(map(int, input().split()))
s = 0
ans = 0
where = 0
for i in range(n):
	if lst[i] == 1:
		ans += 1
		where = 1
	if lst[i] == 0 and i != 0:
		if i + 1 < n and lst[i + 1] == 0:
			where = 0
		elif i + 1 < n:
			if where == 1:
				ans += 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
l += [0, 0, 0, 0]
start = 0
end = n
while start < n and l[start] == 0:
	start += 1
while end >= 0 and l[end] == 0:
	end -= 1
p = 0
i = start
while i <= end:
	if l[i] == 1:
		p += 1
	elif l[i + 1] == 0:
		while l[i + 1] == 0:
			i += 1
	else:
		p += 1
	i += 1
print(p)


import sys
size = int(input())
list = list(map(int, input().split()))
if 1 not in list:
	print(0)
	sys.exit()
counter = 0
pos = list.index(1)
flag = 0
for i in range(pos, size):
	if list[i] == 1:
		counter += 1
	elif list[i] == 0:
		if i != size - 1:
			if list[i + 1] == 0 and flag == 0:
				flag = 1
				continue
			elif list[i + 1] == 1 and flag == 0:
				counter += 1
			elif list[i + 1] == 1 and flag == 1:
				flag = 0
print(counter)


n = int(input())
schedule = [int(i) for i in input().split()]
pos = 0
time = 0
while pos < len(schedule) and schedule[pos] == 0:
	pos += 1
if pos == len(schedule):
	pass
else:
	time = 1
	pos += 1
	while True:
		if pos == len(schedule):
			break
		elif schedule[pos] == 1:
			time += 1
			pos += 1
		elif pos == len(schedule) - 1:
			break
		elif schedule[pos + 1] == 1:
			time += 2
			pos += 2
		else:
			while pos < len(schedule) and schedule[pos] == 0:
				pos += 1
print(time)