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

using namespace std;

vector<long long> find_divisors(long long n) {
    vector<long long> divisors;
    for (long long i = 1; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        long long j = n / i;
        if (i != 1) {
            divisors.push_back(i);
        }
        if (i != j && j != 1) {
            divisors.push_back(j);
        }
    }
    sort(divisors.begin(), divisors.end());
    return divisors;
}

int main() {
    long long total = 0;
    long long n = 0;
    cin >> n;

    const long long cap = n * 2 + 2;
    vector<long long> tab(cap);
    for (long long i = 0; i < n; ++i) {
        cin >> tab[i];
        total += tab[i];
    }

    vector<long long> divisors = find_divisors(total);

    for (long long idx = static_cast<long long>(divisors.size()) - 1; idx >= 0; --idx) {
        vector<long long> tab2(cap, 0);
        long long startIndex = 0;
        long long endIndex = divisors[idx] - 1;
        if (endIndex < 0 || endIndex >= n) {
            continue;
        }

        long long startValue = 0;
        long long j = 0;
        for (; j <= n; j++) {
            long long diff = tab[startIndex] - startValue;
            startValue += diff;

            if (diff < 0 || tab[endIndex] < diff) {
                break;
            }

            tab2[endIndex] = diff;

            startValue -= tab2[startIndex];
            startIndex++;
            endIndex++;
        }

        if (j > n) {
            cout << divisors[idx] << endl;
            return 0;
        }
    }

    if (total == 0) {
        cout << "0" << endl;
        return 0;
    }
    cout << "1" << endl;
    return 0;
}