For this Question: The cost of stock on each day is given in an array A[] of size N. If you can only perform at most two transactions what is the maximum profit you can gain.

Note:- The second transaction can only start after the first one is complete (Sell- >buy- >sell- >buy).The first line of input contains a single integer N. The next line of input contains N space-separated integers depicting the values of A[].

Constraints:-
2 <= N <= 10000
1 <= A[i] <= 1000000000Print the maximum profit gain in at most two transactions.Sample Input:-
5
3 5 2 8 3

Sample Output:-
8

Explanation:-
Buy at index 1, sell at index 2, Buy at index 3, sell at index 8.

Sample Input:-
4
1 2 4 5

Sample Output:-
4, I have written this Solution Code: 
#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795
#define max1 1000001
#define MOD 1000000007

#define read(type) readInt<type>()

#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}



signed main(){
int n;
cin>>n;
int a[n];
FOR(i,n){cin>>a[i];}
int left[n],right[n+1];
right[n]=0;
for(int i=0;i<n;i++){
    left[i]=0;
    right[i]=0;
}
int m = a[n-1];
for(int i=n-2;i>=0;i--){
    m=max(m,a[i]);
    right[i]=max(m-a[i],right[i+1]);
}
m = a[0];
for(int i=1;i<n;i++){
    m=min(m,a[i]);
    left[i]=max(a[i]-m,left[i-1]);
}
int ans=0;
for(int i=0;i<n;i++){
    ans=max(ans,left[i]+right[i+1]);
}
out(ans);
}

, In this Programming Language: C++, Now tell me if this Code is compilable or not?