c++ solution
\nclass Solution {\npublic:\n    pair<int,int>find(int n)\n    {\n        int count2=0;\n        int count5=0;\n        while(n%2==0)\n        {\n            n=
```\nclass Solution {\npublic:\n    pair<int,int>find(int n)\n    {\n        int count2=0;\n        int count5=0;\n        while(n%2==0)\n        {\n            n=n/2;\n            count2++;\n        }\n        while(n%5==0)\n        {\n            n=n/5;\n            count5++;\n        }\n        return {count2,count5};\n        \n    }\n    int maxTrailingZeros(vector<vector<int>>&mat) \n    {\n        int n=mat.size();\n        int m=mat[0].size();\n        vector<vector<vector<int>>>nums(2,vector<vector<int>>(n,vector<int>(m,0)));\n        vector<vector<vector<int>>>top(2,vector<vector<int>>(n,vector<int>(m,0)));\n        vector<vector<vector<int>>>left(2,vector<vector<int>>(n,vector<int>(m,0)));\n        vector<vector<vector<int>>>right(2,vector<vector<int>>(n,vector<int>(m,0)));\n        vector<vector<vector<int>>>bottom(2,vector<vector<int>>(n,vector<int>(m,0)));\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                auto it=find(mat[i][j]);\n                nums[0][i][j]=it.first;\n                nums[1][i][j]=it.second;\n            }\n        }\n        top=left=right=bottom=nums;\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                if(i)\n                {\n                    top[0][i][j]+=top[0][i-1][j];\n                    top[1][i][j]+=top[1][i-1][j];\n                }\n            }\n        }\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                if(j)\n                {\n                    left[0][i][j]+=left[0][i][j-1];\n                    left[1][i][j]+=left[1][i][j-1];\n                }\n            }\n        }\n        for(int i=0;i<n;i++)\n        {\n            for(int j=m-1;j>=0;j--)\n            {\n                if(j!=m-1)\n                {\n                    right[0][i][j]+=right[0][i][j+1];\n                    right[1][i][j]+=right[1][i][j+1];\n                }\n            }\n        }\n        for(int i=n-1;i>=0;i--)\n        {\n            for(int j=0;j<m;j++)\n            {\n                if(i!=n-1)\n                {\n                    bottom[0][i][j]+=bottom[0][i+1][j];\n                    bottom[1][i][j]+=bottom[1][i+1][j];\n                }\n            }\n        }\n        int ans=0;\n        for(int i=0;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                int curr2=nums[0][i][j];\n                int curr5=nums[1][i][j];\n                \n                int top2=top[0][i][j];\n                int top5=top[1][i][j];\n                \n                int right2=right[0][i][j];\n                int right5=right[1][i][j];\n                \n                int bottom2=bottom[0][i][j];\n                int bottom5=bottom[1][i][j];\n                \n                int left2=left[0][i][j];\n                int left5=left[1][i][j];\n                \n                ans=max(ans,min(top2+right2-curr2,top5+right5-curr5));\n                ans=max(ans,min(top2+left2-curr2,top5+left5-curr5));\n                ans=max(ans,min(bottom2+right2-curr2,bottom5+right5-curr5));\n                ans=max(ans,min(bottom2+left2-curr2,bottom5+left5-curr5));\n            }\n        }\n        return ans;\n    }\n};\n```
['Dynamic Programming', 'C', 'Prefix Sum', 'C++']