Each day in Berland consists of $n$ hours. Polycarp likes time management. That's why he has a fixed schedule for each day — it is a sequence $a_1, a_2, \dots, a_n$ (each $a_i$ is either $0$ or $1$), where $a_i=0$ if Polycarp works during the $i$-th hour of the day and $a_i=1$ if Polycarp rests during the $i$-th hour of the day.

Days go one after another endlessly and Polycarp uses the same schedule for each day.

What is the maximal number of continuous hours during which Polycarp rests? It is guaranteed that there is at least one working hour in a day.


-----Input-----

The first line contains $n$ ($1 \le n \le 2\cdot10^5$) — number of hours per day.

The second line contains $n$ integer numbers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 1$), where $a_i=0$ if the $i$-th hour in a day is working and $a_i=1$ if the $i$-th hour is resting. It is guaranteed that $a_i=0$ for at least one $i$.


-----Output-----

Print the maximal number of continuous hours during which Polycarp rests. Remember that you should consider that days go one after another endlessly and Polycarp uses the same schedule for each day.


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

Output
2

Input
6
0 1 0 1 1 0

Output
2

Input
7
1 0 1 1 1 0 1

Output
3

Input
3
0 0 0

Output
0



-----Note-----

In the first example, the maximal rest starts in last hour and goes to the first hour of the next day.

In the second example, Polycarp has maximal rest from the $4$-th to the $5$-th hour.

In the third example, Polycarp has maximal rest from the $3$-rd to the $5$-th hour.

In the fourth example, Polycarp has no rest at all.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
n = int(input())
a = list(map(int, input().split()))
a += a
i = 0
maxx = 0
while i < 2 * n:
	cnt = 0
	if a[i] == 0:
		i += 1
		continue
	while i < 2 * n and a[i] == 1:
		cnt += 1
		i += 1
	maxx = max(cnt, maxx)
print(maxx)


n = int(input())
l = list(map(int, input().split()))
c = 0
m = 0
for i in range(2 * n):
	if l[i % n] == 1:
		c = c + 1
		m = max(m, c)
	elif l[i % n] == 0:
		c = 0
print(m)


n = int(input())
a = input().split()
a = a + a
be = 0
cnt = 0
res = 0
for x in a:
	if x == '1':
		if be == 1:
			cnt += 1
		else:
			cnt = 1
		be = 1
	else:
		res = max(cnt, res)
		cnt = 0
		be = 0
res = max(cnt, res)
print(res)


(n,) = map(int, input().split())
arr = list(map(int, input().split()))
ans = 0
maxi = 0
for i in range(n):
	if arr[i] == 1:
		ans += 1
	elif arr[i] == 0:
		maxi = max(ans, maxi)
		ans = 0
pre = 0
suf = 0
for i in range(n):
	if arr[i] == 1:
		pre += 1
	else:
		break
for i in reversed(range(n)):
	if arr[i] == 1:
		suf += 1
	else:
		break
print(max(pre + suf, maxi))


n = input()
arr = [int(j) for j in input().split()]
count = []
if arr[0] == 1:
	temp = 1
else:
	temp = 0
for i in range(1, len(arr)):
	if arr[i] == 0 and arr[i - 1] == 1:
		count.append(temp)
		temp = 0
	if arr[i] == 1:
		temp = temp + 1
count.append(temp)
max = 0
for i in count:
	if i > max:
		max = i
if len(count) > 1 and arr[0] == 1 and (arr[len(arr) - 1] == 1):
	if max < count[0] + count[len(count) - 1]:
		max = count[0] + count[len(count) - 1]
print(max)


input()
print(max(map(lambda i: len(i), (input().replace(' ', '') * 2).split('0'))))


n = int(input())
l1 = list(map(int, input().split()))
rest = 0
reststart = 0
restend = 0
flag = 0
temp = 0
for i in range(0, n):
	if flag == 0:
		if l1[i] == 1:
			if i == 0:
				flag = 2
			else:
				flag = 1
			temp += 1
	elif l1[i] == 1:
		temp += 1
	else:
		if flag == 2:
			reststart = temp
		rest = max(rest, temp)
		flag = 0
		temp = 0
if l1[n - 1] == 1:
	restend = temp
print(max(rest, reststart + restend))


def solve(n, flags):
	result = 0
	k = 0
	sub_result = 0
	first_time = True
	for ele in flags:
		if ele == 1:
			sub_result += 1
		else:
			result = max(result, sub_result)
			sub_result = 0
			if first_time:
				k = result
			first_time = False
	if ele == 1:
		result = max(result, sub_result + k)
	return result

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


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

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

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7
N = INT()
A = LIST()
A += A
cnt = mx = 0
for i in range(N * 2):
	if A[i] == 1:
		cnt += 1
	else:
		mx = max(mx, cnt)
		cnt = 0
mx = max(mx, cnt)
print(mx)


N = map(int, input().split())
L = list(map(int, input().split()))
ans = 0
ctr = 0
for l in L * 2:
	if not l:
		ans = max(ans, ctr)
		ctr = 0
	else:
		ctr += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
a = a * 2
s = 0
s1 = 0
for i in range(len(a) - 1):
	if a[i] != 0:
		s1 += 1
		s = max(s, s1)
	else:
		s1 = 0
print(s)


Nhour = int(input())
sequence = input()
sequenceSelection = []
if sequence[0] == sequence[len(sequence) - 1] == '1':
	sequence = sequence.split('0')
	for i in range(1, len(sequence) - 1):
		sequenceSelection.append(sequence[i])
	new = sequence[0] + sequence[len(sequence) - 1]
	sequenceSelection.append(new)
else:
	sequence = sequence.split('0')
	for item in sequence:
		if '1' in item:
			sequenceSelection.append(item)
max1 = 0
for item in sequenceSelection:
	max2 = 0
	for i in range(0, len(item)):
		if item[i] == '1':
			max2 += 1
		if max2 > max1:
			max1 = max2
print(max1)


hours = int(input())
crono = input().split()
if '1' not in crono:
	print(0)
else:
	maximum = 0
	aux = 0
	for elemento in crono:
		if elemento == '1':
			aux += 1
		else:
			maximum = max(maximum, aux)
			aux = 0
	if crono[0] == '1' or crono[-1] == '1':
		index = 0
		while crono[index] == '1':
			aux += 1
			index += 1
	maximum = max(maximum, aux)
	print(maximum)


n = input()
a = [int(x) for x in input().split()]
a *= 2
rec = []
cnt = 0
for i in range(len(a)):
	if a[i]:
		cnt += 1
	else:
		rec.append(cnt)
		cnt = 0
print(max(rec))


n = int(input())
s = input()
s = s * 2
s = s.replace(' ', '')
s = s.split('0')
print(max(map(len, s)))


n = int(input())
a = list(map(int, input().split()))
b = a + a
count = int(0)
maxcount = 0
for i in b:
	if i == 1:
		count = count + 1
	else:
		maxcount = max(maxcount, count)
		count = 0
print(maxcount)


n = int(input())
schedule = input().split()
new_schedule = schedule.copy()
schedule = schedule + new_schedule
counter = 0
max_count = 0
for k in range(2 * n):
	if int(schedule[k]) == 1:
		counter += 1
		if counter > max_count:
			max_count = counter
	else:
		counter = 0
print(max_count)


t = int(input())
a = list(map(int, input().split()))
from itertools import groupby
l = a + a
z = [len(list(g[1])) for g in groupby(l) if g[0] == 1]
if len(z) > 0:
	print(max(z))
else:
	print(0)


n = int(input())
a = list(map(int, input().split()))
ta = a + []
for i in range(n):
	if not ta[i]:
		a += [1] * i
		break
for i in range(-1, -n - 1, -1):
	if not ta[i]:
		a = [1] * (-i - 1) + a
		break
co = a[0]
cm = co
for i in range(1, n):
	if a[i] and a[i - 1]:
		co += 1
	else:
		co = a[i]
	cm = max(cm, co)
print(cm)


n = int(input())
arr = list(input().split())
ans = int(0)
Len = len(arr)
for i in range(0, Len):
	arr.append(arr[i])
for i in range(0, Len):
	arr.append(arr[i])
cnt = int(0)
for i in arr:
	if i == '1':
		cnt += 1
	else:
		cnt = 0
	ans = max(ans, cnt)
print(ans)


import sys

def input():
	return sys.stdin.readline().strip()

def print(*x, sep=' ', end='\n'):
	return sys.stdout.write(sep.join(map(str, x)) + end)

def read():
	return sys.stdin.read()

def get():
	return (int(input()), [int(i) for i in input().split()])

def out(*arg):
	if type(arg[0]) == list:
		for i in arg[0]:
			print(i)
	else:
		print(arg)

def main():
	(n, a) = get()
	bock_l = 0
	bock_r = 0
	at_all = 0
	c = 0
	while a[c] == 1:
		bock_l += 1
		c += 1
	c = n - 1
	while a[c] == 1:
		bock_r += 1
		c -= 1
	counter = 0
	for i in range(n):
		if a[i] == 0:
			at_all = max(at_all, counter)
			counter = 0
		else:
			counter += 1
	print(max(bock_l + bock_r, at_all))
main()


n = int(input())
schedule = [int(a) for a in input().split()]
flag = False
aux = 0
m = 0
j = 0
for i in range(2 * n):
	if schedule[j] == 1:
		aux += 1
	else:
		if aux > m:
			m = aux
		aux = 0
	if j == n - 1:
		j = 0
	else:
		j += 1
print(m)


n = int(input())
p = list(map(int, input().split()))
p = p + p
max = 0
q = 0
for i in range(2 * n):
	if p[i] == 1:
		q += 1
		continue
	else:
		if q > max:
			max = q
		q = 0
print(max)


n = int(input())
ar = list(map(int, input().split()))
ans = 0
c = 0
ar += ar
for i in ar:
	if i == 1:
		c += 1
	else:
		c = 0
	ans = max(c, ans)
print(ans)


def problem_1141b():
	n = int(input())
	input_list = input().split(' ')
	for (i, _) in enumerate(input_list):
		input_list[i] = int(input_list[i])
	for _ in range(n):
		input_list.append(0)
	for i in range(n, 2 * n - 1):
		input_list[i] = input_list[i - n]
	count = 0
	answer = 0
	for i in range(2 * n):
		if input_list[i] == 1:
			count += 1
			answer = max(answer, count)
		else:
			count = 0
	print(answer)
	return
problem_1141b()


n = input()
l = list(map(int, input().split()))
s = l + l
ans = 0
tmp = 0
for i in s:
	if i == 1:
		tmp += 1
	else:
		if tmp > ans:
			ans = tmp
		tmp = 0
print(ans)


n = int(input())
a = list(map(int, input().split()))
b = a * 3
rez = 0
mx = 0
for x in b:
	if x == 1:
		rez += 1
	else:
		if rez > mx:
			mx = rez
		rez = 0
print(mx)


n = input()
a = list(map(int, input().split()))
(m, k) = (0, 0)
for x in a:
	if x == 1:
		k += 1
	else:
		if k > m:
			m = k
		k = 0
k += a.index(0)
if k > m:
	m = k
print(m)


n = int(input())
inp = input()
a = [int(ele) for ele in inp.split()]
pos = []
for i in range(len(a)):
	if a[i] == 0:
		pos.append(i)
diff = 0
for i in range(len(pos) - 1):
	if pos[i + 1] - pos[i] - 1 > diff:
		diff = pos[i + 1] - pos[i] - 1
diff2 = len(a) - (pos[-1] - pos[0]) - 1
if diff2 > diff:
	print(diff2)
else:
	print(diff)


from sys import exit
n = int(input())
a = [int(i) for i in input().split()]
mx = 0
nx = 0
st = 0
while a[st] != 0:
	st += 1
for i in range(n):
	if a[(st + i) % n] == 1:
		nx += 1
	else:
		mx = max(nx, mx)
		nx = 0
mx = max(nx, mx)
print(mx)


x = int(input())
os = input()
rs = os.replace(' ', '') * 2
s = rs.split('0')
k = max = 0
for i in s:
	k = len(i)
	if k > max:
		max = k
print(max)


n = int(input())
a = list(map(int, input().split()))
count = 0
maximo = 0
for i in range(n * 2):
	if a[i % n]:
		count += 1
		maximo = max(maximo, count)
	else:
		count = 0
print(maximo)


N = int(input())
a = input()
a = a + a
print(max(list(map(len, ''.join(a.split()).split('0')))))


n = int(input())
a = input().split(' ')
rest = []
k = 0
for j in range(0, 2):
	for i in range(0, n):
		if int(a[i]) == 1:
			k = k + 1
		if int(a[i]) == 0:
			rest.append(k)
			k = 0
print(max(rest))


r = []
n = int(input())
a = map(int, input().split())
x = list(a) * 2
rest = 0
if 1 not in x:
	print(0)
else:
	for i in x:
		if i == 1:
			rest += 1
			r.append(rest)
		elif i == 0:
			rest = 0
	print(max(r))


def main():
	dayHrs = int(input())
	scheduleRaw = input().split(' ')
	schedule = [int(x) for x in scheduleRaw]
	schedule += schedule
	max = 0
	i = 0
	while i < dayHrs:
		if schedule[i] == 0:
			i += 1
		else:
			temp_rest = 0
			while schedule[i] != 0:
				temp_rest += 1
				i += 1
			if temp_rest > max:
				max = temp_rest
	print(max)
main()


n1 = int(input())
n = input().split()
result = 0
count = 0
n += n
for i in range(len(n) - 1):
	if count == 0 and n[i] == '1':
		count += 1
	if n[i] == '1' and n[i] == n[i + 1]:
		count += 1
		if i == len(n) - 2:
			if count > result:
				result = count
	else:
		if count > result:
			result = count
		if count > 0:
			count = 1
print(result)


n = int(input())
a = [int(x) for x in input().split(' ')]
a.extend(a)
for i in range(1, len(a)):
	a[i] += a[i - 1] if a[i] != 0 else 0
print(max(a))


n = int(input())
A = list(map(int, input().split()))
f = 0
now = 0
t = 0
ans = 0
for i in range(n):
	if A[i] == 1:
		if t == 0:
			f += 1
		else:
			now += 1
	else:
		if t == 0:
			t = 1
		if now > 0:
			ans = max(now, ans)
			now = 0
print(max(ans, f + now))


n = int(input())
a = list(map(int, input().split()))
b1 = 0
otd1 = 1
otd = 1
if a.count(1) == 1:
	print(1)
elif a.count(1) == 0:
	print(0)
else:
	if n > 1:
		for ii in range(2):
			for i in a:
				if i == 1:
					if i == b1:
						otd1 += 1
						if otd < otd1:
							otd = otd1
					else:
						otd1 = 1
				b1 = i
	else:
		for i in a:
			if i == 1:
				if i == b1:
					otd1 += 1
					if otd < otd1:
						otd = otd1
				else:
					otd1 = 1
			b1 = i
	print(otd)


from collections import deque
from sys import stdin
(readln, c, m) = (stdin.readline, 0, 0)
dq = deque(maxlen=int(input()))
dq.extend(map(int, readln().split()))
while True:
	t = dq.pop()
	if t == 0:
		break
	dq.appendleft(t)
for t in dq:
	if t == 0:
		(c, m) = (0, max(c, m))
	else:
		c += 1
print(max(c, m))


hours = int(input())
action = list(map(int, input().split())) * 2
serie = max_serie = 0
for i in action:
	if i == 1:
		serie += 1
	else:
		serie = 0
	if serie > max_serie:
		max_serie = serie
print(max_serie)


def solve(a):
	memo = []
	for (i, e) in enumerate(a):
		if i == 0:
			if e == 1:
				memo.append(1)
		elif e == 1:
			if e == a[i - 1]:
				memo[len(memo) - 1] += 1
			else:
				memo.append(1)
	if len(memo) == 0:
		return 0
	c = max(memo)
	d = memo[0] + memo[len(memo) - 1]
	return d if a[0] == 1 and a[len(a) - 1] == 1 and (d > c) else c
n = int(input())
a = [int(x) for x in input().split()]
print(solve(a))


def calculate(hours, n):
	max = 0
	prev = hours[0]
	count = hours[0]
	for i in range(1, n):
		c = 0
		if hours[i] == prev and hours[i] == 1:
			count += 1
			c = count
		else:
			c = count
			count = hours[i]
		if c > max:
			max = c
		prev = hours[i]
	if count > max:
		max = count
	return max
n = int(input())
hours = list(map(int, input().split()))
if hours[0] == 0 or (hours[0] == 1 and hours[n - 1] == 0):
	print(calculate(hours, n))
else:
	m1 = calculate(hours, n)
	count = 0
	prev = 1
	i = 1
	while prev == 1:
		count += 1
		prev = hours[i]
		i += 1
	prev = 1
	i = n - 2
	while prev == 1:
		count += 1
		prev = hours[i]
		i -= 1
	print(max(m1, count))


import sys
input = sys.stdin.readline

def inlt():
	return list(map(int, input().split()))
n = int(input())
a = inlt()
max = 0
somme = 0
a_back = a
for i in range(n):
	a.append(a_back[i])
for i in range(2 * n):
	if a[i] == 1:
		somme += 1
		if somme > max:
			max = somme
	else:
		somme = 0
print(max)


n = int(input())
a = list(map(int, input().split(' ')))
initial = -1
final = n
middle = 0
for i in range(n):
	if a[i] == 1:
		initial = i
	else:
		break
for i in reversed(range(n)):
	if a[i] == 1:
		final = i
	else:
		break
maxn = 0
for i in range(initial + 1, final):
	if a[i] == 1 and a[i - 1] == 1:
		middle += 1
	elif a[i] == 0:
		middle = 0
	else:
		middle = 1
	if middle > maxn:
		maxn = middle
print(max(maxn, initial + 1 + n - final))


n = input()
arr = input().split()
arr = arr + arr
mx = 0
cur = 0
for i in range(0, len(arr)):
	if arr[i] == '1':
		cur = cur + 1
	else:
		if cur > mx:
			mx = cur
		cur = 0
print(mx)


def maxContinual(arr, n):
	maxCount = 0
	count = 0
	l = []
	ind = -1
	for i in range(n):
		if arr[i] == 0:
			ind = i
			break
	if ind == -1:
		return n
	for i in range(ind, n + ind):
		l.append(arr[i % n])
	for i in range(n):
		if l[i] == 1:
			count += 1
		if l[i] == 0:
			maxCount = max(count, maxCount)
			count = 0
	maxCount = max(count, maxCount)
	return maxCount
n = int(input())
arr = list(map(int, input().strip().split(' ')))
print(maxContinual(arr, n))


def solve(n, s):
	s *= 2
	maxi = 0
	cur = 0
	for i in s:
		if i == 1:
			cur += 1
			maxi = max(maxi, cur)
		else:
			cur = 0
	return maxi

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


from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt, sin, cos, ceil, floor
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(1000000000)
INF = float('inf')
(YES, Yes, yes, NO, No, no) = ('YES', 'Yes', 'yes', 'NO', 'No', 'no')
(dy4, dx4) = ([0, 1, 0, -1], [1, 0, -1, 0])
(dy8, dx8) = ([0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1])

def inside(y, x, H, W):
	return 0 <= y < H and 0 <= x < W

def ceil(a, b):
	return (a + b - 1) // b

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	g = gcd(a, b)
	return a / g * b

def euclidean_distance(y1, x1, y2, x2):
	return sqrt((y1 - y2) ** 2 + (x1 - x2) ** 2)

def manhattan_distance(y1, x1, y2, x2):
	return abs(y1 - y2) + abs(x1 - x2)

def main():
	N = int(input())
	A = list(map(int, input().split()))
	A += A + [0]
	ans = 0
	start = -1
	for i in range(len(A)):
		if A[i] == 0:
			if start != -1:
				ans = max(ans, i - start)
				start = -1
		elif start == -1:
			start = i
	print(ans)
main()


input()
print(max(map(len, (input().replace(' ', '') * 2).split('0'))))


n = int(input())
s = list(map(int, input().split(' ')))
max = 0
sf = sl = 0
i = 0
temp = 0
while s[i] != 0:
	sf += 1
	i += 1
i = n - 1
while s[i] != 0:
	sl += 1
	i -= 1
for i in range(len(s) - 1):
	if s[i] == 1:
		temp += 1
		if s[i + 1] != 1:
			if temp > max:
				max = temp
			temp = 0
print(max) if sl + sf < max else print(sl + sf)


n = int(input())
a = [int(i) for i in input().split()] * 2
k = 0
km = 0
for i in range(2 * n - 1):
	if a[i] == 0:
		k = 0
	else:
		k += 1
	km = max(k, km)
print(km)


n = int(input())
a = list(map(int, input().split()))
(ans, ans2, ans1) = (n - 1, 0, 0)
while True:
	if ans < 0 and a[ans] != 1:
		print(max(ans2, ans1))
		exit()
	if a[ans] == 1:
		ans1 += 1
	else:
		ans2 = max(ans2, ans1)
		ans1 = 0
	ans -= 1


n = int(input())
a = ''.join(input().split())
a += a
a = a.split('0')
print(max((len(i) for i in a)))


n = int(input())
a = list(map(int, input().split()))
arr = []
for i in a:
	arr.append(i)
for i in a:
	arr.append(i)
cc = 0
i = 0
ans = 0
while i < 2 * n:
	if arr[i] == 1:
		cc += 1
	else:
		ans = max(cc, ans)
		cc = 0
	i += 1
ans = max(ans, cc)
if ans > n:
	ans = n
print(ans)


n = int(input())
a = list(input().split(' '))
a = a + a
(cont_h, res) = (0, 0)
for i in range(n * 2):
	if a[i] == '1':
		cont_h += 1
	else:
		cont_h = 0
	res = max(res, cont_h)
print(res)


_ = input()
a = list(map(int, input().split()))
a.extend(a)
max = 0
cur = 0
for ai in a:
	if ai == 1:
		cur += 1
		if cur > max:
			max = cur
	else:
		cur = 0
print(max)


import sys
n = int(input())
day = list(map(int, input().split()))
md = 0
cur = 0
for i in day:
	if i == 1:
		cur += 1
	else:
		md = max(cur, md)
		cur = 0
for i in day:
	if i == 1:
		cur += 1
	else:
		md = max(cur, md)
		cur = 0
print(max(cur, md))


n = int(input())
arr = [int(x) for x in input().split()]
arr = arr + arr
(m, cur) = (0, 0)
for i in range(len(arr)):
	if arr[i] == 1:
		m += 1
		cur = max(m, cur)
	else:
		m = 0
print(cur)


a = int(input())
l = list(input().split())
a = ''.join(l * 2)
z = a.split('0')
c = 0
for i in z:
	f = len(i)
	c = max(c, f)
print(c)


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations

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

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

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
mm = 1000000007

def solve():
	t = 1
	for it in range(t):
		n = nu()
		a = li()
		pq = a + a
		cc = 1
		tp = pq[0]
		pr = []
		mx = 0
		for i in range(1, 2 * n):
			if pq[i] == tp:
				cc += 1
			else:
				pr.append((tp, cc))
				if tp == 1:
					mx = max(mx, cc)
				cc = 1
				tp = pq[i]
		if tp == 1:
			mx = max(mx, cc)
		print(mx)
solve()


n = int(input())
lst = input().replace(' ', '').split('0')
lst[len(lst) - 1] += lst[0]
lst.sort(reverse=True)
print(len(lst[0]))


import math
n = int(input())
a = [int(q) for q in input().strip().split()]
s = []
s = a + a
lenn = 0
len_ = 0
for x in range(0, n):
	if a[x] == 1:
		len_ = len_ + 1
	else:
		if len_ > lenn:
			lenn = len_
		len_ = 0
if len_ > lenn:
	lenn = len_
len_ = 0
for x in range(0, 2 * n):
	if s[x] == 1:
		len_ = len_ + 1
	else:
		if len_ > lenn:
			lenn = len_
		len_ = 0
if len_ > lenn:
	lenn = len_
print(lenn)


n = int(input())
l = list(map(int, input().strip().split()[:n]))
k = []
count1 = count2 = count3 = 0
if any(l) == False:
	print(0)
else:
	for x in l:
		if x == 1:
			count1 += 1
		else:
			break
	for x in range(n - 1, -1, -1):
		if l[x] == 1:
			count2 += 1
		else:
			break
	for x in l:
		if x == 1:
			count3 += 1
		else:
			k.append(count3)
			count3 = 0
	if count1 + count2 > max(k):
		print(count1 + count2)
	else:
		print(max(k))


import math
n = int(input())
count = 0
ma = 0
li = list(map(int, input().split()))
li = li * 2
for i in range(len(li)):
	if li[i] == 1:
		count = count + 1
		if ma < count:
			ma = count
	else:
		count = 0
print(ma)


n = int(input())
a = list(map(int, input().split()))
a += a
t = 0
maxt = 0
for e in a:
	if e == 1:
		t += 1
		if t > maxt:
			maxt = t
	else:
		t = 0
print(maxt)


n = int(input())
a = list(map(int, input().split()))
b = []
for i in range(len(a)):
	b.append(a[i])
for i in range(len(a)):
	b.append(a[i])
q = 0
r = set()
for i in b:
	if i:
		q += 1
	else:
		r.add(q)
		q = 0
print(max(r))


n = int(input())
a = [True if x == '1' else False for x in input().split()]
a = a + a
rest_sofar = 0
rest_max = 0
for t in a:
	if t:
		rest_sofar += 1
		rest_max = max(rest_max, rest_sofar)
	else:
		rest_sofar = 0
print(rest_max)


n = int(input())
a = list(map(int, input().split()))
r = 0
s = 0
m = 0
r2 = 1
s2 = 0
for i in range(n):
	if not a[i]:
		r2 = 0
	if a[i] and (not r2):
		r = 1
	else:
		m = max(m, s)
		r = 0
		s = 0
	if r:
		s += 1
	if r2:
		s2 += 1
print(max(m, s2 + s))


input()
data = list(map(int, input().split()))
data += data[:data.index(0)]
res = 0
curr = 0
for v in data:
	curr = (curr + v) * v
	if curr > res:
		res = curr
print(res)


n = int(input())
a = list(map(int, input().split()))
m = 0
m1 = 0
for i in range(n):
	if a[i] == 0:
		m = max(m, m1)
		m1 = 0
	else:
		m1 += 1
for j in range(n):
	if a[j] == 0:
		m = max(m, m1)
		m1 = 0
	else:
		m1 += 1
print(m)


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
j = 0
if n > 1:
	a = a * 2
for i in a:
	if i == 1 and j == 0:
		j = 1
	elif i == 1 and j > 0:
		j += 1
	else:
		j = 0
	ans = max(ans, j)
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
r = 0
l = 0
for i in range(2 * n):
	if a[i % n] == 1:
		l = l + 1
		r = max(r, l)
	else:
		l = 0
print(r)


n = int(input())
a = list(map(int, input().split()))
c = 0
k = 0
j = []
if 1 in a:
	c = 1
for i in range(n - 1):
	if a[i] == a[i + 1] == 1:
		c = c + 1
	if a[i] == 0:
		j.append(c)
		c = 1
j.append(c)
c = max(j)
if 1 not in a:
	c = 0
if a[0] == a[n - 1] == 0:
	print(c)
else:
	i = 0
	while a[i] != 0:
		k = k + 1
		i = i + 1
	a.reverse()
	i = 0
	while a[i] != 0:
		k = k + 1
		i = i + 1
	print(max(c, k))


from sys import stdin
n = int(stdin.readline())
nums = list(map(int, stdin.readline().rstrip().split(' ')))
nums += nums
seq = 0
m = 0
for b in nums:
	if b == 0:
		seq = 0
	else:
		seq += 1
		m = max(m, seq)
print(m)


from math import floor
n = int(input())
arr = [int(x) for x in input().split()]
hell = []
mini = 0
i = 0
while arr[i] == 1:
	i = i + 1
minie = i
j = i
mimi = 0
minmimi = i
while j <= n - 1:
	if arr[j] == 0:
		minmimi = max(minmimi, mimi)
		mimi = 0
	else:
		mimi = mimi + 1
	j = j + 1
print(max(minmimi, mimi + i))


n = int(input())
a = list(map(int, input().split()))
a.extend(a)
longstreak = 0
maxstreak = 0
for i in range(2 * n):
	if a[i] == 0:
		maxstreak = max(maxstreak, longstreak)
		longstreak = 0
	else:
		longstreak += 1
print(maxstreak)


n = int(input())
ar = [int(x) for x in input().split()]
ans = 0
cur = 0
pos = 0
for i in range(0, len(ar)):
	if ar[i] == 0:
		pos = i
		break
i = pos
while True:
	if ar[i] == 1:
		cur += 1
		ans = max(ans, cur)
	else:
		cur = 0
	i += 1
	i = i % n
	if i == pos:
		break
print(ans)


n = int(input())
str1 = str(input()).split()
k = 0
i = n - 1
if int(str1[i]) == 1:
	while int(str1[i]) == 1:
		k += 1
		i -= 1
		if i < 0:
			break
if i == 0:
	print(k)
else:
	i = 0
	m1 = 0
	m2 = 0
	while int(str1[i]) == 1:
		m1 += 1
		i += 1
		if i > n - 1:
			break
	m1 += k
	while i < n - k:
		while int(str1[i]) == 0:
			i += 1
			if i >= n - k:
				break
		if i < n - k:
			while int(str1[i]) == 1:
				m2 += 1
				i += 1
				if i >= n - k:
					break
		if m2 > m1:
			m1 = m2
		m2 = 0
	print(m1)


hours = input()
x = input().replace(' ', '')
x += x
max_all = 0
max_loc = 0
for i in x:
	if i == '1':
		max_loc += 1
	else:
		max_all = max(max_all, max_loc)
		max_loc = 0
print(max_all)


mi = lambda : [int(i) for i in input().split()]
input()
a = mi()
(left, right) = (0, 0)
for i in range(len(a)):
	if a[i] == 0:
		break
	left += 1
for i in range(len(a) - 1, -1, -1):
	if a[i] == 0:
		break
	right += 1
cur = 0
best = 0
for i in a:
	if i == 0:
		cur = 0
	else:
		cur += 1
		best = max(best, cur)
print(max(left + right, best))


n = int(input())
li = list(map(int, input().strip().split()))
newli = li
fin = []
for i in range(n):
	if li[i] == 0:
		break
	else:
		newli.append(1)
newli.append(0)
for i in range(0, len(newli)):
	if newli[i] == 0:
		fin.append(i)
max = 0
for i in range(1, len(fin)):
	if fin[i] - fin[i - 1] - 1 > max:
		max = fin[i] - fin[i - 1] - 1
print(max)


n = int(input())
s = input().replace(' ', '') * 2
s = s.split('0')
print(len(max(s, key=len)))


n = int(input())
l = list(map(int, input().split()))
l1 = 0
l2 = 0
lf = 1
ma = 0
for i in range(n):
	if l[i] == 1:
		l1 += 1
	else:
		break
for i in range(n - 1, -1, -1):
	if l[i] == 1:
		l2 += 1
	else:
		break
for i in range(1, n):
	if l[i] == l[i - 1] == 1:
		lf = lf + 1
		if lf > ma:
			ma = lf
	else:
		lf = 1
print(max(ma, l1 + l2))


n = int(input())
arr = [int(i) for i in input().split()]
arr.extend(arr)
maxl = []
check = False
count = 0
for i in range(len(arr)):
	if arr[i] == 1 and check == False:
		check = True
		count = 0
		count += 1
	elif arr[i] == 1 and check == True:
		count += 1
	elif arr[i] == 0:
		check = False
		maxl.append(count)
print(max(maxl))


q = int(input())
w = list(map(int, input().split()))
z = 0
x = 0
for i in range(q * 2):
	if w[i % q] == 1:
		x += 1
	else:
		if x > z:
			z = x
		x = 0
print(z)


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


n = int(input())
s = ''.join(input().split())
s = s + s
s = s.split('0')
s.sort(key=lambda x: len(x))
print(len(s[-1]))


a = int(input())
b = list(map(int, input().split()))
t = 0
c = 0
p = a
q = 0
for i in range(a // 2):
	if b[i] == 1 and b[p - 1] == 1:
		c += 2
		p -= 1
		q += 1
	elif b[i] == 1:
		c += 1
		q += 1
	else:
		break
while p > q:
	if b[p - 1] == 1:
		c += 1
		p -= 1
	else:
		break
if c > t:
	t = c
for i in range(q, p):
	if b[i] == 1:
		c += 1
	else:
		if t < c:
			t = c
		c = 0
if c > t:
	t = c
print(t)


n = int(input())
l = list(map(int, input().split()))
l = l + l
d = 0
ans = 0
for i in range(2 * n):
	if l[i] == 1:
		d = d + 1
	else:
		ans = max(ans, d)
		d = 0
print(ans)


n = int(input())
a = input().split()
k = 1
b = []
q = 0
for i in range(len(a)):
	a[i] = int(a[i])
a = a + a
for i in range(2 * n - 1):
	if a[i] != 1 and a[i] != a[i + 1]:
		k = 1
		b.append(k)
	elif a[i] == 1 and a[i] == a[i + 1]:
		k += 1
		b.append(k)
for i in range(len(b)):
	if b[i] > q:
		q = b[i]
print(q)


hours = int(input())
arr = list(map(int, input().split()))
rest_hours = 0
max_rest_hours = 0
for item in arr:
	if item == 1:
		rest_hours += 1
	else:
		max_rest_hours = max(max_rest_hours, rest_hours)
		rest_hours = 0
f_ones = 0
i = 0
while i <= hours - 1:
	if arr[i] == 1:
		f_ones += 1
		i += 1
	else:
		break
l_ones = 0
i = hours - 1
while i >= 0:
	if arr[i] == 1:
		l_ones += 1
		i -= 1
	else:
		break
print(max(max_rest_hours, f_ones + l_ones))


n = int(input())
m = list(map(int, input().split()))
ans = 0
temp = 0
i = 0
while m[i] == 1:
	m.append(1)
	i += 1
for j in range(len(m)):
	if m[j] == 1:
		temp += 1
	else:
		ans = max(ans, temp)
		temp = 0
ans = max(temp, ans)
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
arr += arr
temp = 0
answer = 0
for e in arr:
	if e == 1:
		temp += 1
		answer = max(answer, temp)
	else:
		temp = 0
print(answer)


from itertools import groupby

def max_group(a):
	return max((len(list(group)) for (k, group) in groupby(a) if k == 1))

def solve(a):
	if sum(a) == 0:
		return 0
	a = a + a + a
	return max_group(a)

def main() -> None:
	n = int(input())
	a = list(map(int, input().split()))
	print(solve(a))
main()


n = int(input())
a = list(map(int, input().split()))
s = 0
l = 0
k = 0
for i in a:
	if i == 0:
		break
	else:
		k += 1
for i in range(len(a)):
	s += a[i]
	if a[i] == 0:
		s = 0
	l = max(s, l)
if k != 0 and s == l:
	l += k
	print(l)
elif k != 0 and s + k > l:
	print(s + k)
else:
	print(l)


n = int(input())
l = list(map(int, input().split()))
cnt = 0
po1 = 0
po2 = 0
for i in range(n):
	if l[i] == 1:
		cnt += 1
	if l[i] == 0:
		po1 = i
		break
m = n - 1
n = n - 1
while n >= 0:
	if l[n] == 1:
		cnt += 1
	if l[n] == 0:
		po2 = n
		break
	n -= 1
cnt1 = 0
while po1 <= po2:
	if l[po1] == 1:
		cnt1 += 1
	else:
		cnt = max(cnt, cnt1)
		cnt1 = 0
	po1 += 1
print(cnt)


n = int(input())
a = list(map(int, input().split()))
(f, l) = (a.index(0), a[::-1].index(0))
ans = l + f
k = 0
a.append(0)
for i in range(n):
	if a[i] == 1:
		k += 1
	else:
		ans = max(ans, k)
		k = 0
print(ans)


n = int(input())
schedule = [int(i) for i in input().split()]
schedule_continuous = schedule + schedule
count = 0
maximum = 0
for i in range(n * 2):
	if schedule_continuous[i] == 1:
		count += 1
		if count > maximum:
			maximum = count
	else:
		count = 0
print(maximum)


import sys
n = int(input())
line = input().split(' ')
rest_cnt = 0
rest_tmp = 0
for answer in line:
	if answer == '1':
		rest_tmp += 1
	else:
		if rest_tmp > rest_cnt:
			rest_cnt = rest_tmp
		rest_tmp = 0
if rest_tmp > rest_cnt:
	rest_cnt = rest_tmp
for answer in line:
	if rest_cnt == n:
		break
	if answer == '1':
		rest_tmp += 1
	else:
		if rest_tmp > rest_cnt:
			rest_cnt = rest_tmp
		rest_tmp = 0
print(rest_cnt)


n = int(input())
a = [int(i) for i in input().split()]
maxleft = 0
while a[maxleft] == 1:
	maxleft += 1
maxright = 0
while a[n - maxright - 1] == 1:
	maxright += 1
i = 0
prev = -1
maxmid = 0
while i < n:
	if a[i] == 0 and prev != -1:
		if i - prev > maxmid:
			maxmid = i - prev
		prev = -1
	if a[i] == 1 and prev == -1:
		prev = i
	i += 1
print(max(maxleft + maxright, maxmid))


n = int(input())
lst = [int(x) for x in input().split()]
delta = lst.index(0)
for i in range(delta):
	lst.append(lst[i])
max_len = 0
l = 0
for i in range(len(lst)):
	if lst[i] == 1:
		l += 1
	else:
		if l > max_len:
			max_len = l
		if i != len(lst) - 1:
			l = 0
if l > max_len:
	max_len = l
print(max_len)


n = int(input())
a = list(map(int, input().split()))
dmax = 0
dstart = 0
dcur = 0
isStart = True
isRest = False
for i in a:
	if i == 1:
		if not isRest:
			isRest = True
		dcur += 1
		if isStart:
			dstart += 1
	if i == 0:
		if isStart:
			isStart = False
	if isRest and i == 0:
		isRest = False
		if dmax < dcur:
			dmax = dcur
		dcur = 0
if dcur == len(a):
	print(len(a))
elif dcur + dstart > dmax and dmax != len(a):
	print(dcur + dstart)
else:
	print(dmax)


(n, c, v) = (int(input()), 0, 0)
for si in 2 * ''.join(input().split()):
	if si == '1':
		c += 1
		v = max(c, v)
	else:
		c = 0
print(v)


n = input()
a = list(input().split())
(max, k) = (0, 0)
t = False
for i in a:
	if i == '0':
		if k != 0 and t == False:
			max = k
			t = True
		elif k > max:
			max = k
		k = 0
		continue
	else:
		k += 1
if a[-1] == '1' and a[0] == '1':
	for i in a:
		if i == '1':
			k += 1
		else:
			break
if k > max:
	max = k
print(max)


n = int(input())
a = list(map(int, input().split()))
mxlen = 0
alen = 0
for i in a:
	if i == 0:
		alen = 0
	if i == 1:
		alen += 1
	mxlen = max(mxlen, alen)
	past = i
f = 0
if past == 1:
	for i in a:
		if i == 1:
			alen += 1
		else:
			break
		mxlen = max(mxlen, alen)
print(mxlen)


N = int(input())
lst = list(map(int, input().split()))
if 1 not in lst:
	print(0)
else:
	final = []
	final += lst * 3
	count = 1
	high = 1
	for i in range(3 * N - 1):
		if final[i] == 1:
			if final[i + 1] == 1:
				count += 1
		else:
			if high < count:
				high = count
			count = 1
	print(high)


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]

