Language: C++

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;


long long cost(const long long& A, const long long& index, const long long& area){
  if (area==0 || area==4) {
    return A[index];
  } else if (area==1 || area==3) {
    if (A[index]==0) {
      return 2;
    } else if(A[index]%2==0) {
      return 0;
    } else {
      return 1;
    }
  } else {
    if (A[index]%2==0){
      return 1;
    } else {
      return 0;
    }
  }
}

int main() {
  long long n;
  cin >> n;

  long long A[n];
  for(long long i=0;i<n;i++){
    cin >> A[i];
  }

  vector< vector<long long> > dp;
  dp.resize(n);
  for(long long i=0; i<n; i++){
    dp[i].resize(5);
  }

  for(int j=0;j<5;j++){
    dp[0][j] = cost(0,j);
  }

  for(long long i=1;i<n;i++){
    dp[i][0] = dp[i-1][0]+cost(i,0);
    for(int j=1;j<5;J++){
      long long mindp = *std::min_element(dp[i-1].begin(), dp[i-1].begin()+j+1);
      dp[i][j] = min(min(mindp+cost(i,j)), dp[i][j-1])
    }
  }

  long long ans = *std::min_element(dp[L-1].begin(), dp[L-1].end());
  cout << ans << endl;

  return 0;
}

Compiler output:
a.cc: In function 'long long int cost(const long long int&, const long long int&, const long long int&)':
a.cc:10:13: error: invalid types 'const long long int[const long long int]' for array subscript
   10 |     return A[index];
      |             ^
a.cc:12:10: error: invalid types 'const long long int[const long long int]' for array subscript
   12 |     if (A[index]==0) {
      |          ^
a.cc:14:16: error: invalid types 'const long long int[const long long int]' for array subscript
   14 |     } else if(A[index]%2==0) {
      |                ^
a.cc:20:10: error: invalid types 'const long long int[const long long int]' for array subscript
   20 |     if (A[index]%2==0){
      |          ^
a.cc: In function 'int main()':
a.cc:44:20: error: too few arguments to function 'long long int cost(const long long int&, const long long int&, const long long int&)'
   44 |     dp[0][j] = cost(0,j);
      |                ~~~~^~~~~
a.cc:8:11: note: declared here
    8 | long long cost(const long long& A, const long long& index, const long long& area){
      |           ^~~~
a.cc:48:31: error: too few arguments to function 'long long int cost(const long long int&, const long long int&, const long long int&)'
   48 |     dp[i][0] = dp[i-1][0]+cost(i,0);
      |                           ~~~~^~~~~
a.cc:8:11: note: declared here
    8 | long long cost(const long long& A, const long long& index, const long long& area){
      |           ^~~~
a.cc:49:21: error: 'J' was not declared in this scope
   49 |     for(int j=1;j<5;J++){
      |                     ^
a.cc:51:36: error: too few arguments to function 'long long int cost(const long long int&, const long long int&, const long long int&)'
   51 |       dp[i][j] = min(min(mindp+cost(i,j)), dp[i][j-1])
      |                                ~~~~^~~~~
a.cc:8:11: note: declared here
    8 | long long cost(const long long& A, const long long& index, const long long& area){
      |           ^~~~
a.cc:55:40: error: 'L' was not declared in this scope
   55 |   long long ans = *std::min_element(dp[L-1].begin(), dp[L-1].end());
      |                                        ^