<p>You are given an <code>m x n</code> binary matrix <code>grid</code>.</p>

<p>A row or column is considered <strong>palindromic</strong> if its values read the same forward and backward.</p>

<p>You can <strong>flip</strong> any number of cells in <code>grid</code> from <code>0</code> to <code>1</code>, or from <code>1</code> to <code>0</code>.</p>

<p>Return the <strong>minimum</strong> number of cells that need to be flipped to make <strong>all</strong> rows and columns <strong>palindromic</strong>, and the total number of <code>1</code>&#39;s in <code>grid</code> <strong>divisible</strong> by <code>4</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[1,0,0],[0,1,0],[0,0,1]]</span></p>

<p><strong>Output:</strong> <span class="example-io">3</span></p>

<p><strong>Explanation:</strong></p>

<p><img src="https://assets.leetcode.com/uploads/2024/08/01/image.png" style="width: 400px; height: 105px;" /></p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[0,1],[0,1],[0,0]]</span></p>

<p><strong>Output:</strong> <span class="example-io">2</span></p>

<p><strong>Explanation:</strong></p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2024/07/08/screenshot-from-2024-07-09-01-37-48.png" style="width: 300px; height: 104px;" /></p>
</div>

<p><strong class="example">Example 3:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">grid = [[1],[1]]</span></p>

<p><strong>Output:</strong> <span class="example-io">2</span></p>

<p><strong>Explanation:</strong></p>

<p><img alt="" src="https://assets.leetcode.com/uploads/2024/08/01/screenshot-from-2024-08-01-23-05-26.png" style="width: 200px; height: 70px;" /></p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>m == grid.length</code></li>
	<li><code>n == grid[i].length</code></li>
	<li><code>1 &lt;= m * n &lt;= 2 * 10<sup>5</sup></code></li>
	<li><code>0 &lt;= grid[i][j] &lt;= 1</code></li>
</ul>

class Solution:
    def poin(self,point,grid):
        if grid[point[0]][point[1]]==1:
            return 1
        return 0
    
        
        
    def minFlips(self, grid: List[List[int]]) -> int:
        ret=0
        d={}
        one=0
        w=0
        for i in range(len(grid)):
            d1={}
            for j in range(len(grid[0])):
                
                p1=[i,len(grid[0])-j-1]
                p2=[len(grid)-i-1,j]
                p3=[i,j]
                p4=[len(grid)-1-p1[0],p1[-1]]
                if str(p3) in d:
                    break
                s=0
                d[str(p1)]=1
                d[str(p2)]=1
                d[str(p3)]=1
                d[str(p4)]=1
                d1={}
                if str(p1) not in d1:
                    
                    s+=self.poin(p1,grid)
                    d1[str(p1)]=1
                if str(p2) not in d1:
                    
                    s+=self.poin(p2,grid)
                    d1[str(p2)]=1
                if str(p3) not in d1:
                    
                    s+=self.poin(p3,grid)
                    d1[str(p3)]=1
                if str(p4) not in d1:
                    
                    s+=self.poin(p4,grid)
                    d1[str(p4)]=1
                
                
                #print([p1,p2,p3,p4],d1,s)
                if len(d1.keys())==2:
                    if s==1:
                        one+=1
                        w+=2
                        continue
                    if s>=2:
                        w+=2
                    continue
                    
                    
                if len(d1.keys())==1:
                    if s>0:
                        ret+=1
                    continue
                if s==1:
                    ret+=1
                if s==2:
                    ret+=2
                if s==3:
                    ret+=1
            #print(w)
                
        if w%4==0:
            ret+=one
        if w%4==2:
            if one>0:
                ret+=one
            else:
                ret+=2
            
                
                #print(d)
        
        
        return ret
        
                
                
                
                
                
                
                
                
                
                
                
                
81800