CPP || Brute-FORCE || Understandable
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```\nclass Solution {\npublic:\n    vector<vector<int>> resultGrid(vector<vector<int>>& image, int threshold) {\n        int n = image.size(), m = image[0].size();\n        \n        vector<vector<int>> res(n,vector<int>(m,0)), count (n,vector<int>(m,0));\n        vector<int> di = {0,0,1,-1};\n        vector<int> dj = {1,-1,0,0};\n        \n        for (int i = 0; i <= n-3; i++) {\n            for (int j = 0; j <= m-3; j++) {\n                int curr = 0;\n                bool flag = true;\n                for (int nx = i; nx <= i+2; nx++) {\n                    for (int ny = j; ny <= j+2; ny++) {\n                        curr += image[nx][ny];\n                        for (int k = 0; k < 4; k++) {\n                            int dx = nx+di[k], dy = ny+dj[k];\n                            if (dx >= i && dx <= i+2 && dy >= j && dy <= j+2) {\n                                if (abs(image[dx][dy]-image[nx][ny]) > threshold) flag = false;\n                            }\n                        }\n                    }\n                }\n                if (!flag) continue;\n                curr /= 9;\n                for (int dx = 0; dx < 3; dx++) {\n                    for (int dy = 0; dy < 3; dy++) {\n                        count[i+dx][j+dy]++;\n                        res[i+dx][j+dy] += curr;\n                    }\n                }\n            }\n        }\n        \n        for (int i = 0; i < n; i++) {\n            for (int j = 0; j < m; j++) {\n                if (count[i][j] == 0) res[i][j] = image[i][j];\n                else res[i][j] /= count[i][j];\n            }\n        }\n        \n        return res;\n    }\n};\n```
['C++']