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
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<long long,long long>
using namespace std;
using ll = long long;
using ld = long double;

constexpr int SIZE = 1e6+6;

int A[SIZE];
int B[SIZE];
int C[SIZE];
vector<int> D;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int n;
    cin >> n;

    ll sum = 0;

    for (int i=1; i<=n; i++) cin >> A[i];
    for (int i=n+1; i; i--) B[i] = A[i]-A[i-1];

    for (int i=1; i<=n; i++) sum += (ll)A[i];

    for (int i=n; i; i--){
        if (sum%i) continue;
        D.push_back(i);
    }

    int ans = 1;

    for (int d:D){
        for (int i=1; i<=n+1; i++){
            C[i] = B[i]+C[max(0, i-d)];
            if (i <= n+1-d && C[i]<0) break;
            if (i > n+1-d && C[i]!=0) break;
            if (i == n+1){
                cout << d << '\n';
                return 0;
            }
        }
    }

    cout << ans;
return 0;}