def round(n):
	return int(n + 0.5)
n = iread()
sched = viread()
sched *= 2
m = re.findall('1+', ''.join([str(s) for s in sched]))
ans = 0
for thing in m:
	ans = max(len(thing), ans)
print(ans)


n = int(input())
plan = input().split(' ')
s = ''.join(plan)
s = s + s
best = 0
current = 0
for i in range(len(s)):
	if s[i] == '1':
		current = current + 1
		best = max(best, current)
	else:
		current = 0
print(best)


R = lambda : map(int, input().split())
n = int(input())
L = ''.join(input().split())
L = list(map(len, L.split('0')))
l = len(L)
if l == 1:
	print(L[0])
else:
	print(max(max(L), L[0] + L[l - 1]))


size = int(input())
schedule = input().split(' ')
firstStreak = -1
biggestStreak = 0
currentStreak = 0
index = 0
while index < size:
	if schedule[index] == '1':
		currentStreak += 1
	else:
		if currentStreak > biggestStreak:
			biggestStreak = currentStreak
		if firstStreak == -1:
			firstStreak = currentStreak
		currentStreak = 0
	index += 1
currentStreak += firstStreak
if currentStreak > biggestStreak:
	biggestStreak = currentStreak
print(biggestStreak)


from itertools import groupby
input()
a = list(map(int, input().split(' ')))
print(max([0] + [sum((1 for _ in g)) for (k, g) in groupby(a + a) if k == 1]))


n = int(input())
a = list(map(int, input().strip().split()))
one_chunks = list()
idx = 0
curr_count = 0
for ai in a:
	if ai == 1:
		curr_count += 1
	else:
		one_chunks.append(curr_count)
		curr_count = 0
if a[-1] == 1:
	one_chunks.append(curr_count)
max_in_a_day = max(one_chunks)
if a[0] == 1:
	start_chunk = one_chunks[0]
else:
	start_chunk = 0
if a[-1] == 1:
	end_chunk = one_chunks[-1]
else:
	end_chunk = 0
print(max(max_in_a_day, end_chunk + start_chunk))


n = int(input())
lst = list(map(int, input().split()))
lst = lst * 2
(res, result) = (0, 0)
for (i, x) in enumerate(lst):
	if x == 1:
		res += 1
	else:
		(result, res) = (max(res, result), 0)
print(result)


from sys import stdin
stdin.readline()
s = stdin.readline().strip().replace(' ', '')
print(max(map(lambda s: len(s), (s + s).split('0'))))


a = int(input())
b = input().split()
d = []
i = 0
k = 0
max0 = 0
z = 0
for c in range(a):
	d.append(int(b[c]))
	if int(b[c]) == 1:
		i += 1
		if c == len(b) - 1 and d[0] == 1:
			i += z
		if k == 0:
			z = i
		if max0 < i:
			max0 = i
	else:
		k += 1
		i = 0
print(max0)


n = int(input())
l = list(map(int, input().split()))
c = 0
z = []
if c == 0 and 0 not in l:
	print(n)
else:
	for i in range(n):
		if l[i] == 0:
			z.append(i + 1)
	for i in range(len(z) - 1):
		g = z[i + 1] - z[i] - 1
		if c < g:
			c = g
	d = n - z[-1]
	t = z[0] - 1
	if c < d + t:
		c = d + t
	print(c)


n = int(input())
a = [int(x) for x in input().split()]
can_chain = False
if a[0] == 1 and a[-1] == 1:
	can_chain = True
len_a = len(a)
k = 0
indexes = {}
seqs = {}
lseqs = {}
for i in range(len_a):
	if a[i] == 1:
		indexes[i] = k
		try:
			seqs[k].append(i)
			lseqs[k] += 1
		except:
			seqs[k] = [i]
			lseqs[k] = 1
	else:
		k += 1
if can_chain:
	l = len_a - 1
	lseqs[indexes[0]] += lseqs[indexes[l]]
	lseqs[indexes[l]] = 0
if lseqs:
	print(max(zip(lseqs.values(), lseqs.keys()))[0])
else:
	print(0)


n = int(input())
l = list(map(int, input().split())) * 2
maxx = 0
rest = 0
for i in range(n * 2):
	if l[i] == 1:
		rest += 1
		maxx = max(rest, maxx)
	elif l[i] == 0:
		rest = 0
print(maxx)


n = int(input())
s = list(map(int, input().split()))
temp = 0
res = 0
for i in range(n):
	if s[i] == 1:
		temp += 1
		if i == n - 1:
			s[i] = 0
			for i in range(n):
				if s[i] == 1:
					temp += 1
				else:
					if temp > res:
						res = temp
					break
	else:
		if temp > res:
			res = temp
		temp = 0
print(res)


import sys
from collections import defaultdict
strInp = lambda : input().strip().split()
intInp = lambda : list(map(int, strInp()))
n = int(input())
arr = intInp()
arr += arr
last = arr[0]
m = 0
if last == 1:
	m = 1
tmp = m
for i in arr[1:]:
	if last == 1 and i == 1:
		tmp += 1
	if last == 1 and i == 0:
		m = max(m, tmp)
	if last == 0 and i == 1:
		tmp = 1
	last = i
m = max(m, tmp)
print(m)


n = int(input())
l = list(input().split())
s = ''
res = []
for i in l:
	s += i
s = s.split('0')
for i in s:
	res.append(i)
res.append(res[0] + res[-1])
print(len(max(res)))


from itertools import groupby
n = int(input())
A = [int(x) for x in input().split()]
A += A
print(max([0] + [len(list(x[1])) for x in groupby(A) if x[0] == 1]))


a = int(input())
b = list(map(int, input().split()))
t = []
t = b
(maxa, co) = (0, 0)
for elem in b:
	if elem == 1:
		t.append(elem)
	else:
		break
for elem in t:
	if elem == 1:
		co += 1
	elif elem == 0:
		co = 0
	if co > maxa:
		maxa = co
print(maxa)


n = int(input())
schedule = input().split()
max_rest = 0
cand_rest = 0
for i in range(0, 2 * n):
	x = schedule[i % n]
	if x == '1':
		cand_rest += 1
	else:
		max_rest = max(max_rest, cand_rest)
		cand_rest = 0
print(max_rest)


n = int(input())
q = list(map(int, input().split()))
q = q + q
s = 0
a = []
for i in range(len(q)):
	if q[i] == 1:
		s = s + 1
	else:
		a.append(s)
		s = 0
x = 0
if a == []:
	print(s)
else:
	for j in range(len(a)):
		if a[j] >= x:
			x = a[j]
	print(x)


n = int(input())
rest = list(map(int, input().split()))
(i, max_count) = (0, 0)
ones = 0
for k in range(2 * n):
	i = k % n
	if rest[i] == 0:
		ones = 0
	else:
		ones += 1
	max_count = max(max_count, ones)
print(max_count)


n = int(input())
ms = list(map(int, input().split()))
left = n - 1
right = 0
c = 0
max_c = 0
for i in range(n):
	if ms[i] == 0:
		left = min(i, left)
		right = max(i, right)
		c = 0
	else:
		c += 1
		max_c = max(c, max_c)
print(max(max_c, left + n - 1 - right))


m = int(input())
hours = [int(hr) for hr in input().split(' ')]

def solution(hours):
	total_rest = 0
	temp = 0
	if hours[-1] == 1:
		hours = hours + hours
	for hr in hours:
		if hr == 1:
			temp += 1
			if temp > total_rest:
				total_rest = temp
		else:
			temp = 0
	return total_rest
print(solution(hours))


n = int(input())
a = list(map(int, input().split()))
a = a[a.index(0):] + a[:a.index(0)]
n = 0
m = 0
for i in a:
	n = n + 1 if i == 1 else 0
	m = max(n, m)
print(m)


input()
miu = input().split()
miu = miu + miu
max = 0
count = 0
for x in range(len(miu) - 1):
	if miu[x] == '1' and miu[x + 1] == '1':
		count += 1
	if miu[x] == '0' and miu[x + 1] == '0':
		count = 0
	if miu[x] == '1' and miu[x + 1] == '0':
		if count > max:
			max = count
		count = 0
	if miu[x] == '0' and miu[x + 1] == '1':
		count = 1
print(max)


n = int(input())
arr = [int(i) for i in input().split(' ')]
start = True
maxVal = 0
curr = 0
startVal = 0
for i in arr:
	if i == 1:
		curr += 1
	else:
		if start:
			startVal = curr
			start = False
		maxVal = max(maxVal, curr)
		curr = 0
maxVal = max(maxVal, startVal + curr)
print(maxVal)


n = int(input())
a = [int(x) for x in input().split(' ')]
start = 0
i = 0
while i < n and a[i] == 1:
	i += 1
	start += 1
m = start
while i < n:
	cnt = 0
	while i < n and a[i] == 1:
		i += 1
		cnt += 1
	m = max(m, cnt)
	i += 1
end = 0
i = n - 1
while i >= 0 and a[i] == 1:
	i -= 1
	end += 1
m = max(m, start + end)
print(m)


x = int(input())
lst = input().split()
lst = lst + lst + lst
num = 0
lst_0 = []
for value in range(0, len(lst)):
	if lst[value] == '1':
		num += 1
	else:
		lst_0.append(num)
		num = 0
print(max(lst_0))


n = int(input())
days = list(map(int, input().split()))
fzi = -1
for i in range(n):
	if days[i] == 0:
		fzi = i
		break
if fzi != 0:
	days = days[fzi:] + days[:fzi]
max_rest = 0
while days:
	if days[-1] == 1:
		temp = 1
		days.pop()
		while days and days[-1] == 1:
			temp += 1
			days.pop()
		if temp > max_rest:
			max_rest = temp
	else:
		days.pop()
print(max_rest)


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


from itertools import groupby
n = int(input())
val = input().replace(' ', '')
val += val
curr_val = 0
max_val = 0
for v in val:
	if v == '1':
		curr_val += 1
	else:
		if max_val < curr_val:
			max_val = curr_val
		curr_val = 0
print(max_val)


n = int(input())
s1 = input()
s = ''
for i in s1:
	if i == '0' or i == '1':
		s += i
s += s
l = s.split('0')
ans = 0
for i in l:
	ans = max(ans, len(i))
print(ans)


n = int(input())
s = list(input().split())
s.extend(s)
max = 0
c = 0
for i in s:
	if i == '1':
		c += 1
		if c > max:
			max = c
	else:
		c = 0
print(max)


num_hours = input()
day = input()
days = day + ' ' + day
days = sorted(days.replace(' ', '').replace('0', ',').split(','), reverse=True)
print(len(days[0]))


n = int(input())
c = []
k = 0
m = 0
c = input().split()
for v in c:
	if v == '0':
		k = 0
	else:
		k += 1
		if m < k:
			m = k
if c[0] == c[-1] and c[0] == '1':
	nach = 0
	for v in c:
		if v == '0':
			break
		nach += 1
	ko = 0
	for v in c[::-1]:
		if v == '0':
			break
		ko += 1
	m = max([m, nach + ko])
print(m)


def fun():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	ca = 0
	for i in range(n):
		if arr[i] == 1:
			ca += 1
		else:
			ca = 0
		ans = max(ans, ca)
	for i in range(n):
		if arr[i] == 1:
			ca += 1
		else:
			ca = 0
		ans = max(ans, ca)
	print(ans)
fun()


n = int(input())
arr = list(map(int, input().split()))
arr.extend(arr)
maxi = 0
cur = 0
for i in range(len(arr)):
	if arr[i] == 1:
		cur += 1
	else:
		if cur > maxi:
			maxi = cur
		cur = 0
print(maxi)


n = int(input())
arr = list(map(int, input().split()))
arr = 2 * arr
count = 0
prevcount = 0
for i in range(0, len(arr)):
	if arr[i] == 1:
		count = count + 1
	else:
		if count > prevcount:
			prevcount = count
		count = 0
print(prevcount)


n = int(input())
l = list(map(int, input().split()))
li = l + l
max_r = 0
co = 0
for i in li:
	if i == 0:
		if co > max_r:
			max_r = co
		co = 0
	else:
		co += 1
print(max_r)


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


n = int(input())
lst = list(map(int, input().split()))
lst = lst[:] + lst[:]
ans = 0
max_ans = 0
for i in range(2 * n):
	if lst[i] == 0:
		max_ans = max(max_ans, ans)
		ans = 0
	else:
		ans += 1
print(max_ans)


n = int(input())
hours = [i for i in input().split()]
a = 0
b = 0
for i in range(2 * n):
	if hours[i % n] == '1':
		a += 1
	else:
		if a > b:
			b = a
		a = 0
if a > b:
	print(a)
else:
	print(b)


import re
a = int(input())
b = ''.join(list(input().split()))
c = b * 2
s = re.split('[0]+', c)
m = 0
for i in s:
	m = max(m, len(i))
print(m)


R = lambda : map(int, input().split())
n = int(input())
L = list(R())
res = 0
c = 0
for i in range(n):
	if L[i] == 1:
		c += 1
	elif L[i] == 0:
		res = max(res, c)
		c = 0
c1 = 0
for i in range(n):
	if L[i] == 1:
		c1 += 1
	else:
		break
for i in reversed(range(n)):
	if L[i] == 1:
		c1 += 1
	else:
		break
print(max(c1, res))


n = int(input())
a = list(map(int, input().split()))
(b, l) = ([], [])
for i in range(n):
	if a[i] == 0:
		b.append(i)
for i in range(0, len(b) - 1):
	l.append(abs(b[i] - b[i + 1]) - 1)
l.append(abs(-1 * (n - b[-1]) - b[0]) - 1)
print(max(l))


import sys, math, queue
sys.setrecursionlimit(1000000)
n = int(input())
a = list(map(int, input().split()))
p = 0
ans = 0
for i in range(n - 1, -n - 1, -1):
	if a[i] == 0:
		p = 0
	else:
		p += 1
		ans = max(ans, p)
print(ans)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for p in range(t):
		solve()

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

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

def power(a, b):
	ans = 1
	while b > 0:
		if b % 2 == 1:
			ans *= a
		a *= a
		b //= 2
	return ans

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

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 solve():
	n = int(inp())
	a = lis()
	a += a
	pre = [0] * (2 * n + 1)
	for i in range(2 * n):
		if i == 0:
			pre[i] = a[i]
		elif a[i] == 1:
			if a[i - 1] == 1:
				pre[i] = pre[i - 1] + 1
			else:
				pre[i] = a[i]
		else:
			pre[i] = a[i]
	print(max(pre))
testcase(1)


n = int(input())
a = list(map(int, input().split()))
x = 0
l = []
for i in a:
	if i == 1:
		x += 1
		l.append(x)
	elif i == 0:
		x = 0
for i in a:
	if i == 1:
		x += 1
		l.append(x)
	elif i == 0:
		x = 0
if 1 in a:
	if a[-1] == 1:
		x += 1
		print(max(l))
	else:
		print(max(l))
else:
	print(0)


n = int(input())
hr = list(map(int, input().split()))
flag = 0
count = 0
maxRest = 1
i = 0
while i < n:
	if 1 not in hr:
		maxRest = count
		break
	count = 1
	if i + 1 == n:
		break
	if hr[0] == 1 and hr[-1] == 1:
		j = 0
		while hr[j] == 1 and hr[j + 1] == 1:
			count += 1
			j += 1
		j = -1
		while hr[j] == 1 and hr[j + 1]:
			count += 1
			j -= 1
		if count > maxRest:
			maxRest = count
	count = 1
	while hr[i] == 1 and hr[i + 1] == 1:
		i += 1
		count += 1
		if i + 1 == n:
			break
	if count > maxRest:
		maxRest = count
	i += 1
print(maxRest)


n = int(input())
a = input().split()
for i in range(n):
	a.append(a[i])
ans = 0
c = 0
N = 2 * n
for i in range(N):
	if a[i] == '1':
		c += 1
	else:
		ans = max(ans, c)
		c = 0
print(ans)


n = int(input())
a = [int(x) for x in input().split()] * 2
m = 0
c = 0
for i in a:
	m = max(m, c)
	if i == 1:
		c = c + 1
	else:
		c = 0
print(m)


l = input()
inp = list((input() * 2).split('0'))
(largest, sum) = (0, 0)
for num in inp:
	sum = num.count('1')
	if sum > largest:
		largest = sum
	sum = 0
print(largest)


n = int(input())
a = list(map(int, input().split()))
ans = 0
s = 0
for i in range(n):
	if a[i] == 1:
		s += 1
	else:
		s = 0
	ans = max(ans, s)
start = 0
end = 0
for i in range(n):
	if a[i] == 1:
		start += 1
	else:
		break
for i in range(n - 1, -1, -1):
	if a[i] == 1:
		end += 1
	else:
		break
ans = max(ans, start + end)
print(ans)


n = int(input())
b = list(map(int, input().split()))
a = b + b + b
ans = 0
cur_ans = 0
for i in a:
	if i:
		cur_ans += 1
	else:
		ans = max(ans, cur_ans)
		cur_ans = 0
print(ans)


n = int(input())
time = list(map(int, input().split()))
pos = time.index(0)
time = time[pos:len(time)] + time[0:pos]
count = 0
max = 0
for i in range(len(time)):
	if time[i] == 1:
		count += 1
		if count > max:
			max = count
	else:
		count = 0
print(max)


s = input()
stroka = (input() + ' ') * 2
list1 = list(map(int, stroka.split()))
Count = k = 0
for i in list1:
	if i == 1:
		Count += 1
	else:
		if Count > k:
			k = Count
		Count = 0
print(k)


import sys
a = int(input())
b = [int(x) for x in input().split()]
c = b
d = 0
e = 0
for i in range(1, a * 2):
	if b[i % a] == c[i % a - 1] and c[i % a] == 1:
		if d == 0:
			d += 2
		else:
			d += 1
		e = max(d, e)
	else:
		d = 0
	if c[i % a] == 1:
		e = max(e, 1)
print(e)


n = int(input())
s = input().replace(' ', '')
l = s.split('0')
result = len(l[0]) + len(l[-1])
for i in l:
	if len(i) > result:
		result = len(i)
print(result)


n = int(input())
a = list(map(int, input().split()))
(c, ans) = (0, 0)
for i in range(n * 2):
	if a[i % n] != 0:
		c = c + 1
		ans = max(c, ans)
	else:
		c = 0
print(ans)


n = int(input())
a = list(map(int, input().split())) * 2
bmax = 0
b = 0
for i in range(len(a)):
	if a[i] == 1:
		b += 1
		if b > bmax:
			bmax += 1
	elif a[i] == 0:
		b = 0
print(bmax)


n = int(input())
a = list(map(int, input().split()))
x = []
y = 0
for i in range(0, n):
	if a[i] == 1:
		y += 1
		if i == n - 1:
			x.append(y)
	elif y != 0:
		x.append(y)
		y = 0
		x.append(y)
	else:
		x.append(y)
c = max(x)
y = x[0] + x[len(x) - 1]
if y >= n:
	y = n
print(max(c, y))


n = int(input())
a = list(map(int, input().split()))
a2 = a + a
ans = 0
cnt = 0
for i in range(0, 2 * n):
	if a2[i] == 0:
		cnt = 0
	if a2[i] == 1:
		cnt += 1
		ans = max(cnt, ans)
print(ans)


n = int(input())
k = list(map(int, input().split()))
k.extend(k)
(maxc, c) = (0, 0)
for i in range(len(k)):
	if k[i] == 1:
		c += 1
	else:
		if c > maxc:
			maxc = c
		c = 0
print(maxc)


n = int(input())
lst = list(map(int, input().split())) * 2
imax = 0
k = -1
for i in range(2 * n):
	if lst[i] == 1:
		if i - k > imax:
			imax = i - k
	else:
		k = i
print(imax)


n = int(input())
a = [int(t) for t in input().split(' ')]
a.extend(a)
max_ones = 0
ones = 0
for ai in a:
	if ai == 1:
		ones += 1
	else:
		max_ones = max(max_ones, ones)
		ones = 0
print(max_ones)


n = int(input())
c = i = p = 0
a = [int(i) for i in input().split()]
while a[i]:
	c += 1
	i += 1
j = n - 1
while a[j]:
	c += 1
	j -= 1
p = max(p, c)
c = 0
for k in range(i, j + 1):
	if a[k]:
		c += 1
	else:
		p = max(p, c)
		c = 0
print(p)


n = int(input())
lst = list(map(int, input().strip().split(' ')))
m = 0
c1 = 0
i = 0
while i < n:
	j = i + 1
	c = 0
	if lst[i] == 1:
		c += 1
		while j < n and i < n and (lst[i] == lst[j]):
			c += 1
			j += 1
		if c > m:
			m = c
		i = j + 1
	else:
		i += 1
if lst[0] == 1 and lst[n - 1] == 1:
	i = 1
	j = n - 2
	f1 = 0
	f2 = 0
	c1 = 2
	while i < n and j >= 0:
		if lst[i] == 1 and f1 == 0:
			c1 += 1
			i += 1
		else:
			f1 = 1
		if lst[j] == 1 and f2 == 0:
			c1 += 1
			j -= 1
		else:
			f2 = 1
		if f1 == 1 and f2 == 1:
			break
if c1 > m:
	print(c1)
else:
	print(m)


n = input()
seq = list(map(int, input().split()))
ans = -float('inf')
curr = 0
for i in range(len(seq)):
	if seq[i] == 0:
		ans = max(ans, curr)
		curr = 0
	elif seq[i] == 1:
		curr += 1
ans = max(ans, curr)
first = -1
for i in range(len(seq)):
	if seq[i] == 0:
		first = i - 1
		break
last = -1
for i in range(len(seq) - 1, -1, -1):
	if seq[i] == 0:
		last = i + 1
		break
if first != -1 and last != len(seq):
	print(max(len(seq) - last + first + 1, ans))
else:
	print(ans)


n = int(input())
horas = [*map(int, input().split())]
primeiro0 = horas.index(0)
if horas[0] == 1:
	horas += horas[:primeiro0]
cont = 0
maxv = 0
index = 0
for e in horas:
	if e != 0:
		cont += 1
	else:
		cont = 0
	maxv = max(maxv, cont)
print(maxv)


n1 = input().strip()
array = list(map(int, input().split()))
max = 0
index = 0
temp = 0
while temp < len(array):
	if array[temp] == 1:
		array.append(1)
		temp += 1
	else:
		break
while index < len(array):
	if array[index] == 1:
		counter = 0
		while index < len(array):
			if array[index] == 1:
				counter += 1
				index += 1
			else:
				break
		if counter > max:
			max = counter
	else:
		index += 1
print(max)


x = int(input())
y = input()
m = y + ' ' + y
z = m.split()
w = [int(d) for d in z]
t = 0
lit = []
for i in range(len(w)):
	if w[i] == 1:
		t = t + 1
		continue
	elif w[i] == 0:
		lit.append(t)
		t = 0
		continue
print(max(lit))


n = int(input())
ar = list(map(int, input().split()))
cnt = 0
count = 0
count1 = 0
count2 = 0
count3 = 0
flag = ar[0]
for i in range(n):
	if ar[i] == 1:
		flag = 1
	if ar[i] == 1 and flag == 1:
		cnt += 1
	if ar[i] == 0:
		flag = 0
		count = max(cnt, count)
		cnt = 0
for i in range(n):
	if ar[i] == 1:
		count1 += 1
	else:
		break
for i in range(n - 1, -1, -1):
	if ar[i] == 1:
		count2 += 1
	else:
		break
count3 = count2 + count1
count = max(count, count3)
print(count)


n = int(input())
s = str(input())
l = s.split(' ')
maxi = -1
x = False
i = 0
count = 0
while i < n:
	if l[i] == '0':
		if count > maxi:
			maxi = count
		count = 0
		i += 1
		if x == True:
			break
	elif l[i] == '1' and i != n - 1:
		count += 1
		i += 1
	elif i == n - 1 and l[i] == '1':
		count += 1
		i = 0
		x = True
print(maxi)


WORK = 0
REST = 1
n = input()
xd = list(map(int, input().split()))
l = xd + xd
c = 0
longest = 0
for e in l:
	if e == WORK:
		if c > longest:
			longest = c
		c = 0
	else:
		c += 1
print(longest)


n = int(input())
arr = list(map(int, input().split()))
i = 0
j = 0
maxi = 0
ans = 0
for i in range(2 * n):
	if arr[i % n] == 1:
		maxi += 1
		ans = max(ans, maxi)
	else:
		maxi = 0
print(ans)


f = int(input())
lis = list(map(int, input().split())) * 2
maxi = 0
cont = 0
for i in lis:
	if i == 1:
		cont += 1
		if cont > maxi:
			maxi = cont
	else:
		cont = 0
print(maxi)


def main():
	n = int(input())
	hours = list(map(int, input().split()))
	restingHours = 0
	maxRestingHours = 0
	lastHourResting = -100
	consecutiveResting = 0
	for (i, hour) in enumerate(hours):
		if hour == 1:
			restingHours += 1
			if lastHourResting == i - 1:
				consecutiveResting += 1
			lastHourResting = i
		else:
			if consecutiveResting == 0 and lastHourResting == i - 1:
				restingHours -= 1
			else:
				if restingHours > maxRestingHours:
					maxRestingHours = restingHours
				restingHours = 0
			consecutiveResting = 0
	index = 0
	while hours[index] != 0:
		restingHours += 1
		index += 1
	if restingHours > maxRestingHours:
		maxRestingHours = restingHours
	print(maxRestingHours)
main()


n1 = input()
n = list(map(int, input().split()))
n = n * 2
(t, t_max) = (0, 0)
for i in range(len(n)):
	if n[i] == 1:
		t += 1
		if t > t_max:
			t_max = t
	else:
		t = 0
print(t_max)


num = int(input())
a = list(map(int, input().split()))
b = []
a += a
count = 0
i = 0
while i < 2 * num - 1:
	count = 0
	if a[i] == 1:
		count += 1
		for j in range(i + 1, 2 * num):
			if a[j] == 0:
				break
			else:
				count += 1
		i = j
	else:
		i += 1
	b += [count]
print(max(b))


n = int(input())
schedule = list(map(lambda x: int(x), input().split(' ')))
nap_hours = 0
nap_hours_max = 0
for hour in schedule:
	if hour:
		nap_hours += 1
		if nap_hours > nap_hours_max:
			nap_hours_max = nap_hours
	else:
		nap_hours = 0
h = 0
while schedule[h]:
	nap_hours += 1
	if nap_hours > nap_hours_max:
		nap_hours_max = nap_hours
	h += 1
print(nap_hours_max)


inp = int(input())
lst = list(map(int, input().split()))
count = 0
maxCount = 0
for i in lst:
	if i == 1:
		count += 1
	else:
		if count > maxCount:
			maxCount = count
		count = 0
if count > 0 and lst[0] == 1 and (count < len(lst)):
	index = 0
	while lst[index] == 1:
		count += 1
		index += 1
if count > maxCount:
	maxCount = count
print(maxCount)


n = int(input())
data = list(map(int, input().split()))
data += data
result = 0
temp = 0
for i in range(len(data) - 1):
	if data[i] == 1:
		temp += 1
	else:
		result = max(result, temp)
		temp = 0
print(result)


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


n = int(input())
l = list(map(int, input().split(' ')))
if l == [0]:
	print(0)
elif l == [1]:
	print(1)
else:
	(max_, i, j) = (0, 0, 1)
	p = j
	for i in range(n):
		s = 0
		if i > p:
			for j in range(i, n):
				if l[j]:
					s += 1
				else:
					p = j
					if s > max_:
						max_ = s
					break
			else:
				p = j
				if s > max_:
					max_ = s
				break
	(st, en) = (0, -1)
	while l[st]:
		st += 1
	while l[en]:
		en -= 1
	print(max(max_, st - en - 1))


n = int(input())
a = list(map(int, input().split()))
a = a + a
maxi = 0
c = 0
for i in range(len(a)):
	if a[i] == 1:
		c += 1
	else:
		if maxi <= c:
			maxi = c
		c = 0
print(maxi)


n = int(input())
a = list(map(int, input().split()))
cnt = 0
cnt1 = 0
for i in range(n):
	if a[i] == 1:
		cnt1 = cnt1 + 1
		cnt = max(cnt, cnt1)
	else:
		cnt1 = 0
for i in range(n):
	if a[i] == 1:
		cnt1 = cnt1 + 1
		cnt = max(cnt, cnt1)
	else:
		cnt1 = 0
print(cnt)


HrNo = int(input())
HrStr = [int(x) for x in input().split()]
HrStr = HrStr + HrStr[:HrNo]
count = 0
Maxi = 0
for i in range(HrNo * 2 - 1):
	if HrStr[i] == 1 and HrStr[i + 1] == 1:
		count += 1
		if count > Maxi:
			Maxi = count
	else:
		count = 0
if Maxi > 0:
	print(Maxi + 1)
elif 1 in HrStr:
	print(1)
else:
	print(0)


n = int(input())
a = list(map(int, input().split()))
contigous = 0
max_cont = 0
from_0 = False
for i in range(n):
	if a[i]:
		contigous += 1
	else:
		max_cont = max(max_cont, contigous)
		contigous = 0
max_cont = max(max_cont, contigous)
if a[0] and a[-1]:
	contigous = 0
	for i in range(n):
		if a[i]:
			contigous += 1
		else:
			break
	for j in range(n - 1, -1, -1):
		if a[j]:
			contigous += 1
		else:
			break
	max_cont = max(max_cont, contigous)
print(max_cont)


def main():
	n = int(input())
	values = input().split()
	values = 2 * values
	len_value = 0
	max_value = 0
	for index in range(len(values)):
		if int(values[index]):
			len_value += 1
			max_value = max(max_value, len_value)
		else:
			len_value = 0
	print(max_value)
	return max_value
main()


n = int(input())
m = list(map(int, input().split()))
i = 0
while i < n:
	if m[i] == 1:
		m.append(1)
	else:
		break
	i += 1
m.append(0)
curr = 0
mx = 0
for x in m:
	if x == 0:
		mx = max(mx, curr)
		curr = 0
	else:
		curr += 1
print(mx)


def main():
	n = int(input())
	arr = input().split()
	for x in range(n):
		arr[x] = int(arr[x])
		arr.append(arr[x])
	count = 0
	current = 0
	current_count = 0
	for x in range(len(arr)):
		if arr[x] == 0 and current == 1:
			count = max(count, current_count)
			current = 0
			current_count = 0
		elif arr[x] == 1 and current == 0:
			current = 1
			current_count = 1
		elif arr[x] == 1 and current == 1:
			current_count += 1
	print(count)
main()


n = int(input())
li = list(map(int, input().split()))
maks = 0
wsk = 0
for i in range(n):
	if li[i] == 1:
		wsk += 1
	else:
		maks = max(maks, wsk)
		wsk = 0
pocz = 0
kon = 0
for i in range(n):
	if li[i] == 1:
		pocz += 1
	else:
		break
for i in range(n):
	if li[n - 1 - i] == 1:
		kon += 1
	else:
		break
print(max(maks, pocz + kon))


n = int(input())
c = [int(x) for x in input().split()]
mx = 0
s = 0
fl = True
for i in range(n):
	if c[i] == 0:
		if mx < s:
			mx = s
		s = 0
	elif i == n - 1:
		s += 1
		for i1 in c:
			if i1 == 1:
				s += 1
			else:
				if mx < s:
					mx = s
				s = 0
				break
	else:
		s += 1
print(mx)


n = int(input())
l = list(map(int, input().split()))
count = 0
m = []
for i in range(len(l)):
	if l[i] == 1:
		if i == n - 1:
			for j in range(len(l) - 1):
				if l[j] == 1:
					count = count + 1
				else:
					m.append(count)
					break
		count = count + 1
	else:
		m.append(count)
		count = 0
m.append(count)
print(max(m))


n = int(input())
sched = str(input()).split(' ')
sched = ''.join(sched + sched)
curr_num = 0
max_num = 0
for item in sched:
	if item == '1':
		curr_num += 1
		if curr_num > max_num:
			max_num = curr_num
	else:
		curr_num = 0
print(max_num)


n = int(input())
st = input()
st = st.replace(' ', '')
t = ''
t = st + st
ones = t.split('0')
max = 0
for one in ones:
	temp = len(one)
	if temp > max:
		max = temp
print(max)


n = int(input())
l = list(map(int, input().split()))
p = l + l
count = 0
max = 0
for i in p:
	if i == 1:
		count += 1
		if count > max:
			max = count
	if i == 0:
		count = 0
print(max)


import itertools
n = int(input())
s = input()
if s.count('1') == n:
	print(200000)
else:
	y = ''.join(list(itertools.chain(s, ' ', s)))
	x = ''
	for i in y:
		if i != ' ':
			x += i
	a = list(map(len, x.split('0')))
	print(max(a))


n = int(input())
data = list(map(int, input().split()))
data += data
maxi = 0
cnt = 0
for i in range(1, len(data)):
	if data[i] == 1 and data[i - 1] == 1:
		cnt += 1
	elif data[i] == 1:
		cnt = 1
	else:
		maxi = max(maxi, cnt)
		cnt = 0
print(maxi)


n = int(input())
a = list(map(int, input().split()))
f = [0 for c in a]
j = 0
ans = 0
for i in range(n):
	if a[i]:
		if not a[j]:
			j = i
		f[j] += 1
		ans = max(ans, f[j])
	else:
		j = i
if a[0] and a[-1] and j:
	ans = max(ans, f[0] + f[j])
print(ans)


n = int(input())
a = list(map(int, input().split()))[:n]
b = a
for i in range(0, len(a)):
	b.append(a[i])

def maxio(arr, n):
	count = 0
	result = 0
	n = len(b)
	for i in range(0, n):
		if b[i] == 0:
			count = 0
		else:
			count += 1
			result = max(result, count)
	return result
print(maxio(b, n))


n = int(input())
s = input()
s = s.split(' ')
count = 0
maxcount = 0
for i in range(len(s)):
	if s[i] == '1':
		count = count + 1
	else:
		if count > maxcount:
			maxcount = count
		count = 0
i = 0
while count != 0:
	if s[i] == '1':
		count = count + 1
	else:
		break
	i = i + 1
if count > maxcount:
	maxcount = count
print(maxcount)


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

def ca():
	return input().split()

def ii():
	return int(input())
n = ii()
a = ia()
x = a + a + a
n1 = len(x)
c = 0
m = 0
prev = 0
for i in range(n1):
	if prev == 1 and x[i] == 1:
		c += 1
	elif prev == 0 and x[i] == 1:
		c = 1
		prev = 1
	else:
		c = 0
		prev = 0
	if m < c:
		m = c
