Consider all 6 shapes of "L" at each point
\nclass Solution {\npublic: \n    int numberoffives(int n){ //calculates k if n = p1 *p2* (5^k)\n        int cnt=0;\n        while(n%5==0){\n            n/=5;\n
```\nclass Solution {\npublic: \n    int numberoffives(int n){ //calculates k if n = p1 *p2* (5^k)\n        int cnt=0;\n        while(n%5==0){\n            n/=5;\n            cnt++;\n        }\n        return cnt;\n    }\n    int numberoftwos(int n){\n        int cnt=0;\n        while(n%2==0){\n            n/=2;\n            cnt++;\n        }\n        return cnt;\n    }\npublic:\n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        int m=grid.size();\n        int n=grid[0].size();\n        vector<vector<pair<int, int>>> five(m+1, vector<pair<int, int>>(n+1, {0, 0})); // pair.first represents rows prefix sum of number of fives and pair.second represents columns prefix sum of number of fives \n        vector<vector<pair<int, int>>> two(m+1, vector<pair<int, int>>(n+1, {0, 0}));\n        \n        for(int i=0; i<m; i++){\n            for(int j=1; j<n+1; j++){\n                \n                    five[i][j].first= five[i][j-1].first+ numberoffives(grid[i][j-1]);\n                    two[i][j].first= two[i][j-1].first+ numberoftwos(grid[i][j-1]);\n               \n            }\n        } // calculate row prefix\n        \n        for(int j=0; j<n; j++){\n            for(int i=1; i<m+1; i++){\n                \n                    five[i][j].second= five[i-1][j].second+ numberoffives(grid[i-1][j]);\n                    two[i][j].second= two[i-1][j].second+ numberoftwos(grid[i-1][j]);\n               \n            }\n        }// calculate col prefix\n\n        int maxi=INT_MIN;\n        for(int i=0; i<m; i++){ //                                                                                                       \n            for(int j=0; j<n; j++){//                                                                                                     \n\t\t\t// Try all L shapes possible at a given joint(o) we can have at max 6 shapes  ----- o -------\n\t\t\t                                                                                                            \n                //route1\n                int f= numberoffives(grid[i][j]);\n                int t= numberoftwos(grid[i][j]);\n                int ans= min(two[i][j].first+ two[i][j].second+t,  five[i][j].first+ five[i][j].second+f);   \n                //route 2\n                int temp=0;\n                temp= min(two[i][j].first+ (two[m][j].second-two[i][j].second), five[i][j].first+ (five[m][j].second-five[i][j].second));\n                 ans=max(ans, temp);\n                 // route 3\n               temp= min(two[i][n].first-two[i][j].first+ (two[m][j].second-two[i][j].second)-t, five[i][n].first-five[i][j].first+ (five[m][j].second-five[i][j].second)-f);\n                ans=max(ans, temp);\n                // route 4\n                  temp= min(two[i][n].first-two[i][j].first+ (two[i][j].second), five[i][n].first-five[i][j].first+ (five[i][j].second));\n                ans=max(ans, temp);\n                //route 5 && 6\n                temp=min(two[i][n].first,  five[i][n].first);\n                ans=max(ans, temp);\n                temp=min(two[m][j].second,  five[m][j].second);\n                ans=max(ans, temp);\n                // cout<<ans<<" ";\n                maxi= max(ans, maxi);       \n            }\n            // cout<<endl;\n        }\n        return maxi;\n        \n        \n    }\n};\n```
['C', 'Prefix Sum', 'C++']