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
#include <bits/stdc++.h>
using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int n;
	cin >> n;
	vector<int> a(n);
	long long sum = 0;
	for (int& x : a) {
		cin >> x;
		sum += x;
	}
	vector<int> d(n+1);
	d[0] = a[0];
	for (int i = 1; i < n; i++) {
		d[i] = a[i] - a[i-1];
	}
	d[n] = -a[n-1];
	
	for (int k = n; k >= 1; k--) {
		if (sum % k == 0) {
			bool ok = true;
			for (int j = 0; j < k && ok; j++) {
				long long pref = 0;
				for (int pos = j; pos < (int) d.size(); pos += k) {
					pref += d[pos];
					if (pref < 0) {
						ok = false;
						break;
					}
				}
				if (pref) {
					ok = false;
				}
			}
			if (ok) {
				cout << k << "\n";
				return 0;
			}
		}
	}
	assert(false);
}