print(m)


N = int(input())
A = input().split()
WORK_PTN = '0'
REST_PTN = '1'
induces = [i for (i, x) in enumerate(A) if x == WORK_PTN]
firstRestSeq = 0
firstWork = induces[0]
if A[0] == REST_PTN:
	firstRestSeq = firstWork
lastRestSeq = N - induces[-1] - 1
maxLen = 0
prevInd = -1
tmpMaxLen = 0
for ind in induces:
	tmpMaxLen = ind - prevInd - 1
	maxLen = max(maxLen, tmpMaxLen)
	prevInd = ind
maxLen = max(maxLen, lastRestSeq + firstRestSeq)
print(maxLen)


n = int(input(''))
s = list(map(int, input().split()))
s = s + s
t = 0
k = 0
for i in range(2 * n):
	if s[i] == 1:
		k += 1
	else:
		t = max(k, t)
		k = 0
print(t)


import sys
import math

def getAndParseInt(num=1):
	string = sys.stdin.readline().strip()
	if num == 1:
		return int(string)
	else:
		return [int(part) for part in string.split()]

def getAndParseString(num=1, delim=' '):
	string = sys.stdin.readline().strip()
	if num == 1:
		return string
	else:
		return [part for part in string.split(delim)]
n = getAndParseInt()
schedule = getAndParseString(2)
schedule = ''.join(schedule)
schedule_split = schedule.split('0')
schedule_split = [part for part in schedule_split if part != '']
lens = [len(part) for part in schedule_split]
if len(lens) > 0:
	maximum = max(lens)
else:
	maximum = 0
if schedule[0] == '1' and schedule[-1] == '1':
	maximum = max(maximum, lens[0] + lens[-1])
print(maximum)


n = int(input())
list1 = list(map(int, input().split()))
i = 0
j = 0
c = 0
c1 = 0
while i < 2 * n:
	if list1[j] == 1:
		c = c + 1
	else:
		c1 = max(c, c1)
		c = 0
	j = (j + 1) % n
	i = i + 1
print(c1)


def inp_n():
	return int(input())

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

def inp_mul_num():
	return map(int, input().split())
n = inp_n()
l = inp_list()
len = 0
m = 0
for i in range(2 * n):
	if l[i % n] == 1:
		len += 1
		m = max(m, len)
	else:
		len = 0
print(m)


n = int(input())
a = str(input())
(count, max, k) = (0, 0, 0)
big_a = a + a
big_a = big_a.split(' ')
big = ''.join(big_a)
big = big.split('0')
for j in range(len(big)):
	k = big[j].count('1')
	if k > count:
		count = k
print(count)


n = int(input())
a = [int(x) for x in input().rstrip().split()]
a = a * 2
r = 0
i = 0
while i < len(a):
	while i < len(a) and a[i] == 0:
		i += 1
	s = 0
	while i < len(a) and a[i] == 1:
		s += 1
		i += 1
	if s > r:
		r = s
print(r)


n = int(input())
s = input()
s += ' ' + s
l = list(s.split(' '))
m = 0
i = 0
while i < n:
	if l[i] == '1':
		start = i
		c = 0
		while l[i] == '1':
			c += 1
			i += 1
		i -= 1
		m = max(m, c)
	i += 1
print(m)


n = int(input())
a = list(map(int, input().split()))
ans = 0
mas = []
j = 0
for i in range(n):
	if a[i] == 1:
		ans += 1
	else:
		mas.append(ans)
		ans = 0
while a[j] == 1:
	ans += 1
	j += 1
mas.append(ans)
mas.sort(reverse=True)
print(mas[0])


n = int(input())
s = list(input().split())
mx = -1
cou = 0
prev = 1
for i in range(n):
	if s[i] == '0':
		prev = 0
		if cou > mx:
			mx = cou
	if s[i] == '1' and prev == 1:
		cou += 1
	if s[i] == '1' and prev == 0:
		prev = 1
		cou = 1
se = -1
for i in range(n):
	if s[i] == '0':
		se = i - 1
		break
lol = 0
for i in range(n - 1, -1, -1):
	if s[i] == '0':
		break
	lol += 1
print(max(mx, lol + se + 1))


n = int(input())
ai = list(map(int, input().split()))
num = 0
num2 = 0
for i in range(n):
	if ai[i] == 0:
		break
	num += 1
for i in range(n - 1, -1, -1):
	if ai[i] == 0:
		break
	num2 += 1
ans = num + num2
num3 = 0
for i in range(n):
	if ai[i] == 0:
		num3 = 0
	else:
		num3 += 1
		ans = max(ans, num3)
print(ans)


n = int(input())
a = list(map(int, input().split()))
zeroPosition = a.index(0)
a = a[zeroPosition:] + a[:zeroPosition] + [0]
maxResult = 0
result = 0
for i in a:
	if i == 0:
		if result > maxResult:
			maxResult = result
		result = 0
	else:
		result += 1
print(maxResult)


n = int(input())
li = list(map(int, input().split()))
li += li
count = 0
max = count
for i in li:
	if i == 1:
		count += 1
		if max < count:
			max = count
	else:
		count = 0
print(max)


n = int(input())
day = ''.join(input().split())
full_day = day[:] + day[:] + day[:]
print(max(map(len, full_day.split('0'))))


import math
import bisect

def argsort(ls):
	return sorted(range(len(ls)), key=ls.__getitem__)

def f(p=0):
	if p == 0:
		return int(input())
	if p == 1:
		return map(int, input().split())
	elif p == 2:
		return list(map(int, input().split()))
	else:
		return sorted(list(map(int, input().split())))
n = f()
cl = f(2)
a = 0
b = 0
count = 0
for i in range(n):
	if cl[i] == 1:
		count += 1
	else:
		a = max(a, count)
		count = 0
a = max(a, count)
i = 0
count1 = 0
count2 = 0
while i < n and cl[i] == 1:
	count1 += 1
	i += 1
i = n - 1
while i > -1 and cl[i] == 1:
	count2 += 1
	i -= 1
b = count1 + count2
print(max(a, b))


n = int(input())
lst = list(map(int, input().split()))[:n]
p = 0
m = 0
for i in range(n):
	lst.append(lst[i])
for i in range(2 * n):
	if lst[i] == 1:
		p = p + 1
		if p > m:
			m = p
	else:
		p = 0
print(m)


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


num = int(input())
data = list(map(int, input().split()))
mx = 0
running = 0
for i in range(-1 * num, num):
	if data[i] == 1:
		running += 1
		mx = max(running, mx)
	else:
		running = 0
print(mx)


n = int(input())
nums = input().replace(' ', '')
newnums = nums + nums
maxlen = 0
lenth = 0
for i in range(len(newnums)):
	if newnums[i] == '1':
		lenth += 1
	else:
		if lenth > maxlen:
			maxlen = lenth
		lenth = 0
print(maxlen)


import math
n = int(input())
a = list(map(int, input().split()))
a *= 2
sum = 0
m = 0
for i in range(2 * n):
	if a[i] == 1:
		sum += 1
		m = max(m, sum)
	else:
		sum = 0
print(m)


n = int(input())
l = list(map(int, input().split()))
l = l * 2
c = 0
m = 0
for i in l:
	if i == 1:
		c = c + 1
		if c > m:
			m = c
	else:
		c = 0
print(m)


n = int(input())
a = list(map(int, input().split()))
i = 0
q = 0
while a[i] != 0:
	q += 1
	i += 1
i = n - 1
while a[i] != 0:
	q += 1
	i -= 1
w = 0
for i in range(n):
	if a[i] == 1:
		w += 1
	else:
		q = max(q, w)
		w = 0
print(q)


n = int(input())
a = input().split()
b = [0]
count = 0
for i in range(n):
	if a[i] == '1':
		count += 1
		if i == n - 1:
			b.append(count)
	else:
		b.append(count)
		count = 0
if n >= 2:
	if a[0] == '1' and a[n - 1] == '1':
		b.append(b[1] + b[len(b) - 1])
print(max(b))


import sys
n = input()
a = [{'0': False, '1': True}[c] for c in sys.stdin.readline().split()]
(count, maxcount) = (0, 0)
for c in a + a + [False]:
	if c:
		count += 1
	else:
		maxcount = max(maxcount, count)
		count = 0
print(maxcount)


ans = []
n = int(input())
arr = list(map(int, input().split()))
c = 0
p = arr[0]
for i in arr:
	if i == 1:
		c += 1
	elif p:
		ans.append(c)
		c = 0
	p = i
if p:
	ans.append(c)
if len(arr) - 1 and arr[0] == arr[-1] == 1:
	ans.append(ans[-1] + ans[0])
print(max(ans if ans else [0]))


_ = input()
workHours = list(map(int, input().split()))
first0 = workHours.index(0)
last0 = list(reversed(workHours)).index(0)
out = first0 + last0
count = 0
for i in workHours:
	if i == 0:
		if count > out:
			out = count
		count = 0
	else:
		count += 1
print(out)


import math
import bisect
import itertools
import sys
I = lambda : sys.stdin.readline()
mod = 10 ** 9 + 7

def modu(a, m):
	if a % m:
		return a % m
	return m

def mindiff(a):
	b = a[:]
	b.sort()
	m = 10000000000
	for i in range(len(b) - 1):
		if b[i + 1] - b[i] < m:
			m = b[i + 1] - b[i]
	return m

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

def merge(a, b):
	i = 0
	j = 0
	c = 0
	ans = []
	while i < len(a) and j < len(b):
		if a[i] < b[j]:
			ans.append(a[i])
			i += 1
		else:
			ans.append(b[j])
			c += len(a) - i
			j += 1
	ans += a[i:]
	ans += b[j:]
	return (ans, c)

def mergesort(a):
	if len(a) == 1:
		return (a, 0)
	mid = len(a) // 2
	(left, left_inversion) = mergesort(a[:mid])
	(right, right_inversion) = mergesort(a[mid:])
	(m, c) = merge(left, right)
	c += left_inversion + right_inversion
	return (m, c)

def is_prime(num):
	if num == 1:
		return False
	if num == 2:
		return True
	if num == 3:
		return True
	if num % 2 == 0:
		return False
	if num % 3 == 0:
		return False
	t = 5
	a = 2
	while t <= int(math.sqrt(num)):
		if num % t == 0:
			return False
		t += a
		a = 6 - a
	return True

def ceil(a, b):
	if a % b == 0:
		return a // b
	else:
		return a // b + 1

def ncr1(n, r):
	s = 1
	for i in range(min(n - r, r)):
		s *= n - i
		s %= mod
		s *= pow(i + 1, mod - 2, mod)
		s %= mod
	return s
n = int(input())
a = list(map(int, input().split()))
a += a
m = 0
c = 1
if a.count(1) == 0:
	print(0)
else:
	for i in range(2 * n - 1):
		if a[i] == a[i + 1] and a[i] == 1:
			c += 1
		else:
			m = max(c, m)
			c = 1
	print(m)


n = eval(input())
a = list(map(int, input().split()))
a.extend(a)
cnt = 0
l = -1
for i in range(2 * n):
	if a[i] == 1:
		if l == -1:
			l = i
			cnt = max(cnt, 1)
		else:
			cnt = max(cnt, i - l + 1)
	else:
		l = -1
print(cnt)


n = int(input())
a = [int(x) for x in input().split()]
a = a + a
mx = 0
tk = 0
for i in a:
	if i == 1:
		tk += 1
	else:
		if tk > mx:
			mx = tk
		tk = 0
if tk > mx:
	mx = tk
print(mx)


from random import randint
n = int(input())
a = list(map(int, input().split(' ')))
a = a * 2
maxx = 0
tmp = 0
for i in range(n * 2 - 1):
	if a[i] == 1 and a[i + 1] == 0:
		if i == 0 or a[i - 1] == 0:
			tmp += 1
	elif a[i] == 1 and a[i + 1] == 1:
		if tmp == 0:
			tmp += 2
		else:
			tmp += 1
	else:
		if tmp > maxx:
			maxx = tmp
		tmp = 0
print(maxx)


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


n = int(input())
a = list(map(int, input().split()))
counter = 0
final = 0
if a.count(1) == 0:
	print(0)
	exit()
a.extend(a[:a.index(0)])
for i in range(len(a)):
	if a[i] == 1:
		counter += 1
	else:
		counter = 0
	if counter > final:
		final = counter
print(final)


x = int(input())
l = list(map(int, input().split()))
l = l + l
s = ''.join(map(str, l)).split('0')
print(max(map(len, s)))


n = int(input())
A = [int(a) for a in input().split()]
A = A + A
a = 0
ma = 0
for i in range(2 * n):
	if A[i] == 1:
		a += 1
		ma = max(ma, a)
	else:
		a = 0
print(ma)


n = int(input())
a = list(map(int, input().split()))
a += a
a.append(0)
max = 0
cnt = 0
for num in a:
	if num == 1:
		cnt += 1
	else:
		if cnt > max:
			max = cnt
		cnt = 0
print(max)


n = int(input())
arr = list(map(int, input().split()))
temp = 0
max = 0
for i in arr:
	if i == 1:
		temp += 1
	else:
		if temp >= max:
			max = temp
		temp = 0
pre = 0
post = 0
for i in arr:
	if i == 1:
		pre += 1
	else:
		break
for i in range(len(arr) - 1, -1, -1):
	if arr[i] == 1:
		post += 1
	else:
		break
if pre + post > max:
	max = pre + post
print(max)


from sys import stdin, stdout
from collections import defaultdict, Counter, deque
from bisect import bisect, bisect_left
import math
from itertools import permutations
import queue
I = stdin.readline
n = int(I())
arr = [int(x) for x in I().split()]
arr += arr
ans = 0
count = 0
if arr[0] == 1:
	count = 1
	ans = 0
for i in range(1, len(arr)):
	if arr[i] == 1 and arr[i - 1] == 1:
		count += 1
		if count > ans:
			ans = count
	elif arr[i] == 1:
		count = 1
		if ans == 0:
			ans = 1
	else:
		count = 0
print(ans)


n = int(input())
p = input().split(' ')
s = ''
for i in range(n):
	s += p[i]
a = s + s
cnt = 0
mx = 0
for i in range(n * 2):
	if a[i] == '1':
		cnt += 1
	else:
		mx = max(mx, cnt)
		cnt = 0
print(mx)


import math
from collections import defaultdict, Counter, deque

def primeFactor(n):
	if n % 2 == 0:
		return 2
	i = 3
	while i ** 2 <= n:
		if n % i == 0:
			return i
		i += 1
	return n

def main():
	n = int(input())
	arr = list(map(int, input().split()))
	arr = arr * 2
	if 1 in arr:
		ones = 0
		m = 0
		for i in range(len(arr)):
			if arr[i] == 0:
				if m < ones:
					m = ones
				ones = 0
			elif arr[i] == 1:
				ones += 1
		print(m)
	else:
		print(0)
t = 1
for _ in range(t):
	main()


n = int(input())
arr = list(map(int, input().split()))
a = arr + arr + [0]
c = 0
m = 0
for i in range(len(a) - 1):
	if a[i] == 1:
		c += 1
	else:
		m = max(m, c)
		c = 0
print(m)


n = int(input())
s = str(input())
s = s.replace(' ', '')
x = s.split('0')
c = 0
if x[0] != '' and x[-1] != '':
	c = len(x[0]) + len(x[-1])
x.sort(reverse=True)
ans = len(x[0])
print(max(ans, c))


def fun(a, n):
	(rest, curr) = (0, 0)
	for hour in a:
		if hour == 1:
			curr += 1
		else:
			rest = max(rest, curr)
			curr = 0
	next = 0
	while next < n and a[next] == 1:
		next += 1
	rest = max(rest, curr + next)
	print(rest)
n = int(input())
a = [int(x) for x in input().split(' ')]
fun(a, n)


input()
a = list(map(int, input().split()))
a += a
maxkol = 0
kol = 0
for i in range(len(a)):
	if a[i] == 1:
		kol += 1
	else:
		maxkol = max(maxkol, kol)
		kol = 0
print(maxkol)


n = int(input())
bit = input().split()
b = []
for i in range(n):
	b.append(int(bit[i]))
b = b + b
cont = 0
l = []
v = 0
while cont < n:
	while b[cont] == 1:
		v += 1
		cont += 1
	l.append(v)
	v = 0
	cont += 1
print(max(l))


n = int(input())
a = list(map(int, input().split()))
a = a + a
ans = a[0]
prev = a[0]
t = a[0]
for i in range(1, 2 * n):
	if prev and a[i]:
		t += 1
	else:
		t = a[i]
		prev = a[i]
	ans = max(ans, t)
print(ans)


n = int(input())
l = list([int(x) for x in input().split()])
c = 0
max = 0
i = 0
while i < n:
	c = 0
	if l[i] == 1:
		while i < n and l[i] == 1:
			c += 1
			i += 1
		if c > max:
			max = c
	else:
		i += 1
a = 0
b = n - 1
c = 0
if l[0] == 1 and l[n - 1] == 1:
	while a < n and l[a] == 1:
		c += 1
		a += 1
	while b >= 0 and l[b] == 1:
		c += 1
		b -= 1
	if c > max:
		max = c
print(max)


a = int(input())
x = 0
y = 0
t = []
t = list(map(int, input().split()))
t = t * 2
for i in range(a * 2):
	if t[i] == 1:
		x += 1
	else:
		if x > y:
			y = x
		x = 0
print(y)


n = int(input())
l = ''.join(input().split()) * 2
l = l.split('0')
l = [len(j) for j in l]
print(max(l))


n = int(input())
l = list(map(int, input().split()))
max = 0
i = 0
while i < n:
	j = i
	if l[i] == 1:
		count = 0
		while j < n:
			if l[j] != 0:
				count += 1
				j += 1
			else:
				break
		if count > max:
			max = count
	if j > i:
		i = j
	else:
		i += 1
if l[0] == 1 and l[-1] == 1:
	count1 = 0
	count2 = 0
	for i in l:
		if i == 0:
			break
		else:
			count1 += 1
	for i in reversed(l):
		if i == 0:
			break
		else:
			count2 += 1
	if count1 + count2 > max:
		max = count1 + count2
print(max)


(n, x, count, Max, j) = (int(input()), list(map(int, input().split(' '))), 0, 0, 0)
for i in range(len(x)):
	if x[i] == 1:
		count += 1
	else:
		(Max, count) = (max(Max, count), 0)
if x[0] == 1 and count != 0:
	while x[j] != 0:
		(count, j) = (count + 1, j + 1)
print(max(Max, count))


n = int(input())
a = list(map(int, input().split()))
first = 0
ans = 0
flag = False
l = 0
while l < n:
	r = l
	cnt = 0
	while r < n and a[r] == 1:
		if l == 0:
			first += 1
		else:
			cnt += 1
		if r == n - 1:
			flag = True
		r += 1
	if l == 0:
		ans = max(ans, first)
	if flag:
		ans = max(ans, first + cnt)
	else:
		ans = max(ans, cnt)
	l = r + 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
if a[-1] == 1:
	i = 0
	while a[i] == 1 and i < n:
		a.append(1)
		i += 1
a += [0]
total = 0
ans = 0
for i in a:
	if i == 1:
		total += 1
	else:
		ans = max(ans, total)
		total = 0
print(ans)


n = int(input())
list1 = [int(x) for x in input().split()] * 2
prev = 2
counter = 0
maxi = 0
for i in list1:
	if i == prev and prev == 1:
		counter += 1
	else:
		counter = 0
	if counter > maxi:
		maxi = counter
	prev = i
if 1 in list1:
	print(maxi + 1)
else:
	print(0)


num = int(input())
arr = list(map(int, input().split()))
arr = arr + arr
mx = 0
ct = 0
for n in arr:
	if n == 1:
		ct += 1
		mx = max(ct, mx)
	else:
		ct = 0
print(mx)


n = int(input())
a = [int(i) for i in input().split()]
if 0 in a:
	a += a
	k = 0
	s = 0
	for i in range(2 * n - 1):
		if a[i] == a[i + 1] == 1:
			s += 1
		elif a[i] == a[i + 1] == 0:
			continue
		elif a[i] == 1 and a[(i + 1) % n] == 0:
			if s > k:
				k = s
			else:
				s = 1
		else:
			s = 1
	print(k)
else:
	pass


n = int(input())
ls = input().split(' ')
ls = ls * 2
count = 0
max = 0
for i in ls:
	if i == '1':
		count += 1
	else:
		if max < count:
			max = count
		count = 0
print(max)


n = int(input())
l = list(map(int, input().split()))
dw = 0
dwf = dw
for i in range(n):
	if l[i] == 1:
		dw += 1
		if dw > dwf:
			dwf = dw
	else:
		dw = 0
i = 0
while l[i] == 1:
	dw += 1
	if dw > dwf:
		dwf = dw
	i += 1
print(dwf)


n = int(input())
a = list(map(int, input().split()))
z = 2 * a
N = len(z)
c = []
k = 0
for i in range(N - 1):
	if z[i] == 1:
		k += 1
	elif z[i] == 1 and z[i + 1] == 1:
		k += 1
	else:
		k = 0
	c.append(k)
print(max(c))


d = int(input())
entrada = []
entrada = input().split()
totalMesmo = 0
total = 0
first = 0
firstCount = 0
lastCount = 0
for k in range(0, d):
	i = int(entrada[k])
	if i == 1:
		total = total + 1
		if total > totalMesmo:
			totalMesmo = total
		if k == d - 1:
			lastCount = total
	else:
		if first == 0:
			firstCount = total
			first = 1
		total = 0
print(max(totalMesmo, lastCount + firstCount))


T = int(input())
L = list(map(int, input().split()))
for i in range(T):
	L.append(L[i])
req = []
c = 0
for j in range(len(L)):
	if L[j] == 1:
		c = c + 1
	elif L[j] == 0:
		req.append(c)
		c = 0
if len(req) == 0:
	print(T)
else:
	print(max(req))


a = int(input())
l = [int(i) for i in input().split()]
for i in range(len(l)):
	l.append(l[i])
cont = 0
maior = -1
for i in range(len(l)):
	if l[i] == 1:
		cont += 1
	elif l[i] == 0:
		maior = max(cont, maior)
		cont = 0
maior = max(cont, maior)
print(maior)


amount = int(input())
array = [int(s) for s in input().split()]
max_ = 0
pref = [array[0]]
for i in range(1, len(array)):
	if array[i] == 1:
		pref.append(pref[-1] + 1)
	else:
		pref.append(0)
max_ = max(pref)
if array[0] == 1 and array[-1] == 1:
	for i in range(len(array)):
		if array[i] == 0:
			left_z = i
			break
	if pref[left_z - 1] + pref[-1] > max_:
		max_ = pref[left_z - 1] + pref[-1]
print(max_)


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	a.append(a[i])
ans = 0
i = 0
while i < 2 * n:
	if a[i] == 0:
		i += 1
		continue
	cur = 0
	while i < 2 * n and a[i] == 1:
		i += 1
		cur += 1
	ans = max(ans, cur)
	i += 1
print(ans)


n = int(input())
li = list(map(int, input().split()))
c = 0
m = 0
for i in li:
	if i == 1:
		c += 1
	else:
		if c > m:
			m = c
		c = 0
i = 0
while li[i]:
	c += 1
	i += 1
if m < c:
	m = c
print(m)


days = int(input())
sched = list(map(int, input().split()))
largest = 0
current = 0
first = -1
last = -1
for (i, x) in enumerate(sched):
	if x == 1:
		current += 1
	else:
		if first == -1:
			first = i
		last = i
		current = 0
	largest = max(current, largest)
wrap = len(sched) - last + first - 1
ans = max(largest, wrap)
print(ans)


n = input()
a = list(map(len, input().replace(' ', '').split('0')))
print(max(max(a), a[0] + a[-1]))


length = int(input())
str = [int(x) for x in input().split()]
first = 0
for i in str:
	if i == 1:
		first += 1
	else:
		break
last = 0
for i in reversed(str):
	if i == 1:
		last += 1
	else:
		break
bestSub = 0
soFar = 0
for i in str:
	if i == 1:
		soFar += 1
	else:
		if soFar > bestSub:
			bestSub = soFar
		soFar = 0
print(max(first + last, bestSub))


n = int(input())
schedule = []
schedule = input().split(' ')
temp = 0
start_seq = 0
max_c = 0
for i in range(len(schedule)):
	if schedule[i] == '1':
		temp += 1
	else:
		if max_c == 0 and i - temp == 0:
			start_seq = temp
		if max_c < temp:
			max_c = temp
		temp = 0
if max_c < temp:
	max_c = temp
if max_c < temp + start_seq:
	max_c = temp + start_seq
print(max_c)


n = int(input())
d = input().split()
f = 0
rest = [0]
for i in range(n - 1, -1 * n, -1):
	if d[i] == '1':
		f += 1
		rest.append(f)
	else:
		f = 0
print(max(rest))


n = int(input())
a = list(map(int, input().split()))
temp = 0
s = 0
x = 0
for i in a:
	if i == 1:
		s += i
	elif i == 0:
		if s > temp:
			temp = s
		s = 0
if s > temp:
	temp = s
if temp > 0 and temp != n:
	ind = a.index(0)
	for i in range(ind):
		x += a[i]
	for i in range(n - 1, -1, -1):
		if a[i] == 0:
			break
		else:
			x += a[i]
if x > temp:
	print(x)
else:
	print(temp)


hours = int(input())
schedule = list(map(int, input().split()))
j = 0
while schedule[j] == 1:
	schedule.append(schedule[j])
	j += 1
count = 0
result = 0
for i in range(hours + j):
	if schedule[i] == 0:
		count = 0
	else:
		count += 1
		result = max(result, count)
print(result)


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


input()
S = input()
S = (S + S).replace(' ', '')
if '1' not in S:
	print(0)
	exit()
(MAX, i, Curr) = (0, 0, 0)
while i < len(S):
	(Curr, MAX) = (Curr + 1 if S[i] == '1' else 0, max(Curr, MAX))
	i += 1
print(MAX)


n = int(input())
r = input().split()
ll = ''.join(r).find('0')
rl = ''.join(r).rfind('0')
ml = []
ml.extend([n - rl - 1 + ll])
k = 0
for i in range(ll + 1, rl + 1):
	if r[i] == '0':
		ml.extend([k])
		k = 0
	else:
		k += 1
print(max(set(ml)))


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
n = ii()
a = li()
a += a[:-1]
ans = 0
i = 0
while i < len(a):
	j = i + 1
	while j < len(a) and a[i] == a[j]:
		j += 1
	if a[i] == 1:
		ans = max(ans, j - i)
	i = j
print(ans)


n = int(input())
s = ''.join(input().split()) * 2
s = s.split('0')
s = [len(i) for i in s]
print(max(s))


is_debug = False
n = int(input())
s = input().replace(' ', '')
s = s * 2
a = s.split('0')
print(f's={s}, a={a}', end='|') if is_debug else ''
v = -1
for i in range(len(a)):
	v = max(v, len(a[i]))
print(f'{v}')


N = int(input())
H = list(map(int, input().split()))
t = 0
i = 0
M = 0
while i < N:
	while i < N and H[i] == 1:
		t += 1
		i += 1
	if M < t:
		M = t
	t = 0
	while i < N and H[i] == 0:
		i += 1
if M < t:
	M = t
	t = 0
t = 0
i = 0
while i < N and H[i] == 1:
	t += 1
	i += 1
j = N - 1
while j > i and H[j] == 1:
	t += 1
	j -= 1
if M < t:
	M = t
print(M)


n = input()
arr = list(map(int, input().split(' ')))
i = 0
max_ = 0
current = 0
flag = False
while i < len(arr):
	if arr[i] == 1:
		current += 1
	else:
		if max_ < current:
			max_ = current
		current = 0
		if flag == True:
			break
	i += 1
	if i == len(arr) and arr[0] == 1 and (arr[i - 1] == 1) and (flag == False):
		i = 0
		flag = True
if current > max_:
	max_ = current
print(max_)


n = int(input())
a = [int(o) for o in input().split()]
lol = a[:] + a[:]
loa = len(lol)
lll = [0] * loa
lll[0] = lol[0]
for i in range(1, loa):
	if lol[i] == 1:
		lll[i] = lol[i] + lll[i - 1]
d = max(lll)
if d > n:
	print(n)
else:
	print(d)


length = input()
days = input().split()
loop = 0
if days[0] == '1' and days[len(days) - 1] == '1':
	start = 0
	n = 0
	while n < len(days) and days[n] == '1':
		start += 1
		n += 1
	end = 0
	n = len(days) - 1
	while n > -1 and days[n] == '1':
		end += 1
		n = n - 1
	loop = start + end
maxblock = 0
block = 0
m = 0
while m < len(days):
	if days[m] == '1':
		block += 1
	if days[m] == '0':
		if block > maxblock:
			maxblock = block
		block = 0
	m += 1
if block > maxblock:
	maxblock = block
if maxblock > loop:
	print(maxblock)
else:
	print(loop)


def test():
	n = input()
	ls = [int(i) for i in input().split(' ')]
	counts = [s for s in ls]
	counts = counts + counts
	ls = ls + ls
	for s in range(1, len(ls)):
		if ls[s] == 1 and ls[s] == ls[s - 1]:
			counts[s] = counts[s - 1] + 1
	print(max(counts))
test()


def rest(inputlist):
	newlist = inputlist * 2
	absmax = 0
	tempmax = 0
	for i in newlist:
		if i == 1:
			tempmax += 1
		else:
			if tempmax > absmax:
				absmax = tempmax
			tempmax = 0
	return absmax
t = input()
inputlist = list(map(int, input().split()))
print(rest(inputlist))


n = int(input())
days = str(input())
days = [x for x in days + days if x != ' ']
max_h = 0
temp = 0
for i in days:
	if i == '1':
		temp += 1
	else:
		if temp > max_h:
			max_h = temp
		temp = 0
print(max_h)


n = int(input())
s = input().replace(' ', '')
cnt = 0
ans = 0
ss = s + s
for i in range(n * 2):
	if ss[i] == '1':
		cnt += 1
	else:
		cnt = 0
	ans = max(cnt, ans)
print(ans)


n = int(input())
a = list(map(int, input().split(' ')))
t = [0] * n
(t[0], c, p) = (a[0], a[0], a[0])
for i in range(1, n):
	p *= a[i]
	t[i] = a[i] * (1 + t[i - 1])
	c = max(c, p * t[i])
result = max(max(t), c + t[n - 1])
print(result)


n = int(input())
a = list(map(int, input().split()))
(count, greatest) = (0, 0)
(add, i) = ([], 0)
while a[i] != 0:
	add.append(1)
	i += 1
a = a + add
for i in a:
	if i == 1:
		count += 1
	else:
		if greatest < count:
			greatest = count
		count = 0
print(greatest if count < greatest else count)


n = int(input())
l = list(map(int, input().split()))
ans = 0
max = 0
for i in range(2):
	for j in range(n):
		ans += l[j]
		if ans > max:
			max = ans
		ans *= l[j]
print(max)


n = int(input())
a = list(map(int, input().split()))
for i in range(len(a)):
	if a[i] == 1:
		a.append(a[i])
	else:
		break
counter = 0
res = 0
for i in a:
	if i == 1:
		counter += 1
		res = max(res, counter)
	else:
		res = max(res, counter)
		counter = 0
print(res)


n = int(input())
a = ''.join(list(input().split()))
(c, i) = (0, 0)
x = a.find('0')
(c, d) = (x, x)
while True:
	y = a.find('0', x + 1, n)
	if y == -1:
		if d + n - x - 1 > c:
			c = d + n - x - 1
		break
	if y - x - 1 > c:
		c = y - x - 1
	x = y
print(c)


n = int(input())
a = input() + ' '
a *= 2
max = count = 0
for i in a:
	ch = ord(i)
	if ch == ord(' '):
		continue
	elif ch == ord('0'):
		max = count if count > max else max
		count = 0
	else:
		count += 1
print(max)


def main():
	n = int(input())
	a0 = list(map(int, input().split()))
	a = [*a0, *a0]
	mx = 0
	start = 0
	while start < len(a) and a[start] == 0:
		start += 1
	if start == len(a):
		print(0)
	else:
		end = start
		while end < len(a):
			end += 1
			if end < len(a) and a[end] == 0:
				mx = max(mx, end - start)
				start = end + 1
				while start < len(a) and a[start] == 0:
					start += 1
				end = start
		print(mx)
main()


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	if a[i] == 1:
		a += [a[i]]
		n += 1
	else:
		break
maxc = 0
maxcc = 0
for i in range(n):
	if a[i] == 0:
		maxc = max(maxc, maxcc)
		maxcc = 0
	else:
		maxcc += 1
maxc = max(maxc, maxcc)
print(maxc)


n = int(input())
l = list(map(int, input().split(' ')))
c = 0
res = 0
for i in range(n):
	if l[i] == 1:
		c += 1
		res = max(c, res)
	else:
		c = 0
start = 0
for i in range(n):
	if l[i] == 1:
		start += 1
	else:
		break
end = 0
for i in range(n):
	if l[n - 1 - i] == 1:
		end += 1
	else:
		break
if start == n:
	print(n)
else:
	print(max(res, start + end))


n = int(input())
timetable = input().replace(' ', '') * 2
timetable = timetable.split('0')
max_break = 0
for i in timetable:
	if len(i) > max_break:
		max_break = len(i)
print(max_break)


(n, i) = (int(input()), 0)
list = [int(i) for i in input().split()]
temp = []
while i < n:
	count = 0
	while i < n and list[i] == 1:
		count += 1
		i += 1
	temp.append(count)
	i += 1
k = temp[len(temp) - 1]
if list[0] == 1 and list[n - 1] == 1:
	temp.append(k + temp[0])
print(max(temp))


n = int(input())
a = input()
a = a.replace(' ', '')
a = a * 2
t = 0
m = 0
for i in a:
	if i == '0':
		if t > 0:
			m = max(t, m)
		t = 0
	else:
		t += 1
print(m)


n = int(input())
schedule = input().replace(' ', '')
schedule = ''.join(schedule).lstrip('1')
no_of_ones = n - len(schedule)
schedule += '1' * no_of_ones
max_rest_days = 0
count = 0
for day in schedule:
	if day == '0':
		max_rest_days = max(count, max_rest_days)
		count = 0
	else:
		count += 1
print(max(max_rest_days, count))


n = int(input())
arr = list(map(int, input().split()))
arr.extend(arr)
ans = 0
i = 0
while i < len(arr):
	if arr[i] == 0:
		i += 1
	else:
		j = i
		while j < len(arr) and arr[j] == 1:
			ans = max(ans, j - i + 1)
			j += 1
		i = j
print(ans)


n = int(input())
a1 = list(map(int, input().split()))
a = []
d = set(a)
if len(d) == 1:
	print(n)
else:
	count = 0
	b = []
	i = 0
	a = a1 + a1
	for x in a:
		if x == 1:
			count += 1
			if i == n - 1:
				b.append(count)
		else:
			b.append(count)
			count = 0
		i += 1
	m = max(b)
	if a[-1] == 1 and a[0] == 1 and (m == 1):
		print(2)
	else:
		print(m)


n = int(input())
a = []
tokens = input().split()
for element in tokens:
	a.append(int(element))
maximum = 0
current = 0
for i in range(len(a)):
	if a[i] == 1:
		current += 1
		if i == len(a) - 1:
			j = 0
			while a[j] == 1:
				current += 1
				j += 1
	else:
		current = 0
	if current >= maximum:
		maximum = current
print(maximum)


n = int(input())
a = [int(x) for x in input().split()]
a = a * 2
answer = 0
i = 0
while i < len(a):
	if a[i] == 1:
		currentrun = 1
		i += 1
		while i < len(a) and a[i] == 1:
			currentrun += 1
			i += 1
		if currentrun > answer:
			answer = currentrun
	else:
		i += 1
print(answer)


n = int(input())
str = input()
arr = [int(ele) for ele in str.split(' ')]

def max(a, b):
	if a > b:
		return a
	else:
		return b
ans = 0
ctr = 0
for i in range(n):
	if arr[i] == 1:
		ctr += 1
		ans = max(ans, ctr)
	else:
		ctr = 0
ans1 = 0
pos = 0
for i in range(n):
	if arr[i] == 1:
		ans1 += 1
		pos += 1
	else:
		break
for i in range(n - 1, -1, -1):
	if i <= pos:
		break
	if arr[i] == 1:
		ans1 += 1
	else:
		break
print(max(ans1, ans))


n = int(input())
s = ''.join(map(str, input().split()))
s = 2 * s
c = 0
li = []
li.append(0)
for i in s:
	if i == '1':
		c += 1
		li.append(c)
	else:
		c = 0
print(max(li))


n = int(input())
A = list(map(int, input().split()))
A.append(0)
ans = 0
i = 0
while i < len(A):
	c = 0
	if A[i] == 1:
		while A[i] == 1:
			c += 1
			i += 1
	ans = max(ans, c)
	i += 1
k = list(set(A))
if len(k) == 1:
	if k[0] == 1:
		print(len(A))
	else:
		print(0)
