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
82
83
84
85
86
87
88
89
#include <iostream>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
using namespace std;

typedef long long int LL;

const int MAX_N = 100005;

int n, res;
int a[MAX_N];
LL sum;

bool check(int width)
{
    int points[MAX_N] = {0};
    int curr = 0;

    for (int i = 0; i < n; ++i)
    {
        if (curr > a[i])
        {
            return false;
        }

        if (curr < a[i])
        {
            int ending = i + width - 1;
            if (ending >= n)
            {
                return false;
            }

            int diff = a[i] - curr;
            curr += diff;

            points[i + width - 1] -= diff;
        }

        curr += points[i];
    }

    return true;
}

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

    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> a[i];
        sum += a[i];
    }

    int sq = sqrt(sum);
    int ile = 0;
    //cout << sq << endl;
    for (int i = 1; i <= sq && i <= n; ++i)
    {
        if (sum % i != 0)
        {
            continue;
        }

        if (i <= n && check(i))
        {
            res = max(res, i);
            //++ile;
        }

        LL other = sum / i;
        if (other <= n && check(other))
        {
            res = max(res, int(other));
            //++ile;
        }

        //cout << i << endl;
    }

    cout << res << endl;
    //cout << "ile: " << ile << endl;
    return 0;
}