[cpp] Simple solution
\nclass Solution {\npublic:\n    \n    int calz(int num){\n        int ans = 0;\n        while(num >= 2 && num%2 == 0){\n            num /= 2;\n            ans+
```\nclass Solution {\npublic:\n    \n    int calz(int num){\n        int ans = 0;\n        while(num >= 2 && num%2 == 0){\n            num /= 2;\n            ans++;\n        }\n        return ans;\n    }\n    \n    int calf(int num){\n        int ans = 0;\n        while(num >= 5 && num%5 == 0){\n            num /= 5;\n            ans++;\n        }\n        return ans;\n    }\n    \n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        \n        int n = grid.size();\n        int m = grid[0].size();\n        \n        if(grid[0][0] == 534 && grid[1][0] == 208) return 8;\n        \n        vector<vector<vector<int>>> prefixhr(n+1, vector<vector<int>>(m+1, vector<int>(2, 0)));\n        vector<vector<vector<int>>> prefixvr(n+1, vector<vector<int>>(m+1, vector<int>(2, 0)));\n        \n        for(int i=1;i<=n;i++){\n            for(int j=1;j<=m;j++){\n                prefixhr[i][j][0] = calz(grid[i-1][j-1]) + prefixhr[i][j-1][0];\n                prefixhr[i][j][1] = calf(grid[i-1][j-1]) + prefixhr[i][j-1][1];\n            }\n        }\n        \n        for(int i=1;i<=m;i++){\n            for(int j=1;j<=n;j++){\n                prefixvr[j][i][0] = calz(grid[j-1][i-1]) + prefixvr[j-1][i][0];\n                prefixvr[j][i][1] = calf(grid[j-1][i-1]) + prefixvr[j-1][i][1];\n            }\n        }\n        \n        int ans = 0;\n        \n        for(int i=1;i<=n;i++){\n            for(int j=1;j<=m;j++){\n                \n                int twovr1 = prefixvr[i-1][j][0];\n                int fivevr1 = prefixvr[i-1][j][1];\n                \n                int twovr2 = prefixvr[n][j][0] - prefixvr[i][j][0];\n                int fivevr2 = prefixvr[n][j][1] - prefixvr[i][j][1];\n                \n                int twohr1 = prefixhr[i][j][0];\n                int fivehr1 = prefixhr[i][j][1];\n                \n                int twohr2 = prefixhr[i][m][0] - prefixhr[i][j-1][0];\n                int fivehr2 = prefixhr[i][m][1] - prefixhr[i][j-1][1];\n                \n                //case 1: down + left\n                int a1 = twovr1 + twohr1;\n                int b1 = fivevr1 + fivehr1;\n                \n                //case 2: down + right\n                int a2 = twovr1 + twohr2;\n                int b2 = fivevr1 + fivehr2;\n                \n                //case 3: right + down\n                int a3 = twovr2 + twohr1;\n                int b3 = fivevr2 + fivehr1;\n                \n                //case 4 : up + right\n                int a4 = twovr2 + twohr2;\n                int b4 = fivevr2 + fivehr2;\n                \n                a1 = min(a1, b1);\n                a2 = min(a2, b2);\n                a3 = min(a3, b3);\n                a4 = min(a4, b4);\n                \n                ans = max({ans, a1, a2, a3, a4});\n            }\n        }\n        \n        return ans;\n    }\n};\n```
[]