Beats 100% | O(1) space | East to understand | Linear time, One pass
Intuition\n Describe your first thoughts on how to solve this problem. \nIt is given that we can perform operation to any adjacent elements any number of time. 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nIt is given that we can perform operation to any adjacent elements any number of time. Lets analyze the operation. \n- We will be able to change sign of any number by perfoming series of operations(as there are no restriction on number of operations). \n- The operation will change sign of 2 values. So if there are even number negative values present in matrix, we can always make it positive by performing series of operation. \n- If there are odd number of negative values present, then i will choose which element i want to make negative. It is always beneficial to have the smallest value as negative. (Note we can also convert positive number to negative with same operation). Ex. if i have **[2, 3, -5, 6]** in my matrix, then i will **convert 2 -> -2 and -5 -> 5, [-2, 3, 5, 6]** and this will give me max sum. \n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nIterate over the matrix and do the following steps\n- Take sum of absolute values. \n- Count negative values. \n- Track minimum element in terms of absolute value. \n\nIf negative count is even, the return sum\nelse, **subtract 2 * minElement** as minElement will be converted to negative value, and we have already added abs(minElement) in our answer, so first we have subtract that from answer and then -minELement, and return value.\n\n# Complexity\n- Time complexity: O(NM)\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity: O(1)\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    long long maxMatrixSum(vector<vector<int>>& matrix) {\n        int n = matrix.size(); \n        long long ans = 0; \n        int cnt = 0; \n        int minElement = 2e5; \n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < n; j++) {\n                if (matrix[i][j] < 0) {\n                    cnt++; \n                }\n                ans += abs(matrix[i][j]); \n                minElement = min(minElement, abs(matrix[i][j])); \n            }\n        }\n        if (cnt % 2) {\n            ans -= 2 * minElement; \n        }\n        return ans; \n    }\n};\n```
['C++']