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
#include <bits/stdc++.h>
using namespace std;
#define pass (void)0
//#define int long long

//signed main(){
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    vector<int> pla;
    long long SUMA=0;
    for(int i=0; i<n; i++){
        int a;
        cin >> a;
        pla.push_back(a);
        SUMA += a;
    }
    int res=1;
    
    for(int k=2; k<=n; k++){
        vector<int> b(n, 0);
        bool ok=true;
        //for(int i=0; i<=n-k; i++){ //i<n-k
        //    for(int j=0; j<k; j++){
        //        b[i+j] += pla[i]-b[i];
        //        //b[i+j]++;
        //    }
        //}
        if(SUMA % k != 0 ){
            continue;
        }
        long long sum=0;
        for(int j=0; j<n; j += k){
            sum += pla[j];
        }
        if(sum>0 && SUMA % sum != 0){
            ok=false;
        }
        else{
            for(int i=0; i<=n-k; i++){ //i<n-k
                int val = pla[i]-b[i];
                if(val<0){
                    ok=false;
                    
                }
                else{
                    for(int j=0; j<k; j++){
                        b[i+j] += val;
                    }   
                }
            }
        }
        
        
        //for(int i=0; i<n; i++){
        //    cout << b[i] << ' ';
        //}
        //cout << endl;
        if(ok){
            for(int i=0; i<n; i++){
                if(pla[i]!=b[i]){
                    ok=false;
                    break;
                }
            }    
        }
        
        
        if(ok){
            res=max(res, k);
        }
    }
    
    cout <<res;
}