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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int n;
    cin >> n;
    int64_t total = 0;
    vector<int> A(n);
    for (auto& a : A) {
        cin >> a;
        total += a;
    }

    auto check = [&](int d) {
        vector<int> delta(n + 1);
        int cnt = 0;
        for (int i = 0; i < n; ++i) {
            cnt += delta[i];
            if (A[i] == cnt) { continue; }
            if (A[i] < cnt) { return false; }
            if (i + d > n)  { return false; }
            delta[i + d] -= A[i] - cnt;
            cnt = A[i];
        }
        return true;
    };

    for (int d = n; d > 1; --d) {
        if (total % d != 0) { continue; }
        if (check(d)) {
            cout << d << '\n';
            return 0;
        }
    }
    cout << 1 << '\n';
    return 0;
}