C++ solutions
\n\tclass Solution {\npublic:\n\npair<long long,long long> util(int val){\n    \n    int x=0;\n    while(val>0 && val%5==0){\n        val=val/5;\n        x++;\n
```\n\tclass Solution {\npublic:\n\npair<long long,long long> util(int val){\n    \n    int x=0;\n    while(val>0 && val%5==0){\n        val=val/5;\n        x++;\n    }\n    int y=0;\n    while(val>0 && val%2==0){\n        val=val/2;\n        y++;\n    }\n    return {x,y};\n    \n}\n\nlong long util(vector<vector<int>>& grid){\n    \n    int n=grid.size();\n    int m=grid[0].size();\n    pair<long long,long long> matrix[n][m];\n    pair<long long,long long> matrix1[n][m];\n    pair<long long,long long> matrix2[n][m];\n    \n    //making the first grid;\n    for(int i=0;i<n;i++)\n        for(int j=0;j<m;j++){\n            int val=grid[i][j];\n            matrix[i][j]=util(val);\n        }\n    \n    //right to left\n    for(int i=0;i<n;i++){\n        for(int j=m-1;j>=0;j--){\n            if(j==m-1)\n                matrix1[i][j]=matrix[i][j];\n            else\n                matrix1[i][j]={matrix[i][j].first+matrix1[i][j+1].first,matrix[i][j].second+matrix1[i][j+1].second};\n\n        }\n    }\n    for(int i=0;i<n;i++){\n        for(int j=0;j<m;j++){\n            if(j==0)\n                matrix2[i][j]=matrix[i][j];\n            else\n                matrix2[i][j]={matrix[i][j].first+matrix2[i][j-1].first,matrix[i][j].second+matrix2[i][j-1].second};\n        }\n    }\n    long long res=0;\n    \n    //calculating by traversing from up to down\n    \n    for(int j=0;j<m;j++){\n        pair<long long,long long>sum={0,0};\n        for(int i=0;i<n;i++){\n            sum={sum.first+matrix[i][j].first,sum.second+matrix[i][j].second};\n            res=max(res,min(sum.first,sum.second));\n            if(j>0){\n            pair<long long,long long>p1=matrix2[i][j-1];\n            res=max(res,min(sum.first+p1.first,sum.second+p1.second));\n            }\n            if(j<m-1){\n                pair<long long,long long>p1=matrix1[i][j+1];\n            res=max(res,min(sum.first+p1.first,sum.second+p1.second));\n            }\n               \n        }            \n        \n    }\n    return res;\n    \n}\n\nint maxTrailingZeros(vector<vector<int>>& grid) {\n    \nint m=grid[0].size();\n    int n=grid.size();\n    vector<vector<int>>grid2(m,vector<int>(n,0));\n    for(int i=0;i<n;i++){\n        for(int j=0;j<m;j++){\n            grid2[j][i]=grid[i][j];\n        }\n    }\n    long long res=0;\n      res=max(util(grid),util(grid2));\n    vector<vector<int>>grid3(n,vector<int>(m,0));\n    for(int i=0;i<grid.size();i++){\n        for(int j=0;j<grid[0].size();j++){\n            grid3[n-i-1][j]=grid[i][j];       \n        }\n    }\n    return max(res,util(grid3));\n    \n    \n}\n};\n```
['C', 'C++']