Memoized solution very easy to understand 
IntuitionSimple idea is by trying all possible approached to fill colors in the housed while keeping in track of conditions i.e. adjacent and equidistant houses
# Intuition
Simple idea is by trying all possible approached to fill colors in the housed while keeping in track of conditions i.e. adjacent and equidistant houses are not colored the same so we get idea of recursion for trying all possible combinations then we memoize it.

# Approach
We take two matrices one for first half of cost matrix i.e `cost1` and other for second half of cost matrix i.e. `cost2` and then we reverse `cost2` the idea being it makes it east to check equidistant condition

Lets say we have two indices `i1` and `i2`. `i1` points to `cost1` and `i2` points to `cost2` now since we havfe reversed `cost2` matrix `i1` and `i2` point to equidistant houses so we need to keep track that

house `i1` and house `i1 - 1` are not of same color (adjacent)
house `i2` and house `i2 - 1` are not of same color (adjacent)
house `i1` and house `i2` are not of same color (equidistant)

Relation between `i1` and `i2` is `i2 = i1 + n/2` so this is how we can reduce parameters

`cur_color1` is color of house at `i1`
`cur_color2` is color of house at `i2`

so `cur_color1` should not be equal to `color1` since `color1` is color of `i1 - 1` house i.e. adjacent 
 
`cur_color2` should not be equal to `color2` since `color2` is color of `i2 - 1` house i.e. adjacent 

`cur_color1` should not be equal to `cur_color2` since `cur_color1` is equidistant from `cur_color2` house i.e. adjacent 

Hope this helps
Please Give it a like

# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->

# Code
```cpp []
class Solution {
public:
    // idx -> current house to be coloured
    // color1 -> color of house at idx - 1 in first half
    // color2 -> color of house at idx - 1 in second half
    static const int N = 1e5 + 1;
    long long dp[N][4][4];
    long long helper(int idx, vector<vector<int>> &cost1, vector<vector<int>> &cost2, int color1, int color2){
        if(idx == (int)cost1.size()) return 0;
        if(dp[idx][color1][color2] != -1) return dp[idx][color1][color2];
        long long ans = 1e18;
        for(int cur_color1 = 0; cur_color1 < 3; ++cur_color1){
            if(cur_color1 != color1){ // adjacent check
                for(int cur_color2 = 0; cur_color2 < 3; ++cur_color2){
                    if(cur_color2 != cur_color1 and cur_color2 != color2){ // equidistant check
                        long long cost = helper(idx + 1, cost1, cost2, cur_color1, cur_color2);
                        ans = min(ans, cost1[idx][cur_color1]*1LL + cost2[idx][cur_color2]*1LL + cost);
                    }
                }
            }
        }
        return dp[idx][color1][color2] = ans;
    }
    long long minCost(int n, vector<vector<int>>& cost) {
        memset(dp, -1, sizeof(dp));
        vector<vector<int>> cost1, cost2;
        for(int i = 0; i < n; ++i){
            if(i < n/2){
                cost1.push_back(cost[i]);
            }else{
                cost2.push_back(cost[i]);
            }
        }
        reverse(cost2.begin(), cost2.end());
        return helper(0, cost1, cost2, 3, 3);
    }
};

```
['Dynamic Programming', 'Recursion', 'Memoization', 'C++']