SIMPLEST CODE FOR THIS PROBLEM  |  Go till half by keeping in mind color you used in ends 
IntuitionApproachComplexity
Time complexity:

Space complexity:
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->

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

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

# Code
```python3 []
class Solution:
    def minCost(self, n: int, cost: List[List[int]]) -> int:


        @cache
        def dp(index,prevleft,prevright):
            if index==n//2:
                return 0 
            else:
                ans = float("inf")
                for x in range(3):
                    for y in range(3):
                        if x!=y and prevleft!=x and prevright!=y:
                            ans = min(ans,cost[index][x]+cost[-1-index][y]+dp(index+1,x,y))
                return ans 
        return dp(0,-1,-1)

```
['Python3']