#pragma GCC optimize("O3") #include using namespace std; const int M = 998244353; const long long LM = 1LL << 60; int main() { cin.tie(0); ios::sync_with_stdio(0); int n; // n = 200000; cin >> n; vector a(n); for (int i = 0; i < n; ++i) { // a[i] = i + 1; cin >> a[i]; } vector> vv; int SQ = 500; vector v = { 0, 200010 }; int ans = 0; for (int i = 0; i < n; ++i) { for (auto& x : vv) { a[i] -= *prev(upper_bound(x.begin(), x.end(), a[i])); } a[i] -= *prev(upper_bound(v.begin(), v.end(), a[i])); if (a[i] > 0) { ++ans; vector nex; for (int j = 0; j < (int)v.size(); ++j) { nex.push_back(v[j]); if (j + 1 < (int)v.size() && v[j] + a[i] < v[j + 1]) { nex.push_back(v[j] + a[i]); } } v = nex; } if ((i + 1) % SQ == 0) { vv.push_back(v); v = { 0, 200010 }; } } cout << ans << '\n'; return 0; }