Language: C++

//#include <bits/stdc++.h>
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <climits>
#include <iomanip>

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define ROF(i, j, k) for(int i = (int)(j); i >= (int)(k); --i)
#define FORLL(i, n, m) for(long long i = n; i < (long long)(m); i++)
#define SORT(v, n) sort(v, v+n)
#define REVERSE(v) reverse((v).begin(), (v).end())

using namespace std;
using ll = long long;
const ll MOD=1000000007LL;
typedef pair<int, int> P;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }

template<class T> bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T> bool chmin(T &a,const T &b){if(a>b){a=b;return 1;}return 0;}

const int MAXN = 200005;

ll a[MAXN], dp[MAXN];
ll sum, ans;

int
main(void){  
  ios_base::sync_with_stdio(false);
  cin.tie(0);

  ll n;
  cin >> n;
  memset(dp, 0, sizeof(dp));
  dp[0][0] = 0;
  FOR(i, 1, n+1){
    cin >> a[i];
    dp[i][0] = min(dp[i-1][0], sum) + (a[i] & 1 ? 1 : (a[i] ? 0 : 2));
    dp[i][1] = min(dp[i-1][1], dp[i-1][2]) + (a[i] & 1 ? 1 : (a[i] ? 0 : 2));
    dp[i][2] = min(dp[i-1][0], min(sum, dp[i-1][2])) + (a[i] & 1 ? 0 : 1);
    sum+=a[i];
  }

  for(sum = 0, ans = 1e18, i=n; i>=0; i--){
    ans = min(ans, min({dp[i][0], dp[i][1], dp[i][2]}) + (sum += a[i+1]));
  }
  cout << ans << endl;
  return 0;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:58:8: error: invalid types 'll {aka long long int}[int]' for array subscript
   58 |   dp[0][0] = 0;
      |        ^
a.cc:61:10: error: invalid types 'll {aka long long int}[int]' for array subscript
   61 |     dp[i][0] = min(dp[i-1][0], sum) + (a[i] & 1 ? 1 : (a[i] ? 0 : 2));
      |          ^
a.cc:61:27: error: invalid types 'll {aka long long int}[int]' for array subscript
   61 |     dp[i][0] = min(dp[i-1][0], sum) + (a[i] & 1 ? 1 : (a[i] ? 0 : 2));
      |                           ^
a.cc:62:10: error: invalid types 'll {aka long long int}[int]' for array subscript
   62 |     dp[i][1] = min(dp[i-1][1], dp[i-1][2]) + (a[i] & 1 ? 1 : (a[i] ? 0 : 2));
      |          ^
a.cc:62:27: error: invalid types 'll {aka long long int}[int]' for array subscript
   62 |     dp[i][1] = min(dp[i-1][1], dp[i-1][2]) + (a[i] & 1 ? 1 : (a[i] ? 0 : 2));
      |                           ^
a.cc:62:39: error: invalid types 'll {aka long long int}[int]' for array subscript
   62 |     dp[i][1] = min(dp[i-1][1], dp[i-1][2]) + (a[i] & 1 ? 1 : (a[i] ? 0 : 2));
      |                                       ^
a.cc:63:10: error: invalid types 'll {aka long long int}[int]' for array subscript
   63 |     dp[i][2] = min(dp[i-1][0], min(sum, dp[i-1][2])) + (a[i] & 1 ? 0 : 1);
      |          ^
a.cc:63:27: error: invalid types 'll {aka long long int}[int]' for array subscript
   63 |     dp[i][2] = min(dp[i-1][0], min(sum, dp[i-1][2])) + (a[i] & 1 ? 0 : 1);
      |                           ^
a.cc:63:48: error: invalid types 'll {aka long long int}[int]' for array subscript
   63 |     dp[i][2] = min(dp[i-1][0], min(sum, dp[i-1][2])) + (a[i] & 1 ? 0 : 1);
      |                                                ^
a.cc:67:28: error: 'i' was not declared in this scope
   67 |   for(sum = 0, ans = 1e18, i=n; i>=0; i--){
      |                            ^
a.cc:68:23: error: no matching function for call to 'min(<brace-enclosed initializer list>)'
   68 |     ans = min(ans, min({dp[i][0], dp[i][1], dp[i][2]}) + (sum += a[i+1]));
      |                    ~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:2:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   candidate expects 2 arguments, 1 provided
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 1 provided
In file included from /usr/include/c++/14/algorithm:61,
                 from a.cc:6:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   template argument deduction/substitution failed:
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   candidate expects 2 arguments, 1 provided