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
#include <iostream>
#include <algorithm>
#include <queue>
#include <utility>
#include <numeric>

bool check(const std::vector<int>& ambers, int k) {
    std::queue<std::pair<int,int>> ongoing;
    int active = 0;
    for (int i = 0; i < ambers.size(); i++) {
        if (!ongoing.empty() && ongoing.front().first == i) {
            active -= ongoing.front().second;
            ongoing.pop();
        }
        int needed = ambers[i] - active;
        if (needed < 0) {
            return false;
        }
        if (needed > 0) {
            if (i + k > ambers.size()) {
                return false;
            }
            ongoing.push({i + k, needed});
            active += needed;
        }
    }
    return true;
}

int main() {
    int n;
    std::cin >> n;
    std::vector<int> ambers(n);
    for (int i = 0; i < n; i++) {
        std::cin >> ambers[i];
    }

    long long total = std::accumulate(ambers.begin(), ambers.end(), 0LL); 
    for (int k = n; k >= 1; k--) {
        if (total % k != 0) {
            continue;
        }
        if (check(ambers, k)) {
            std::cout << k << std::endl;
            break;
        }
    }
    return 0;
}