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
#include <bits/stdc++.h>
using namespace std;
bool check(int k,int n,const vector<int>& a) 
{
    vector<long long> x(n+1,0);
    for (int i=1; i<=n; i++) {
        long long d=0;
        if(i==1)
        {
            d=a[i-1];
        }
        else
        {
            d=a[i-1]-a[i-2];
        }
        if(i>k)
        {
            x[i]=d+x[i-k];
        }
        else
        {
            x[i]=d;
        }
        if (x[i]<0) return false;
        if (i>n-k+1&&x[i]>0) return false;
    }
    return true;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int> a(n);
    long long S=0;
    for (int i=0; i<n; ++i) 
    {
        cin>>a[i];
        S+=a[i];
    }
    int L=1;
    while (L<n && a[L]>=a[L-1]) L++;
    int R=1;
    while (R<n&&a[n-R-1]>=a[n-R]) R++;
    int lm=min({n,L,R});

    vector<int> dziel;
    for (long long i=1; i*i<=S; i++)
    {
        if (S%i==0)
        {
            if (i<=lm) dziel.push_back(i);
            if (S/i<=lm) dziel.push_back(S/i);
        }
    }
    sort(dziel.begin(), dziel.end(),greater<int>());
    for (int i:dziel)
    {
        if (check(i,n,a)) 
        {
            cout<<i;
            return 0;
        }
    }
}