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
78
79
80
81
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

vector<int> getDivisors(ll num, int maxVal) {
    vector<int> small, large;

    for (ll i = 1; i <= sqrt(num); i++) {
        if (num % i == 0) {
            ll other = num / i;

            if (i <= maxVal)
                small.push_back(i);

            if (other != i && other <= maxVal)
                large.push_back(other);
        }
    }

    for (int i = large.size() - 1; i >= 0; i--) {
        small.push_back(large[i]);
    }

    return small;
}

vector<ll> update;

bool test(vector<int>& a, int k) {
    unsigned int n = a.size();
    ll extra = 0;
    fill(update.begin(), update.begin() + k, 0LL);
    for (unsigned int i = 0; i < n; ++i) {
        extra -= update[i];
        ll curr = a[i] - extra;
        extra += curr;
        if (curr < 0) {
            return false;
        }
        if (i + k <= n) {
            update[i + k] = curr;
        } else if (curr > 0) {
            return false;
        }
    }
    // cout << k << endl;
    // for (unsigned int i = 0; i <= n; ++i) {
    //     cout << update[i] << " ";
    // }
    // cout <<endl;
    // for (unsigned int i = 0; i < n; ++i) {
    //     cout << a[i] << " ";
    // }
    // cout <<endl;
    return true;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);

    int n, tmp;
    cin >> n;
    vector<int> a;
    for (int i = 0; i < n; i++) {
        cin >> tmp;
        a.push_back(tmp);
    }
    update.assign(n + 1, 0);

    long long sum = accumulate(a.begin(), a.end(), 0LL);
    vector<int> candidates = getDivisors(sum, n);
    for (int i = candidates.size() - 1; i >= 0; --i) {
        if (test(a, candidates[i])) {
            cout << candidates[i] << endl;
            return 0;
        }
    }
    
    return 0;
}