Simple C++
\nclass Solution {\nprivate:\n    bool check(int n,int m,int row,int col){\n        return row>=(n-3)&&col>=(m-3)&&row<n&&col<m;\n    }\npublic:\n    vector<vec
```\nclass Solution {\nprivate:\n    bool check(int n,int m,int row,int col){\n        return row>=(n-3)&&col>=(m-3)&&row<n&&col<m;\n    }\npublic:\n    vector<vector<int>> resultGrid(vector<vector<int>>& image, int threshold) {\n        int n = image.size();\n        int m = image[0].size();\n        map<pair<int,int>,vector<int>>mp;\n        int dx[4]={0,0,1,-1};\n        int dy[4]={1,-1,0,0};\n        for(int i=0;i<=n-3;i++){\n            for(int j=0;j<=m-3;j++){\n                int total = 0;\n                bool flag = 1;\n                for(int x=i;x<i+3;x++){\n                    for(int y=j;y<j+3;y++){\n                        for(int k=0;k<4;k++){\n                            if(check(i+3,j+3,x+dx[k],y+dy[k])){\n                                if(abs(image[x][y]-image[x+dx[k]][y+dy[k]])>threshold){\n                                    flag=0;break;\n                                }\n                            }\n                        }\n                        total+=image[x][y];\n                    }\n                }\n         if(flag){\n                int res = floor(total/9);\n                 for(int x=i;x<i+3;x++){\n                    for(int y=j;y<j+3;y++){\n                        mp[{x,y}].push_back(res);\n                    }\n                 }\n              }\n           }\n        }\n        vector<vector<int>>result(image);\n        for(int i=0;i<n;i++){\n            for(int j=0;j<m;j++){\n                int divident = 0,divisor = 0;\n                for(auto&it:mp[{i,j}]){\n                    ++divisor;\n                    divident+=it;\n                }\n               if(divisor!=0)result[i][j]=floor(divident/divisor);\n            }\n        }\n        return result;\n    }\n};\n```
['C++']