else:
	count = 0
	i = 0
	j = 0
	if A[0] == 1 and A[n - 1] == 1:
		while A[i] == 1 or A[n - 1 - j] == 1:
			if A[i] == 1:
				count += 1
				i += 1
			if A[n - 1 - j] == 1:
				count += 1
				j += 1
	ans = max(ans, count)
	print(ans)


n = input()
input_ = input().split()
input_ = list(map(int, input_))
count = 0
max_ = 0
for i in input_:
	if i == 0:
		count = 0
	if i == 1:
		count += 1
		max_ = max(count, max_)
count = 0
for i in input_:
	if i == 1:
		count += 1
	else:
		break
for i in input_[::-1]:
	if i == 1:
		count += 1
	else:
		break
max_ = max(count, max_)
print(max_)


n = int(input())
s = input().split()
mx = 0
count = 0
for i in range(2 * n):
	if s[i % n] == '1':
		count += 1
		mx = max(mx, count)
	else:
		count = 0
print(mx)


n = int(input())
l = [*map(int, input().split())]
H = MAX = 0
Ind = -1
for i in range(n):
	if l[i] == 1:
		H += 1
		Ind = i
	else:
		if H > MAX:
			MAX = H
		H = 0
if Ind == n - 1:
	c = 0
	for i in range(n - 1, -1, -1):
		if l[i] == 0:
			break
		else:
			c += 1
	for i in range(n):
		if l[i] == 0:
			break
		else:
			c += 1
	print(max(MAX, H, c))
else:
	print(max(MAX, H))


n = int(input())
l = input().split(' ')
k = []
for i in range(n - 1, 0, -1):
	if l[i] == '1':
		k.append('1')
	else:
		break
k.extend(l)
l = k
c = 0
m = 0
for i in l:
	if i == '1':
		c += 1
		if c > m:
			m = c
	else:
		c = 0
print(m)


n = int(input())
a = list(map(int, input().split()))
ans = 0
consecutive = 0
for i in range(n):
	if a[i] == 1:
		consecutive += 1
	else:
		consecutive = 0
	ans = max(ans, consecutive)
L = 0
for i in range(n):
	if a[i] == 1:
		L += 1
	else:
		break
R = 0
for i in range(n - 1, -1, -1):
	if a[i] == 1:
		R += 1
	else:
		break
print(max(ans, min(n, L + R)))


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict
import math

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
n = intIn()
a = listIn()
b = []
for i in range(n):
	if a[i] == 1:
		b.append(1)
	else:
		break
a += b
cnt = float('-inf')
c = 0
for i in range(len(a)):
	if a[i] == 1:
		c += 1
	else:
		cnt = max(cnt, c)
		c = 0
cnt = max(cnt, c)
print(cnt)


n = int(input())
schedule = list(map(int, input().split()))
schedule = schedule + schedule
ans = 0
i = 0
while i < n * 2 - 1:
	if schedule[i] == 1:
		curr = 1
		j = i + 1
		while j < n * 2 and schedule[j] == 1:
			curr += 1
			j += 1
		ans = max(ans, curr)
		i = j - 1
	i += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
s = set(a)
if len(s) == 1 and 1 in s:
	print(n)
	return
k = 0
ma = 0
for i in range(n):
	if a[i]:
		k += 1
	else:
		ma = max(ma, k)
		k = 0
for i in range(n):
	if a[i]:
		k += 1
	else:
		ma = max(ma, k)
		k = 0
print(max(ma, k))


n = int(input())
a = input()
a += ' ' + a
b = [i for i in a.split()]
ans = 0
t = 0
for i in range(2 * n):
	if b[i] == '1':
		t += 1
	else:
		ans = max(ans, t)
		t = 0
print(ans)


print(max([0] + [sum((1 for _ in g)) for (k, g) in __import__('itertools').groupby(list(map(int, (input(), input())[1].split(' '))) * 2) if k == 1]))


n = int(input())
l = input()
l = l.replace(' ', '')
l = l + l
m = []
c = 0
for i in l:
	if i == '1':
		c += 1
	else:
		m.append(c)
		c = 0
print(max(m))


n = int(input())
a = list(map(lambda w: len(w), ''.join(input().split()).split('0')))
print(max(max(a), a[0] + a[-1]) if len(a) > 1 else max(a))


total = int(input())
rest = list(input().split())
rest += rest
count = 0
ans = 0
for i in range(2 * total):
	if rest[i] == '1':
		count += 1
	else:
		ans = max(count, ans)
		count = 0
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
w = len(a)
for e in range(w):
	a.append(a[e])
l = 0
maxl = 0
start = 0
for x in range(len(a)):
	if a[x] == 1:
		if start == 0:
			start = 1
			l += 1
		else:
			l += 1
	elif start == 1:
		maxl = max(maxl, l)
		l = 0
print(maxl)


n = int(input())
a = list(map(int, input().split()))
lst = []
s = a.index(0)
a = a[::-1]
s = s + a.index(0)
a = a[::-1]
lst.append(s)
for i in range(len(a)):
	if a[i] == 0:
		for j in range(i + 1, len(a)):
			if a[j] == 0:
				lst.append(j - i - 1)
				break
print(max(lst))


n = int(input())
l = list(map(int, input().split()))
m = -1
c = 0
last = 0
first = 0
f = 0
for i in range(n):
	if l[i] == 0:
		c = 0
		if f == 0:
			first = i
			f = 1
	else:
		c += 1
		if i == n - 1:
			last = c
	m = max(m, c)
print(max(m, first + last))


a = int(input())
l = list(map(int, input().split()))
l = l * 2
count = 0
q = []
for i in l:
	if i == 1:
		count += 1
	else:
		q += [count]
		count = 0
print(max(q))


n = int(input())
darling = input()
darling = darling.split()
zero = two = 0
for i in range(0, n * 2):
	if darling[i % n] == '0':
		two = 0
	else:
		two += 1
	zero = max(zero, two)
print(zero)


n = input()
seq = input().split()
seq = seq + seq
seq_sum = 0
lst = []
for i in seq:
	if int(i) == 0:
		seq_sum = int(i)
	else:
		seq_sum = seq_sum + int(i)
	lst.append(seq_sum)
print(max(lst))


import sys
import math
import bisect

def main():
	n = int(input())
	A = list(map(int, input().split()))
	A.extend(A)
	max_val = 0
	val = 0
	for i in range(len(A)):
		if A[i]:
			val += 1
		else:
			val = 0
		max_val = max(max_val, val)
	print(max_val)
main()


import itertools as it
input()
a = [int(x) for x in input().split()]
a = a + a
b = []
for (x, y) in it.groupby(a):
	b.append(list(y))
l = []
for i in range(len(b)):
	if all(b[i]):
		l.append(len(b[i]))
if len(l) != 0:
	print(max(l))
else:
	print(0)


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


n = int(input())
a = (''.join(input().split()) * 2).split('0')
print(len(max(a, key=len)))


n = int(input())
a = [int(i) for i in input().split()]
a.extend(a)
(i, j) = (0, 0)
m = 0
while i < len(a):
	while j < len(a) and a[j] == 1:
		j += 1
	j += 1
	m = max(m, j - i - 1)
	i = j
print(m)


import math
import random
import sys
from collections import defaultdict as dd
mod = 7 + 10 ** 9
col = dd(int)
g = dd(list)
n = int(input())
l = [1 - int(i) for i in input().split()]
m = 0
i = 0
ans = 0
cur = 0
while i < n:
	if l[i] == 0:
		cur += 1
		i += 1
	else:
		i += 1
		cur = 0
	ans = max(ans, cur)
st = 0
while l[st] == 0:
	st += 1
en = 0
while l[n - en - 1] == 0:
	en += 1
print(max(ans, st + en))


n = int(input())
a = [int(i) for i in input().split(' ')]
r = a[0]
b = []
t = 1
ans = 0
if n == 1:
	print(a[0])
else:
	for i in range(1, n):
		if a[i] != r:
			b.append((r, t))
			if r == 1:
				ans = max(ans, t)
			r = a[i]
			t = 1
		else:
			t += 1
	if r == 1:
		ans = max(ans, t)
	b.append((a[i], t))
	if len(b) >= 3:
		if b[0][0] == 1 and b[-1][0] == 1:
			ans = max(ans, b[0][1] + b[-1][1])
	print(ans)


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


import sys
DBG = True
n = int(input())
a = list(map(int, input().split()))
zfound = False
seq = 0
maxseq = 0
firstseq = 0
for i in range(n):
	if a[i] == 1:
		seq += 1
	else:
		if seq > maxseq:
			maxseq = seq
		if not zfound:
			firstseq = seq
			zfound = True
		seq = 0
if seq + firstseq > maxseq:
	maxseq = seq + firstseq
print(maxseq)


n = int(input())
a = list(map(int, input().split()))
(ans, tmp, k) = (0, 1, 0)
b = []
tmp = a[0]
for i in range(len(a)):
	if a[i] == tmp:
		k += 1
	else:
		if tmp == 1:
			b.append(k)
		k = 1
		tmp = a[i]
if k and tmp == 1:
	b.append(k)
if a[0] == a[-1] and a[0] == 1:
	b.append(b[0] + b[-1])
b.append(0)
print(max(b))


n = int(input())
l = list(input().split())
s = ''.join(l)
s += s

def co(a):
	c = 0
	m = 0
	for i in a:
		if i == '1':
			c += 1
			if m < c:
				m = c
		else:
			c = 0
	return m
print(co(s))


n = int(input())
l = [int(x) for x in input().split()]
k = 0
a = 0
b = 0
for i in range(2 * n):
	k = i
	if k > n - 1:
		k = k - n
	if l[k] == 1:
		a = a + 1
	if l[k] == 0:
		a = 0
	b = max(a, b)
print(b)


N = input()
arr = list(map(int, input().split()))
arr = arr * 2
maxRest = 0
temp = 0
for i in range(len(arr)):
	if arr[i] == 1:
		temp += 1
	else:
		if temp > maxRest:
			maxRest = temp
		temp = 0
print(maxRest)


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
a = list(mints())
a = a + a
i = 0
n = len(a)
r = 0
while i < len(a):
	j = i + 1
	while j < n and a[j] == a[i]:
		j += 1
	if a[i] == 1:
		r = max(r, j - i)
	i = j
print(r)


n = int(input())
a = list(map(int, input().split()))
max_k = 0
k = 0
r = 0
for i in range(2 * n):
	if a[i % n] == 1:
		k += 1
		if i % n == 0:
			r += 1
	else:
		if k > max_k:
			max_k = k
		k = 0
		if r == 2:
			break
if k > max_k:
	max_k = k
print(max_k)


n = int(input())
t = input()
t = t.split()
for i in range(len(t)):
	t[i] = int(t[i])
first = True
start = 0
end = 0
best = 0
streak = 0
for i in range(len(t)):
	if t[i] == 1:
		streak += 1
	else:
		if first:
			start = streak
		first = False
		if streak > best:
			best = streak
		streak = 0
if streak > best:
	best = streak
if not first:
	end = streak
if start + end > best:
	best = start + end
print(best)


n = int(input())
sched = list(map(int, input().split()))
double = sched + sched
maxim = 0
count = 0
for i in double:
	if i == 1:
		count += 1
	if i == 0:
		if count > maxim:
			maxim = count
		count = 0
print(maxim)


n = int(input())
l = list(map(int, input().split()))
cursum = 0
maxSoFar = 0
for i in l:
	if i == 1:
		cursum = cursum + 1
		if cursum > maxSoFar:
			maxSoFar = cursum
	else:
		cursum = 0
i = 0
j = 0
for a in l:
	if a == 1:
		i += 1
	else:
		break
for k in range(n - 1, -1, -1):
	if l[k] == 0:
		break
	j += 1
print(max(maxSoFar, min(n, i + j)))


n = int(input())
ar = list(map(int, input().strip().split()))
c = 0
if ar[0] == 1 and ar[-1] == 1:
	i = 0
	while i < n and ar[i] == 1:
		c += 1
		i += 1
	i = n - 1
	while i >= 0 and ar[i] == 1:
		c += 1
		i -= 1
cs = [0]
s = 0
for i in range(n):
	if ar[i] == 1:
		s += 1
		cs.append(s)
	else:
		s = 0
ans = max(cs)
if ans > c:
	print(ans)
else:
	print(c)


n = int(input())
num_arr = list(map(int, input().split()))
count = 0
max_count = 0
num_arr = num_arr + num_arr
for i in num_arr:
	if i == 1:
		count += 1
	if i == 0:
		if max_count <= count:
			max_count = count
		count = 0
print(max_count)


n = input()
s = ''.join(input().split())
ss = (str(s) + str(s)).split('0')
ss.sort()
ans = len(ss[-1])
if len(ss) == 0:
	print(0)
else:
	print(ans)


n = int(input())
a = list(map(int, input().split()))
st = a + a + a
k = 0
mxk = 0
for i in st:
	if i == 1:
		k += 1
	else:
		mxk = max(mxk, k)
		k = 0
print(mxk)


g = int(input())
s = list(map(int, input().split()))
s = s + s
streak = False
maxs = 0
currs = 0
for i in s:
	if i == 1 and streak:
		currs += 1
		if currs > maxs:
			maxs = currs
	elif i == 1:
		streak = True
		currs = 1
		if currs > maxs:
			maxs = currs
	else:
		streak = False
		currs = 0
print(maxs)


n = int(input())
inp = input()
arr = list(map(int, inp.split()))

def ans(n, arr):
	ml = 0
	cl = 0
	for i in range(2 * n):
		if arr[i % n] == 1:
			cl += 1
		else:
			if cl > ml:
				ml = cl
			cl = 0
	return ml
print(ans(n, arr))


n = int(input())
a = list(map(int, input().split()))
c = []
t = 0
for i in a:
	if i == 1:
		t += 1
	else:
		c.append(t)
		t = 0
c.append(t)
if a[0] == 1 and a[-1] == 1:
	c.append(c[0] + c[-1])
print(max(c))


N = int(input())
ls = list(map(int, input().split()))
cnt = 0
Max = cnt
for i in range(N):
	if ls[i] == 1:
		cnt += 1
	else:
		Max = max(Max, cnt)
		cnt = 0
if ls[-1] == 0:
	print(Max)
else:
	i = 0
	while ls[i] != 0:
		cnt += 1
		i += 1
	Max = max(Max, cnt)
	print(Max)


import sys

def process(n, a):
	smax = 0
	s = 0
	s_begin = 0
	s_end = 0
	start = True
	for i in a:
		if i == 0 and start:
			s_begin = s
			start = False
		if i == 1:
			s = s + 1
		else:
			if s > smax:
				smax = s
			s = 0
	return max(smax, s + s_begin)
c = 0
for line in sys.stdin:
	if c == 0:
		n = int(line.rstrip())
		c = 1
	else:
		a = [int(x) for x in line.rstrip().split()]
x = process(n, a)
sys.stdout.write(str(x) + '\n')


n = int(input())
l = []
curr = 0
ans = []
s = input().split()
for i in range(n):
	l.append(int(s[i]))
for i in range(n):
	if l[i] == 1:
		curr += 1
		ans.append(curr)
	else:
		curr = 0
		ans.append(0)
if l[0] == 1 and l[n - 1] == 1:
	i = 0
	while l[i] != 0:
		i += 1
	if i == n:
		print(n)
	else:
		ans.append(ans[n - 1] + i)
		print(max(ans))
else:
	print(max(ans))


n = int(input())
line = list(input().strip().split(' '))
current_rest = 0
max_rest = 0
round = 0
while round < 2:
	for i in range(n):
		if line[i] == '1':
			current_rest += 1
		elif line[i] == '0':
			current_rest = 0
		max_rest = max(current_rest, max_rest)
	round += 1
print(max_rest)


n = int(input())
a = input().split()
a = a + a
mx = 0
count = 0
for i in range(2 * n):
	if a[i] == '1':
		count += 1
		if count >= mx:
			mx = count
	else:
		count = 0
print(mx)


n = int(input())
days = list(map(int, input().split()))
wk = 0
wks = []
for i in range(len(days)):
	if days[i] == 1:
		if i == 0 and days[-1] == 1:
			for j in range(len(days) - 1, 0, -1):
				if days[j] == 1:
					wk += 1
				else:
					break
			wk += 1
		else:
			wk += 1
	elif days[i] == 0:
		wks.append(wk)
		wk = 0
wks.append(wk)
wk = 0
print(max(wks))


n = int(input())
a = [int(i) for i in input().split()]
a = a + a
e = 0
l = []
for i in range(0, len(a)):
	if a[i] == 1:
		e = e + 1
	else:
		l.append(e)
		e = 0
l.append(e)
print(max(l))


n = int(input())
b = list(map(int, input().split()))
count = 0
count1 = 0
a = b
for i in range(0, len(b)):
	a.append(b[i])
for i in range(0, 2 * n):
	if a[i] == 1:
		count += 1
		if count >= count1:
			count1 = count
	else:
		count = 0
print(count1)


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


n = int(input().strip())
arr = list(map(int, input().strip().split()))
arr += arr
globalMax = 0
currMax = 0
for i in arr:
	if i == 1:
		currMax += 1
	else:
		globalMax = max(globalMax, currMax)
		currMax = 0
print(globalMax)


n = int(input())
a = list(map(int, input().split()))
(pref, suf, maxi) = (0, 0, 0)
pos = 0
while pos < n:
	if a[pos] == 1:
		r = pos + 1
		while r < n and a[r] == 1:
			r += 1
		maxi = max(maxi, r - pos)
		pos = r
	else:
		pos += 1
pos = n - 1
while pref < n and a[pref] == 1:
	pref += 1
while pos >= 0 and a[pos] == 1:
	suf += 1
	pos -= 1
print(max(pref + suf, maxi))


n = int(input())
l = list(map(int, input().split(' ')))
for i in range(n):
	l.append(l[i])
m = 0
maxi = 0
for i in range(n + n):
	if l[i] == 1:
		m += 1
	else:
		maxi = max(m, maxi)
		m = 0
maxi = max(m, maxi)
print(maxi)


n = int(input())
arr = list(map(int, input().split(' ')))
arr = arr + arr
pfsum = [0 for i in range(0, 2 * n)]
pfsum[0] = arr[0]
for i in range(1, 2 * n):
	if arr[i] == 0:
		continue
	else:
		pfsum[i] = pfsum[i - 1] + arr[i]
pfsum.sort()
print(pfsum[-1])


n = int(input())
hours = [int(i) for i in input().split()]
hours += hours
count = 0
result = 0
for i in range(n * 2 - 1):
	if hours[i] == 1:
		count += 1
	elif i > n:
		result = max(result, count)
		break
	else:
		result = max(count, result)
		count = 0
print(result)


def f(t):
	temp = 0
	long = 0
	for hour in t:
		if hour == 1:
			temp += 1
		else:
			if temp > long:
				long = temp
			temp = 0
	if t[-1] == 1:
		i = 0
		while t[i] == 1:
			i += 1
			temp += 1
	return max([temp, long])
a = int(input())
b = input().split()
c = list(map(int, b))
print(f(c))


hours = int(input())
schedule = list(map(int, input().split()))
schedule = schedule + schedule
count = 0
list1 = []
flag = 0
for i in schedule:
	if i == 1 and flag == 0:
		count += 1
		flag = 1
	elif i == 0 and flag == 1:
		flag = 0
		list1.append(count)
		count = 0
	elif i == 1 and flag == 1:
		count += 1
if len(list1) > 0:
	print(max(list1))
else:
	print(0)


n = int(input())
s = input()
s = s + s
len = 0
maxlen = 0
for i in s:
	if i == '1':
		len += 1
	elif i == '0':
		if len > maxlen:
			maxlen = len
		len = 0
print(maxlen)


n = int(input())
a = list(map(int, input().rstrip().split()))
maxi = 0
if n == 1:
	if a[0] == 1:
		print(1)
		exit()
	else:
		print(0)
		exit()
count = 0
l = 0
for i in range(n):
	if a[i] == 1:
		l += 1
	else:
		maxi = max(l, maxi)
		l = 0
maxi = max(l, maxi)
count = 0
for i in range(n - 1, -1, -1):
	if a[i] == 1:
		count += 1
	else:
		break
if count == 0:
	pass
else:
	for i in range(n):
		if a[i] == 1:
			count += 1
		else:
			break
maxi = max(count, maxi)
print(maxi)


def next_int():
	return int(input())

def next_int_list():
	return [int(i) for i in input().split(' ')]

def next_float():
	return float(input())

def next_float_list():
	return [int(i) for i in input().split(' ')]

def next_string():
	return input()

def print_int_list(l):
	print(' '.join([str(i) for i in l]))
n = next_int()
xs = next_int_list()
xs.extend(xs)
max_d = 0
curr_d = 0
for i in xs:
	if i == 1:
		curr_d += 1
	else:
		if curr_d > max_d:
			max_d = curr_d
		curr_d = 0
if curr_d > max_d:
	max_d = curr_d
print(max_d)


n = int(input())
len_start = -1
len_max = 0
len_now = 0
for i in input().split():
	if i == '1':
		len_now += 1
	elif i == '0':
		if len_start == -1:
			len_start = len_now
		if len_max < len_now:
			len_max = len_now
		len_now = 0
len_start += len_now
print(max(len_start, len_max))


n = int(input())
a = input().split()
i = 0
s = 0
maximum = 0
if a[0] == '1' and a[n - 1] == '1':
	while a[i] == '1':
		a.append(a[i])
		i += 1
	n = len(a)
while i < n:
	if a[i] == '1':
		s += 1
	else:
		maximum = max(maximum, s)
		s = 0
	i += 1
maximum = max(maximum, s)
print(maximum)


totalHours = int(input())
schedule = list(map(int, input().split()))
currResting = 0
currMaxResting = 0
for i in schedule + schedule:
	if i:
		currResting += 1
	else:
		currResting = 0
	if currResting > currMaxResting:
		currMaxResting = currResting
print(currMaxResting)


n = int(input())
x = list(map(int, input().split()))
for i in x:
	if i == 1:
		x.append(i)
	else:
		break
max1 = 0
ones = 0
for i in x:
	if i == 1:
		ones += 1
		if ones > max1:
			max1 = ones
	else:
		ones = 0
print(max1)


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


n = int(input())
l = [int(num) for num in input().split()]
if l[0] == 1 and l[n - 1] == 1:
	l = l * 2
	k = l.index(0)
	n = n + k
(c, max) = (0, 0)
for i in range(n):
	if l[i] == 1:
		c = c + 1
		if c > max:
			max = c
	else:
		c = 0
print(max)


tc = 1
while tc:
	tc -= 1
	n = int(input())
	ls = list(map(int, input().split()))
	new = ls + ls
	res = 0
	maxtill = 0
	for item in new:
		if item == 1:
			maxtill += 1
		else:
			maxtill = 0
		if maxtill > res:
			res = maxtill
	print(res)


n = int(input())
a = [int(i) for i in input().split()]
c = []
count = 0
f = 0
for j in a:
	if j:
		if f:
			count += 1
		else:
			count = 1
		f = 1
	else:
		f = 0
		c.append(count)
		count = 0
c.append(count)
if a[0] == a[-1] == 1:
	c[0] += c[-1]
print(max(c))


n = int(input())
arr = list(map(int, input().split()))
max1 = 0
if arr[0] and arr[-1]:
	i = 0
	while arr[i] == 1 and i < n:
		max1 += 1
		i += 1
	j = n - 1
	while j > i and arr[j] == 1:
		max1 += 1
		j -= 1
i = 0
max2 = 0
while i < n:
	j = i
	while j < n and arr[j] == 1:
		j += 1
	if j - i > max2:
		max2 = j - i
	i = j + 1
print(max(max1, max2))


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	a.append(a[i])
k = 0
k_max = 0
for i in range(2 * n):
	if a[i] == 1:
		k += 1
		if k > k_max:
			k_max = k
	if a[i] == 0:
		k = 0
print(k_max)


import sys
n = int(input())
x = int(sys.stdin.read(1))
t = x
vec = [2 * t - 1]
res = 0
for i in range(1, n):
	sys.stdin.read(1)
	x = int(sys.stdin.read(1))
	if t == x:
		vec[-1] += 2 * t - 1
	else:
		res = max(res, vec[-1])
		t = x
		vec += [2 * t - 1]
res = max(res, vec[-1])
if len(vec) > 2:
	res = max(res, vec[0] + vec[-1])
print(res)


def main():

	def cmp_to_key(mycmp):

		class K(object):

			def __init__(self, obj, *args):
				self.obj = obj

			def __lt__(self, other):
				return mycmp(self.obj, other.obj) < 0

			def __gt__(self, other):
				return mycmp(self.obj, other.obj) > 0

			def __eq__(self, other):
				return mycmp(self.obj, other.obj) == 0

			def __le__(self, other):
				return mycmp(self.obj, other.obj) <= 0

			def __ge__(self, other):
				return mycmp(self.obj, other.obj) >= 0

			def __ne__(self, other):
				return mycmp(self.obj, other.obj) != 0
		return K
	input()
	print(max(map(len, (input() * 2).replace(' ', '').split('0'))))
for qwerty in range(1):
	main()


n = input()
raw = input().replace(' ', '').split('0')
if raw[0] != '' and raw[-1] != '':
	raw[0] = raw[0] + raw[-1]
m = max(raw)
print(len(m) if m != '' else 0)


def process(A, n):
	temp = 0
	temp1 = 0
	res = 0
	while True:
		if temp1 == len(A) - 1:
			break
		if A[temp1] == 1 and A[temp1 + 1] == 1:
			temp = temp + 1
			res = max(res, temp + 1)
		else:
			temp = 0
		temp1 = temp1 + 1
	res1 = 0
	for i in reversed(A):
		if i == 1:
			res1 = res1 + 1
		else:
			break
	for i in A:
		if i == 1:
			res1 = res1 + 1
		else:
			break
	print(max(res, res1))
n = int(input())
A = [int(x) for x in input().split()]
process(A, n)


n = int(input())
a = input().split()
line = 0
mx = 0
ln = 0
for i in range(n):
	if a[n - i - 1] == '1' and i != n - 1:
		ln = ln + 1
	else:
		break
for i in range(n - ln):
	if a[i] == '1':
		line = line + 1
	if i == 0 and a[i] == '1' and (a[n - 1] == '1'):
		line = line + ln
	if a[i] == '0':
		mx = max(line, mx, ln)
		line = 0
if mx != 0:
	print(mx)
else:
	print(line)


x = input()
s = input().split(' ')
uns = 0
zeros = 0
x = []
for i in range(0, len(s)):
	if s[i] == '0':
		if uns > 0:
			x.append(uns)
			uns = 0
		zeros = 1
	elif s[i] == '1':
		uns += 1
		if zeros == 1:
			zeros = 0
			x.append(-1)
		if i == len(s) - 1:
			x.append(uns)
if len(x) == 0:
	print(0)
elif len(x) == 1:
	print(x[0])
elif x[0] > 0 and x[-1] > 0:
	x[0] += x[-1]
if len(x) > 1:
	print(max(x))


n = int(input())
l = list(map(int, input().split()))
l = l + l
ans = 0
v = []
for i in range(len(l)):
	if l[i] == 1:
		ans += 1
		v.append(ans)
	else:
		ans = 0
if len(v) >= 1:
	print(max(v))
else:
	print('0')


n = int(input())
l = list(map(int, input().split()))
cnt = 0
tmp = 0
for i in range(n):
	if l[i] == 0:
		cnt = max(cnt, tmp)
		tmp = 0
	else:
		tmp += 1
cnt = max(cnt, tmp)
if l.count(1) == len(l):
	print(n)
	exit()
else:
	uk1 = 0
	uk2 = n - 1
	while l[uk1] != 0:
		uk1 += 1
	while l[uk2] != 0:
		uk2 -= 1
	cnt = max(cnt, uk1 + (n - uk2 - 1))
print(cnt)


import re
input()
a = input().replace(' ', '')
print(max([0, *map(len, re.findall('1+', a + a))]))


n = int(input())
l = list(map(int, input().split()))

def counter(l):
	ans = 0
	while l:
		x = l.pop()
		c = 1
		while l and l[-1] == x:
			l.pop()
			c += 1
		if x == 1:
			ans = max(ans, c)
	return ans
ans = counter(l + l)
print(ans)


(n, l) = (int(input()), input())
k = [x.count('1') for x in l.split('0')]
print(max(k[-1] + k[0], max(k)))


n = int(input())
l = [int(i) for i in input().split()]
x = []
cnt = 0
for i in l:
	if i == 1:
		cnt += 1
	else:
		x.append(cnt)
		cnt = 0
if cnt > 0:
	for i in l:
		if i == 1:
			cnt += 1
		else:
			x.append(cnt)
			break
print(max(x))


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


n = int(input())
l = list(map(int, input().split()))
last = 0
k = 0
mx = 0
for i in l:
	if i == 1:
		if last == 0:
			k = 1
		else:
			k += 1
	if i == 0:
		if k > mx:
			mx = k
		k = 0
	last = i
i = 0
if l[-1] == 1:
	while l[i] == 1:
		k += 1
		i += 1
	if k > mx:
		mx = k
print(mx)


N = int(input())
A = list(map(int, input().split()))
res = 0
len = 0
for i in range(0, 2 * N):
	if A[i % N] == 1:
		len += 1
		res = max(len, res)
	else:
		len = 0
print(res)


n = int(input())
a = [int(x) for x in input().split()]
a = a + a
for i in range(1, n * 2):
	if a[i] != 0:
		a[i] += a[i - 1]
print(max(a))


from collections import Counter
n = int(input())
s = list(input().split())
s = s + s
import re
pattern = '(1+)'
ans = re.findall(pattern, ''.join(s))
ans.append([])
print(len(max(ans, key=lambda X: len(X))))


n = int(input())
l = list(map(int, input().split()))
x = []
c = len(l)
z = 0
aa = 0
if l[-1] == 1:
	ll = reversed(l)
	for tt in ll:
		if tt == 1:
			aa += 1
		if tt == 0:
			break
ans = 0
for rt in range(z, c):
	if l[rt] == 1:
		ans += 1
	if l[rt] == 0:
		x.append(ans)
		ans = 0
bn = x[0] + aa
if bn < max(x):
	print(max(x))
else:
	print(bn)


n = int(input())
l = [int(x) for x in input().split()]
total = 0
new_list = []
for i in range(n):
	if l[i] == 0:
		if total != 0:
			new_list.append(total)
		new_list.append(0)
		total = 0
	else:
		total += 1
if total != 0:
	new_list.append(total)
new_list[0] += new_list[len(new_list) - 1]
print(max(new_list))


n = int(input())
a = list(map(int, input().split()))
if set(a) == {1}:
	print(n)
	quit()
rest_1 = 0
for i in range(n):
	if a[i] == 1:
		rest_1 += 1
	else:
		break
rest_2 = 0
for i in range(n):
	if a[-(i + 1)] == 1:
		rest_2 += 1
	else:
		break
max_ = rest_1 + rest_2
rest = 0
for i in range(n):
	if a[i] == 1:
		rest += 1
	else:
		if rest > max_:
			max_ = rest
		rest = 0
print(max_)


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split(' ')))
b = [0] * n
for i in range(n):
	if i == 0:
		b[i] = a[i]
	elif a[i] == 1:
		b[i] = b[i - 1] + 1
	else:
		b[i] = 0
if a[-1] == 1:
	i = 0
	while i < n:
		if a[i] == 1:
			i = i + 1
		else:
			break
	b[-1] = b[-1] + i
print(min(max(b), n))


n = input()
l = ''.join(input().split())
l += l
l = l.split('0')
print(max((len(i) for i in l)))


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	if a[i] == 0:
		k = i
		break
a = a[k + 1:len(a)] + a[0:k + 1]
m = 0
p = 0
for i in range(n):
	if a[i] == 0:
		m = max(m, p)
		p = 0
	else:
		p += 1
print(m)


n = int(input())
z = list(map(int, input().split()))
arr = []
count = 0
step = 0
status = False
while step < n:
	if step == 0:
		if z[step] == 1:
			count += 1
			if z[-1] == 1:
				status = True
				counti = 1
			while status:
				if z[-counti] == 1:
					count += 1
				counti += 1
				if z[-counti] == 0:
					status = False
					break
	elif z[step] == 1:
		count += 1
	else:
		arr.append(count)
		count = 0
	step += 1
arr.append(count)
print(max(arr))


n = int(input())
A = input().replace(' ', '') * 2
print(max(map(len, A.split('0'))))


n = int(input())
l = list(map(int, input().split()))
l2 = l
l2.extend(l)
d = 0
o = 0
if sum(l2) == 0:
	print(0)
else:
	for i in range(len(l2) - 1):
		if l2[i] == l2[i + 1] and l2[i] == 1:
			d += 1
			if d > o:
				o = d
		else:
			d = 0
	print(o + 1)


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


n = int(input())
num = list(map(int, input().split(' ')))
result_num = []
max_len = 0
temp_len = 0
for item in num:
	if item == 0:
		if max_len < temp_len:
			max_len = temp_len
		temp_len = 0
	else:
		temp_len += 1
for item in num:
	if item == 0:
		break
	else:
		temp_len += 1
if max_len < temp_len:
	max_len = temp_len
print(max_len)


def solve():
	N = int(input())
	A = [int(k) for k in input().split()]
	if N == 1:
		print(1 if A[0] == 1 else 0)
		return
	ans = 0
	if A[0] == 0 or A[-1] == 1:
		i = 0
		while i < N and A[i] == 1:
			ans += 1
			i += 1
		i = 1
		while i < N + 1 and A[-i] == 1:
			ans += 1
			i += 1
	cur = 0
	for i in range(N):
		if A[i] == 1:
			cur += 1
		else:
			if cur > ans:
				ans = cur
			cur = 0
	print(ans)
solve()


def calculateMaximumRest(a):
	c = 0
	r = 0
	l = len(a)
	for i in range(2 * l):
		if a[i % l] == 0:
			c = 0
			if i >= l:
				break
		else:
			c += 1
			r = max(r, c)
	return r
_ = input()
arr = [int(z) for z in input().split()]
print(calculateMaximumRest(arr))


smax = 0
max = 0
input()
smth = input().split() * 2
for i in smth:
	if i == '0':
		if max > smax:
			smax = max
		max = 0
	else:
		max += 1
print(smax)


_ = input()
tokens = input().split()
res = 0
cur = 0
for t in tokens + tokens:
	t = int(t)
	cur = cur + t if t == 1 else 0
	res = max(res, cur)
print(res)


n = int(input())
L = input().split()
for i in range(0, len(L)):
	L[i] = int(L[i])
c = 0
x = 0
for i in range(0, 2 * len(L)):
	if L[i % len(L)] == 0:
		if c > x:
			x = c
		c = 0
		continue
	elif L[i % len(L)] == 1:
		c += 1
print(x)


n = int(input())
a = list(map(int, input().split())) * 2 + [0]
k = 0
ans = 0
for i in a:
	if i:
		k += 1
	else:
		if k > ans:
			ans = k
		k = 0
print(ans)


n = int(input())
a = list(map(int, input().split()))
l = n
if 1 not in a:
	print(0)
	exit()
if 0 not in a:
	print(n)
	exit()
(cnt, ans) = (1, 0)
for i in range(0, len(a) - 1):
	if a[i] and a[i + 1]:
		cnt += 1
	else:
		ans = max(cnt, ans)
		cnt = 1
ans = max(cnt, ans)
if a[0] and a[n - 1]:
	cnt = 0
	f = 0
	for i in range(0, n):
		if a[i] == 0:
			f = 1
			break
		cnt += 1
	if f:
		p = n - 1
		while a[p] and p >= 0:
			cnt += 1
			p -= 1
	ans = max(ans, cnt)
print(ans)


n = int(input())
A = [int(x) for x in input().split()]
A = A + A
ans = 0
i = 0
while i < len(A):
	if A[i] == 0:
		i += 1
	else:
		j = i + 1
		while j < len(A) and A[j] == 1:
			j += 1
		ans = max(ans, j - i)
		i = j
print(ans)


x = int(input())
l = list(map(int, input().split()))
t = 0
z = 0
for i in range(x):
	if l[i] == 1:
		t = t + 1
	else:
		t = 0
	z = max(t, z)
if l[x - 1] == 1:
	j = 0
	while l[j] != 0:
		t = t + 1
		j = j + 1
z = max(z, t)
print(z)


from itertools import groupby as gp
n = int(input())
a = input().split()
arr = []
mx = 0
i = 0
for (k, g) in gp(a):
	arr.append([k, len(list(g))])
	if arr[i][0] == '1':
		mx = max(arr[i][1], mx)
	i += 1
if len(arr) >= 2:
	if arr[0][0] == '1' and arr[-1][0] == '1':
		mx = max(mx, arr[0][1] + arr[-1][1])
print(mx)


n = input()
ln = [int(i) for i in input().split(' ')]
n = 0
first = True
lastn = 0
firstn = 0
mx = 0
for i in range(0, len(ln)):
	if ln[i] == 0:
		if ln[-1]:
			lastn = n
		if first and ln[0]:
			firstn = n
			first = False
		if n > mx:
			mx = n
		n = 0
	else:
		n += 1
