C++ || EASY || CLEAN SHORT || BEST UNDERSTANDABLE SOLUTION
\n# Code\n\nclass Solution {\npublic:int q=0;\n    vector<vector<int>> resultGrid(vector<vector<int>>& g, int t) {\n        map<pair<int,int>,int> qq,p;\n      
\n# Code\n```\nclass Solution {\npublic:int q=0;\n    vector<vector<int>> resultGrid(vector<vector<int>>& g, int t) {\n        map<pair<int,int>,int> qq,p;\n        int m=g.size(),n=g[0].size();\n        for(int i=0;i<m;i++)\n        {\n            for(int j=0;j<n;j++)\n            {\n                if(i+1<m&&j+1<n&&i-1>=0&&j-1>=0)\n                {\n                    int a=g[i][j],b=g[i+1][j],c=g[i-1][j],d=g[i][j-1],e=g[i][j+1],x=g[i-1][j-1],y=g[i-1][j+1],\n                    z=g[i+1][j-1],u=g[i+1][j+1];\n                    \n                    if(abs(x-c)<=t && abs(c-y)<=t && abs(x-d)<=t && abs(e-y)<=t && abs(e-u)<=t && abs(u-b)<=t && abs(b-z)<=t && abs(d-z)<=t && abs(a-b)<=t&&abs(a-c)<=t&&abs(a-d)<=t&&abs(a-e)<=t)\n                    {\n                        int s=a+b+c+d+e+g[i-1][j-1]+g[i+1][j+1]+g[i-1][j+1]+g[i+1][j-1];\n                        int r=s/9;\n                        \n                        p[{i,j}]+=r;\n                        qq[{i,j}]++;\n\n                        p[{i+1,j}]+=r;\n                        qq[{i+1,j}]++;\n                        \n                        p[{i-1,j}]+=r;\n                        qq[{i-1,j}]++;\n                        \n                        p[{i,j+1}]+=r;\n                        qq[{i,j+1}]++;\n                        \n                        p[{i,j-1}]+=r;\n                        qq[{i,j-1}]++;\n                        \n                        p[{i+1,j+1}]+=r;\n                        qq[{i+1,j+1}]++;\n                        \n                        p[{i-1,j-1}]+=r;\n                        qq[{i-1,j-1}]++;\n                        \n                        p[{i-1,j+1}]+=r;\n                        qq[{i-1,j+1}]++;\n                        \n                        p[{i+1,j-1}]+=r;\n                        qq[{i+1,j-1}]++;\n                    }\n                }\n            }\n        }\n        vector<vector<int>> v(m,vector<int> (n,0));\n        for(int i=0;i<m;i++)\n        {\n            for(int j=0;j<n;j++)\n            if(p.count({i,j}))\n                    v[i][j]=p[{i,j}]/qq[{i,j}];\n                else\n                v[i][j]=g[i][j];\n        }\n        return v;\n    }\n};\n```
['C++']