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

using namespace std;
#define all(a) (a).begin(),(a).end()
#define ll long long
#define pii pair<int,int>
#define pb push_back
#define F first 
#define S second
#define INF (ll)1e18
#define int ll

void solve(){

    int n; cin >> n;
    int sum = 0;
    vector<int> a(n);
    vector<int> cnt(n);
    for (int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
    }
    vector<int> divisors;
    divisors.pb(sum);
    for (int i = 2; i*i <= sum; i++){
        if (sum % i == 0){
            divisors.pb(i);
            if (i*i != sum) divisors.pb(sum/i);
        }
    }
    sort(all(divisors));
    int ans = 1;
    int bad = 1;
    for (int d : divisors){
        if (d > n) continue;
        //if (gcd(d, bad) != 1) continue;
        int cur = 0;  
        bool ok = true;
        for (int i = 0; i < n; i++){
            if (i - d >= 0) cur -= cnt[i-d];
            if (i <= n-d){
                if (a[i] < cur){
                    ok = false;
                    break;
                }
                cnt[i] = a[i] - cur;
                cur += cnt[i];
            } else {
                if (a[i] != cur){
                    ok = false;
                    break;
                }
                cnt[i] = 0;
            }
        }
        if (ok){
            ans = d;
        } else {
            bad = lcm(bad, d);
        }
    }
    cout << ans << "\n";

}

int32_t main(){

    ios::sync_with_stdio(0);
    cin.tie(0);

    int t=1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}