if ln[-1]:
	lastn = n
if n > mx:
	mx = n
print(max(mx, firstn + lastn))


n = int(input())
ar = list(map(int, input().split()))
lB = 0
checkLB = 1
curOnes = 0
last = ''
curMax = 0
for a in ar:
	if a == 1:
		if checkLB == 1:
			lB += 1
			curOnes += 1
			curMax = lB
		else:
			curOnes += 1
			curMax = max(curMax, curOnes)
	else:
		if checkLB == 1:
			checkLB = 0
			curOnes = 0
		curOnes = 0
print(max(curMax, curOnes + lB))


n = int(input())
(max, k, symbols, symbols2) = (0, 0, 0, 0)
line = input().replace(' ', '')
for item in line:
	if item != '0':
		symbols = symbols + 1
	else:
		break
for i in reversed(range(0, n)):
	if line[i] != '0':
		symbols2 = symbols2 + 1
	else:
		break
for i in range(len(line)):
	if line[i] == '1':
		k = k + 1
		if k > max:
			max = k
	else:
		k = 0
if line[n - 1] == '1':
	if max < symbols + symbols2:
		max = symbols + symbols2
print(max)


def go():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	a *= 2
	s = 0
	m = 0
	for i in range(len(a)):
		if a[i] == 0:
			s = 0
		s += a[i]
		m = max(m, s)
	return m
print(go())


import sys
n = list(map(int, input().split()))
a = list(map(int, input().split()))
s = ''.join((str(x) for x in a))
s = s + s + s
count = 0
mx = -1 - sys.maxsize
for x in s:
	if x == '1':
		count += 1
	else:
		mx = max(mx, count)
		count = 0
print(max(mx, count))


n = input()
a = list(map(int, input().split()))
count = 0
count1 = 0
count2 = 0
for i in a:
	if i == 1:
		count += 1
		if count > count1:
			count1 += 1
	else:
		count = 0
if a[-1] == a[0] == 1:
	f = 0
	while a[f] == 1:
		count2 += 1
		f += 1
	f = -1
	while a[f] == 1:
		count2 += 1
		f -= 1
print(max(count1, count2))


n = int(input())
counter = 0
counter1 = 0
arr = [int(x) for x in input().split()]
arr = arr * 2
for i in range(len(arr)):
	if arr[i] == 1:
		counter1 += 1
	else:
		counter1 = 0
	counter = max(counter, counter1)
print(counter)


n = int(input())
a = list(map(int, input().split()))
a *= 2
k = 0
result = 0
for i in range(n * 2):
	if a[i] == 1:
		k += 1
		result = max(k, result)
	else:
		k = 0
print(result)


n = int(input())
work = list(map(int, input().split())) * 2
ans = 0
cur = 0
for isRest in work:
	ans = max(ans, cur)
	cur = cur + 1 if isRest else 0
print(max(ans, cur))


n = int(input())
a = list(map(int, input().split()))
a = a + a
ans = 0
cnt = 0
for it in a:
	if it == 0:
		ans = max(ans, cnt)
		cnt = 0
	else:
		cnt += 1
ans = max(ans, cnt)
print(ans)


n = int(input())
arr = [int(x) for x in input().split()]
arr = arr + arr
count = 0
max_ = 0
for i in arr:
	if i == 1:
		count = count + 1
	else:
		count = 0
	max_ = max(count, max_)
print(max_)


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


n = int(input())
l = [int(i) for i in input().split()]
l = l + l
i = 0
u = 0
while i < 2 * n:
	if l[i] == 1:
		s = 0
		while l[i] == 1 and i < 2 * n:
			s += 1
			i += 1
			if i >= 2 * n - 1:
				break
		u = max(s, u)
	else:
		i += 1
print(u)


n = int(input())
l = list(map(int, input().split()))
for i in range(n):
	l.append(l[i])
c = 0
mx = 0
for i in l:
	if i == 0:
		if mx < c:
			mx = c
		c = 0
	else:
		c += 1
print(mx)


n = int(input())
arr = list(map(int, input().split()))
arr = arr * 2
prev_count = 0
max_count = 0
for i in range(len(arr)):
	if arr[i] == 0:
		prev_count = 0
	else:
		prev_count += 1
		if prev_count >= max_count:
			max_count = prev_count
print(max_count)


def solve_it(n, hours):
	omax = 0
	cmax = 0
	for i in range(3):
		for h in hours:
			if h == 0:
				omax = max(omax, cmax)
				cmax = 0
			if h == 1:
				cmax += 1
	return omax
n = int(input())
hours = list(map(int, input().split()))
print(solve_it(n, hours))


n = int(input())
a = [int(x) for x in input().split()]
max_len = 0
current_len = 0
a += a
for i in range(2 * n):
	if a[i] == 1:
		current_len += 1
	else:
		max_len = max(max_len, current_len)
		current_len = 0
print(max_len)


class CodeforcesTask1141BSolution:

	def __init__(self):
		self.result = ''
		self.n = 0
		self.schedule = []

	def read_input(self):
		self.n = int(input())
		self.schedule = input()

	def process_task(self):
		td = (self.schedule * 2).replace(' ', '')
		c = 0
		sc = [len(x) for x in td.split('0') if len(x)]
		if sc:
			c = max(sc)
		self.result = str(c)

	def get_result(self):
		return self.result
Solution = CodeforcesTask1141BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


from sys import setcheckinterval, stdin
setcheckinterval(1000)
iin = lambda : int(stdin.readline())
lin = lambda : list(map(int, stdin.readline().split()))
n = iin()
a = lin()
ch = 0
ans = 0
for i in range(2 * n):
	if a[i % n] == 1:
		ch += 1
	else:
		ans = max(ch, ans)
		ch = 0
print(ans)


n = int(input())
a = list(map(int, input().split()))
a += a
tmp = 0
num = 0
for i in range(len(a)):
	if a[i] == 1:
		tmp += 1
	else:
		num = max(tmp, num)
		tmp = 0
num = max(num, tmp)
print(num)


n = int(input())
a = list(map(int, input().split()))
b = []
for i in a:
	b.append(i)
for i in a:
	b.append(i)
c = 0
max = 0
for i in range(n + n):
	if b[i] == 1:
		c += 1
	else:
		if c > max:
			max = c
		c = 0
print(max)


n = int(input())
l = list(map(int, input().split()))
l *= 2
r_temp = 0
r_max = 0
rev = 0
for i in l:
	if i == 1:
		r_temp += 1
	else:
		r_max = max(r_max, r_temp)
		r_temp = 0
print(r_max)


a = input()
a = int(a)
b = input().split()
l = []
for i in b:
	l.append(int(i))
l = l * 3
k = 0
max = 0
for i in l:
	if i == 1:
		k += 1
	else:
		if max < k:
			max = k
		k = 0
if max < k:
	max = k
print(max)


n = int(input())
s = input().split()
t = s[s.index('0'):] + s[:s.index('0')]
cm = 0
c = 0
for i in reversed(t):
	if i == '1':
		c += 1
	else:
		if cm < c:
			cm = c
		c = 0
print(cm)


n = int(input())
l = list(map(int, input().split()))
for i in range(n):
	l.append(l[i])
temp = 0
out = temp
for i in range(2 * n):
	if l[i] == 1:
		temp += 1
		out = max(out, temp)
	else:
		temp = 0
		out = max(out, temp)
print(out)


n = int(input())
w = [*map(int, input().split())]
l = []
i = 0
while i < n:
	j = i
	while j < n and w[j] == 1:
		j += 1
	l.append(j - i)
	i = j
	while j < n and w[j] == 0:
		j += 1
	l.append(j - i)
	i = j
res = max(l[::2])
if l[-1] == 0:
	res = max(res, l[0] + l[-2])
print(res)


x = int(input())
t = False
(l, k) = (0, 0)
p = list(map(int, input().split()))
for i in range(2 * x):
	if i >= x:
		n = i - x
	else:
		n = i
	if p[n] == 0:
		k = max(k, l)
		l = 0
		continue
	l += 1
print(k)


import sys
from math import ceil
from collections import deque
n = int(input())
a = [int(i) for i in input().split()]
for i in a.copy():
	a.append(i)
c = 0
ans = 0
for i in range(2 * n):
	if a[i] == 1:
		c += 1
		ans = max(ans, c)
	else:
		c = 0
print(ans)


l_c = int(input())
l = list(map(int, input().split()))
real_ans = 0
ans = 0
prev = -1
for i in range(len(l) * 2):
	if i == 0:
		prev = l[i]
		if l[i] == 1:
			ans += 1
		continue
	elif l[i % len(l)] == 1:
		ans += 1
	else:
		real_ans = ans if ans > real_ans else real_ans
		ans = 0
print(real_ans)


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	a.append(a[i])
best = -1
cur = 0
for i in range(0, 2 * n):
	if a[i] == 1:
		cur += 1
	else:
		if cur > best:
			best = cur
		cur = 0
print(best)


from sys import stdin

def func(arr):
	ans = 0
	count = 0
	for i in range(len(arr)):
		if arr[i] == 1:
			count += 1
		else:
			ans = max(ans, count)
			count = 0
	return ans
n = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
count1 = 0
for i in range(n):
	if arr[i] == 1:
		count1 += 1
	else:
		break
count2 = 0
for i in range(n - 1, -1, -1):
	if arr[i] == 1:
		count2 += 1
	else:
		break
print(max(count1 + count2, func(arr)))


n = int(input())
data = [int(i) for i in input().split()]
if data[0] == data[-1] == 1:
	first0 = data.index(0)
	last0 = n - list(reversed(data)).index(0) - 1
	ans = data[0:first0].count(1) + data[last0:].count(1)
else:
	ans = 1 if data[0] == 1 else 0
flag = True if data[0] == 1 else False
count = 1 if flag else 0
for i in range(1, n):
	if flag:
		if data[i] == 1:
			count += 1
		else:
			count = 0
			flag = False
	elif data[i] == 1:
		count = 1
		flag = True
	else:
		count = 0
	ans = max(ans, count)
print(ans)


a = input()
score = [int(x) for x in input().split()]
score = score * 2
count = 0
maxi = 0
b = int(a) * 2
for i in range(b):
	if score[i] == 1:
		count += 1
		if count > maxi:
			maxi = count
	elif score[i] == 0:
		count = 0
print(maxi)


n = int(input())
l = [int(i) for i in input().split()]
l = l + l
maxi = 0
c = 0
for i in l:
	if i == 1:
		c += 1
	else:
		maxi = max(maxi, c)
		c = 0
print(maxi)


n = int(input())
a = list(map(int, input().split())) * 2
out = 0
mx = 0
for x in a:
	if x == 1:
		out += 1
		mx = max(mx, out)
	else:
		out = 0
print(mx)


n = int(input())
arr = list(map(int, input().split()))
c = 0
p1 = 0
p2 = n - 1
while p1 < p2:
	if arr[p1] == 1:
		p1 += 1
		c += 1
	if arr[p2] == 1:
		p2 -= 1
		c += 1
	if arr[p1] == 0 and arr[p2] == 0:
		break
maxi = 0
ans = 0
for i in range(n):
	if arr[i] == 1:
		ans += 1
		maxi = max(maxi, ans)
	else:
		ans = 0
print(max(c, maxi))


n = int(input())
l = list(map(int, input().split()))
(c, le) = (0, 0)
i = 0
while i < 2 * n:
	if l[i % n] == 1:
		le += 1
		c = max(c, le)
	else:
		le = 0
	i += 1
print(c)


n = int(input())
arr = list(map(int, input().split()))
pos_zero = []
for i in range(n):
	if arr[i] == 0:
		pos_zero.append(i)
count = 0
for i in range(len(pos_zero) - 1):
	diff = pos_zero[i + 1] - pos_zero[i] - 1
	count = max(count, diff)
ending = n - pos_zero[-1] + pos_zero[0] - 1
count = max(count, ending)
print(count)


n = int(input())
schedule = input().split()
schedule = schedule + schedule
max_rest = 0
cand_rest = 0
for x in schedule:
	if x == '1':
		cand_rest += 1
	else:
		max_rest = max(max_rest, cand_rest)
		cand_rest = 0
print(max_rest)


n = int(input())
a = list(map(int, input().split()))
b = [0] * (2 * n)
for i in range(n):
	b[i] = a[i]
j = 0
for i in range(n, 2 * n):
	b[i] = a[j]
	j += 1
maxh = 0
i = 0
while i < len(b):
	h = 0
	while i < len(b) - 1 and b[i] == 1:
		h += 1
		if b[i + 1] == 0:
			if maxh < h:
				maxh = h
			h = 0
		i += 1
	i += 1
print(maxh)


n = int(input())
schedule = ''.join([k for k in input().split()])
schedule = schedule * 2
rest_periods = [0]
rest_periods += [len(part) for part in schedule.split('0') if '1' in part]
print(max(rest_periods))


INF = 100000000
from collections import defaultdict
t = 1
for test in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	curInd = 0
	maxSeg = 0
	tmp = 0
	for i in range(2 * n + 1):
		curInd = (curInd + 1) % n
		if a[curInd] == 1:
			tmp += 1
		else:
			maxSeg = max(tmp, maxSeg)
			tmp = 0
	print(maxSeg)


n = int(input())
a = list(map(int, input().split()))
i = 0
maxLength = 0
currLength = 0
flag = True
while True:
	if not flag and a[i] == 0:
		if maxLength < currLength:
			maxLength = currLength
		break
	if a[i] == 0:
		if maxLength < currLength:
			maxLength = currLength
		currLength = 0
	else:
		currLength += 1
	i += 1
	if i == n:
		flag = False
		i = 0
print(maxLength)


input()
nums = list(map(int, input().split()))
i = -1
s = 0
while -i <= len(nums) and nums[i] == 1:
	s += 1
	i -= 1
start = 0
while start < len(nums) and nums[start] == 1:
	s += 1
	start += 1
s = [s]
while start < len(nums):
	start += 1
	if s[-1] != 0:
		s.append(0)
	while start < len(nums) and nums[start] == 1:
		s[-1] += 1
		start += 1
print(max(s))


n = int(input())
regime = list(map(int, input().split(' '))) * 2
streak = 0
maxs = 0
for h in regime[1:]:
	if h == 1:
		streak += 1
	else:
		cmpr = h
		maxs = max(streak, maxs)
		streak = 0
print(maxs)


n = int(input())
A = list(map(int, input().split()))
A = A * 3
calct = 0
calc2 = 0
for i in range(len(A)):
	if A[i]:
		calct += 1
	else:
		calc2 = max(calc2, calct)
		calct = 0
print(calc2)


n = int(input())
arr = list(map(int, input().split()))
arr += arr
maxRest = 0
curRest = 0
for x in arr:
	if x == 1:
		curRest += 1
	else:
		if curRest > maxRest:
			maxRest = curRest
		curRest = 0
print(maxRest)


n = int(input())
if n > 1:
	ar = list(map(int, input().split()))
elif n == 1:
	ar = [int(input())]
else:
	raise RuntimeError
if ar[-1] == 1:
	idx = 0
	while ar[idx] == 1:
		ar.append(ar[idx])
		idx += 1
longest_len = 0
current_len = 0
for i in ar:
	if i == 1:
		current_len += 1
	else:
		current_len = 0
	if current_len > longest_len:
		longest_len = current_len
print(longest_len)


num = int(input())
arr = [int(i) for i in input().split()]
arr *= 3
ans = 0
cnt = 0
for i in range(num * 3):
	if arr[i] == 1:
		cnt += 1
		if cnt > ans:
			ans = cnt
	else:
		cnt = 0
print(ans)


from sys import stdin
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
arr = arr + arr
count = 0
max_count = 0
for i in range(len(arr)):
	if arr[i] == 1:
		count += 1
		max_count = max(max_count, count)
	else:
		count = 0
print(max_count)


from math import gcd
n = input()
l = input()
l = l + ' ' + l
l = l.split('0')
print(max([i.count('1') for i in l]))


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


import sys
from functools import reduce
n = map(int, sys.stdin.readline())
arr = list(map(int, sys.stdin.readline().split()))
arr.extend(arr)
max_counter = 0
counter = 0
for x in arr:
	if x == 1:
		counter += 1
	else:
		max_counter = counter if counter > max_counter else max_counter
		counter = 0
print(max_counter)


n = int(input())
day = [int(i) for i in input().split()]
ans = 0
if day[0] == 1 and day[len(day) - 1] == 1:
	beg = day.index(0)
	end = len(day) - 1
	for i in range(len(day) - 1, -1, -1):
		if day[i] == 0:
			end = i
			break
	ans = beg - 1 + (n - end)
current = 0
for i in range(len(day)):
	if day[i] == 1:
		current += 1
	else:
		if current > ans:
			ans = current
		current = 0
if current > ans:
	ans = current
print(ans)


n = int(input())
a = list(map(int, input().split()))
count = 0
midcount = 0
for i in range(n):
	if a[i] == 1:
		count += 1
	else:
		if count > midcount:
			midcount = count
		count = 0
i = 0
startcount = 0
while a[i] != 0:
	startcount += 1
	i += 1
print(max(midcount, count + startcount))


def kadane(lis):
	su = 0
	n = len(lis)
	max = 0
	for i in range(n):
		if lis[i] == 0:
			e = -1
		else:
			e = 1
		if e < 0:
			su = 0
		else:
			su += 1
		if su > max:
			max = su
	return max

def find(lis):
	lis = lis + lis
	maximum = kadane(lis)
	maximum1 = 0
	print(maximum)
n = int(input())
lis = [int(i) for i in input().split()]
find(lis)


n = int(input())
arr = list(map(int, input().split(' ')))
ans = 0
c = 0
for d in arr + arr:
	if d:
		c += 1
	else:
		c = 0
	ans = max(ans, c)
print(ans)


n = int(input())
my_list = list(map(int, input().split()))
twice = my_list * 2
maxcount = 0
count = 0
for i in range(len(twice)):
	if twice[i] == 1:
		count += 1
	else:
		maxcount = max(maxcount, count)
		count = 0
print(maxcount)


TN = 1

def solution():
	n = int(input())
	a = list(map(int, input().split()))
	ans0 = []
	ans1 = []
	cur = a[0]
	cnt = 0
	for i in range(n):
		if a[i] == cur:
			cnt += 1
		else:
			if cur == 0:
				ans0.append(cnt)
			else:
				ans1.append(cnt)
			cnt = 1
			cur = a[i]
	if cur == 0:
		ans0.append(cnt)
	else:
		ans1.append(cnt)
	if a[0] == 1 and a[-1] == 1:
		try:
			print(max(max(ans1), ans1[0] + ans1[-1]))
		except:
			print(0)
	else:
		try:
			print(max(ans1))
		except:
			print(0)
while TN != 0:
	solution()
	TN -= 1


input()
a = [int(x) for x in input().split()]
a *= 3
l = 0
c = 0
for x in a:
	if x == 1:
		c += 1
	else:
		l = max(l, c)
		c = 0
print(l)


from sys import stdin

def ip():
	return [int(i) for i in stdin.readline().split()]

def sp():
	return [str(i) for i in stdin.readline().split()]

def pp(A):
	for i in A:
		print(i)

def solve():
	n = int(input())
	A = ip()
	A.extend(A)
	rs = 0
	ans = 0
	for i in range(len(A)):
		if A[i] == 1:
			rs += 1
			ans = max(ans, rs)
		else:
			rs = 0
	return ans
print(solve())


n = int(input())
schedule = input().split() * 2
num = 0
Max = 0
for a in schedule:
	if a == '1':
		num += 1
	if a == '0':
		if Max < num:
			Max = num
		num = 0
print(Max)


n = int(input())
a = list(map(int, input().split()))
count_rest = 0
max_rest = 0
for i in range(n):
	if a[i] == 1:
		count_rest += 1
		if i == n - 1:
			k = 0
			while a[k] == 1:
				k += 1
				count_rest += 1
			if count_rest > max_rest:
				max_rest = count_rest
	else:
		if count_rest > max_rest:
			max_rest = count_rest
		count_rest = 0
print(max_rest)


n = int(input())
x = [int(i) for i in input().split() * 2]
r = 1
if 1 in x:
	maxe = 1
else:
	maxe = 0
for i in range(len(x) - 1):
	if x[i] == 1 and x[i + 1] == 1:
		r = r + 1
		maxe = max(maxe, r)
	else:
		r = 1
print(maxe)


cnt = lambda s, x: s.count(x)
ii = lambda : int(input())
si = lambda : input()
f = lambda : map(int, input().split())
dgl = lambda : list(map(int, input()))
il = lambda : list(map(int, input().split()))
n = ii()
l = il()
l.extend(l)
mx = 0
c = 0
for i in l:
	if i == 1:
		c += 1
	else:
		mx = max(mx, c)
		c = 0
print(max(mx, c))


n = int(input())
l = list(map(int, input().split()))
for i in range(n - 1):
	l.append(l[i])
dp = []
c = 0
ans = 0
for i in l:
	if i == 1:
		c += 1
	else:
		ans = max(ans, c)
		c = 0
ans = max(ans, c)
print(ans)


n = int(input())
seq = [int(s) for s in input().split()] * 2
prev = None
n = 0
max_n = 0
for s in seq:
	if s == 1:
		n += 1
	else:
		max_n = max(max_n, n)
		n = 0
max_n = max(max_n, n)
print(max_n)


def maxWDays(n, arr):
	i = 0
	j = n - 1
	temp = 0
	if arr[0] == 1 or arr[j] == 1:
		while arr[i] != 0 and i < j:
			temp += 1
			i += 1
		while arr[j] != 0 and i < j:
			temp += 1
			j -= 1
	ans = temp
	temp1 = 0
	while i < n:
		if arr[i] == 1:
			temp1 += 1
		else:
			ans = max(ans, temp1)
			temp1 = 0
		i += 1
	return ans
n = int(input())
arr = list(map(int, input().split()))
print(maxWDays(n, arr))


n = int(input())
c = list(map(int, input().split()))
count_1_first = 0
maxim = 0
for i in range(len(c)):
	if c[i] == 1:
		count_1_first += 1
	else:
		break
for i in range(len(c) - 1, -1, -1):
	if c[i] == 1:
		count_1_first += 1
	else:
		break
tot = 0
flag = 0
flag1 = 0
if c[-1] == 1:
	flag1 = 1
else:
	flag1 = 0
for i in range(len(c)):
	if c[i] == 1:
		tot += 1
		flag = 0
	else:
		maxim = max(tot, maxim)
		tot = 0
if flag == 1:
	if flag1 == 1:
		print(max(maxim, count_1_first))
	else:
		print(maxim)
else:
	maxim = max(maxim, tot)
	if flag1 == 1:
		print(max(maxim, count_1_first))
	else:
		print(maxim)


n = int(input())
schedule = list(map(int, input().split()))
temp1 = 0
while schedule[temp1] == 1:
	temp1 += 1
result = temp1
i = temp1
temp2 = 0
while i < n:
	if schedule[i] == 1:
		temp2 += 1
	else:
		if result < temp2:
			result = temp2
		temp2 = 0
	i += 1
if temp2 > 0:
	if temp2 + temp1 > result:
		result = temp1 + temp2
print(result)


n = int(input())
a = list(map(int, input().split()))
b = a.index(0)
c = a[::-1].index(0)
r = b + c
k = 0
for i in range(b, n - c):
	if a[i] == 1:
		k += 1
	else:
		r = max(r, k)
		k = 0
print(r)


n = int(input())
a = [*map(int, input().split())]
p = a[0]
c = 0
ans = 0
for i in a + a:
	if i != p:
		if p == 1:
			ans = max(ans, c)
		c = 1
		p = i
	else:
		c += 1
print(ans)


data = []
n = int(input())
data = list(map(int, input().split()))
data *= 2
maximal_continuous = 0
pre = -1
count = 0
for (pos, _item) in enumerate(data):
	item = int(_item)
	if pos == 0:
		if item == 1:
			maximal_continuous = count = 1
		pre = item
		continue
	if item == 1 and pre == 0:
		count = 1
	if item == 1 and pre == 1:
		count += 1
	if count > maximal_continuous:
		maximal_continuous = count
	if item == 0:
		count = 0
	pre = item
print(maximal_continuous)


hours = int(input())
day = input().split(' ')
day = day[day.index(str(0)):] + day[:day.index(str(0))]
i = 1
length = 0
longest_length = 0
while i <= hours - 1:
	if day[i] == str(1):
		length += 1
		i += 1
	else:
		if length > longest_length:
			longest_length = length
		length = 0
		i += 1
if length > longest_length:
	longest_length = length
print(longest_length)


n = int(input())
x = input().split(' ')
y = []
t = ''
for i in x:
	if i == '1':
		t += '1'
	else:
		y.append(len(t))
		t = ''
if t != '':
	y.append(len(t))
if x[0] == '1' and x[-1] == '1':
	print(max(y[0] + y[-1], max(y)))
else:
	print(max(y))


n = int(input())
temp = [int(num) for num in input().split()]
a = temp + temp
(ans, ar) = (0, [])
for i in a:
	if i == 1:
		ans += 1
	else:
		ar.append(ans)
		ans = 0
print(max(ar))


n = int(input())
b = list(map(int, input().split()))
c = 2 * b
x = 0
res = 0
for i in range(len(c) - 1):
	if c[i] == 1:
		x += 1
		if res < x:
			res += 1
	if c[i + 1] != 1:
		x = 0
print(res)


n = int(input())
s = list(map(int, input().split()))
ind = []
for (i, j) in enumerate(s):
	if j == 1:
		ind.append(i)
if len(ind) == 0:
	print(0)
	exit()
else:
	last = ind[0]
	num = 1
	res = 0
	for i in range(1, len(ind)):
		if ind[i] == last + 1:
			last = last + 1
			num += 1
		else:
			res = max(res, num)
			num = 1
			last = ind[i]
	res = max(res, num)
	if ind[-1] == n - 1 and ind[0] == 0:
		u = 1
		i = 1
		while ind[i] == ind[i - 1] + 1 and i < n:
			u += 1
			i += 1
		i = n - 1
		while s[i] == 1 and i >= 0:
			i -= 1
			u += 1
		res = max(res, u)
	print(res)


n = int(input())
l = list(map(int, input().split()))
cons = []
if l[0] == 0:
	cons.append(0)
current = 0
for x in l:
	if x == 1:
		current += 1
	elif current:
		cons.append(current)
		current = 0
if current:
	cons.append(current)
	current = 0
if l[-1] == 0:
	cons.append(0)
print(max(max(cons), cons[0] + cons[-1]))


n = int(input())
a = list(map(int, input().split()))
a *= 3
count = 0
mcount = 0
for i in range(len(a)):
	if a[i] == 1:
		count += 1
	else:
		mcount = max(count, mcount)
		count = 0
print(mcount)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a += a
	cur = 0
	ans = 0
	for x in a:
		if x == 1:
			cur += 1
		if x == 0 and cur != 0:
			ans = max((ans, cur))
			cur = 0
	print(ans)
main()


n = int(input())
A = list(map(int, input().split()))
B = []
a = 2
while a > 0:
	for i in A:
		B.append(i)
	a -= 1
ans = 0
l = 0
for i in range(2 * n):
	if B[i] == 1:
		l += 1
	if B[i] == 0:
		ans = max(l, ans)
		l = 0
ans = max(ans, l)
print(ans)


n = int(input())
data = list(map(int, input().split()))
c = 0
m = 0
for i in data:
	if i:
		c += 1
	else:
		if c > m:
			m = c
		c = 0
for i in data:
	if i:
		c += 1
	else:
		if c > m:
			m = c
		break
print(m)


n = int(input())
a = list(map(int, input().split()))
al = []
count = 0
for i in range(0, n):
	if i == n - 1:
		if a[i] == 1:
			count += 1
			if a[0] == 1:
				for j in range(0, n - 1):
					if a[j] == 1:
						count += 1
					else:
						break
			al.append(count)
		else:
			al.append(count)
			count = 0
	elif a[i] == 1:
		count += 1
	else:
		al.append(count)
		count = 0
print(max(al))


hours = int(input().strip())
schedule = input().strip().replace(' ', '')
schedule = ''.join([schedule, schedule])
schedule = schedule.split('0')
print(len(sorted(schedule, key=len)[-1]))


n = int(input())
a = list(map(int, input().split()))
maxlen = 0
if a[0] == 1 and a[-1] == 1:
	a += a
nowlen = 0
for i in a:
	if i == 1:
		nowlen += 1
		if nowlen > maxlen:
			maxlen = nowlen
	else:
		if nowlen > maxlen:
			maxlen = nowlen
		nowlen = 0
print(maxlen)


from itertools import cycle

def main():
	n = int(input())
	a = list(map(int, input().split()))
	if 1 not in a:
		return 0
	(ans, cur) = (0, 1)
	for i in range(n - 1):
		if a[i] == a[i + 1] == 1:
			cur += 1
		else:
			ans = max(ans, cur)
			cur = 1
	cur_end = 0
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			cur_end += 1
		else:
			break
	cur_begin = 0
	for i in range(n):
		if a[i] == 1:
			cur_begin += 1
		else:
			break
	ans = max(ans, cur_end + cur_begin)
	return ans
print(main())


n = int(input())
l = list(map(int, input().split()))
k = []
while len(l) != 0 and l[len(l) - 1] == 1:
	k.append(1)
	l.pop()
for i in l:
	k.append(i)
ans = 0
mx = 0
for i in k:
	if i == 1:
		ans += 1
		mx = max(mx, ans)
	else:
		ans = 0
print(mx)


amount = int(input())
hours = input()
results = []
hours_2 = []
counter = 0
for hour in hours.split(' '):
	hours_2.append(int(hour))
for (index, item) in enumerate(hours_2):
	if item == 1:
		counter += 1
		if index == len(hours_2) - 1:
			results.append(counter)
	else:
		results.append(counter)
		counter = 0
if hours_2[0] == 1 and hours_2[-1] == 1:
	counter = 0
	for i in hours_2:
		if i == 1:
			counter += 1
		else:
			results.append(counter)
			break
	counter = 0
	for i2 in hours_2[::-1]:
		if i2 == 1:
			counter += 1
		else:
			results.append(counter)
			break
if hours_2[0] == 1 and hours_2[-1] == 1:
	print(max(max(results), results[-1] + results[-2]))
else:
	print(max(results))


hours = int(input())
wNr = [int(w) for w in input().split()]
wNr = wNr * 2
(r, lr) = (0, 0)
for i in wNr:
	if i != 0:
		r += 1
		if r > lr:
			lr = r
	else:
		r = 0
print(lr)


from math import *
n = int(input())
a = list(map(int, input().split(' ')))
tmp = 0
mx = 0
for i in a:
	if i == 1:
		if tmp == 0:
			tmp = 1
		else:
			tmp += 1
	else:
		tmp = 0
	mx = max(mx, tmp)
mx2 = 0
i = n - 1
while a[i] != 0:
	mx2 += 1
	i -= 1
i = 0
while a[i] != 0:
	mx2 += 1
	i += 1
print(max(mx2, mx))


n = int(input())
l = list(map(int, input().strip().split()))
(maxi, count) = (0, 0)
for i in range(0, len(l) - 1):
	if l[i] == 1:
		count += 1
		maxi = max(maxi, count)
	else:
		count = 0
c = 0
for i in range(0, len(l) - 1):
	if l[i] == 1 and l[i + 1] == l[i]:
		c += 1
	else:
		break
cx = 0
for i in range(len(l) - 1, 0, -1):
	if l[i] == 1 and l[i - 1] == l[i]:
		cx += 1
	else:
		break
if l[len(l) - 1] == 1:
	cx += 1
if l[0] == 1:
	c += 1
print(max(maxi, c + cx))


N = int(input())
lst = list(map(int, input().split()))
count = 0
maxi = 0
for i in range(len(lst)):
	if lst[i] == 1:
		count += 1
		maxi = max(maxi, count)
	else:
		count = 0
for i in range(len(lst)):
	if lst[i] == 1:
		count += 1
		maxi = max(maxi, count)
	else:
		count = 0
print(max(maxi, count))


n = int(input())
s = input().split(' ')
mas = []
k = 0
for i in range(n):
	if s[i] == '0':
		mas.append(k)
		mas.append(0)
		k = 0
	else:
		k += 1
mas.append(k)
mas.append(mas[0] + mas[-1])
print(max(mas))


n = int(input())
arr = list(map(int, input().split()))
i = 0
while arr[i] != 0:
	i += 1
m = -1
k = 0
j = i
started = False
while not started or j != i:
	started = True
	j += 1
	j %= len(arr)
	while arr[j] != 0:
		j += 1
		j %= len(arr)
		k += 1
	m = max(k, m)
	k = 0
print(m)


n = int(input())
st = input() * 2
print(max(map(len, st.replace(' ', '').split('0'))))


n = int(input())
A = list(map(int, input().split()))
m = 0
x = 0
s = 0
for i in range(0, n):
	if A[i] == 1:
		s += 1
	else:
		break
while s != 0:
	A.append(1)
	s -= 1
for i in range(0, len(A)):
	if A[i] == 1:
		x += 1
		m = max(m, x)
	else:
		x = 0
print(m)


n = int(input())
a = input()
wh = a.split()
first_list = []
second_list = []
for i in wh * 2:
	if '1' == i:
		first_list.append('1')
	if '1' != i:
		if len(first_list) >= len(second_list):
			second_list = first_list[:]
			first_list.clear()
		else:
			first_list.clear()
if len(first_list) >= len(second_list):
	second_list = first_list[:]
	first_list.clear()
cnt = len(second_list)
print(cnt)


garbage = input()
z = list(map(int, input().rstrip().split(' ')))
if z[0] and z[-1]:
	to_add = 0
	for i in z:
		if i == 1:
			to_add += 1
		else:
			break
	z = z + [1] * to_add
max_r = 0
i = 0
while i < len(z):
	rest = 0
	for a in range(i, len(z)):
		if z[a] == 1:
			rest = rest + 1
			i = i + 1
		else:
			i = i + 1
			break
	if rest > max_r:
		max_r = rest
print(max_r)


n = int(input())
a = input().split()
a += a
m = 0
num = 0
for i in a:
	if i == '1':
		num += 1
	else:
		num = 0
	if num > m:
		m = num
print(m)


from sys import stdin, stdout

def inp():
	return int(stdin.readline())

def minp():
	return map(int, stdin.readline().rstrip().split())

def linp():
	return list(minp())

def main():
	n = inp()
	l = linp()
	ll = [1]
	cnt = 0
	if l.count(0) == n:
		print(0)
		exit()
	for i in range(n):
		if l[i] != 1:
			break
		else:
			cnt += 1
	for i in range(n - 1, -1, -1):
		if l[i] != 1:
			break
		else:
			cnt += 1
	ll.append(cnt)
	cnt = 0
	for i in range(n - 1):
		if l[i] == 1 and l[i + 1] == 1:
			cnt += 1
		else:
			ll.append(cnt)
			cnt = 1
	ll.append(cnt)
	print(max(ll))
main()


q = int(input())
w = input().split()
a = []
n = 0
for i in w:
	if i == '1':
		n += 1
	else:
		a.append(n)
		n = 0
if w[-1] == '1':
	a.append(n + a[0])
print(max(a))


X = int(input())
Y = list(input().split()) * 2
n = 0
m = 0
for i in Y:
	if i == '0':
		if n > m:
			m = n
		n = 0
	else:
		n += 1
print(m)


n = int(input())
a = list(map(int, input().split()))
m = -float('inf')
s = 0
for i in range(n):
	if a[i] == 0:
		m = max(m, s)
		s = 0
	else:
		s += 1
i = 0
while a[i] != 0:
	s += 1
	i += 1
m = max(m, s)
print(m)


n = int(input())
a = [int(i) for i in input().split()]
mm = 0
count = 0
i = 0
while i < 2 * n:
	if a[i % n] == 1:
		count += 1
	else:
		if count > mm:
			mm = count
		count = 0
	i += 1
print(mm)


n = int(input())
a = [int(s) for s in input().split()]
a.extend(a)
s = ''
for i in a:
	s += str(i)
a = s.split('0')
maxlen = 0
for i in a:
	if len(i) > maxlen:
		maxlen = len(i)
print(maxlen)


n = int(input())
mat = input().split()
step = mat.index('0')
mat = mat[step:] + mat[0:step]
s = ''.join((i for i in mat))
s = max(map(len, (st for st in s.split('0'))))
print(s)


n = int(input())
first = -1
last = -1
longest = 0
cur = 0
for (i, inp) in enumerate(input().split()):
	inp = int(inp)
	if inp == 1:
		cur += 1
		longest = max(cur, longest)
	elif inp == 0:
		cur = 0
		if first == -1:
			first = i
cur += first
longest = max(longest, cur)
print(longest)


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


n = int(input())
a = list(map(int, input().split()))
a = a * 2
ans = [0]
if a[0] == 1:
	ans.append(1)
for i in range(1, len(a)):
	if a[i] == a[i - 1] and a[i] == 1:
		ans.append(ans[-1] + 1)
	elif a[i] == 1:
		ans.append(1)
