C++ bruteforce implementation
```\nclass Solution {\npublic:\n    vector> resultGrid(vector>&arr, int threshold) {\n        \n       int n=arr.size();\n       int m=arr[0].size();\n       ve
```\nclass Solution {\npublic:\n    vector<vector<int>> resultGrid(vector<vector<int>>&arr, int threshold) {\n        \n       int n=arr.size();\n       int m=arr[0].size();\n       vector<vector<int>> ans(n,vector<int>(m));\n       ans=arr;\n       map<pair<int,int>,pair<int,int>> mp;\n       for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                \n                if(j+2<=m-1 && i+2<=n-1){\n                    int sum=0;\n                    bool possible=true;\n                    for(int row=i;row<=i+2;row++){\n                        bool flag=1;\n                        for(int col=j;col<=j+2;col++){\n                            if(col+1<=m-1 && col+1<=j+2){\n                                int diff=abs(arr[row][col]-arr[row][col+1]);\n                                if(diff>threshold){\n                                    flag=0;\n                                    break;\n                                }\n                            }\n                            if(col-1>=0 && col-1>=j){\n                                int diff=abs(arr[row][col]-arr[row][col-1]);\n                                if(diff>threshold){\n                                    flag=0;\n                                    break;\n                                }\n                            }\n                            if(row+1<=n-1 && row+1<=i+2){\n                                int diff=abs(arr[row][col]-arr[row+1][col]);\n                                if(diff>threshold){\n                                    flag=0;\n                                    break;\n                                }\n                            }\n                            if(row-1>=0 && row-1>=i){\n                                int diff=abs(arr[row][col]-arr[row-1][col]);\n                                if(diff>threshold){\n                                    flag=0;\n                                    break;\n                                }\n                            }\n                            sum=sum+arr[row][col];\n                        }\n                        if(flag==0){\n                            possible=false;\n                            break;\n                        }\n                    }\n                    if(possible==true){\n                        \n                        for(int row=i;row<=i+2;row++){\n                            for(int col=j;col<=j+2;col++){\n                                mp[{row,col}].second++;\n                                mp[{row,col}].first=mp[{row,col}].first+sum/9;\n                            }\n                        }\n                    }\n                }\n            }\n        }\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                if(mp[{i,j}].second==0){\n                    continue;\n                }\n                ans[i][j]=mp[{i,j}].first/mp[{i,j}].second;\n            }\n        }\n        return ans;\n    }\n};
[]