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
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = (int)a; i <= (int)b; ++i)
#define RFOR(i, a, b) for(int i = (int)a; i >= (int)b; --i)
#define in insert
#define pb push_back
#define fi first
#define se second
#define ll long long
#define ull unsigned long long
using namespace std;

const int MAX = 1e5 + 7;
ll tab[MAX], sums[MAX];
ll n;

bool chc(ll k) {
    FOR(i, 1, n) sums[i] = 0;
    bool tf = true;
    FOR(i, 1, n - k + 1) {
        sums[i] += sums[i - 1];
        if(sums[i] <= tab[i]) {
            ll ile = tab[i] - sums[i];
            sums[i] += ile;
            sums[i + k] -= ile;
        } else tf = false;
    }
    FOR(i, n - k + 2, n) {
        sums[i] += sums[i - 1];
        if(sums[i] != tab[i]) tf = false;
    }
    return tf;
}

void solve() {
    cin >> n;
    ll sum = 0;
    FOR(i, 1, n) {cin >> tab[i]; sum += tab[i];}
    ll res = 0;
    RFOR(i, n, 1) {
        if(sum % i == 0) {
            bool akt = chc(i);
            if(akt) {res = i; break;}
        }
    }
    cout << res;
}

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