# 2020/01/05 # 累積和 from itertools import accumulate n=int(input()) a=list(map(int,input().split())) A=list(accumulate(a)) sum_a=A[-1] max_a=max(a) def divisors(n): div=[] for i in range(1,int(n**0.5)+1): if n%i==0: div.append(i) if i!=n//i: div.append(n//i) div.sort(reverse=True) return div class BinarySearch: def __init__(self,arr,key,low,high): import sys sys.setrecursionlimit(10**7) self.arr=arr self.key=key self.low=low self.high=high self.size=len(self.arr) def search(self): mid=(self.high+self.low)//2 if mid>=self.size or self.high<0: return -1 if self.arr[mid]==self.key: return mid if self.high==self.low:return -1 elif self.arr[mid]>self.key: self.high=mid-1 else: self.low=mid+1 return self.search() div=divisors(sum_a) res=[i for i in div if i<=max_a] for r in res: d=sum_a//r for d in range(d,sum_a+1,d): bs=BinarySearch(A,d,0,len(A)) res=bs.search() if res<0:break else: print(r) exit()