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;

typedef long long ll;

#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) int(a.size())
#define f(i, a, b) for (int i = a; i < b; i++)
#define rep(i, a) f(i, 0, a)
#define int ll
#define tv(a, x) for (auto& a : x)
#define DUZO 1000000000000000000LL
#define en "\n"
#define cn continue
using pii = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vii = vector<pii>;

int n;

vi kand;
vi a;
vi pref; //pomocnicze do dodawania

bool da_sie(int k) {
    f(i, 0, n+ 1) pref[i] = 0;
    f(i, 0, n) {
        if (i) pref[i] += pref[i - 1]; //teraz pref[i] to ile dodajemy
        if (a[i] >= pref[i]) {
            int del = a[i] - pref[i];
            if (del==0) cn;
            pref[i] += del;
            if ((i + k) > n) {return false;}
            pref[i + k] -= del;
        } 
        else {return false;}
    }
    return true;
}

void solve() {
    cin >> n;
    a.resize(n);
    f(i, 0, n) cin >> a[i];
    int sum = 0;
    f(i, 0, n) sum += a[i];
    for (int x = 1; (x * x) <= sum; x++) {
        if (sum%x == 0) {
            if (x <= n) kand.pb(x);
            if ((sum/x) <= n) kand.pb(sum/x);
        }
    }
    pref.resize(n + 1);
    reverse(all(kand));
    tv(ele, kand) {
        if (da_sie(ele)) {
            cout << ele << en;
            return;
        }
    }
    cout << 1 << en;
}

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int q = 1;
    //cin >> q;
    while (q--) {
        solve();
    }
    return 0;
}