c++ solution memoization
Code
# Code
```cpp []
class Solution {
public:
    long long dp[(100000 / 2) + 1][4][4];
    long long find(vector<vector<int>>& cost, int n, int index, int prev1 = -1,
                   int prev2 = -1) {
        if (index >= n / 2)
            return 0;
        if (dp[index][prev1 + 1][prev2 + 1] != -1) {
            return dp[index][prev1 + 1][prev2 + 1];
        }
        long long ans = 1e18;
        for (int first = 0; first < 3; first++) {
            for (int second = 0; second < 3; second++) {
                if (first != prev1 && second != prev2 && first != second) {
                    ans = min(ans, cost[index][first] +
                                       cost[n - index - 1][second] +
                                       find(cost, n, index + 1, first, second));
                }
            }
        }
        return dp[index][prev1 + 1][prev2 + 1] = ans;
    }
    long long minCost(int n, vector<vector<int>>& cost) {
        memset(dp, -1, sizeof(dp));
        return find(cost, n, 0);
    }
};
```
['C++']