Python
\n\nclass Solution:\n    def maxTrailingZeros(self, grid) :\n        matrix = grid \n        self.ans,prefix,suffix = 0,[i[:] for i in matrix ],[i[:] for i in m
\n```\nclass Solution:\n    def maxTrailingZeros(self, grid) :\n        matrix = grid \n        self.ans,prefix,suffix = 0,[i[:] for i in matrix ],[i[:] for i in matrix ]\n      \n        def f(n):\n            x,y =0,0\n            while n%2==0:\n                n = n//2\n                x+=1\n            while n% 5==0:\n                n = n // 5\n                y+=1\n            return x,y\n\n        for i in prefix:\n            for n,v in enumerate(i):\n                if n==0 : i[0] =f(v)\n                else:\n                    x,y = f(v)\n                    a,b = i[n-1]\n                    i[n]=x+a,y+b\n\n        for i in suffix :\n            for n in range(len(i)-1,-1,-1):\n                if n == len(i)-1:i[n]=f(i[n])\n                else:\n                    x,y = f(i[n])\n                    a,b= i[n+1]\n                    i[n]=x+a,y+b\n\n        for j in range(len(matrix[0])):\n            two,five =0,0\n            for i in range(len(matrix)):\n                self.ans = max(self.ans,min(two+prefix[i][j][0],five + prefix[i][j][1]))\n                self.ans = max(self.ans , min(two + suffix[i][j][0] , five + suffix[i][j][1]))\n\n                x,y = f(matrix[i][j])\n                two +=x\n                five +=y \n            \n            two,five = 0,0\n            for i in range(len(matrix)-1,-1,-1):\n                self.ans = max(self.ans,min(two+prefix[i][j][0],five + prefix[i][j][1]))\n                self.ans = max(self.ans , min(two + suffix[i][j][0] , five + suffix[i][j][1]))\n                x,y = f(matrix[i][j])\n                two +=x\n                five +=y \n      \n        return self.ans \n```
['Python3']