1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <bits/stdc++.h>
using namespace std;

typedef long long int lli;

const int MAXN = 100005;

lli t[MAXN];
lli fut[MAXN];
lli res = 1;
lli s = 0;
lli n;

void check(lli x) {
// 	printf(" %lld\n", x);
	if (x > n)
		return;
	
	if (x <= res)
		return;
	
	lli act = 0;
	
	for (int i=0; i<=n; i++)
		fut[i] = 0;
	
	for (int i=0; i<n; i++) {
		act -= fut[i];
		lli st = t[i] - act;
		act += st;
		
		if (st < 0)
			return;
		if (st > 0) {
			if (i + x > n)
				return;
			fut[i+x] = st;
		}
	}
	
	res = x;
}

int main() {
	scanf("%lld", &n);
	
	for (int i=0; i<n; i++) {
		scanf("%lld", &t[i]);
		s += t[i];
	}
	
	vector<lli> v;
	
	for (lli i=1; i*i<=s; i++) {
		if (s%i == 0) {
			v.push_back(i);
			check(s/i);
			
			if (res > 1) {
				printf("%lld\n", res);
				return 0;
			}
		}
	}
	
	while (!v.empty()) {
		lli x = v.back();
		v.pop_back();
		check(x);
		
		if (res > 1) {
			printf("%lld\n", res);
			return 0;
		}
	}
	
	printf("%lld\n", res);
	
	return 0;
}