Prefix sum vertically and horizontally of factors 2 and 5
\nclass Solution {\npublic:\n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        int n = grid.size();\n        int m = grid[0].size();\n        int a
```\nclass Solution {\npublic:\n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        int n = grid.size();\n        int m = grid[0].size();\n        int ans = 0;\n        \n        vector<vector<pair<int,int>>> ngrid(n,vector<pair<int,int>>(m,{0,0}));\n        vector<vector<pair<int,int>>> vert(n,vector<pair<int,int>>(m,{0,0}));\n        vector<vector<pair<int,int>>> hor(n,vector<pair<int,int>>(m,{0,0}));\n        \n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                auto x = func(grid[i][j]);\n                ngrid[i][j].first = x.first;\n                ngrid[i][j].second = x.second;\n            }\n        }\n        \n        for(int j=0; j<m; j++){\n            vert[0][j] = ngrid[0][j]; \n            for(int i=1; i<n; i++){\n                vert[i][j].first = vert[i-1][j].first + ngrid[i][j].first;\n                vert[i][j].second = vert[i-1][j].second + ngrid[i][j].second;\n                \n            }\n        }\n        \n        for(int i=0; i<n; i++){\n            hor[i][0] = ngrid[i][0]; \n            for(int j=1; j<m; j++){\n                hor[i][j].first = hor[i][j-1].first+ngrid[i][j].first;\n                hor[i][j].second = hor[i][j-1].second+ngrid[i][j].second;\n            }\n        }\n        \n        for(int i=0; i<n; i++){\n            for(int j=0; j<m; j++){\n                vector<pair<int,int> > v(4);\n                \n                v[0].first = (i-1 >= 0 ?  vert[i-1][j].first : 0);\n                v[0].second = (i-1 >= 0 ?  vert[i-1][j].second : 0);\n                \n                v[1].first = ( vert[n-1][j].first - vert[i][j].first);\n                v[1].second = ( vert[n-1][j].second - vert[i][j].second);\n                \n                v[2].first = (j-1 >= 0 ?  hor[i][j-1].first : 0);\n                v[2].second = (j-1 >= 0 ?  hor[i][j-1].second : 0);\n                \n                v[3].first = ( hor[i][m-1].first - hor[i][j].first);\n                v[3].second = ( hor[i][m-1].second - hor[i][j].second);                \n                \n                int cmax = 0;\n                \n                for(int k=0; k<4; k++){\n                    for(int l = k+1;  l<4; l++){\n                        int sum = min(v[k].first+v[l].first+ngrid[i][j].first, v[k].second+v[l].second+ngrid[i][j].second);\n                        \n                        cmax = max(cmax, sum);\n                    }\n                }\n                \n                ans = max(ans,cmax);\n            }\n        }\n        return ans;\n    }\n    \n    pair<int,int> func(int x){\n        int two = 0,five=0;\n        while(x>0 && x%2 == 0){\n            two++;\n            x = x/2;\n        }\n        \n        while(x>0 && x%5 == 0){\n            five++;\n            x = x/5;\n        }\n        \n        return {two,five};\n    }\n};\n```
['C', 'Prefix Sum']