C++ | Easy to understand | 100% faster and 100% less memory usage
As  at most one turn is possible so for a particular cell we have 6 choices\nBy storing number of two\'s and five\'s we can get the count of 10\'s easily\n\n#de
**As  at most one turn is possible so for a particular cell we have 6 choices**\n**By storing number of two\'s and five\'s we can get the count of 10\'s easily**\n```\n#define F first\n#define S second\nclass Solution {\npublic:\n    int maxTrailingZeros(vector<vector<int>>& v) {\n        int n=v.size();\n        int m=v[0].size();\n        vector<vector<pair<int,int>>>cntx(n,vector<pair<int,int>>(m));// for vertical counting prefix sum matrix \n        vector<vector<pair<int,int>>>cnty(n,vector<pair<int,int>>(m));// for horizontal counting  suffix sum matrix\n        vector<vector<pair<int,int>>>orr(n,vector<pair<int,int>>(m));// for original counting\n        for(int i=0;i<n;i++)\n        {\n           for(int j=0;j<m;j++)\n           {\n               int x=0;\n               int y=0;\n               int p=v[i][j];\n               while(p%2==0)\n               {\n                   p=p/2;\n                   x++;\n               }\n               while(p%5==0)\n               {\n                   p=p/5;\n                   y++;\n               }\n               // for storing the number of 2\'s and 5\'s in a particular cell\n               cntx[i][j]={x,y};\n               cnty[i][j]={x,y};\n               orr[i][j]={x,y};\n           }\n        }\n        // Prefix sum vertical matrix\n        for(int i=1;i<n;i++)\n        {\n            for(int j=0;j<m;j++)\n            {\n                cntx[i][j].F+=cntx[i-1][j].F;\n                cntx[i][j].S+=cntx[i-1][j].S;\n            }\n        }\n        // suffix sum horizontal matrix\n         for(int i=0;i<n;i++)\n        {\n            for(int j=m-2;j>=0;j--)\n            {\n              cnty[i][j].F+=cnty[i][j+1].F;\n              cnty[i][j].S+=cnty[i][j+1].S;\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               // no. of 2\'s and 5\'s from top to i,j cell\n                pair<int,int> up=cntx[i][j];\n                 // no. of 2\'s and 5\'s from i+1,j to bottom cell\n                pair<int,int> down={cntx[n-1][j].F-cntx[i][j].F,cntx[n-1][j].S-cntx[i][j].S};\n                 // no. of 2\'s and 5\'s from i,j to rightmost cell\n                pair<int,int> right=cnty[i][j];\n                 // no. of 2\'s and 5\'s from leftmost cell to i,j-1 cell\n                pair<int,int> left={cnty[i][0].F-cnty[i][j].F,cnty[i][0].S-cnty[i][j].S};\n                int cnt=0;\n                // calculating no. of 2\'s and 5\'s for each of the 6 cases\n                //     |\n                //     |  \n                \n                cnt=max(cnt,min(up.F+down.F,up.S+down.S));\n                \n                //      |\n                //   ___|\n                \n                cnt=max(cnt,min(up.F+left.F,up.S+left.S));\n                \n                //     |\n                //     |_____\n                \n                cnt=max(cnt,min(up.F+right.F-orr[i][j].F,up.S+right.S-orr[i][j].S));\n                \n                //     _______\n                //       \n                \n                cnt=max(cnt,min(left.F+right.F,left.S+right.S));\n                //      ____\n                //     |\n                //     |  \n                \n                cnt=max(cnt,min(right.F+down.F,right.S+down.S));\n                //      ____\n                //          |\n                //          |  \n                \n                cnt=max(cnt,min(left.F+down.F+orr[i][j].F,left.S+down.S+orr[i][j].S));\n                ans=max(ans,cnt);\n            }\n        }\n        return ans;\n    }\n};\n```
['C', 'Prefix Sum']