#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ull = unsigned long long; using ll = long long; using ld = long double; #define all(v) v.begin(), v.end() #define rep(i, n) for (ll i = 0; i < n; ++i) #define rep2(i, n, m) for (ll i = n; i <= m; ++i) #define rep3(i, n, m) for (ll i = n; i >= m; --i) template using pqg = priority_queue, greater>; template using pq = priority_queue; template inline bool chmax(S &a, T b) { if (a < b) { a = b; return true; } return false; } template inline bool chmin(S &a, T b) { if (a > b) { a = b; return true; } return false; } int main() { int n; cin >> n; vector a(n); rep(i, n) cin >> a[i]; int sum = accumulate(all(a), 0); int ans = 0; auto f = [&](int val, int num) { int s = 0, c = 0; bool ok = true; rep(j, n) { s += a[j]; if (s > val) ok = false; if (s == val) s = 0, ++c; } if (s) ok = false; if (ok) chmax(ans, num); }; rep2(i, 1, sqrt(sum)) { if (sum % i) continue; int val = sum / i, num = i; f(val, num); f(num, val); } cout << ans << endl; return 0; }