Language: C++

#include <bits/stdc++.h>
using namespace std;

const int inf = 1e15 + 10, N = 1e5 + 10;
int a[N], n, ans = inf;
long long dp[N][6], ans = inf;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
		
	for (int i = 0; i < n; i++)
		for (int j = 0; j < 5; j++)
			dp[i][j] = inf;
		
	for (int i = 0; i < n; i++){
		for (int j = 0; j < 5; j++){
			int w = 0;
			if(a[i] == 0 && j != 0 && j != 4)
				w = 1 + (j % 2);
			else if(j == 2 && a[i] % 2 == 0)
				w = 1;
			else if((j == 1 || j == 3) && a[i] % 2 != 0)
				w = 1;
			else if((j == 0 || j == 4))
				w = a[i];
				
			for (int k = 0; k <= j; k++)
				dp[i][j] = min(dp[i - 1][k] + w, dp[i][j]);	
		}
	}
	
	for (int i = 0; i < 5; i++)
		ans = min(ans, dp[n - 1][i]);
	
	cout << ans;
}

Compiler output:
a.cc:4:22: warning: overflow in conversion from 'double' to 'int' changes value from '1.00000000000001e+15' to '2147483647' [-Woverflow]
    4 | const int inf = 1e15 + 10, N = 1e5 + 10;
      |                 ~~~~~^~~~
a.cc:6:21: error: conflicting declaration 'long long int ans'
    6 | long long dp[N][6], ans = inf;
      |                     ^~~
a.cc:5:14: note: previous declaration as 'int ans'
    5 | int a[N], n, ans = inf;
      |              ^~~
a.cc: In function 'int main()':
a.cc:38:26: error: no matching function for call to 'min(int&, long long int&)'
   38 |                 ans = min(ans, dp[n - 1][i]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/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:   template argument deduction/substitution failed:
a.cc:38:26: note:   deduced conflicting types for parameter 'const _Tp' ('int' and 'long long int')
   38 |                 ans = min(ans, dp[n - 1][i]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~
/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, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/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:   candidate expects 1 argument, 2 provided
/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:   template argument deduction/substitution failed:
a.cc:38:26: note:   mismatched types 'std::initializer_list<_Tp>' and 'int'
   38 |                 ans = min(ans, dp[n - 1][i]);
      |                       ~~~^~~~~~~~~~~~~~~~~~~