N = int(input()) a = list(map(int,input().split())) sm = 0 d = [] for e in a: sm += e for i in range(1, sm + 1): if(i * i > sm): break if sm % i == 0: d.append(i) if i != sm / i: d.append(sm/i) d.sort(reverse = True) for e in d: flag = True g = sm/e b = a.copy() for i in range(len(b)): if b[i] > g: flag = False break if b[i] < g and i != len(b) - 1: b[i + 1] += b[i] if flag : print(e) exit()