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
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

vector<ll> r,x;
ll n, fur;

bool check(ll curr) {
	for(int i=0; i<curr; ++i) x[i] = r[i];
	for(ll i=curr; i<n; ++i) {
		x[i] = x[i-curr] + r[i];
		if(x[i] < 0) return 0;
	}
	for(int i=n-curr+1; i<n; ++i) if(x[i]!=0) return 0;
	return 1;
}

#ifdef _WIN32
#define getchar_unlocked getchar
#endif

inline int readint()
{
    char c = getchar_unlocked();
    while((c < '0' || c > '9') && c != '-') c = getchar_unlocked();
    bool neg = false;
    if(c == '-') neg = true, c = getchar_unlocked();
    int res = 0;
    while(c >= '0' && c <= '9') res = res * 10 + c - '0', c = getchar_unlocked();
    return neg? -res : res;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	// cin >> n;
	n=readint();
	vector<ll> a(n);
	x.resize(n);
	r.resize(n);
	// for(ll i=0; i<n; ++i) cin >> a[i];
	for(ll i=0; i<n; ++i) a[i] = readint();
	for(ll i=1; i<n; ++i) r[i] = a[i] - a[i-1];
	r[0] = a[0];
	fur = n;
	for(int i=0; i<n; ++i) {
		if(r[i] < 0) {
			fur = i;
			break;
		}
	}
	ll suma = 0;
	for(auto y : a) suma += y;
	ll res = 1;
	for(ll i=2; i*i <= suma; ++i) {
		if(suma%i == 0) {
			if(i <= fur && check(i)) res = max(res,i);
			if(i!=suma/i && suma/i <= fur && check(suma/i)) res = max(res,suma/i);
		}
	}
	cout << res << "\n";

	return 0;
}