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
#include <bits/stdc++.h>

#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

using namespace std;

#ifdef LOCAL
template<typename A, typename B>
auto&operator<<(auto&o,pair<A, B>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<&","[!i++]<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif

using i64 = long long;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<i64, i64>;
using vi = vector<int>;
using vll = vector<i64>;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(14);
	cerr << fixed << setprecision(6);

	int n;
	cin >> n;
	vll heights(n);
	for (auto &x : heights) { cin >> x; }

	const i64 total = accumulate(ALL(heights), i64{0});
	heights.insert(heights.begin(), 0);
	heights.push_back(0);

	auto CheckWidth = [&](int k) {
		if (total % k != 0) {
			return false;
		}

		for (int r = 0; r < k; ++r) {
			i64 cur_delta = 0;
			for (int i = r; i + 1 < SZ(heights); i += k) {
				cur_delta += (heights[i + 1] - heights[i]);
				if (cur_delta < 0) {
					return false;
				}
			}
			if (cur_delta != 0) {
				return false;
			}
		}
		return true;
	};

	for (int k = n; k >= 1; --k) {
		if (CheckWidth(k)) {
			cout << k << "\n";
			return 0;
		}
	}

	assert(false);
}