func_code_string: #include <bits/stdc++.h>   using namespace std;   using ll = long long int;   using ld = long double;   template <typename Arg1>   void debug_out(const char* name, Arg1&& arg1) {     cerr << name <<   =   << arg1 <<   ]           <<   n ;   }   template <typename Arg1, typename... Args>   void debug_out(const char* names, Arg1&& arg1, Args&&... args) {     const char* comma = strchr(names + 1,  , );     cerr.write(names, comma - names) <<   =   << arg1 <<  , ;     debug_out(comma + 1, args...);   }   const long long mod = 1e9 + 7;   const long long N = 5e3 + 5, M = 2e5 + 5;   long long n;   long long v[N];   long long solve(long long l, long long r) {     if (r < l) return 0;     long long res = r - l + 1;     long long mn = *min_element(v + l, v + r + 1);     for (long long i = (l); i <= (r); ++i) v[i] -= mn;     long long ans = mn;     for (long long i = (l); i <= (r); ++i) {       if (v[i] == 0) {         ans += solve(l, i - 1);         l = i + 1;       }     }     ans += solve(l, r);     res = min(res, ans);     return res;   }   void Solve_main() {     cin >> n;     for (long long i = (1); i <= (n); ++i) cin >> v[i];     cout << solve(1, n) <<   n ;   }   int32_t main() {     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);     srand(chrono::high_resolution_clock::now().time_since_epoch().count());     long long tc = 1;     for (long long i = 1; i <= tc; i++) {       Solve_main();     }     cerr <<  [time:  << 1.0 * clock() / CLOCKS_PER_SEC <<  s]  ;     return 0;   }   