Accepted python solution
This solution got accpeted. But it is too long!\nCould someone help me to simplify it? Thanks!\n\nclass Solution:\n    def maxTrailingZeros(self, grid: List[Lis
This solution got accpeted. But it is too long!\nCould someone help me to simplify it? Thanks!\n```\nclass Solution:\n    def maxTrailingZeros(self, grid: List[List[int]]) -> int:\n        m, n = len(grid), len(grid[0])\n        m_five = [[0] * n for _ in range(m)]\n        m_two = [[0] * n for _ in range(m)]\n        hor_five = [[0] * n for _ in range(m)]\n        hor_five_r = [[0] * n for _ in range(m)]\n        hor_two = [[0] * n for _ in range(m)]\n        hor_two_r = [[0] * n for _ in range(m)]\n        ver_five = [[0] * n for _ in range(m)]\n        ver_five_r = [[0] * n for _ in range(m)]\n        ver_two = [[0] * n for _ in range(m)]\n        ver_two_r = [[0] * n for _ in range(m)]\n        \n        for i in range(m):\n            for j in range(n):\n                x = grid[i][j]\n                cnt = 0\n\n                if x % 5 == 0:\n                    cnt += 1\n                if x % 25 == 0:\n                    cnt += 1\n                if x % 125 == 0:\n                    cnt += 1\n                if x % 625 == 0:\n                    cnt += 1\n\n                m_five[i][j] = cnt\n                cnt = 0\n                if x % 512 == 0:\n                    cnt = 9\n                elif x % 256 == 0:\n                    cnt = 8\n                elif x % 128 == 0:\n                    cnt = 7\n                elif x % 64 == 0:\n                    cnt = 6\n                elif x % 32 == 0:\n                    cnt = 5\n                elif x % 16 == 0:\n                    cnt = 4\n                elif x % 8 == 0:\n                    cnt = 3\n                elif x % 4 == 0:\n                    cnt = 2\n                elif x % 2 == 0:\n                    cnt = 1\n                m_two[i][j] = cnt\n        for i in range(m):\n            for j in range(n):\n                if j == 0:\n                    hor_two[i][j] = m_two[i][j]\n                    hor_five[i][j] = m_five[i][j]\n                else:\n                    hor_two[i][j] = m_two[i][j] + hor_two[i][j - 1]\n                    hor_five[i][j] = m_five[i][j] + hor_five[i][j - 1]\n            cur_five = cur_two = 0\n            for j in range(n - 1, -1, -1):\n                if j == n - 1:\n                    hor_two_r[i][j] = m_two[i][j]\n                    hor_five_r[i][j] = m_five[i][j]\n                else:\n                    hor_two_r[i][j] = hor_two_r[i][j + 1] + m_two[i][j]\n                    hor_five_r[i][j] = hor_five_r[i][j + 1] + m_five[i][j]\n        \n\n        for j in range(n):\n            for i in range(m):\n                if i == 0:\n                    ver_five[i][j] = m_five[i][j]\n                    ver_two[i][j] = m_two[i][j]\n                else:\n                    ver_five[i][j] = m_five[i][j] + ver_five[i - 1][j]\n                    ver_two[i][j] = m_two[i][j] + ver_two[i - 1][j]\n            for i in range(m - 1, -1, -1):\n                if i == m - 1:\n                    ver_five_r[i][j] = m_five[i][j]\n                    ver_two_r[i][j] = m_two[i][j]\n                else:\n                    ver_two_r[i][j] = m_two[i][j] + ver_two_r[i + 1][j]\n                    ver_five_r[i][j] = m_five[i][j] +ver_five_r[i + 1][j]\n        \n        res = 0\n        for i in range(m):\n            for j in range(n):\n                res = max(res, min(hor_five[i][j] + ver_five[i][j] - m_five[i][j], hor_two[i][j] + ver_two[i][j] - m_two[i][j]),\n                min(hor_five_r[i][j] + ver_five[i][j] - m_five[i][j], hor_two_r[i][j] + ver_two[i][j] - m_two[i][j]),\n                min(hor_five[i][j] + ver_five_r[i][j] - m_five[i][j], hor_two[i][j] + ver_two_r[i][j] - m_two[i][j]),\n                min(hor_five_r[i][j] + ver_five_r[i][j] - m_five[i][j], hor_two_r[i][j] + ver_two_r[i][j] - m_two[i][j]))\n        return res\n                \n ```
['Python']