Efficient Use of Prefix Sums, owing to @votrubac
\narray<int, 2> operator+(const array<int, 2> &l, const array<int, 2> &r) { return { l[0] + r[0], l[1] + r[1] }; }\narray<int, 2> operator-(const array<int, 2> 
```\narray<int, 2> operator+(const array<int, 2> &l, const array<int, 2> &r) { return { l[0] + r[0], l[1] + r[1] }; }\narray<int, 2> operator-(const array<int, 2> &l, const array<int, 2> &r) { return { l[0] - r[0], l[1] - r[1] }; }\n\nint pairs(const array<int, 2> &p) { return min(p[0], p[1]); }\n\nclass Solution {\npublic:\n    int factors(int i, int f) {\n        return i % f ? 0 : 1 + factors(i / f, f);\n    }\n    \n    // https://leetcode.com/problems/maximum-trailing-zeros-in-a-cornered-path/discuss/1955515/Prefix-Sum-of-Factors-2-and-5\n    \n    int maxTrailingZeros(vector<vector<int>>& grid) {\n        \n        int m = grid.size(), n = grid[0].size(), res = 0;\n        vector<vector<array<int, 2>>> h(m, vector<array<int, 2>>(n + 1)), v(m + 1, vector<array<int, 2>>(n));\n        for (int i = 0; i < m; ++i)\n            for (int j = 0; j < n; ++j) {\n                array<int, 2> f25 = { factors(grid[i][j], 2), factors(grid[i][j], 5) };\n                v[i + 1][j] = v[i][j] + f25;\n                h[i][j + 1] = h[i][j] + f25;\n            }\n        for (int i = 0; i < m; ++i)\n            for (int j = 0; j < n; ++j) {\n                auto v1 = v[i + 1][j], v2 = v[m][j] - v[i][j];\n                auto h1 = h[i][j], h2 = h[i][n] - h[i][j + 1];\n                res = max({res, pairs(v1 + h1), pairs(v1 + h2), pairs(v2 + h1), pairs(v2 + h2)});\n                \n                // 4 paths \n                // suppose you\'re on (i, j) cell\n                // then either you can have vertical_top path + horizantal_right path ( L shaped) OR vertical_top path + horizantal_left path ( mirrored L)\n                // OR vertical_down + hori_right OR vertical_down + hori_left\n                // \n                \n            }\n        return res;\n    }\n};\n```
['C']