Simple python3 solution
Complexity
Time complexity: O(n)

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

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

# Code
```python3 []
class Solution:
    def minCost(self, n: int, cost: List[List[int]]) -> int:        
        prev_dp = {(-1, -2): 0}
        for i in range(n // 2):
            dp = {}
            j = n - i - 1
            for a, a_cost in enumerate(cost[i]):
                for b, b_cost in enumerate(cost[j]):
                    if a == b:
                        continue
                    prev_cost = min(
                        cost
                        for (prev_a, prev_b), cost in prev_dp.items()
                        if prev_a != a and prev_b != b
                    )
                    dp[(a, b)] = a_cost + b_cost + prev_cost
            prev_dp = dp
        return min(prev_dp.values())
```
['Dynamic Programming', 'Python3']