print(max(ans))


n = int(input())
l = list(map(int, input().split()))
l = l + l
c = 0
import math
m = -math.inf
for i in range(len(l)):
	if l[i] == 1:
		c = c + 1
	else:
		m = max(c, m)
		c = 0
m = max(c, m)
print(m)


n = int(input())
n1 = list(map(int, input().split()[:n]))
s = n1 + n1
w = 0
lst = []
for i in s:
	if i == 1:
		w = w + 1
	else:
		lst.append(w)
		w = 0
print(max(lst))


from itertools import groupby
input()
s = input().replace(' ', '')
A = [len(list(g)) for (k, g) in groupby(s) if k == '1']
x = max(A, default=0)
if len(A) > 1:
	print(max(x, A[0] + A[-1]) if s[0] == s[-1] == '1' else x)
else:
	print(x)


n = int(input())
a = list(map(int, input().split()))
aa = a + a + a
r = 0
t = 0
for (i, v) in enumerate(zip(aa, aa[1:])):
	if v == (1, 0):
		r = max(r, i - t)
	elif v == (0, 1):
		t = i
print(r)


n = int(input())
l = list(map(int, input().split()))
b = l + l
cnt = 0
mxcnt = 0
for i in b:
	if i == 1:
		cnt += 1
	else:
		mxcnt = max(cnt, mxcnt)
		cnt = 0
print(mxcnt)


n = int(input())
a = list(map(int, input().split()))
pre_rest = post_rest = cnt = ans = 0
for i in range(n):
	if 1 == a[i]:
		cnt += 1
		ans = max(ans, cnt)
	else:
		cnt = 0
if 1 == a[0] and 1 == a[n - 1]:
	pre_rest = post_rest = 1
	for i in range(1, n - 1):
		if 1 == a[i]:
			pre_rest += 1
		else:
			break
	else:
		print(n)
		exit()
	for i in range(n - 2, 0, -1):
		if 1 == a[i]:
			post_rest += 1
		else:
			break
	print(max(ans, pre_rest + post_rest))
else:
	print(ans)


n = int(input())
a = list(map(int, input().split()))
x = n - 1
d = 0
while x > 0 and a[x] == 1:
	x -= 1
	d += 1
y = 0
d1 = 0
while y < n and a[y] == 1:
	y += 1
	d += 1
ans = d + d1
tmp = 0
for i in range(y, x + 1):
	if a[i] == 1:
		tmp += 1
	else:
		ans = max(ans, tmp)
		tmp = 0
print(ans)


n = int(input())
ar = list(map(int, input().split()))
ans = 0
m = 0
for i in range(2 * n):
	if ar[i % n] == 1:
		ans += 1
	else:
		m = max(ans, m)
		ans = 0
	m = max(m, ans)
print(m)


n = int(input())
tab = input().split()
tab += tab
c = 0
m = 0
for i in tab:
	if i == '1':
		c += 1
	else:
		c = 0
	if c > m:
		m = c
print(m)


n = int(input())
S = list(map(int, input().split()))
S.extend(S)
ans = 0
cnt = 0
for i in S:
	if i:
		cnt += 1
	else:
		ans = max(ans, cnt)
		cnt = 0
print(ans)


n = int(input())
li = [int(x) for x in input().split()]
first = 0
last = 0
max = 0
f_ind = 0
l_ind = n - 1
if li[0] == 1:
	i = 1
	first = 1
	while li[i] != 0:
		first = first + 1
		f_ind = i
		i = i + 1
if li[l_ind] == 1:
	i = n - 2
	last = 1
	while li[i] != 0:
		last = last + 1
		l_ind = i
		i = i - 1
i = f_ind + 1
while i < l_ind:
	if li[i] == 1:
		count = 1
		i = i + 1
		while li[i] == 1:
			count = count + 1
			i = i + 1
		if max < count:
			max = count
	i = i + 1
if max > first + last:
	print(max)
else:
	print(first + last)


n = int(input())
l = [int(x) for x in input().split()]
c = 0
mx = 0
for i in range(n):
	if l[i] == 1:
		c += 1
		if c > mx:
			mx = c
	else:
		c = 0
j = 0
c1 = 0
while l[j] == 1:
	c1 += 1
	j += 1
j = n - 1
c2 = 0
while l[j] == 1:
	c2 += 1
	j -= 1
d = c1 + c2
print(max(d, mx))


n = int(input())
a = list(map(int, input().split()))
relax = 1
a = a[:] * 2
otv = []
q = len(a)
kox = 0
for i in range(q - 1):
	if 1 in a:
		kox += 1
		if a[i] == 1 and a[i + 1] == 1:
			relax += 1
			otv.append(relax)
		else:
			relax = 1
	else:
		print(0)
		break
if len(otv) > 0:
	print(max(otv))
elif relax == 1 and kox > 0:
	print(relax)


n = int(input())
d = input().split()
d += d
maior = 0
cont = 0
for i in d:
	if i == '1':
		cont += 1
	else:
		if cont > maior:
			maior = cont
		cont = 0
if maior == 0:
	maior = cont
print(maior)


n = int(input())
l = list(map(int, input().split()))
k = 0
init = 0
maxe = 0
for i in range(n):
	if l[i] == 1:
		k += 1
	else:
		maxe = max(k, maxe)
		k = 0
for i in range(n):
	if l[i] == 1:
		init += 1
	else:
		break
final = 0
for j in range(n - 1, -1, -1):
	if l[j] == 1:
		final += 1
	else:
		break
print(max(maxe, final + init))


n = int(input())
s = str(input().replace(' ', ''))
s = s + s + s
v = list(s.split('0'))
print(len(max(v, key=len)))


n = int(input())
a = input().split()
cnt_start_end = 0
for i in a:
	if i == '0':
		break
	cnt_start_end += 1
for i in a[::-1]:
	if i == '0':
		break
	cnt_start_end += 1
max_cnt = cnt_start_end
cnt = 0
for i in a:
	if i == '0':
		max_cnt = max(max_cnt, cnt)
		cnt = 0
	else:
		cnt += 1
print(max_cnt)


n = int(input())
a = list(map(int, input().split()))
res = 0
now = 0
for j in range(3 * n):
	i = j % n
	if a[i]:
		now += 1
	else:
		if now:
			res = max(now, res)
		now = 0
res = max(now, res)
print(res)


n = int(input())
s = input()
s += ' ' + s
days2 = s.split()
counter = 0
maxc = 0
for i in days2:
	if i == '1':
		counter += 1
		if counter > maxc:
			maxc = counter
	if i == '0':
		counter = 0
print(maxc)


n = int(input())
ll = input()
l = ll + ' ' + ll
l = l.split(' ')
d = 0
maxd = 0
for i in l:
	i = int(i)
	if i == 1:
		d = d + 1
	if i == 0:
		maxd = max(maxd, d)
		d = 0
print(maxd)


from bisect import bisect_right as br
from bisect import bisect_left as bl
from collections import *
from itertools import *
import functools
import sys
import math
import random
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b, x, y):
	return abs(a - x) + abs(b - y)

def numIN(x=' '):
	return map(int, sys.stdin.readline().strip().split(x))

def charIN():
	return sys.stdin.readline().strip().split()

def dis(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def maxsum(a):
	l = []
	msf = 0
	meh = 0
	for i in range(len(a)):
		meh += a[i][1]
		if meh < 0:
			meh = 0
		elif msf < meh:
			msf = meh
			l.append(a[i])
	return (l[::-1], msf)
n = int(input())
l = list(numIN())
l += l
cnt = 0
mx = 0
for i in range(2 * n):
	if l[i] == 1:
		cnt += 1
	else:
		mx = max(mx, cnt)
		cnt = 0
print(mx)


n = int(input())
a = list((int(x) for x in input().split()))
s = 0
while a[s] == 1:
	s += 1
e = len(a) - 1
while a[e] == 1:
	e -= 1
e = len(a) - 1 - e
m = 0
current = e
for i in range(len(a)):
	if a[i] == 1:
		current += 1
	else:
		m = max(current, m)
		current = 0
m = max(m, current + s)
print(m)


n = eval(input())
s = input().split(' ')
arr = list(map(int, s))
count = 0
max = 0
for i in range(n):
	if arr[i] == 0:
		if max < count:
			max = count
		count = 0
	else:
		count += 1
i = 0
if count != 0:
	while arr[i] != 0 and i < n:
		count += 1
		i += 1
if count > max:
	max = count
print(max)


def MaxSumSubArray(l):
	maxx = -9999999999999999999
	curr_summ = 0
	for i in range(len(l)):
		curr_summ += l[i]
		maxx = max(maxx, curr_summ)
		if curr_summ < 0:
			curr_summ = 0
	return maxx

def rest(l):
	curr = 0
	maxx = -1
	f = False
	for i in range(len(l) - 1):
		if l[i] == 1 and curr == 0:
			curr = 1
			maxx = max(maxx, curr)
		elif l[i] == 1 and l[i + 1] == 1:
			curr += 1
			maxx = max(maxx, curr)
		if i == len(l) - 2:
			if l[-2] == 1 and l[-1] == 1:
				curr += 1
				maxx = max(maxx, curr)
		if l[i] == 0:
			maxx = max(maxx, curr)
			curr = 0
	maxx = max(maxx, curr)
	return maxx
N = int(input())
l = list(map(int, input().split()))
l *= 2
for i in range(len(l)):
	if l[i] == 0:
		l[i] = -9999999
ans = MaxSumSubArray(l)
print(max(ans, 0))


n = int(input())
work_h = list(map(int, input().split()))
temp = 0
while work_h[temp] == 1:
	work_h.append(1)
	temp += 1
work_h.append(0)
max = 0
cnt = 0
for i in range(len(work_h)):
	if work_h[i] == 1:
		cnt += 1
	else:
		if cnt > max:
			max = cnt
		cnt = 0
print(max)


input()
s = [len(i) for i in ''.join(input().split()).split('0')]
s[0] += s.pop()
print(max(s))


n = int(input())
a = [int(x) for x in input().split()]
count = 0
m = 0
for i in a:
	if i == 1:
		count += 1
	else:
		if m < count:
			m = count
		count = 0
if count > 0:
	for i in a:
		if i == 1:
			count += 1
		else:
			if m < count:
				m = count
			break
print(m)


n = int(input())
a = list(map(int, input().split()))
c = 0
cc = 0
mx = 0
k = 0
f = 0
for i in range(n):
	if i == 0 or k == 1:
		if a[i] == 1:
			cc += 1
			f = 1
			k = 1
		else:
			k = 0
		continue
	if a[i] == 1:
		c += 1
		mx = max(mx, c)
	else:
		c = 0
if f == 1:
	mx = max(mx, c + cc)
	print(mx)
else:
	print(mx)


n = int(input())
a = list(map(int, input().split()))
b = 0
c = 0
for i in a * 2:
	if i == 1:
		b += 1
		if b > c:
			c = b
	elif i == 0:
		b = 0
print(c)


n = int(input())
l = list(map(int, input().split()))
emp = []
ch = l[0]
c = 0
for i in l:
	if ch == i:
		c += 1
	else:
		if ch == 1:
			emp.append(c)
		ch = i
		c = 1
if ch == 1:
	emp.append(c)
if l[0] == 1 and l[-1] == 1:
	emp.append(emp[0] + emp[-1])
if not emp:
	print(0)
else:
	print(max(emp))


n = int(input())
arr = list(map(int, input().split(' ')))
arr += arr
cnt = 0
mx = 0
for x in arr:
	if x == 1:
		cnt += 1
	else:
		mx = max(mx, cnt)
		cnt = 0
print(mx)


n = int(input())
L = list(map(int, input().split()))
L1 = L
k = 0
while k < n:
	if L[k] == 0:
		break
	else:
		L1.append(1)
	k += 1
L1 += [0]
mayor = 0
cont = 0
for k in range(len(L1)):
	if L1[k] == 0:
		if cont > mayor:
			mayor = cont
		cont = 0
	else:
		cont += 1
print(mayor)


n = int(input())
l = list(map(int, input().split()))
m = 0
t = 0
for i in range(n - 1, -1, -1):
	if l[i] == 1:
		t += 1
	else:
		if t > m:
			m = t
		t = 0
if t > m:
	m = t
s = 0
e = 0
for i in l:
	if i == 1:
		s += 1
	else:
		break
for i in range(n - 1, -1, -1):
	if l[i] == 1:
		e += 1
	else:
		break
if s + e > m:
	m = s + e
print(m)


n = int(input())
l = [int(x) for x in input().split()]
ans = [0 for i in range(n)]
for i in range(n):
	if l[i] == 0:
		ans[i] = 0
	elif l[i] == 1 and i == 0:
		ans[i] = 1
	else:
		ans[i] = ans[i - 1] + 1
max = max(ans)
ct = 0
for i in range(n - 1, -1, -1):
	if l[i] == 1:
		ct += 1
	else:
		break
b = 0
for i in range(n):
	if l[i] == 0:
		break
	else:
		b += 1
if max < b + ct:
	max = b + ct
print(max)


n = int(input())
a = list(map(int, input().split()))
a = a + a
maxLen = 0
curLen = 0
for i in range(len(a)):
	if a[i] == 1:
		curLen = curLen + 1
		if curLen > maxLen:
			maxLen = curLen
	else:
		curLen = 0
print(maxLen)


lam = int(input())
a = list(map(int, input().split()))
sam = 0
jam = []
l = 0
ham = 0
for x in range(lam):
	if a[x] == 1:
		sam += 1
	else:
		if l == 0:
			ham += sam
			l = 1
		jam.append(sam)
		sam = 0
kam = a[::-1]
sam = 0
if l == 1:
	for x in range(lam):
		if kam[x] == 1:
			sam += 1
		else:
			break
	jam.append(ham + sam)
print(max(jam))


from collections import deque
n = int(input())
a = deque(map(int, input().split()))
i = a.index(0)
a.rotate(-(i + 1))
count = 0
m = 0
for x in range(n):
	if a[x] == 1:
		count += 1
	if a[x] == 0:
		if count > m:
			m = count
		count = 0
print(m)


n = int(input())
l = input().split()
c = 0
for i in l:
	if i == '1':
		l.append('1')
		c += 1
	else:
		l.append('0')
		break
if l[c] == '1':
	maxx = 1
else:
	maxx = 0
t = c
c = 0
for i in range(t, n + t + 1):
	if l[i] == '1':
		c += 1
	else:
		if maxx < c:
			maxx = c
		c = 0
print(maxx)


n = int(input())
r = list(map(int, input().split()))
c = 0
co = []
for i in range(n):
	if r[i] == 1:
		c += 1
	else:
		co.append(c)
		c = 0
co.append(c)
if r[n - 1] == 1 and r[0] == 1:
	co[0] += co[len(co) - 1]
print(max(co))


m = int(input())
a = list(map(int, input().split()))
s = 0
e = 0
i = 0
j = 0
ma = 0
if a[0] == 1:
	while i < len(a) and a[i] == 1:
		if a[i] == 1:
			s += 1
		i += 1
	ma = s
while i < len(a):
	if i == len(a) - 1:
		if a[i] == 1:
			j += 1
			e = j
			if j > ma:
				ma = j
	if a[i] == 1:
		j += 1
	else:
		if j > ma:
			ma = j
		j = 0
	i += 1
if e + s > ma:
	print(e + s)
else:
	print(ma)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
n = int(input())
l = list(map(int, input().split()))
l = l[:] + l[:]
c = 0
ans = 0
for i in range(len(l)):
	if l[i] == 1:
		c += 1
		ans = max(ans, c)
	else:
		c = 0
print(ans)


n = int(input())
a = list(map(int, input().split()))
for i in range(n):
	a.append(a[i])
max1 = 0
i = 0
while i < 2 * n:
	if a[i] == 1:
		j = 1
		while i + j < 2 * n and a[i + j] == 1:
			j += 1
		if j > max1:
			max1 = j
		i += j
	else:
		i += 1
print(max1)


__author__ = 'NIORLYS'
n = int(input())
h = list(map(int, input().split()))
h *= 2
i = 0
count = 0
current_max = 0
while i < 2 * n:
	if h[i] == 1:
		count += 1
	else:
		current_max = max(count, current_max)
		count = 0
	i += 1
print(current_max)


a = int(input())
b = ''.join(input().split(' '))
b *= 2
a = b.split('0')
c = set(a)
maior = 0
for x in a:
	maior = max(maior, len(x))
print(maior)


from itertools import groupby
nb_hours = int(input())
schedule = [int(x) for x in input().split()]
schedule += schedule
schedule = groupby(schedule)
maxs = 0
for (i, g) in schedule:
	if i == 1:
		maxs = max(maxs, len(list(g)))
print(maxs)


n = int(input())
lst = list(map(int, input().split()))
lst = lst + lst
count = 0
large = 0
for i in lst:
	if i == 1:
		count += 1
	else:
		if count > large:
			large = count
		count = 0
print(large)


L = []
n = int(input())
L = list(map(int, input().split()))
rest = 0
first_rest = 0
last_rest = 0
max_rest = 0
kontrola = 1
for i in range(n):
	if L[i] == 1:
		rest += 1
		if kontrola == 1:
			first_rest += 1
		if max_rest < rest:
			max_rest = rest
	if L[i] == 0:
		rest = 0
		kontrola = 0
if rest + first_rest > max_rest:
	max_rest = rest + first_rest
print(max_rest)


def main():
	n = int(input())
	hrs = list(map(int, input().split()))
	count = 0
	counts = []
	for i in hrs:
		if i == 1:
			count += 1
		else:
			counts.append(count)
			count = 0
	ans = max(counts)
	if hrs[-1] == 1:
		counts.append(count)
		ans = max(counts)
		if hrs[0] == 1:
			m = counts[0] + counts[-1]
			if m > ans:
				ans = m
	print(ans)
main()


pp = print
li = list
tp = tuple
bg = 1000000000.0
sg = -1000000000.0
rd = round
ss = sorted
sj = ''.join
nl = '\n'

def solve():
	pass

def main():
	for i in range(int(input())):
		solve()
n = int(input())
z = [*map(int, input().split())]
try:
	z += z[:z.index(0)]
except:
	pass
ans = 0
t = 0
for i in z:
	if i == 1:
		t += 1
	else:
		ans = max(ans, t)
		t = 0
ans = max(ans, t)
print(ans)


n = int(input())
a = input().split()
maxRest = 0
rest = 0
for i in range(n):
	if int(a[i]) == 1:
		rest += 1
		if maxRest < rest:
			maxRest = rest
		if int(i) == n - 1 and int(a[i]) == 1:
			i = 0
			while int(a[i]) == 1:
				rest += 1
				i += 1
				if maxRest < rest:
					maxRest = rest
	else:
		rest = 0
print(maxRest)


from collections import *
n = int(input())
a = list(map(int, input().split()))
a += a
ct = 0
ans = 0
for i in range(2 * n):
	if a[i] == 1:
		ct += 1
	else:
		ans = max(ans, ct)
		ct = 0
print(ans)


n = int(input())
arr = list(map(int, input().split()))
maxa = 0
ans = 0
for i in range(n):
	if arr[i] == 0:
		ans = 0
	else:
		ans += 1
	if ans > maxa:
		maxa = ans
left = 0
for i in range(n):
	if arr[i] == 1:
		left += 1
	else:
		break
right = 0
for i in range(n - 1, -1, -1):
	if arr[i] == 1:
		right += 1
	else:
		break
suma = left + right
if suma > maxa:
	maxa = suma
print(maxa)


n = int(input())
ai = list(map(int, input().split()))
streaks = [0]
streaking = False
ai.extend(ai)
for a in ai:
	if streaking == False:
		if a == 1:
			streak = 1
			streaking = True
		else:
			continue
	elif a == 1:
		streak += 1
	else:
		streaks.append(streak)
		streaking = False
print(max(streaks))


n = int(input())
l = [int(j) for j in input().split()]
i = 0
t1 = 0
t2 = 0
while l[i] == 1:
	t1 = t1 + 1
	i = i + 1
ma = t1
f = 0
while i < n:
	if l[i] == 1 and f == 0:
		f = 1
		t2 = 1
	elif l[i] == 1 and f == 1:
		t2 += 1
	else:
		f = 0
		if t2:
			ma = max(ma, t2)
			t2 = 0
	i = i + 1
if t2:
	ma = max(t1 + t2, ma)
print(ma)


n = int(input())
a = list(map(int, input().split()))
curr_cnt = 1 if a[0] == 1 else 0
max_cnt = curr_cnt
for i in range(1, 2 * n):
	if a[i % n] == 0:
		curr_cnt = 0
	elif a[(i - 1) % n] == 0:
		curr_cnt = 1
	else:
		curr_cnt += 1
	max_cnt = max(curr_cnt, max_cnt)
print(max_cnt)


n = int(input())
l = list(input().split())
c = ''
for i in l:
	c += i
k = []
for i in c.split('0'):
	k.append(i)
k.append(k[0] + k[-1])
print(len(max(k)))


n = int(input())
arr = list(map(int, input().split(' ')))
arr = arr * 2
streak = 0
maxstreak = 0
for i in range(2 * n):
	if arr[i] == 1:
		streak += 1
	else:
		streak = 0
	maxstreak = max(maxstreak, streak)
print(maxstreak)


import math
import time
from collections import defaultdict, deque
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
ans = 0
temp = 0
for i in a:
	if i == 1:
		temp += 1
	else:
		ans = max(ans, temp)
		temp = 0
pre = 0
i = 0
while a[i] == 1:
	i += 1
	pre += 1
suf = 0
i = n - 1
while a[i] == 1:
	i -= 1
	suf += 1
print(max(ans, pre + suf))


(n, mx) = (input(), 0)
a = list(map(int, input().split()))
if (1 in a) == False:
	print(0)
else:
	t = 1
	for i in range(len(a) - 1):
		if a[i] == 1 and a[i] == a[i + 1]:
			t += 1
		else:
			if t > mx:
				mx = t
			t = 1
	if mx < t:
		mx = t
	(t, s, g) = (0, 0, -1)
	if a.count(0) != 0:
		while a[s] == 1:
			t += 1
			s += 1
		while a[g] == 1:
			g -= 1
			t += 1
	if t > mx:
		mx = t
	print(mx)


n = int(input())
x = list(map(int, input().split()))
b = 0
c = 0
for i in range(0, 2 * n):
	if x[i % n] == 1:
		b += 1
		c = max(b, c)
	else:
		b = 0
print(c)


n = int(input())
A = [*map(int, input().split())]
m = 0
(frst, end) = (-1, -1)
i = 0
while i < n:
	if A[i] == 1:
		j = 1
		while i + j < n and A[i + j] == 1:
			j += 1
		if i == 0:
			frst = j
		if i + j == n:
			end = j
		i += j
		m = max(m, j)
	else:
		i += 1
if frst != -1 and end != -1:
	m = max(m, frst + end)
print(m)


from math import *
n = int(input())
a = list(map(int, input().split()))
a += a + [0]
km = 0
k = 0
for i in range(n + n):
	if a[i]:
		k += 1
	else:
		if k > km:
			km = k
		k = 0
print(km)


def main():
	x = int(input())
	s = list(map(int, input().split()))
	max = 0
	n = 0
	for i in range(0, x):
		s.append(s[i])
	for it in s:
		if it == 1:
			n += 1
		else:
			if n > max:
				max = n
			n = 0
	print(max)
main()


n = int(input())
a = input().split()
start_end = a[0] == '1' and a[-1] == '1'
best = 0
if start_end:
	i = 0
	while a[i] == '1':
		(best, i) = (best + 1, i + 1)
	i = n - 1
	while a[i] == '1':
		(best, i) = (best + 1, i - 1)
ln = 0
for i in range(n):
	if a[i] == '1':
		ln += 1
	else:
		(best, ln) = (max(best, ln), 0)
best = max(best, ln)
print(best)


n = int(input())
a = list(map(int, input().split()))
b = a
c = a + b
maxm = 0
count = 0
for ai in c:
	if ai == 1:
		count += 1
	else:
		if maxm < count:
			maxm = count
		count = 0
print(maxm)


input()
z = 0
m = 0
for i in (input() * 2).replace('', ' ').split():
	if i == '1':
		z = z + 1
	else:
		m = max(m, z)
		z = 0
print(max(m, z))


N = int(input())
A = [int(x) for x in input().split()]
(m1, m2, m3, cnt, m4) = (0, 0, 0, 0, 0)
if A[0] == 1 and A[len(A) - 1] == 1:
	for i in range(N):
		if A[i] == 1:
			m1 += 1
		else:
			break
	for i in range(N - 1, -1, -1):
		if A[i] == 1:
			m2 += 1
		else:
			break
	for i in range(N):
		if A[i] == 1:
			cnt += 1
		elif cnt > m3:
			m3 = cnt
			cnt = 0
		else:
			cnt = 0
		if i == N - 1:
			if cnt > m3:
				m3 = cnt
	if m1 + m2 > m3:
		print(m1 + m2)
	else:
		print(m3)
else:
	for i in range(N):
		if A[i] == 1:
			cnt += 1
		elif cnt > m4:
			m4 = cnt
			cnt = 0
		else:
			cnt = 0
		if i == N - 1:
			if cnt > m4:
				m4 = cnt
	print(m4)


n = int(input())
l = list(map(int, input().split()))
c = 0
i = 0
while i < n:
	d = 0
	x = i
	while i < n and l[i] == 1:
		d += 1
		i += 1
	c = max(c, i - x)
	i += 1
d = 0
i = 0
while i < n and l[i] == 1:
	d += 1
	i += 1
l.reverse()
i = 0
while i < n and l[i] == 1:
	d += 1
	i += 1
c = max(c, d)
print(c)


import sys
n = int(sys.stdin.readline())
l = list(map(int, sys.stdin.readline().split()))
maxm = 0
count = 0
for i in l:
	if i == 0:
		maxm = max(maxm, count)
		count = 0
	else:
		count += 1
count1 = 0
for i in range(n):
	if l[i] == 0:
		break
	else:
		count1 += 1
for i in range(n - 1, -1, -1):
	if l[i] == 0:
		break
	else:
		count1 += 1
maxm = max(maxm, count1)
print(maxm)


def arr_inp():
	return [int(x) for x in input().split()]
(n, a, out) = (int(input()), arr_inp(), 0)
c = 0
for i in range(n):
	if a[i]:
		c += 1
		out = max(out, c)
	else:
		a = a[i:]
		break
a = list(reversed(a))
for i in range(len(a)):
	if a[i]:
		c += 1
		out = max(out, c)
	else:
		c = 0
		a = a[i:]
		break
for i in range(len(a)):
	if a[i]:
		c += 1
		out = max(out, c)
	else:
		c = 0
print(out)


input()
arr = input().split()
arr *= 2
best = 0
curr = 0
for e in arr:
	if e == '1':
		curr += 1
		if curr > best:
			best = curr
	else:
		curr = 0
print(best)


def arr_inp():
	return [int(x) for x in input().split()]
(n, a, out, c) = (int(input()), arr_inp(), 0, 0)
for i in range(n * 2):
	if a[i % n]:
		c += 1
		out = max(out, c)
	else:
		c = 0
print(out)


from sys import stdin as sin
input()
hs = ''.join([s for s in sin.readline().strip().split(' ')])
hs2 = hs + hs
hs3 = hs2.split('0')
print(max([len(i) for i in hs3]))


n = int(input(''))
arr = list(map(int, input().split()))
dp = [0] * n
dp[0] = arr[0]
for i in range(1, n):
	if arr[i] == 0:
		dp[i] = 0
	else:
		dp[i] = dp[i - 1] + 1
if dp[0]:
	dp[0] += dp[n - 1]
for i in range(1, n):
	if arr[i] == 0:
		dp[i] = 0
	else:
		dp[i] = dp[i - 1] + 1
print(max(dp))


def solve(x):
	if 0 not in x:
		return len(x) // 2
	count = 0
	maxx = 0
	for i in x:
		if i == 1:
			count += 1
			if count > maxx:
				maxx = count
		else:
			count = 0
	return maxx
t = int(input())
x = str(input()).split(' ') * 2
x = [int(i) for i in x]
print(solve(x))


n = int(input())
b = input()
b = b + ' ' + b
b = b.split('0')
b = [len(x.split()) for x in b]
print(max(b))


n = int(input())
list1 = list(map(int, input().split(' ')))
array1 = []
count = 0
for i in range(2 * n):
	if list1[i % n] == 1:
		count += 1
	else:
		array1.append(count)
		count = 0
print(max(array1))


n = int(input())
a = list(map(int, input().split()))
b = a + a
cnt = 0
mcnt = 0
for i in b:
	if i == 1:
		cnt += 1
	else:
		mcnt = max(mcnt, cnt)
		cnt = 0
print(mcnt)


k = int(input())
q = [int(i) for i in input().split()]
qq = q.copy()
for i in qq:
	q.append(i)
(n, n1) = (0, 0)
for i in q:
	if i == 1:
		n += 1
		if n > n1:
			n1 = n
	else:
		n = 0
print(n1)


n = int(input())
a = list(map(int, input().split()))
a = a * 2
res = 1
ga = []
for i in range(n * 2 - 1):
	if a[i] == a[i + 1] == 1:
		res += 1
	else:
		ga.append(res)
		res = 1
ga.append(res)
if max(a) == 0:
	print(0)
else:
	print(max(ga))


from sys import stdin, stdout
for t in range(1):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().split()))
	a += a
	n *= 2
	cs = s = 0
	for i in range(n):
		cs += 1 if a[i] else -n
		s = max(cs, s)
		if cs < 0:
			cs = 0
	print(s)


n = int(input())
s = list(input().split()) * 2
g = 0
p = []
for i in s:
	if i == '1':
		g += 1
	else:
		p.append(g)
		g = 0
print(max(p))


n = input()
s = input()
l = s.split(' ')
l = list(map(int, l))
k = 0
c = 0
l1 = []
for i in l:
	if i == 1 and k == 1:
		c += 1
	if i == 1 and k == 0:
		k = 1
		c = 1
	if i == 0 and k == 1:
		k = 0
		l1.append(c)
		c = 0
if c != 0:
	l1.append(c)
if len(l1) == 0:
	print(0)
else:
	l2 = l1.copy()
	l2.sort()
	if l[0] == l[-1] and l[0] == 1 and (l1[0] + l1[-1] > l2[-1]):
		print(l1[0] + l1[-1])
	else:
		print(l2[-1])


n = int(input())
a = list(map(int, input().split()))
rest = 0
restmax = 0
for i in range(2 * len(a)):
	k = i % len(a)
	if a[k] == 1:
		rest += 1
		if restmax < rest:
			restmax = rest
	else:
		rest = 0
print(restmax)


n = int(input())
lst = list(map(int, input().split()))
for i in range(0, n):
	lst.append(lst[i])
cnt = 0
maxn = 0
for i in range(0, n * 2):
	if lst[i] == 0:
		cnt = 0
	else:
		cnt += 1
		maxn = max(maxn, cnt)
print(maxn)


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
curr_cnt = 1 if a[0] == 1 else 0
max_cnt = curr_cnt
cnts = Counter(a)
if cnts[1] == len(a):
	print(n)
else:
	for i in range(1, 2 * n):
		if a[i % n] == 0:
			curr_cnt = 0
		elif a[(i - 1) % n] == 0:
			curr_cnt = 1
		else:
			curr_cnt += 1
		max_cnt = max(curr_cnt, max_cnt)
	print(max_cnt)


n = int(input())
a = list(map(int, input().split()))
q = []
k = 0
b = a + [0]
for s in b:
	if s == 0:
		q.append(k)
		k = 0
	else:
		k += 1
g = 0
if a[0] == 1 and a[-1] == 1:
	if 0 in a:
		for w in a:
			if w == 0:
				break
			g += 1
		a.reverse()
		for w in a:
			if w == 0:
				break
			g += 1
	else:
		g += len(a)
f = max(max(q), g)
print(f)


n = int(input())
l = list(map(int, input().split()))
y = l + l
c = 0
test = 0
res = 0
for i in range(2 * n):
	if test == 0:
		c = 0
		if y[i] == 1:
			c += 1
			test = 1
	elif y[i] == 1:
		c += 1
	else:
		res = max(res, c)
		test = 0
print(res)


n = int(input())
days = list(map(int, input().split()))
max_counter = 0
counter = 0
for day in days + days:
	if day == 1:
		counter += 1
	else:
		max_counter = max(max_counter, counter)
		counter = 0
max_counter = max(max_counter, counter)
print(max_counter)


n = int(input())
schedule = list(map(int, input().split()))
start = schedule.index(0)
i = start + 1
i = i % n
(highest, count) = (0, 0)
while i != start:
	if schedule[i] == 1:
		count += 1
	else:
		if count > highest:
			highest = count
		count = 0
	i = (i + 1) % n
else:
	if count > highest:
		highest = count
		count = 0
print(highest)


n = int(input())
string = input().replace(' ', '')
string = string + string
i = 0
mx = 0
while i < 2 * n:
	if string[i] == '1':
		j = i
		count = 0
		while j < 2 * n and string[j] == '1':
			count += 1
			j += 1
		mx = max(count, mx)
		i = j
	else:
		i += 1
print(mx)


n = int(input())
m = [int(i) for i in input().split()]
temp = 0
mx = 0
for i in range(2 * n):
	if m[i % n] == 1:
		temp += 1
	else:
		if mx < temp:
			mx = temp
		temp = 0
if mx < temp:
	print(temp)
else:
	print(mx)


import sys
import math
fileoperation = 0
if fileoperation:
	orig_stdout = sys.stdout
	orig_stdin = sys.stdin
	inputfile = open('W:/Competitive Programming/input.txt', 'r')
	outputfile = open('W:/Competitive Programming/output.txt', 'w')
	sys.stdin = inputfile
	sys.stdout = outputfile
mod = 1000000007

def nospace(l):
	ans = ''.join((str(i) for i in l))
	return ans
t = 1
for tt in range(t):
	n = int(input())
	a = list(map(int, sys.stdin.readline().split(' ')))
	b = 2 * a
	ans = 0
	curr = 0
	for i in range(len(b)):
		if b[i] == 1:
			curr += 1
		else:
			ans = max(ans, curr)
			curr = 0
	print(ans)
if fileoperation:
	sys.stdout = orig_stdout
	sys.stdin = orig_stdin
	inputfile.close()
	outputfile.close()


n = int(input())
l = list(map(int, input().split()))
i = 0
a = []
if l[i] == 0:
	a.append(0)
else:
	while l[i] == 1:
		i += 1
	a.append(i)
while i < n - 1:
	c = 0
	if l[i] == 0:
		while i < n - 1 and l[i + 1] == 1:
			c += 1
			i += 1
	i += 1
	a.append(c)
if l[n - 1] == 0:
	a.append(0)
a[0] += a.pop()
print(max(a))


n = int(input())
x = list(map(int, input().split()))
x += x
(rest1, max_rest) = (0, 0)
for i in range(2 * n):
	if x[i] == 1:
		rest1 += 1
	elif x[i] == 0:
		if rest1 > max_rest:
			max_rest = rest1
		rest1 = 0
print(max(rest1, max_rest))


def solve():
	n = int(input())
	a = list(map(int, input().split()))
	a = a * 2
	(cnt, mx) = (0, 0)
	for val in a:
		if val == 1:
			cnt = cnt + 1
		else:
			mx = max(cnt, mx)
			cnt = 0
	return mx
print(solve())


n = int(input())
m = list(map(int, input().split()))
t = 0
ans = 0
for i in m + m:
	t = t + 1 if i else 0
	ans = max(ans, t)
print(ans)


hours = int(input())
schedule = list(map(int, input().split()))
dp = hours * [0]
for i in range(hours):
	if schedule[i] == 1:
		dp[i] = dp[i - 1] + 1
	else:
		dp[i] = 0
if dp[hours - 1] > 0:
	i = 0
	while dp[i] > 0:
		dp[i] += dp[hours - 1]
		i += 1
print(max(dp))


n = int(input())
l = list(map(int, input().split()))
c = 0
fc = 0
for i in range(2 * n):
	if l[i % n] == 1:
		c += 1
		fc = max(c, fc)
	else:
		c = 0
print(fc)


n = int(input())
a = input()
b = a.split(' ')
a = list(map(int, b))
dau = 0
ln = 0
dem = 0
if a[0] == 1:
	dau = 1
for i in range(n):
	if a[i] == 1:
		dem = dem + 1
	else:
		if dem > ln:
			ln = dem
		dem = 0
i = 1
if dau == 1:
	while a[i] == 1:
		dau = dau + 1
		i = i + 1
dem = dem + dau
if dem > ln:
	ln = dem
print(ln)


input()
ip = list(map(int, input().split()))
seq = ''
for i in ip:
	seq += str(i)
seq = seq.split('0')
m = 0
for i in seq:
	m = max(m, len(i))
if ip[0] == 1 and ip[len(ip) - 1] == 1:
	m = max(m, len(seq[0]) + len(seq[len(seq) - 1]))
print(m)


