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
#include <iostream>
#include <vector>
#include <deque>

using namespace std;

bool isValid(const vector<long long> &ambers, long long wave) {
    if (wave > ambers.size()) {
        return false;
    }
    if (wave == 1) {
        return true;
    }
    // cout << "checking wave: " << wave << endl;
    deque<long long> window;
    long long sum = 0;
    for (int i = 0; i < ambers.size(); ++i) {
        if (i >= wave) {
            sum -= window.front();
            window.pop_front();
        }
        if (sum > ambers[i]) {
            // cout << "invalid at index: " << i << " sum: " << sum << " ambers[i]: " << ambers[i] << endl;
            return false;
        }
        if (i <= ambers.size() - wave) {
            // cout << "pushing: " << ambers[i] - sum << endl;
            window.push_back(ambers[i] - sum);
            sum = ambers[i];
        }
        if (sum != ambers[i]) {
            // cout << "invalid at index: " << i << " sum: " << sum << " ambers[i]: " << ambers[i] << endl;
            return false;
        }
        // cout << "index: " << i << " sum: " << sum << " ambers[i]: " << ambers[i] << endl;
    }
    return true;
}

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


    long long n;
    cin >> n;
    vector<long long> a(n);
    long long sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        sum += a[i];
    }
    // cout << "sum: " << sum << endl;
    long long max = 0;
    for (long long i = 1; i * i <= sum; ++i) {
        // cout << "i: " << i << endl;
        if (sum % i == 0) {
            // cout << "divisor: " << i << " " << sum / i << endl;
            bool valid = isValid(a, sum / i);
            if (valid) {
                cout << sum / i << endl;
                return 0;
            }
            valid = isValid(a, i);
            if (valid) {
                max = i;
            }
        }
    }
    cout << max << endl;
}