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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

const int N = 1e5 + 4;
ll tab[N];
int delta[N];
vector<ll> candidates;

bool check(int k, int n){
    int currAmount = 0;
    for(int i = 1 ; i <= n ; i++) delta[i] = 0;
    for(int i = 1 ; i <= n ; i++){
        currAmount += delta[i];
        if(currAmount < tab[i]){
            if(i + k > n + 1) return 0;
            delta[i + k] = -(tab[i] - currAmount);
        }else if(currAmount > tab[i]) return 0;
        currAmount = tab[i];
    }
    return 1;
}

ll solve(ll n){
    ll ans = 1, sum = 0;
    for(int i = 1 ; i <= n ; i++) sum += tab[i];
    if(sum <= n) candidates.push_back(sum);
    vector<ll> vec;
    vec.push_back(1);
    for(ll i = 2 ; i * i <= sum ; i++){
        if(i > n) break;
        if(sum % i == 0){
            if(sum / i <= n) candidates.push_back(sum / i);
            vec.push_back(i);
        }
    }
    for(int i = vec.size() - 1 ; i >= 0 ; i--){
        candidates.push_back(vec[i]);
    }
    for(ll x : candidates){
        if(check(x, n)) return x;
    }
    return ans;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    for(int i = 1 ; i <= n ; i++){
        cin >> tab[i];
    }
    cout << solve(n) << '\n';
}