x = int(input())
y = [int(i) for i in input().split()] * 2
ll = 0
max_ll = 0
for a in y:
	if a == 1:
		ll = ll + 1
	else:
		max_ll = max(ll, max_ll)
		ll = 0
print(max_ll)


N = int(input())
l = input().split()
s = ''.join(l)
s1 = s * 2
max = 0
count = 0
for i in range(1, len(s1)):
	if s1[i] == '1' and s1[i - 1] == '1':
		count += 1
		if count > max:
			max = count
	else:
		count = 0
if max > 0:
	print(max + 1)
elif '1' in s:
	max = 1
	print(max)
else:
	print(max)


n = int(input())
s = [int(x) for x in input().split()]
s = s + s
c = 0
ans = 0
if s[0] == 1:
	temp = 1
	c = 1
else:
	temp = 0
for i in range(1, len(s)):
	if s[i] == 1:
		if temp == 0:
			c = 1
		else:
			c = c + 1
		temp = 1
	else:
		ans = max(ans, c)
		c = 0
ans = max(ans, c)
print(ans)


n = int(input())
a = [int(i) for i in input().split(' ')]
a = a * 2
ans = 0
cur = 0
for i in range(len(a)):
	if a[i] == 1:
		cur += 1
	elif i != 0:
		ans = max(cur, ans)
		cur = 0
print(ans)


n = int(input())
a = input().replace(' ', '') * 2
print(max(map(len, a.split('0'))))


def run(n, a):
	res = []
	t = 0
	for i in range(n):
		if a[i] == 1:
			t += 1
			if i == n - 1:
				res.append(t)
		else:
			res.append(t)
			t = 0
	if t != 0:
		co = 0
		for i in range(n - 1, -1, -1):
			if a[i] == 1:
				co += 1
			else:
				break
		for i in range(n):
			if a[i] == 1:
				co += 1
			else:
				break
		res[-1] = co
	return max(res)
n = int(input())
a = list(map(int, input().split()))
print(run(n, a))


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = sys.stdin.readline().split()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_int(self):
		return int(self.next())

	def solve(self):
		n = self.next_int()
		x = [self.next_int() for _ in range(0, n)] * 2
		r = 0
		i = 0
		while i < n:
			if x[i] != 1:
				i += 1
				continue
			j = i
			while j < 2 * n and x[j] == 1:
				j += 1
			r = max(r, j - i)
			i = j
		print(min(n, r))
Main().solve()


import re, math, decimal, bisect

def read():
	return input().strip()

def iread():
	return int(input().strip())

def viread():
	return [int(_) for _ in input().strip().split()]
n = iread()
nums = viread()
counts = [0]
for i in nums:
	if i == 1:
		counts[-1] += 1
	else:
		counts.append(0)
print(max(max(counts), counts[0] + counts[-1]))


n = int(input())
hours_act = [int(i) for i in input().split(' ')]
num_cont_days = [0]
cur_num_cont_days = 0
for act in hours_act:
	if act == 1:
		cur_num_cont_days += 1
	else:
		if cur_num_cont_days != 0:
			num_cont_days.append(cur_num_cont_days)
		cur_num_cont_days = 0
if cur_num_cont_days != 0:
	for act in hours_act:
		if act == 1:
			cur_num_cont_days += 1
		else:
			num_cont_days.append(cur_num_cont_days)
			break
print(max(num_cont_days))


n = input()
A = list(map(int, input().split()))
B = A + A
C = []
contador = 0
for x in B:
	if x == 1:
		contador = contador + 1
		C.append(contador)
	elif x == 0:
		contador = 0
		C.append(contador)
print(max(C))


n = int(input())
A = list(map(int, input().split()))
A = A + A
cnt = 0
mx = 0
for i in A:
	if i:
		cnt = cnt + 1
		mx = max(mx, cnt)
	else:
		cnt = 0
print(mx)


N = int(input())
arr = input()
arr = [int(x) for x in arr.split(' ')]
arr = arr + arr
idx = 0
idx2 = 0
res = 0
while idx < 2 * N and idx2 < 2 * N:
	if arr[idx2] == 1:
		res = max(res, idx2 - idx + 1)
		idx2 += 1
	else:
		idx2 += 1
		idx = idx2
print(res)


n = int(input())
arr = list(map(int, input().split(' ')))
len1 = 0
len2 = 0
for i in range(0, n * 2):
	if arr[i % n] == 1:
		len1 += 1
	else:
		len2 = max(len2, len1)
		len1 = 0
print(len2)


n = int(input())
hrs = list(map(int, input().split()))
rest = [0]
count = 0
if hrs[0] == 1 and hrs[n - 1] == 1:
	for i in hrs:
		if i == 1:
			count += 1
		else:
			break
	for i in range(n):
		if hrs[n - 1 - i] == 1:
			count += 1
		else:
			break
	rest.append(count)
	count = 0
for i in range(n):
	if hrs[i] == 1:
		count += 1
		if i == n - 1:
			rest.append(count)
	elif hrs[i] == 0 and count != 0:
		rest.append(count)
		count = 0
print(max(rest))


n = int(input())
shedule = list(map(int, input().split()))
maxchill = -1
firstch = 0
lastchill = 0
i = 0
temp = 0
while i < n:
	if shedule[i] == 1:
		firstch += 1
		i += 1
	else:
		break
i = 0
while i < n:
	if shedule[i] == 1:
		temp += 1
	else:
		if temp > maxchill:
			maxchill = temp
		temp = 0
	i += 1
j = -1
while j > -n:
	if shedule[j] == 1:
		lastchill += 1
		j -= 1
	else:
		break
print(max(maxchill, lastchill + firstch))


def main():
	n = int(input())
	a = [int(x) for x in input().split(' ')]
	start_idx = find_1_after_0(a)
	temp_count = 0
	for i in range(start_idx, start_idx + len(a)):
		norm_i = normalized_index(i, len(a))
		if a[norm_i] == 1:
			temp_count += 1
			a[norm_i] = temp_count
		else:
			temp_count = 0
			a[norm_i] = 0
	print(max(a))

def normalized_index(i, size):
	return i % size

def find_1_after_0(arr):
	prev_val = arr[0]
	for i in range(1, len(arr)):
		if prev_val == 0 and arr[i] == 1:
			return i
		prev_val = arr[i]
	return 0
main()


from sys import stdin, stdout
from bisect import bisect_right, bisect_left
from math import gcd
a = int(stdin.readline())
lst = [int(i) for i in stdin.readline().split()]
l = 0
ans = 0
t = True
for i in lst:
	if i:
		l += 1
	else:
		if t:
			t = False
			f = l
		ans = max(l, ans)
		l = 0
	q = l
ans = max(f + q, ans)
stdout.write(str(ans))


a = int(input())
p = list(map(int, input().split(' ')))
pp = p + p
count = 0
result = 0
n = a * 2
for i in range(0, n):
	if pp[i] == 0:
		count = 0
	else:
		count += 1
		result = max(result, count)
print(result)


n = int(input())
l = list(map(int, input().strip().split()))
mx = 0
cur = 0
for i in l:
	if i == 1:
		cur += 1
	else:
		cur = 0
	mx = max(cur, mx)
last = 0
for i in range(n - 1, -1, -1):
	if l[i] == 1:
		last += 1
	else:
		break
for i in range(n):
	if l[i] == 1:
		last += 1
	else:
		break
mx = max(mx, last)
print(mx)


n = int(input())
z = list(map(int, input().split()))
count = 0
max = 0
a = []
for i in z:
	a.append(i)
for i in z:
	a.append(i)
for i in range(len(a)):
	if a[i] == 1:
		count += 1
	else:
		if max < count:
			max = count
		count = 0
		if i == len(a) - 1:
			i = 0
print(max)


n = int(input())
l = list(map(int, input().split()))
(result, c) = (0, 0)
l1 = l + l
for i in range(len(l1)):
	if l1[i] == 0:
		c = 0
	else:
		c += 1
		result = max(c, result)
print(result)


n = input()
s = input().split()
s = s + s
max = 0
kol = 0
for elem in s:
	if elem == '1':
		kol += 1
		if kol > max:
			max = kol
	if elem == '0':
		kol = 0
print(max)


def main():
	n = int(input())
	hours = list(map(int, input().split()))
	max_rest = 0
	rest = 0
	hours += hours
	for h in hours:
		if h == 1:
			rest += 1
		else:
			if rest > max_rest:
				max_rest = rest
			rest = 0
	print(max_rest)
main()


from sys import stdin
n = int(stdin.readline())
nums = list(map(int, stdin.readline().split()))
temp = 0
longest = 0
for i in range(0, 2 * n):
	if nums[i % n] == 1:
		temp += 1
	else:
		if temp > longest:
			longest = temp
		temp = 0
print(longest)


t = int(input())
k = list(map(int, input().split()))
k = k + k
s = []
count = 0
for i in k:
	if i == 1:
		count = count + 1
	else:
		s.append(count)
		count = 0
print(max(s))


n = int(input())
c = 0
ans = 0
a = list(map(int, input().split()))
for i in range(n):
	if i == n - 1:
		for j in range(n):
			if a[j] == 1:
				c += 1
			else:
				break
	if a[i] == 1:
		c += 1
	else:
		c = 0
	if c > ans:
		ans = c
print(ans)


input()
s = input().replace(' ', '')
s += s
ind = []
for (i, j) in enumerate(s):
	if j == '0':
		ind.append(i)
ans = 0
for (i, j) in zip(ind, ind[1:]):
	ans = max(ans, j - i)
print(ans - 1)


input()
s = ''.join((input() * 2).split()).split('0')
print(max(map(len, s)))


def continuousRest(A):
	counter = 0
	maximum = 0
	firstSequence = 0
	n = len(A)
	index = 0
	if A[0] == 1:
		firstSequence += 1
		for i in range(1, n):
			if A[i] == 1:
				firstSequence += 1
			else:
				index = i + 1
				break
	maximum = firstSequence
	for i in range(index, n):
		if A[i] == 1 and i < n - 1:
			counter += 1
		elif A[i] == 0:
			if counter > maximum:
				maximum = counter
			counter = 0
		elif i == n - 1 and A[i] == 1:
			counter += firstSequence + 1
			if counter > maximum:
				maximum = counter
	print(maximum)
n = int(input())
arr = list(map(int, input().split()))
continuousRest(arr)


n = int(input())
lst = [int(x) for x in input().split()]
jlst = lst + lst
flag = 0
cnt = 0
maxx = 0
if lst[-1] == 1 and lst[0] == 1:
	for i in jlst:
		if i == 1:
			flag = 1
			cnt = cnt + 1
		elif flag == 1 and i == 0:
			flag = 0
			if cnt >= maxx:
				maxx = cnt
			cnt = 0
else:
	for i in lst:
		if i == 1:
			flag = 1
			cnt = cnt + 1
		elif flag == 1 and i == 0:
			flag = 0
			if cnt >= maxx:
				maxx = cnt
			cnt = 0
if cnt >= maxx:
	maxx = cnt
print(maxx)


n = int(input())
l = list(map(int, input().split()))
ans = 0
ans1 = 0
x = []
for i in range(n):
	if l[i] == 1:
		ans += 1
	else:
		break
for i in range(n - 1, -1, -1):
	if l[i] == 1:
		ans += 1
	else:
		break
for i in range(n):
	if l[i] == 1:
		ans1 += 1
		x.append(ans1)
	else:
		ans1 = 0
		x.append(ans1)
print(max(ans, max(x)))


m = int(input())
l = list(map(int, input().split()))
b = []
i = 0
while i < len(l):
	if l[i] == 1:
		c = 0
		while i < len(l) and l[i] == 1:
			i += 1
			c += 1
		b.append(c)
	else:
		i += 1
if len(b) == 0:
	print(0)
elif l[0] == 0 or l[-1] == 0:
	print(max(b))
else:
	print(max(b[-1] + b[0], max(b)))


n = int(input())
l = [int(i) for i in input().split()]
max = 0
count = 0
l = l + l
for i in range(len(l)):
	if l[i] == 1:
		count += 1
	if l[i] == 0:
		count = 0
	if count > max:
		max = count
print(max)


def solve(tt):
	max_rest = 0
	rest = 0
	prev_rest = False
	for a in tt:
		if a is True:
			rest += 1
			if rest > max_rest:
				max_rest = rest
		else:
			rest = 0
	if rest > 0:
		for a in tt:
			if a is False:
				break
			rest += 1
	return max(rest, max_rest)
n = int(input())
tt = [t == '1' for t in input().split()]
print(solve(tt))


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


import sys, os
from collections import Counter
import heapq
import math
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import os.path
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def listt():
	return [int(i) for i in input().split()]
t = 1
for _ in range(t):
	n = int(input())
	l = listt()
	l = l + l
	k = []
	c = 0
	for i in range(0, 2 * n):
		if l[i] == 1:
			c += 1
		else:
			k.append(c)
			c = 0
	print(max(k))


hours_a_day = int(input())
schedule = [int(x) for x in input().split(' ')]
schedule = schedule + schedule
maximum = 0
soma = 0
for i in schedule:
	if i == 1:
		soma += 1
		if soma > maximum:
			maximum = soma
	else:
		soma = 0
if maximum > hours_a_day:
	maximum = hours_a_day
print(maximum)


n = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
hours = []
count = 1
temp1 = 0
temp2 = 0
for i in range(len(a) - 1):
	if a[i] == 1:
		temp1 += 1
	else:
		break
for i in range(len(a) - 1, -1, -1):
	if a[i] == 1:
		temp2 += 1
	else:
		break
temp3 = temp1 + temp2
hours.append(temp3)
for i in range(len(a) - 1):
	if a[i] == a[i + 1] == 1:
		count += 1
		temp = count
		hours.append(temp)
	else:
		count = 1
print(max(hours))


import itertools
n = int(input())
r = input()
m = []
for e in r.split():
	m.append(int(e))
ranges = []
cont = False
cr = 0
for (a, i) in enumerate(itertools.cycle(m)):
	if i == 1:
		if cont:
			cr += 1
		else:
			cont = True
			cr += 1
	else:
		ranges.append(cr)
		cr = 0
		cont = False
	if a > len(m) * 2:
		break
print(max(ranges))


n = int(input())
l = input().split()
l = ''.join(l)
l = l + l
ll = map(len, l.split('0'))
print(max(ll))


c = 0
l = []
n = int(input())
valores = input().split()
i = -1
j = False
while True:
	i += 1
	if valores[i] == '1' and i == n - 1:
		c += 1
		i = -1
		j = True
	elif valores[i] == '1':
		c += 1
	else:
		l.append(c)
		if i == n - 1:
			break
		c = 0
		if j == True:
			break
print(max(l))


n = int(input())
a = list(map(int, input().split()))
a.append(-1)
b = []
count = 0
for i in a:
	if i == 1:
		count += 1
	else:
		b.append(count)
		count = 0
a.remove(-1)
c1 = 0
for i in a:
	if i == 1:
		c1 += 1
	else:
		break
a.reverse()
c2 = 0
for i in a:
	if i == 1:
		c2 += 1
	else:
		break
a.reverse()
if a[-1] == 0:
	print(max(b))
elif c1 + c2 >= max(b):
	print(c1 + c2)
else:
	print(max(b))


def main():
	n = int(input())
	a = [int(x) for x in input().split()]
	first_zero_idx = -1
	for i in range(n):
		if a[i] == 0:
			first_zero_idx = i
			break
	last_zer_idx = -1
	for i in reversed(range(n)):
		if a[i] == 0:
			last_zer_idx = i
			break
	max_ones_seq_len = 0
	_tmp = 0
	for i in range(n):
		if a[i] == 1:
			_tmp += 1
		else:
			max_ones_seq_len = max(max_ones_seq_len, _tmp)
			_tmp = 0
	return max(n - last_zer_idx + first_zero_idx - 1, max_ones_seq_len)
res = main()
print(res)


a = int(input())
x = list(map(int, input().split()))
x.extend(x)
total = 0
count = 0
for i in range(len(x)):
	if x[i] == 1:
		count = count + 1
	else:
		if count > total:
			total = count
		count = 0
print(total)


n = int(input())
line = input().split(' ')
count = 0
array = []
res = []
for i in range(n):
	array.append(int(line[i]))
for i in range(n):
	if int(line[i]) == 0:
		break
	else:
		array.append(int(line[i]))
array.append(0)
for i in range(len(array)):
	if array[i] == 1:
		count += 1
	else:
		res.append(count)
		count = 0
print(max(res))


n = int(input())
a = list(map(int, input().split(' ')))
(f1, f0) = (-1, -1)
maxi = 0
(c1, c0) = (-1, -1)
for i in range(n):
	if a[i] == 1:
		if c1 == -1:
			c1 = i
		if f1 == -1:
			f1 = i
	else:
		if c1 != -1:
			hold = i - c1
			c1 = -1
			if maxi < hold:
				maxi = hold
		if f0 == -1:
			f0 = i
if f1 == -1:
	print(0)
elif f1 == c1:
	print(n - c1)
elif a[0] == 1 and a[-1] == 1:
	print(max(maxi, n - c1 + f0 - f1))
else:
	print(maxi)


n = int(input())
a = list(map(int, input().split()))
i = 0
g = 0
l = []
for j in range(n):
	if a[j] == 1:
		g = g + 1
	else:
		l.append(g)
		g = 0
l.append(g)
h = l[0] + l[-1]
g = max(l)
print(max(g, h))


n = int(input())
arr = [int(i) for i in input().split()]
timet = 2 * arr
maxx = 0
c = 0
for x in timet:
	if x == 1:
		c += 1
		if c > maxx:
			maxx = c
	else:
		c = 0
print(maxx)


n = int(input())
a = list(map(int, input().split()))
mstart = -1
mend = -1
(start, end) = (-1, -1)
cur = 0
ma = -1
for i in range(n):
	if i == n - 1 and a[i] == 1:
		mend = i
	if a[i] == 1:
		cur += 1
		if mstart == -1:
			mstart = i
	if cur >= ma:
		ma = cur
		start = mstart
		end = mend
	if a[i] == 0:
		mend = i
		mstart = -1
		cur = 0
if end != n - 1 and start != 0:
	print(ma)
elif end == n - 1:
	for i in range(n):
		if a[i] == 1:
			ma += 1
		else:
			break
	print(ma)
else:
	for i in range(n - 1, -1, -1):
		if a[i] == 1:
			ma += 1
		else:
			break
	print(ma)


l = input()
inp = list(filter(None, (input() * 2).split('0')))
(largest, sum) = (0, 0)
for num in inp:
	for x in num:
		if x == '1':
			sum += 1
	if sum > largest:
		largest = sum
	sum = 0
print(largest)


input()
print(max([len(e) for e in ''.join((input() * 2).split()).split('0')]))


import sys

def pro():
	return sys.stdin.readline().strip()

def rop():
	return map(int, pro().split())

def main():
	a = int(pro())
	s = list(rop())
	q = []
	i = 0
	p = 0
	while i != a - 1:
		if s[i] == 1:
			while s[i] == 1:
				if i == a - 2:
					i += 1
					p += 1
					break
				else:
					i += 1
					p += 1
			q.append(p)
			p = 0
		else:
			while s[i] == 0:
				if i == a - 2:
					i += 1
					break
				else:
					i += 1
			q.append(0)
	if s[-1] == 0:
		q.append(0)
	elif q[-1] != 0:
		q[-1] += 1
	else:
		q.append(1)
	e = max(q)
	if len(q) > 1:
		w = q[0] + q[-1]
		if e < w:
			print(w)
		else:
			print(e)
	else:
		print(e)
main()


n = int(input().rstrip())
A = list(map(int, input().rstrip().split()))
max_rest = 0
i = 0
rest = 0
start = 0
isStart = True
for i in range(n):
	if A[i] == 1:
		rest += 1
	else:
		if isStart:
			start = rest
			isStart = False
		rest = 0
	max_rest = max(max_rest, rest)
if rest != 0:
	max_rest = max(max_rest, rest + start)
print(max_rest)


n = int(input())
nums = [int(x) for x in input().split()]
nums += nums
a = 0
res = 0
for i in nums:
	if i == 1:
		a += 1
		res = max(res, a)
	else:
		a = 0
print(res)


n = int(input())
arr = list(map(int, input().split()))
arr = arr + arr
cnt = 0
m = 0
for i in arr:
	if i == 0:
		m = max(m, cnt)
		cnt = 0
	else:
		cnt += 1
print(m)


n = int(input())
(counter, b) = (0, [])
a = input().split()
for i in a:
	if i == '1':
		counter += 1
	else:
		b.append(counter)
		counter = 0
if counter > 0:
	b.append(counter)
if len(b) > 1:
	b[0] += b.pop()
print(max(b))


n = int(input())
s = input()
s = 2 * s
s = s.replace(' ', '')
ln = 0
mx = 0
for i in range(len(s)):
	if s[i] == '1':
		ln += 1
	else:
		mx = max(mx, ln)
		ln = 0
print(mx)


n = int(input())
A = list(map(int, input().split()))
A += A
from itertools import groupby
B = groupby(A)
ans = 0
for (key, group) in B:
	if key == 1:
		ans = max(ans, len(list(group)))
print(ans)


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


n = int(input())
a = list(map(int, input().split()))
i = 0
ms = 0
while i <= n - 1:
	if a[i] == 1:
		s = 1
		while a[(i + 1) % n] == 1:
			s += 1
			i += 1
		ms = max(s, ms)
	i += 1
print(ms)


import sys
fin = sys.stdin.readline
n = int(fin())
a_list = [int(elem) for elem in fin().split()] * 2
assert len(a_list) == 2 * n
max_rest_hours = 0
cur_rest_hours = 0
for a in a_list:
	if not a:
		cur_rest_hours = 0
	else:
		cur_rest_hours += 1
	max_rest_hours = max(max_rest_hours, cur_rest_hours)
print(max_rest_hours)


n = int(input())
a = [int(item) for item in input().split()] * 2
i = 0
ans = 0
while i < n:
	if a[i] == 0:
		i += 1
		continue
	j = i
	while a[j] == 1:
		j += 1
	ans = max(ans, j - i)
	i = j
print(min(n, ans))


a = int(input())
w = '1'
b = [str(s) for s in input().split()]
n = 0
n2 = 0
maximum = 0
n1 = 0
for i in range(a):
	if b[i] == '1':
		n += 1
		continue
	if b[i] == '0':
		if w == '1':
			n1 = n
			n = 0
			w = '0'
		else:
			if n > maximum:
				maximum = n
			n = 0
		continue
n1 += n
maximum = max(n1, maximum)
print(maximum)


n = int(input())
b = list(map(int, input().split()))
c = 0
mx = 0
for i in b:
	if i == 1:
		c = c + 1
	else:
		mx = max(mx, c)
		c = 0
for i in b:
	if i == 1:
		c = c + 1
	else:
		mx = max(mx, c)
		c = 0
print(mx)


n = int(input())
hours = list(map(int, input().split(' ')))
first = 0
last = 0
for i in range(n):
	if hours[i] == 1:
		first = first + 1
	else:
		break
for i in range(n - 1, -1, -1):
	if hours[i] == 1:
		last = last + 1
	else:
		break
repeat = 0
maxrepeat = 0
for hour in hours:
	if hour == 1:
		repeat = repeat + 1
	else:
		if repeat > maxrepeat:
			maxrepeat = repeat
		repeat = 0
if repeat > maxrepeat:
	maxrepeat = repeat
print(max(first + last, maxrepeat))


no_of_hours = int(input())
time = input().split(' ')
if time.count('0') == no_of_hours:
	print(0)
elif time.count('1') == no_of_hours:
	print(no_of_hours)
else:
	first_zero = time.index('0')
	time = time + time[:first_zero]
	print(max([len(i) for i in ''.join(time).split('0')]))


n = int(input())
hours = list(map(int, input().split()))
curr = 0
maxim = 0
if 0 in hours:
	i = 0
	while hours[i] == 1:
		i += 1
		maxim += 1
	i = len(hours) - 1
	while hours[i] == 1:
		i -= 1
		maxim += 1
for hour in hours:
	if hour:
		curr += 1
		maxim = max(maxim, curr)
	else:
		curr = 0
print(maxim)


n = int(input())
a = list(map(int, input().split()))
maxi = 0
x = 0
mini = 10000000000
maxii = -1
for i in range(n):
	if a[i] == 1:
		x += 1
		if x > maxi:
			maxi = x
	else:
		if i > maxii:
			maxii = i
		if i < mini:
			mini = i
		x = 0
print(max(maxi, sum(a[0:mini]) + sum(a[maxii:n])))


n = int(input())
v = [int(x) for x in input().split(' ')]
v += v
n *= 2
qt = 0
melhor = 0
for i in range(0, n):
	if v[i] == 1:
		qt += 1
		melhor = max(melhor, qt)
	else:
		qt = 0
print(melhor)


size = int(input())
arr = [int(i) for i in input().split()]
len_from_end = 0
max_len = 0
curr_len = 0
for i in range(2 * size):
	if arr[i % size]:
		curr_len += 1
		max_len = max(curr_len, max_len)
	else:
		curr_len = 0
print(max_len)


input()
s = input().replace(' ', '')
a = [i for (i, c) in enumerate(s + s) if '1' > c]
print(max((y - x for (x, y) in zip(a, a[1:]))) - 1)


n = int(input())
arr = list(map(int, input().split(' ')))
a = arr * 2
c = 1
maximum = 1
flag = 1
if flag not in a:
	print('0')
else:
	for i in range(1, len(a)):
		if a[i - 1] == 1 and a[i] == 1:
			c = c + 1
		else:
			c = 1
		if c > maximum:
			maximum = c
	print(maximum)


test = int(input())
l = list(map(int, input().split()))
ans = 0
temp = 0
n = len(l)
for i in range(n * 2):
	if l[i % n] == 1:
		temp += 1
	else:
		temp = 0
	ans = max(ans, temp)
print(ans)


n = int(input())
a = list(map(int, input().split()))
a = a + a
found = False
count = 0
l = []
for i in range(2 * n):
	if not found and a[i] == 1:
		count = 1
		found = True
		continue
	if found and a[i] == 1:
		count += 1
	if a[i] == 0:
		found = False
		l.append(count)
		count = 0
print(max(l))


n = int(input())
h = list(map(int, input().split()))
t = 0
r = 0
for i in h + h:
	t = t + 1 if i else 0
	r = max(r, t)
print(r)


n = int(input())
hours = [int(i) for i in input().split()]
state = 0
first = 0
maxim = 0
current = 0
for (i, v) in enumerate(hours):
	if state == 0 and v == 0:
		state = 1
		maxim = current
		current = 0
	elif state == 0 and v == 1:
		current += 1
		first += 1
	elif state == 1 and v == 0:
		maxim = max(maxim, current)
		current = 0
	else:
		current += 1
		if i == n - 1:
			maxim = max(maxim, current + first)
print(maxim)


def getMaxLength(arr, n):
	count = 0
	result = 0
	for i in range(0, n):
		if arr[i] == 0:
			count = 0
		else:
			count += 1
			result = max(result, count)
	return result
l = int(input())
inp = list(map(int, input().split()))
inp.extend(inp)
print(getMaxLength(inp, len(inp)))


n = int(input())
arr = list(map(int, input().split()))
lst = [0] * (2 * n + 1)
for i in range(0, n):
	lst[i] = arr[i]
for i in range(n, 2 * n):
	lst[i] = arr[i - n]
count = 0
i = 0
j = 0
while i < 2 * n:
	while i + 1 < 2 * n and lst[i] and (lst[i + 1] == lst[i]):
		i += 1
	if lst[i]:
		i += 1
		count = max(count, i - j)
		j = i
	else:
		i += 1
		j += 1
print(count)


n = input()
schedule = input()
twice = schedule + ' ' + schedule
arr = twice.split()
answer = 0
arr2 = []
for i in range(len(arr)):
	temp = arr[i]
	if temp == '1':
		answer += 1
	else:
		arr2.append(answer)
		answer = 0
print(max(arr2))


n = int(input())
horas = input().replace(' ', '')
horas = horas + horas + horas
horas = horas.split('0')
print(max([len(k) for k in horas]))


import sys
n = int(sys.stdin.readline())
A = [int(i) for i in sys.stdin.readline().split()]
A = A * 3
m = 0
temp = 0
for i in A:
	if i == 0:
		if temp > m:
			m = temp
		temp = 0
	elif i == 1:
		temp += 1
sys.stdout.write(str(m))


input()
s = input()
s = s.split()
a = []
for i in range(len(s)):
	a.append(int(s[i]))
a.extend(a)
sum = []
sum.append(a[0])
for i in range(1, len(a)):
	if a[i] == 0:
		sum.append(0)
	else:
		sum.append(sum[i - 1] + 1)
print(max(sum))


def count_max_1(word):
	max = 0
	count = 0
	for letter in word:
		if letter == '1':
			count += 1
		else:
			if count > max:
				max = count
			count = 0
	if count > max:
		max = count
	return max
n = int(input())
day = [x for x in input().split()]
day = ''.join(day)
max = count_max_1(day)
greater = True
while greater:
	day += day
	count = count_max_1(day)
	if count > max:
		max = count
	else:
		greater = False
print(max)


R = lambda : map(int, input().split())
n = R()
arr = [0]
arr += list(R())
arr += [0]
cnt = 1
c = []
for i in range(1, len(arr)):
	if arr[i] == arr[i - 1]:
		cnt += 1
	else:
		if arr[i - 1] == 1:
			c += [cnt]
		cnt = 1
ma = 0
for i in c:
	ma = max(ma, i)
if (arr[1] == 1) & (arr[len(arr) - 2] == 1):
	ma = max(ma, c[0] + c[len(c) - 1])
print(ma)


n = int(input())
a = input()
a = 2 * a.split()
c = 0
d = []
for i in range(2 * n):
	if a[i] == '1':
		c += 1
	if a[i] == '0':
		d.append(c)
		c = 0
print(max(d))


input()
arr = (input() * 2).replace(' ', '').replace('10', '1 0').replace('01', '0 1').split(' ')
print(max([0, *map(len, [i for i in arr if i[0] == '1'])]))


n = int(input())
t = [int(x) for x in input().split()]
m = []
mm = 0
for i in t:
	if i == 1:
		mm += 1
	else:
		m += [mm]
		mm = 0
		break
m2 = max(m)
m = []
for i in t:
	if i == 1:
		mm += 1
	else:
		m += [mm]
		mm = 0
m += [mm]
m[-1] += m2
print(max(m))


