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: introductory

Starter code:

Solutions:
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=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())
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())
a = list(map(int, input().split()))
t = 0
ans = 0
for i in a + a:
  t = t + 1 if i else 0
  ans = max(ans, t)
print(ans)
  


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())
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()))
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())
ans=0
curr=0
l=list(map(int,input().split()))
for i in range(2*n):
         if(l[i%n]==1):
                  curr+=1
         else:
                  curr=0
         ans=max(ans,curr)
print(ans)

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)

# # Soru 1
#
# nm = list(map(int, input().split()))
# n = nm[0]
# m = nm[1]
#
# if int(m/n) != m/n:
#     print(-1)
# elif m/n == 1:
#     print(0)
# else:
#     x = m//n
#     count = 0
#     while x%2 == 0:
#         x = x//2
#         count += 1
#     while x%3 == 0:
#         x = x//3
#         count += 1
#     if x != 1:
#         print(-1)
#     else:
#         print(count)
# Soru 2
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)




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)


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)


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()))
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)

#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)

isdebug = False
try :
    #raise ModuleNotFoundError
    import pylint
    import numpy
    def dprint(*args, **kwargs):
        #print(*args, **kwargs, file=sys.stderr)
        # in python 3.4 **kwargs is invalid???
        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())     #idle 中不会执行 atexit

if isdebug and len(sys.argv) == 1:
    red_inout()

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

def solve(): 
    pass
    
T_ = 1    
#T_, = getIntList()

for iii_ in range(T_):
    #solve()
    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)
    



#JMD
#Nagendra Jha-4096

 
import sys
import math

#import fractions
#import numpy
 
###File Operations###
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

###Defines...###
mod=1000000007
 
###FUF's...###
def nospace(l):
    ans=''.join(str(i) for i in l)
    return ans
 
 
 
##### Main ####
t=1
for tt in range(t):
    n=int(input())
    #n,k,s= map(int, sys.stdin.readline().split(' '))
    a=list(map(int,sys.stdin.readline().split(' ')))
    b=2*a
    #print(b)
    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)

    
    
#####File Operations#####
if(fileoperation):
    sys.stdout = orig_stdout
    sys.stdin = orig_stdin
    inputfile.close()
    outputfile.close()

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)

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())
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)



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)

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

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())
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)

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())
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)