Language: C++

#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

void yes(){
	cout<<"YES";
	exit(0);
}

void no(){
	cout<<"NO";
	exit(0);
}

const int size = 5e5 + 7; 
// int arr;
long long int arr[size];
int dp[size];
// int d1[size];
// int dn[size];
pair<int, long long int> dl[size], dr[size];
// int special_nodes[size];
// bool visited[size];
// vector<int> graph[size];

// void bfs(int u, int *arr) {
// 	queue<int> q;
// 	memset(visited, 0, sizeof(visited));
// 	q.push(u);
// 	visited[u] = true;
// 	while(!q.empty()) {
// 		int t = q.front();
// 		q.pop();
// 		for(int x: graph[t]){
// 			if(!visited[x]) {
// 				visited[x] = true;
// 				arr[x] = arr[t] + 1;
// 				q.push(x);
// 			}
// 		}
// 	}
// }

long long int solve(int i, int n) {
	if(i > n) return INT_MAX;
	if(i== n) return 0;
	if(dp[i] != -1) return dp[i];
	long long int ans = INT_MAX;
	if(i + 1 <= n) ans = min(ans, solve(i +1, n) + abs(arr[i+1] - arr[i]));
	if(i +2<=n) ans = min(ans, solve(i+2, n) + abs(arr[i+2] - arr[i]));
	dp[i] = ans;
	return ans;
}

int main() {
	int n;
	cin>>n;
	for(int x=1;x<=n;x++){
		cin>>arr[x];
	}
	for(int x=0;x<size;x++) dp[x] = -1;
	// dp[]	
	cout<<solve(1, n);
}


Compiler output:
a.cc:28:19: error: reference to 'size' is ambiguous
   28 | long long int arr[size];
      |                   ^~~~
In file included from /usr/include/c++/14/string:53,
                 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:1:
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:26:11: note:                 'const int size'
   26 | const int size = 5e5 + 7;
      |           ^~~~
a.cc:29:8: error: reference to 'size' is ambiguous
   29 | int dp[size];
      |        ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:26:11: note:                 'const int size'
   26 | const int size = 5e5 + 7;
      |           ^~~~
a.cc:32:29: error: reference to 'size' is ambiguous
   32 | pair<int, long long int> dl[size], dr[size];
      |                             ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:26:11: note:                 'const int size'
   26 | const int size = 5e5 + 7;
      |           ^~~~
a.cc:32:39: error: reference to 'size' is ambiguous
   32 | pair<int, long long int> dl[size], dr[size];
      |                                       ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:26:11: note:                 'const int size'
   26 | const int size = 5e5 + 7;
      |           ^~~~
a.cc: In function 'long long int solve(int, int)':
a.cc:56:26: error: 'INT_MAX' was not declared in this scope
   56 |         if(i > n) return INT_MAX;
      |                          ^~~~~~~
a.cc:14:1: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
   13 | #include <cstring>
  +++ |+#include <climits>
   14 | using namespace std;
a.cc:58:12: error: 'dp' was not declared in this scope
   58 |         if(dp[i] != -1) return dp[i];
      |            ^~
a.cc:59:29: error: 'INT_MAX' was not declared in this scope
   59 |         long long int ans = INT_MAX;
      |                             ^~~~~~~
a.cc:59:29: note: 'INT_MAX' is defined in header '<climits>'; this is probably fixable by adding '#include <climits>'
a.cc:60:60: error: 'arr' was not declared in this scope
   60 |         if(i + 1 <= n) ans = min(ans, solve(i +1, n) + abs(arr[i+1] - arr[i]));
      |                                                            ^~~
a.cc:61:56: error: 'arr' was not declared in this scope
   61 |         if(i +2<=n) ans = min(ans, solve(i+2, n) + abs(arr[i+2] - arr[i]));
      |                                                        ^~~
a.cc:62:9: error: 'dp' was not declared in this scope
   62 |         dp[i] = ans;
      |         ^~
a.cc: In function 'int main()':
a.cc:70:22: error: 'arr' was not declared in this scope
   70 |                 cin>>arr[x];
      |                      ^~~
a.cc:72:23: error: reference to 'size' is ambiguous
   72 |         for(int x=0;x<size;x++) dp[x] = -1;
      |                       ^~~~
/usr/include/c++/14/bits/range_access.h:272:5: note: candidates are: 'template<class _Tp, long unsigned int _Nm> constexpr std::size_t std::size(const _Tp (&)[_Nm])'
  272 |     size(const _Tp (&)[_Nm]) noexcept
      |     ^~~~
/usr/include/c++/14/bits/range_access.h:262:5: note:                 'template<class _Container> constexpr decltype (__cont.size()) std::size(const _Container&)'
  262 |     size(const _Container& __cont) noexcept(noexcept(__cont.size()))
      |     ^~~~
a.cc:26:11: note:                 'const int size'
   26 | const int size = 5e5 + 7;
      |           ^~~~
a.cc:72:33: error: 'dp' was not declared in this scope
   72 |         for(int x=0;x<size;x++) dp[x] = -1;
      |                                 ^~