input()
l = ((' ' + input()) * 2 + ' ').split('0')
print(len(max(l, key=len)) // 2)


ent = int(input())
vetor = input()
vetb = 2 * vetor.split()
vetb.append('0')
cont = 0
resp = []
for num in vetb:
	if num == '1':
		cont += 1
	else:
		resp.append(cont)
		cont = 0
print(max(resp))


n = input()
a = list()
a = [int(i) for i in input().split()]
count = 0
if a[0] == 1:
	a.extend(a[:a.index(0, 1)])
a.append(0)
b = list()
for i in a:
	if i == 1:
		count += 1
	else:
		b.append(count)
		count = 0
print(max(b))


n = int(input())
a = list(map(int, input().split()))
beg = 0
end = 0
c = 0
cmax = 0
for j in range(2 * n):
	i = j % n
	if a[i] == 0:
		c = 0
	else:
		c += 1
	if c > cmax:
		cmax = c
print(cmax)


T = int(input())
arr = list(map(int, input().split()))
cont = 0
maxi = 0
something = 0
i = 0
while i < len(arr):
	if arr[i] == 1:
		cont += 1
		if maxi < cont:
			maxi = cont
	elif arr[i] == 0:
		cont = 0
	i += 1
	if i == len(arr) and arr[-1] == 1 and (arr[0] == 1) and (something < 2):
		i = 0
		something += 1
print(maxi)


n = int(input())
saatler = list(map(int, input().split()))
saatler = saatler * 3
n *= 3
sonuc_aday = []
sayac = 0
for i in range(n - 1):
	if saatler[i] == saatler[i + 1] and saatler[i] == 1:
		sayac += 1
	elif not sayac == 0:
		sonuc_aday.append(sayac + 1)
		sayac = 0
if len(sonuc_aday) != 0:
	print(max(sonuc_aday))
elif 1 in saatler:
	print(1)
else:
	print(0)


n = int(input())
a = [i for i in map(int, input().split())]
l = r = m = 0
curr = 0
lch = rch = 1
for i in range(len(a)):
	if a[i]:
		curr += 1
		m = max(m, curr)
	else:
		curr = 0
	if lch and a[i]:
		l += 1
	else:
		lch = 0
for i in range(len(a) - 1, -1, -1):
	if rch and a[i]:
		r += 1
	else:
		rch = 0
		break
print(max(l + r, m))


def main():
	n = int(input())
	a = list(map(int, input().split()))
	a.extend(a.copy())
	(ret, tmp) = (a[0], a[0])
	for i in range(1, 2 * n):
		if a[i] == 1:
			tmp += 1
		else:
			tmp = 0
		ret = max(ret, tmp)
	print(ret)
main()


n = int(input())
l = list(map(int, input().split()))
s = 0
c = 0
e = 0
m = []
for i in range(n):
	if l[i] == 1:
		if i == 0:
			s = 1
		c += 1
	else:
		m.append(c)
		c = 0
if c != 0:
	m.append(c)
	c = 0
	e = 1
if s == 1 and e == 1:
	m.append(m[0] + m[-1])
print(max(m))


n = int(input())
a = list(map(int, input().split()))
beg = 0
en = 0
ina = 0
maxina = 0
ist = False
for i in a:
	if not ist and i == 1:
		ina += 1
		beg += 1
	elif i == 0:
		maxina = max(maxina, ina)
		ist = True
		ina = 0
		en = 0
	elif ist and i == 1:
		ina += 1
		en += 1
print(max(beg + en, maxina))


from sys import stdin, stdout
N = int(stdin.readline())
arr = list(map(int, stdin.readline().split()))
arr.extend(arr)
m = 0
count = 0
for i in range(len(arr)):
	if arr[i] == 1:
		count += 1
		m = max(count, m)
	else:
		count = 0
print(m)


n = int(input())
l = [int(x) for x in input().split()]
v = []
a = 0
for i in range(len(l)):
	if l[i] == 1:
		a += 1
	else:
		v.append(a)
		a = 0
	if i == n - 1 and l[-1] == 1:
		if l[i] == 1:
			for i in range(n - 1):
				if l[i] == 1:
					a += 1
				else:
					break
			v.append(a)
print(max(v))


N = int(input())
A = list(map(int, input().split()))
optimal = 0
if A[0] == 1 and A[-1] == 1:
	leading = 0
	ending = 0
	for i in range(N):
		if A[i] == 1:
			leading += 1
		else:
			break
	for i in range(N - 1, -1, -1):
		if A[i] == 1:
			ending += 1
		else:
			break
	optimal = leading + ending
current = 0
for a in A:
	if a == 0:
		optimal = max(optimal, current)
		current = 0
	else:
		current += 1
optimal = max(optimal, current)
print(optimal)


n = int(input())
a = list(map(int, input().split()))
(k, m, s) = (n - 1, 0, 0)
while True:
	if k < 0 and a[k] != 1:
		print(max(m, s))
		exit()
	if a[k] == 1:
		s += 1
	else:
		m = max(m, s)
		s = 0
	k -= 1


from itertools import cycle
n = int(input())
hours = [int(i) for i in input().split()]
max_continuous = 0
current_continuous = 0
for (_, i) in zip(range(len(hours) * 2), cycle(hours)):
	if i == 1:
		current_continuous += 1
	elif current_continuous > max_continuous:
		max_continuous = current_continuous
		current_continuous = 0
	else:
		current_continuous = 0
print(max_continuous)


n = int(input())
arr = [int(x) for x in input().split()]
a = arr + arr
mx = 0
i = 0
while i < 2 * n:
	c = 0
	while i < 2 * n and a[i] == 1:
		c += 1
		i += 1
	mx = max(c, mx)
	if i < 2 * n and a[i] == 0:
		i += 1
print(mx)


import copy

def sleepy_boi(arr):
	new_arr = copy.copy(arr)
	for i in arr:
		if i == 0:
			break
		else:
			new_arr.append(i)
	j = 0
	ans = 0
	tmp = 0
	while j < len(new_arr):
		if new_arr[j] == 1:
			tmp += 1
		else:
			ans = max(ans, tmp)
			tmp = 0
		j += 1
	return max(ans, tmp)
n = int(input())
arr = list(map(int, input().rstrip().split()))
print(sleepy_boi(arr))


n = int(input())
sche = [int(x) for x in input().split()]
times = 0
MAX = 0
for i in range(-n, n):
	if sche[i] == 1:
		times += 1
		if times > MAX:
			MAX = times
	else:
		times = 0
print(MAX)


n = int(input())
a = [int(x) for x in input().split()]
a += a[:]
count = 0
answer = 0
for i in a:
	if i == 1:
		count += 1
	else:
		count = 0
	answer = max(count, answer)
print(answer)


n = int(input())
a = list(map(int, input().split()))
b = a + a
c = 1
m = 0
for i in range(len(b) - 1):
	if b[i] == b[i + 1] and b[i] == 1:
		c += 1
	else:
		m = max(m, c)
		c = 1
m = max(m, c)
if b.count(1) == 0:
	print(0)
else:
	print(m)


def con(d):
	val = 0
	pre = 0
	for i in d:
		if i == 0:
			val = max(val, pre)
			pre = 0
			continue
		pre += 1
	return val
n = int(input())
a = list(map(int, input().split()))
b = a + a
c = con(b)
print(c)


n = int(input())
lis = [int(x) for x in input().split()]
lis = lis + lis
li = [0] * (n * 2)
for i in range(2 * n):
	if lis[i] == 0:
		li[i] = 0
	else:
		li[i] = li[i - 1] + 1
print(max(li))


n = int(input())
maxx = 0
count = 0
data = [int(x) for x in input().split()]
s = []
for i in range(n):
	if data[i] == 1:
		count += 1
		if count > maxx:
			maxx = count
	else:
		s.append(count)
		if count != 0:
			s.append(0)
		count = 0
	if i == n - 1 and count != 0:
		s.append(count)
print(max(maxx, s[0] + s[-1]))


maxT = 0
maxN = 0
n = int(input())
a = [int(x) for x in input().split()]
j = 0
while a[j] == 1:
	a.append(1)
	j += 1
for i in range(len(a)):
	if a[i] == 1:
		maxT += 1
		if maxT > maxN:
			maxN = maxT
	else:
		maxT = 0
print(maxN)


n = int(input())
l = [int(x) for x in input().split()]
(ans, c) = (0, 0)
for i in range(2 * n):
	if l[i % n] == 1:
		c += 1
		ans = max(ans, c)
	else:
		c = 0
print(ans)


gi = lambda : list(map(int, input().strip().split()))
(n,) = gi()
l = gi() * 3
ans = 0
temp = 0
for e in l:
	if e == 0:
		ans = max(ans, temp)
		temp = 0
	else:
		temp += 1
print(ans)


n = int(input())
hoursString = input()
hoursListStr = list(hoursString.split(' '))
hoursListInt = list(map(int, hoursListStr))
result = 0
series = 0
for i in range(n * 2):
	if hoursListInt[i % n] == 1:
		series += 1
		result = max(result, series)
	else:
		series = 0
print(result)


n = int(input())
raw = input().split(' ')
raw += raw
resp = 0
count = 0
for i in raw:
	if i == '1':
		count += 1
	elif i == '0':
		if resp < count:
			resp = count
		count = 0
print(resp)


n = int(input())
hours = [int(x) for x in input().split(' ')]
add_one = []
for i in range(n):
	if hours[i] == 1:
		add_one.append(1)
	else:
		break
add_two = []
for i in range(n):
	if hours[n - 1 - i] == 1:
		add_two.append(1)
	else:
		break
hours = add_two + hours + add_one
result = 0
stock = 0
for i in hours:
	if i == 1:
		stock += 1
	else:
		stock = 0
	if stock > result:
		result = stock
print(result)


input()
L = input()
L = L + L + L
L = list(''.join(L.split()))
cnt = 0
ans = 0
for x in L:
	if x == '1':
		cnt += 1
	else:
		cnt = 0
	ans = max(ans, cnt)
print(ans)


n = int(input())
a = list(map(int, input().split()))
otv = 0
i = 0
cou = 0
while i < n and a[i] == 1:
	cou += 1
	i += 1
i = n - 1
while i != 0 and a[i] == 1:
	cou += 1
	i -= 1
if cou > n:
	otv = n
else:
	otv = cou
p = 1
while p < n:
	cou = 0
	if a[p] == 0:
		p += 1
	else:
		while p < n and a[p] == 1:
			p += 1
			cou += 1
	if cou > otv:
		otv = cou
print(otv)


n = int(input())
m = list(map(int, input().split()))
ans = 0
k = 1
mas = []
for i in range(n - 1):
	if m[i] == m[i + 1]:
		k += 1
	elif m[i] == 1:
		mas.append(k)
		ans = max(ans, k)
		k = 1
	else:
		k = 1
if m[n - 1] == m[0] and m[0] == 1:
	k += mas[0]
	ans = max(ans, k)
if m[-1] == 0:
	k = 0
ans = max(ans, k)
print(ans)


n = int(input())
lst = list(map(int, input().split()))
lst = lst + lst
max_count = 0
count = 0
for x in lst:
	if x == 1:
		count += 1
		if max_count < count:
			max_count = count
	else:
		count = 0
print(max_count)


from sys import stdin, stdout
from collections import Counter

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

def ei():
	return map(int, stdin.readline().split())

def ip():
	return int(stdin.readline().strip())

def op(ans):
	return stdout.write(str(ans) + '\n')
input()
x = [len(i) for i in ''.join((input() * 2).split()).split('0')]
print(max(x))


n = int(input())
a = [int(j) for j in input().split()]
count = 0
prevmax = 0
maxcount = 0
var = 0
tempvar = 0
firstind = 0
lastind = 0
for x in range(n):
	if a[x] == 0:
		var = 1
		ind = x
		break
if var == 1:
	for x in range(ind, -n + ind - 1, -1):
		var2 = 1
		if a[x] == 1:
			count += 1
			if tempvar == 0:
				ind = x
				tempvar = 1
		else:
			if count > maxcount:
				prevmax = maxcount
				maxcount = count
				firstind = ind
				lastind = x + 1
				var2 = 0
			if count > prevmax and var2 == 1:
				prevmax = count
			count = 0
			tempvar = 0
	if lastind < 0:
		lastind += n
	if firstind < 0:
		firstind += n
print(maxcount)


n = int(input())
l = list(map(int, input().strip().split()))
ma = 0
f = 0
c = 0
s = ''
for i in range(len(l)):
	s = s + str(l[i])
b = s + s
for i in range(len(b) - 1):
	if b[i] == '1' and b[i + 1] == '1':
		c += 1
		ma = max(ma, c)
	else:
		c = 0
if len(set(l)) == 1 and l[0] == 0:
	print(0)
else:
	print(ma + 1)


n = int(input())
arr = [int(i) for i in input().split()]
currcount = 0
maxcount = -99999999
arr = arr + arr
for ele in arr:
	if ele == 1:
		currcount += 1
	else:
		currcount = 0
	maxcount = max(maxcount, currcount)
print(maxcount)


n = int(input())
a = [int(x) for x in input().split()] * 2
maxk = 0
k = 0
for x in a:
	if x == 1:
		k += 1
		if k > maxk:
			maxk = k
	else:
		k = 0
print(maxk)


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


nn = int(input())
ll = list(map(int, input().split()))
for _ in range(nn - 1):
	ll.append(ll[_])
count = 0
ans = 0
for i in ll:
	if i == 1:
		count += 1
		ans = max(ans, count)
	else:
		ans = max(ans, count)
		count = 0
ans = max(ans, count)
print(ans)


n = int(input())
a = 2 * [int(i) for i in input().split()]
rest = []
hours = 1
for i in range(2 * n - 1):
	if a[i] == a[i + 1] == 1:
		hours += 1
	else:
		rest.append(hours)
		hours = 1
if 1 not in a:
	rest = [0]
print(max(rest))


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
A += A
A += A
ANS = 0
REST = 0
for a in A:
	if a == 1:
		REST += 1
	else:
		if ANS < REST:
			ANS = REST
		REST = 0
print(ANS)


def Noofones(A):
	left = 0
	count = 0
	window = 0
	for right in range(len(A)):
		if A[right] == 0:
			count = count + 1
		while count > 0:
			if A[left] == 0:
				count = count - 1
			left = left + 1
		if right - left + 1 > window:
			window = right - left + 1
	print(window)
n = int(input())
a = list(map(int, input().split()))
a += a
Noofones(a)


n = int(input())
l = input()
l += l
print(max(list(map(lambda w: len(w), ''.join(l.split()).split('0')))))


horas = int(input())
stringg = input()
stringg = stringg.split(' ')
stringg = stringg + stringg
mayor = 0
acumulador = 0
for n in range(2 * horas):
	if stringg[n] == '1':
		acumulador += 1
	else:
		if acumulador > 0:
			if acumulador > mayor:
				mayor = acumulador
		acumulador = 0
print(mayor)


input()
x = 2 * list(map(int, input().split())) + [0, 0, 0]
days = 0
i = 0
D = []
if 1 not in x:
	print(0)
	exit(0)
while i < len(x):
	days = 0
	if x[i]:
		days = 0
		while x[i + 1]:
			days += 1
			i += 1
		D.append(days)
		i += 1
	else:
		i += 1
print(max(D) + 1)


n = input()
dayStr = input()
n = int(n)
dayArr = dayStr.split()
for num in range(len(dayArr)):
	dayArr[num] = int(dayArr[num])
maxRest = 0
morningRest = 0
isMorningRest = 1
eveningRest = 0
isEveningRest = 1
rest = 0
for h in dayArr:
	if h == 1:
		rest += 1
		if isMorningRest == 1:
			morningRest += 1
		if rest > maxRest:
			maxRest = rest
	else:
		rest = 0
		isMorningRest = 0
for i in range(len(dayArr) - 1, -1, -1):
	if dayArr[i] == 1:
		if isEveningRest == 1:
			eveningRest += 1
	else:
		break
nightRest = eveningRest + morningRest
if nightRest > maxRest:
	maxRest = nightRest
print(maxRest)


n = int(input())
a = [int(i) for i in input().split()]
mx = 0
k = 0
for i in range(len(a)):
	a.append(a[i])
a.append(0)
for i in range(len(a)):
	if a[i] == 0:
		if mx < k:
			mx = k
		k = 0
	else:
		k += 1
print(mx)


n = int(input())
m = list(map(int, input().split()))
m = m * 2
d = 0
c = []
for i in m:
	if i == 1:
		d += 1
	else:
		c.append(d)
		d = 0
print(max(c))


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
l = zz()
l = l + l
ans = 0
x = l[0]
t = 0
for i in range(1, n * 2):
	if x + l[i] == 2:
		if t == 0:
			t += 1
		t += 1
	else:
		ans = max(ans, t)
		t = 0
	x = l[i]
ans = max(ans, t)
if ans == 0:
	if l.count(1) >= 1:
		ans += 1
print(ans)


l = input()
l = int(l)
t = input().split()
f = 0
m = 0
c = 0
for i in range(len(t)):
	t[i] = int(t[i])
for i in range(len(t)):
	if t[i] == 0:
		f = i
		break
for i in range(len(t)):
	if t[(i + f) % l] == 1:
		c += 1
		if c > m:
			m = c
	else:
		c = 0
print(m)


def rest(lst):
	(i, c, maximum) = (0, 0, 0)
	if lst[0] != 0:
		while lst[i] != 0:
			i += 1
	for j in range(len(lst)):
		if lst[(i + j) % len(lst)] == 1:
			c += 1
			maximum = max(c, maximum)
		else:
			c = 0
	return maximum
m = int(input())
a = [int(i) for i in input().split()]
print(rest(a))


n = int(input())
a = [int(x) for x in input().split()]
a *= 2
answer = 0
counter = 0
for i in range(2 * n):
	if a[i] == 1:
		counter += 1
	else:
		answer = max(answer, counter)
		counter = 0
print(answer)


n = int(input())
data = [int(x) for x in input().split(' ')]
arr = []
p = 0
for e in data:
	if e == 0:
		if p:
			arr.append(p)
		arr.append(0)
		p = 0
	else:
		p += 1
if p:
	arr.append(p)
if len(arr) > 1:
	arr.append(arr[0] + arr[-1])
print(max(arr))


n = int(input())
arr = input().strip()
arr = ''.join(arr.split())
arr = arr.split('0')
ans = 0
for s in arr:
	tmp = len(s)
	if tmp > ans:
		ans = tmp
if len(arr[0]) + len(arr[-1]) >= ans and len(arr) > 1:
	ans = len(arr[0]) + len(arr[-1])
print(ans)


n = int(input())
s = 0
s1 = 0
b = 0
c = 0
a = [int(s) for s in input().split()]
for i in range(n):
	if a[i] == 1:
		s1 += 1
	else:
		if s < s1:
			s = s1
		s1 = 0
for i in range(n):
	if a[i] == 1:
		b += 1
	else:
		break
for i in range(n, 0, -1):
	if a[i - 1] == 1:
		c += 1
	else:
		break
if c + b < n:
	if s < c + b:
		s = c + b
print(s)


n = int(input())
hours = [int(i) for i in input().split(' ')]
hours.extend(hours)
restConsecutive = 0
maxResting = 0
index = len(hours) - 1
while len(hours) > 0:
	if hours[index] == 1:
		restConsecutive += 1
	else:
		restConsecutive = 0
	if restConsecutive > maxResting:
		maxResting += 1
	hours.pop()
	index -= 1
print(maxResting)


import sys
n = int(input())
an = list(map(int, sys.stdin.readline().split()))
n *= 2
an = an * 2
ans = 0
beg = 0
end = 0
while beg < n:
	while beg < n and an[beg] != 1:
		beg += 1
	if beg >= n:
		break
	end = beg + 1
	while end < n and an[end] == 1:
		end += 1
	if end - beg > ans:
		ans = end - beg
	beg = end
print(ans)


import re
n = int(input())
s = input().replace(' ', '')
r = '[1]{1,}'
p = re.findall(r, s)
if s[0] == '1' and s[-1] == '1':
	p[0] = p[0] + p[-1]
if len(p) > 0:
	print(len(max(p)))
else:
	print(0)


n = int(input())
A = list(map(int, input().split()))
maxl = 0
maxr = 0
if A[0] == 1:
	max1 = 1
else:
	max1 = 0
for i in range(n):
	if A[i] == 1:
		maxl += 1
	else:
		break
for i in range(n - 1, -1, -1):
	if A[i] == 1:
		maxr += 1
	else:
		break
lmax = max1
for i in range(1, n):
	if A[i] == A[i - 1] and A[i] == 1:
		max1 += 1
	else:
		if max1 > lmax:
			lmax = max1
		max1 = A[i]
print(max(maxr + maxl, lmax))


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


n = int(input())
a = [int(x) for x in input().split()] * 2
m = 0
l = 0
for i in a:
	if i == 1:
		l += 1
		if l > m:
			m = l
	else:
		l = 0
print(m)


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)
isdebug = False
try:
	import pylint
	import numpy

	def dprint(*args, **kwargs):
		print(*args, file=sys.stderr)
	dprint('debug mode')
	isdebug = True
except Exception:

	def dprint(*args, **kwargs):
		pass

def red_inout():
	inId = 0
	outId = 0
	if not isdebug:
		inId = 0
		outId = 0
	if inId > 0:
		dprint('use input', inId)
		try:
			f = open('input' + str(inId) + '.txt', 'r')
			sys.stdin = f
		except Exception:
			dprint('invalid input file')
	if outId > 0:
		dprint('use output', outId)
		try:
			f = open('stdout' + str(outId) + '.txt', 'w')
			sys.stdout = f
		except Exception:
			dprint('invalid output file')
		atexit.register(lambda : sys.stdout.close())
if isdebug and len(sys.argv) == 1:
	red_inout()

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

def solve():
	pass
T_ = 1
for iii_ in range(T_):
	(N,) = getIntList()
	za = getIntList()
	la = 0
	big = 0
	for i in range(N):
		if za[i] == 1:
			la += 1
			big = max(la, big)
		else:
			la = 0
	r = big
	tot = 0
	for x in za:
		if x:
			tot += 1
		else:
			break
	for x in reversed(za):
		if x:
			tot += 1
		else:
			break
	r = max(tot, big)
	print(r)


input()
s = list(map(int, input().split()))
s *= 2
l = 0
k = 0
for n in s:
	if n == 1:
		l += 1
	else:
		k = max(k, l)
		l = 0
print(k)


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


n = int(input())
a = [int(s) for s in input().split()]
st = 0
en = 0
i = 0
while a[i] == 1:
	st += 1
	i += 1
i = len(a) - 1
while a[i] == 1:
	en += 1
	i -= 1
rest = st + en
past = 0
for i in range(len(a)):
	if a[i] == 1:
		past += 1
	else:
		if past > rest:
			rest = past
		past = 0
print(rest)


n = int(input())
a = list(map(int, input().split()))
m = -1
t = 0
p = 0
i = 0
while True:
	if i == n:
		p = 1
	if a[i % n] == 1:
		t += 1
	elif a[i % n] == 0:
		m = max(t, m)
		t = 0
		if p == 1:
			break
	i += 1
m = max(t, m)
print(m)


n = int(input())
days = [int(x) for x in input().split(' ')]
dp = list()
if days[0] == 1:
	cnt = 1
else:
	cnt = 0
for i in range(1, n):
	if days[i] == days[i - 1] == 1:
		cnt += 1
	elif days[i] == days[i - 1] == 0:
		continue
	else:
		dp.append(cnt)
		if days[i] == 1:
			cnt = 1
		else:
			cnt = 0
dp.append(cnt)
if days[0] == days[-1] == 1:
	dp[0] = dp[0] + dp[-1]
print(max(dp))


n = int(input())
s = str(input()).split()
x = 0
m = 0
for i in range(2 * n):
	if int(s[i % n]) == 1:
		x += 1
	else:
		m = max(m, x)
		x = 0
print(m)


input()
s = list(map(int, input().split()))
l = s
for i in s:
	if i == 0:
		break
	else:
		l.append(1)
max1 = 0
max2 = 0
for i in range(0, len(l) - 1):
	if l[i + 1] == l[i] and l[i] == 1:
		max2 += 1
	else:
		max2 = 0
	max1 = max(max1, max2)
max1 = max1 + 1
if l.count(1) > 0:
	print(max1)
else:
	print(0)


import sys
import collections
import math
import heapq
from operator import itemgetter

def getint():
	return int(input())

def getints():
	return [int(x) for x in input().split(' ')]
n = getint()
a = getints()
result = 0
cur = 0
if a[0] == 1:
	i = n - 1
	while i >= 0 and a[i] == 1:
		cur += 1
		i -= 1
for val in a:
	if val == 1:
		cur += 1
		result = max(result, cur)
	else:
		cur = 0
result = min(n, result)
print(str(result))


n = input()
my_s = [int(x) for x in input().split(' ')]
my_s = 2 * my_s
count = 0
max_count = 0
for i in range(len(my_s)):
	if my_s[i] == 1:
		count += 1
		if max_count < count:
			max_count = count
	else:
		count = 0
print(max_count)


n = int(input())
a = list(map(int, input().split()))

def polycarp(n, a):
	full = a + a
	max_rest = 0
	current_rest = 0
	for i in range(2 * n):
		if full[i] == 1:
			current_rest += 1
		elif max_rest < current_rest:
			max_rest = current_rest
			current_rest = 0
		else:
			current_rest = 0
	if 0 not in full:
		print(2 * n)
	else:
		print(max_rest)
polycarp(n, a)


n = int(input())
l = list(map(int, input().split()))
l = l + l
maxm = 0
x = 0
for i in l:
	if i == 1:
		x += 1
	else:
		maxm = max(maxm, x)
		x = 0
maxm = max(maxm, x)
print(maxm)


n = int(input())
a = [int(s) for s in input().split()]
lenstab = 0
maxlen = 0
i = 0
pre = 1
while i < n + lenstab:
	if a[i % n] == 1:
		lenstab += 1
		if lenstab > maxlen:
			maxlen = lenstab
	else:
		lenstab = 0
	i += 1
print(maxlen)


n = int(input())
l = list(input().split())
i = 0
while i < n and l[i] == '1':
	i += 1
x = '1' * i
l.append(x)
s = ''.join(l)
a = s.split('0')
ans = 0
for i in a:
	ans = max(ans, len(i))
print(ans)


n = int(input())
a = list(map(int, input().split()))
a = a * 2
last = -1
res = 0
for (index, val) in enumerate(a):
	if val == 0:
		last = index
	elif index - last > res:
		res = index - last
print(res)


n = int(input())
A = list(map(int, input().split()))
best = 0
s = 0
for _ in range(2):
	for i in range(len(A)):
		if A[i] == 0:
			A[i] = -n
		s = max(A[i], s + A[i])
		best = max(s, best)
print(best)


n = int(input())
ls = list(map(int, input().split()))
flag = 1
mx = -1
c = 0
ii = 0
ls2 = []
for i in range(n - 1, -1, -1):
	if ls[i] == 0:
		ii = i
		break
if ii < n - 1:
	ls2 = ls[ii + 1:]
ls2 = ls2 + ls[:ii + 1]
for i in ls2:
	if i == 1:
		c = c + 1
	else:
		if c > mx:
			mx = c
		c = 0
if 0 not in ls2:
	mx = n
print(mx)


n = int(input())
a = list(map(int, input().split()))
cout = 0
crr = 1
first = 0
for i in range(0, n):
	if a[0] == 0:
		temp = 0
	elif i < n - 1 and a[i + 1] == 0 and (first == 0):
		temp = crr
		first = 1
	if a[n - 1] == 1:
		last = crr
	else:
		last = 0
	if i < n - 1 and a[i] == 1 and (a[i + 1] == 1):
		crr = crr + 1
	else:
		if crr > cout:
			cout = crr
		crr = 1
if last + temp >= cout:
	print(last + temp)
elif cout == 1:
	print(0)
else:
	print(cout)


n = int(input())
a = [int(i) for i in input().split()]
a *= 2
rest = []
count = 1
for i in range(1, 2 * n):
	if a[i] == a[i - 1] == 1:
		count += 1
		rest.append(count)
	else:
		count = 1
if len(rest) == 0 and 1 not in a:
	print(0)
elif len(rest) == 0 and 1 in a:
	print(1)
else:
	print(max(rest))


n = int(input())
l = list(map(int, input().split()))
c = 0
a = []
k = 0
d = 0
for i in range(len(l)):
	if l[i] == 1:
		c = c + 1
	else:
		a.append(c)
		c = 0
a.append(c)
for i in range(len(l)):
	if l[i] != 0:
		k = k + 1
	else:
		break
for i in range(len(l) - 1, -1, -1):
	if l[i] != 0:
		d = d + 1
	else:
		break
print(max(k + d, max(a)))


import sys
import math

def main():
	n = int(sys.stdin.readline().strip())
	s = sys.stdin.readline().strip()
	s = s + ' ' + s + ' -1'
	r = list(map(int, s.split()))
	count = 0
	res = 0
	for i in range(len(r)):
		if r[i] == 1:
			count += 1
		else:
			res = max(count, res)
			count = 0
	print(res)
main()


n = int(input())
s = []
t = list(map(int, input().split()))
p = 0
if t.count(0) == 0:
	print(len(t))
else:
	for i in range(len(t)):
		if t[i] == 1:
			p += 1
		else:
			s.append(p)
			p = 0
	if p > 0:
		s.append(p)
	if t[0] == 1 and t[-1] == 1:
		s.append(s[0] + s[-1])
	print(max(s))


n = int(input(''))
l = input().split()
k = [int(i) for i in l]
k = k * 2
sum = 0
max = 0
for i in k:
	if i == 1:
		sum += 1
	else:
		if max < sum:
			max = sum
		sum = 0
print(max)


a = int(input())
l = list(map(int, input().split()))
(k, c) = ([], 0)
for x in range(a):
	if l[x] == 0:
		k.append(x - c)
		c = x + 1
k.append(a - c + k[0])
print(max(k))


n = int(input())
lst = list(map(int, input().split()))
lst = lst + lst
cu = [0] * (2 * n)
maximum = 0
for i in range(0, 2 * n):
	if i == 0:
		cu[i] = lst[i]
	elif lst[i] == 0:
		cu[i] = 0
		if cu[i - 1] > maximum:
			maximum = cu[i - 1]
	else:
		cu[i] = cu[i - 1] + lst[i]
print(maximum)


n = int(input())
ar = list(map(int, input().split()))
ar = 2 * ar
maks = 0
cnt = 0
for i in ar:
	if i:
		cnt += 1
	else:
		maks = max(cnt, maks)
		cnt = 0
print(maks)


n = int(input())
a = [int(x) for x in input().split()]
a[n:] = a
cnt = 0
best = 0
for x in a:
	if x:
		cnt += 1
		best = max(best, cnt)
	else:
		cnt = 0
print(best)


n = int(input())
S = list(map(int, input().split()))
fl = 0
tmp = 0
out = 0
for i in S:
	if i == 1:
		if fl == 1:
			tmp += 1
		else:
			tmp = 1
			fl = 1
		if i == n - 1:
			if tmp > out:
				out = tmp
	else:
		fl = 0
		if tmp > out:
			out = tmp
fst = 0
if S[0] == 1:
	fst = 1
	j = 1
	while j != n - 1 and S[j] == 1:
		j += 1
		fst += 1
lst = 0
if S[-1] == 1:
	lst = 1
	k = -2
	while k != -n and S[k] == 1:
		k -= 1
		lst += 1
if fst + lst > out:
	print(fst + lst)
else:
	print(out)


n = int(input())
arr = list(map(int, input().split()))
arr += arr
count = 0
maxCount = 0
for i in range(n * 2 - 1):
	if arr[i] == 1 and arr[i + 1] == 1:
		count += 1
	elif arr[i] == 0 and arr[i + 1] == 1:
		count = 1
	maxCount = max(maxCount, count)
print(maxCount)


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
l = a + a
c = 0
nl = [0] * len(l)
for i in range(2 * n):
	if l[i] == 0:
		c = 0
		nl[i] = c
	else:
		c += 1
		nl[i] = c
nl.sort()
print(nl[2 * n - 1])


numero = int(input())
lista = [int(x) for x in input().split()]
maior = 0
contador = 0
for i in range(len(lista) * 2):
	if lista[i % len(lista)] == 1:
		contador += 1
	else:
		if contador > maior:
			maior = contador
		contador = 0
print(maior)


n = int(input())
a = input().replace(' ', '')
b = a.split('0')
x = len(b[0]) + len(b[-1])
if '1' not in a:
	ans = 0
else:
	c = [y for y in b if len(y) > 0]
	ans = max(len(max(c, key=len)), x)
print(ans)


n = int(input())
l = list(map(int, input().split()))
le = 0
res = 0
for i in range(2 * n):
	if l[i % n] == 1:
		le += 1
		res = max(le, res)
	else:
		le = 0
print(res)


n = int(input())
p = input().rstrip().split(' ')
if p.count('0') == 0:
	print(n)
elif p.count('1') == 0:
	print(0)
else:
	p = p * 2
	T = 0
	maxf = -9999
	for i in range(0, len(p)):
		if int(p[i]) == 1:
			T += 1
		else:
			if T > maxf:
				maxf = T
			T = 0
	print(maxf)


n = int(input())
li = list(map(str, input().split()))
li = li * 2
li = ''.join(li)
li = li.replace('0', ' ')
li1 = li.split()
try:
	print(len(max(li1)))
except:
	print(0)


a = int(input())
l = input().split()
s = ''
s = s.join(l)
s = s * 2
m = 0
r = 0
for i in s:
	if i == '1':
		r = r + 1
	else:
		if r > m:
			m = r
		r = 0
if r > m:
	m = r
print(m)


n = int(input())
arr = input().split(' ')
arr = arr + arr
cnt = 0
tmp = 0
for i in arr:
	if i == '0':
		if tmp > cnt:
			cnt = tmp
		tmp = 0
	else:
		tmp += 1
print(cnt)


n = int(input())
a = list(map(int, input().rstrip().split()))
som = 0
new = 0
for i in range(n):
	if a[i] == 0:
		new = 0
	else:
		new += 1
		som = max(som, new)
le = a.index(0)
b = a[::-1]
ri = b.index(0)
estr = le + ri
print(max(som, estr))


n = int(input())
l = list(map(int, input().split()))
z = []
count = 0
for i in range(n):
	if l[i] == 1:
		count += 1
	else:
		z.append(count)
		count = 0
z.append(count)
m = max(z)
if l[0] == 1 and l[-1] == 1:
	print(max(m, z[0] + z[-1]))
else:
	print(m)


days = input()
hours = list(map(int, input().split()))
max = 0
current = 0
for i in hours:
	if i == 1:
		current += 1
	else:
		if current > max:
			max = current
		current = 0
for j in hours:
	if j == 0:
		if current > max:
			max = current
		break
	else:
		current += 1
print(max)


import itertools
n = int(input())
a = list(map(int, input().split()))
i = a.index(0)
a = a[i:] + a[:i]
result = max((len(list(g)) * k for (k, g) in itertools.groupby(a)))
print(result)


hours = int(input())
jobs = input().split()
final = 0
oldfinal = 0
for i in range(hours):
	jobs[i] = int(jobs[i])
jobs = jobs + jobs
for count in range(hours * 2 - 1):
	if jobs[count] == 1:
		final = final + 1
	else:
		if final > oldfinal:
			oldfinal = final
		final = 0
print(oldfinal)


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


n = int(input())
l = list(map(int, input().split())) * 2
cb = 0
cl = 0
for i in l:
	if i == 1:
		cl += 1
	else:
		cb = max(cb, cl)
		cl = 0
cb = max(cb, cl)
print(cb)


n = int(input())
a = list(map(int, input().split()))
h = []
for i in range(2):
	for i in a:
		h.append(i)
Max = 0
u = 0
for i in range(n * 2):
	if h[i] == 1:
		u += 1
	elif i != n * 2 - 1 and h[i] == 0:
		if u > Max:
			Max = u
		u = 0
print(Max)


x1 = input()
x = input().split()
for i in range(len(x)):
	x[i] = int(x[i])
max = 0
add = 0
count = 0
chk = 1
for i in x:
	chk *= i
	if chk == 1:
		count += 1
	else:
		if count > max:
			max = count
		count = 0
		chk = 1
for i in x:
	chk *= i
	if chk == 1:
		count += 1
	else:
		if count > max:
			max = count
		count = 0
		chk = 1
		break
print(max)


from collections import defaultdict as dd, deque as dq
import math, string
import sys

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	S = getInts()
	seqs = []
	curr = 0
	for j in range(N):
		if j == 0:
			curr += 1
			continue
		if S[j] == S[j - 1]:
			curr += 1
		else:
			if S[j] == 0:
				seqs.append(curr)
			curr = 1
	if S[-1] == 1:
		seqs.append(curr)
	if len(seqs) > 1 and S[0] == S[-1] == 1:
		seqs[0] += seqs[-1]
		seqs.pop()
	if not seqs:
		return 0
	return max(seqs)
print(solve())


n = int(input())
arr = input()
arr = arr + ' ' + arr
k = 0
maxx = 0
for i in arr.split():
	if i == '1':
		k += 1
		maxx = max(k, maxx)
	else:
		k = 0
print(maxx)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools
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 [int(x) for x in sys.stdin.readline().split()]

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 main():
	n = I()
	a = LI()
	aa = a + a
	r = 0
	t = 0
	for c in aa:
		if c == 1:
			t += 1
		else:
			if r < t:
				r = t
			t = 0
	return r
print(main())


n = int(input())
s = input().split()
s = ''.join(s)
s = s + s
counter = 0
i = 0
while i < 2 * n:
	loopCounter = 0
	if s[i] == '1' and i < 2 * n - 1:
		while s[i] == '1' and i < 2 * n - 1:
			loopCounter = loopCounter + 1
			if i < 2 * n - 2:
				i = i + 1
			else:
				i += 1
				break
		if s[i] == '0' and i < 2 * n - 1:
			i += 1
		if loopCounter > counter:
			counter = loopCounter
	else:
		i = i + 1
print(counter)


def f(n, arr):
	i = 0
	count_start = 0
	while i < len(arr) and arr[i] == 1:
		count_start += 1
		i += 1
	if i == len(arr):
		return count_start
	max_count = count_start
	now_count = 0
	while i < len(arr):
		if arr[i] == 1:
			now_count += 1
		else:
			max_count = max(max_count, now_count)
			now_count = 0
		i += 1
	if arr[i - 1] == 1:
		max_count = max(max_count, now_count + count_start)
	return max_count
n = int(input())
arr = list(map(int, input().split()))
print(f(n, arr))


k = int(input())
a = input()
b = a.split('0')
k = []
for i in b:
	k.append(i.count('1'))
print(max(k[-1] + k[0], max(k)))


n = int(input())
z = input()
h = z.count('1')
if h == 0:
	print(0)
	exit(0)
l = z + ' ' + z
l = l.split('0')
c = []
for i in l:
	try:
		z = i.strip()
		z = z.split(' ')
		s = 0
		for j in z:
			s += int(j)
		c.append(s)
	except:
		pass
print(max(0, max(c)))


def mp():
	return map(int, input().split())
n = int(input())
a = list(mp())
a = a[:] + a[:]
cnt = 0
ans = cnt
for i in range(2 * n):
	if a[i] == 0:
		ans = max(ans, cnt)
		cnt = 0
	else:
		cnt += 1
ans = max(ans, cnt)
print(ans)


n = int(input())
rests = [int(x) for x in input().split()]
index = 0
for i in range(n):
	if rests[i] == 0:
		index = i
		break
if index:
	rests = rests[index:] + rests[:index]
mx = 0
cnt = 0
for rest in rests:
	if rest == 1:
		cnt += 1
	else:
		cnt = 0
	mx = max(mx, cnt)
print(mx)


def line():
	return map(int, input().split())
from itertools import chain, groupby, takewhile
from operator import not_
input()
a = list(line())
print(max((len(list(g)) for (k, g) in groupby(chain(a, takewhile(bool, a))) if k), default=0))


s = int(input())
a = list(map(int, input().split()))
a.reverse()
d = a.index(0)
a.reverse()
b = len(a) - d - 1
s = 0
j = len(a) - b - 1
if a.count(1) != 0:
	s = a.index(1)
max = 0
y = 0
if a[0] == 0 or a[len(a) - 1] == 0:
	for i in range(s, len(a)):
		if a[i] == 1:
			y = y + 1
		else:
			if y > max:
				max = y
			y = 0
else:
	for i in range(s, len(a)):
		if a[i] == 1:
			j = j + 1
		else:
			if j > max:
				max = j
			j = 0
if y > max:
	print(y)
else:
	print(max)


a = input()
ss = [int(x) for x in input().split()]
for j in range(int(a)):
	ss.append(ss[j])
count = 0
maxi = 0
for i in range(int(a) * 2):
	if ss[i] == 1:
		count = count + 1
		if count > maxi:
			maxi = count
	elif ss[i] == 0:
		count = 0
print(maxi)


def sleep(h, arr):
	length = list(map(lambda a: len(a), arr))
	return max(len(arr[0]) + len(arr[-1]), max(length))
h = int(input())
arr = ''.join(input().split())
print(sleep(h, arr.split('0')))


n = int(input())
ls = [int(i) for i in input().split()]
count = 0
maxi = 0
for i in ls:
	if i == 1:
		count += 1
		if count > maxi:
			maxi = count
	else:
		if count > maxi:
			maxi = count
		count = 0
if count:
	for i in ls:
		if i == 1:
			count += 1
		else:
			break
if count > maxi:
	maxi = count
print(maxi)


n = int(input())
a = [int(x) for x in input().split()]
a = a + a
b = [a[0]]
i = 1
while i < 2 * n:
	if a[i] == 1 and b[-1] > 0:
		b[-1] += 1
		i += 1
	else:
		b.append(a[i])
		i += 1
print(max(b))


n = int(input())
a = list(map(int, input().split()))
o = []
for i in range(2 * n):
	o.append(a[i % n])
m = 0
t = 0
for i in range(2 * n):
	if o[i] == 1:
		t += 1
	else:
		if t > m:
			m = t
		t = 0
print(m)


N = int(input())
s = list(map(int, input().split()))
s = s + s
rest = 0
temp = 0
for i in s:
	if i == 1:
		temp += 1
		if temp > rest:
			rest = temp
	else:
		temp = 0
print(rest)


n = int(input())
a = list(map(int, input().split()))
m = 0
c = [0]
j = 0
if a[-1] == 1:
	while a[j] == 1:
		a.append(1)
		j += 1
for i in range(len(a)):
	if a[i] == 1:
		m += 1
		c.append(m)
	else:
		m = 0
print(max(c))


n = int(input())
a = input().split()
a += a
p = 0
seq = 0
for i in a:
	if i == '1':
		seq += 1
	else:
		if seq > p:
			p = seq
		seq = 0
if p == 0:
	p = seq
print(p)


a = int(input())
n = 2 * list(map(int, input().split()))
s = 0
z = set()
for i in range(len(n)):
	if n[i] == 1:
		s += 1
		z.add(s)
	else:
		s = 0
		z.add(s)
print(max(z))


n = int(input())
day = list(map(int, input().split()))
a = day + day
max_len = 0
cur_len = 0
is_active = False
start_pos = 0
for i in range(n):
	if a[i] == 0:
		start_pos = i
		break
for i in range(start_pos + 1, start_pos + n + 1):
	if a[i] == 1 and (not is_active):
		cur_len = 1
		is_active = True
	elif a[i] == 1 and is_active:
		cur_len += 1
	elif a[i] == 0 and is_active:
		is_active = False
		max_len = max(max_len, cur_len)
print(max_len)