my solution
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        ios_base::sync_with_stdio(0);\n        cin.tie(nullptr);\n        cout.tie(nullptr);\n        \n        int m=image.size();\n        int n=image[0].size();\n        \n        if(m<3 || n<3){\n            return image;\n        }\n        \n        vector<vector<int>> region(m, vector<int>(n,-1));\n        bool has_region=false;\n        map<pair<int, int>, vector<int>> mp;\n        for(int i=0;i<m-2;++i){\n            for(int j=0;j<n-2;++j){\n                if(region_check(image, i, j, threshold)){\n                    has_region=true;\n                    cal(image, region, i, j, mp);\n                }\n            }\n        }\n\n        for(int i=0;i<m;i++){\n            for(int j=0;j<n;j++){\n                if(region[i][j]==-1){\n                    region[i][j]=image[i][j];\n                }\n            }\n        }\n\n        for(int i=0;i<m;i++){\n            for(int j=0;j<n;j++){\n                if(mp[{i,j}].size()!=0){\n                    region[i][j]=accumulate(mp[{i,j}].begin(),mp[{i,j}].end(),0)/mp[{i,j}].size();\n                }\n            }\n        }\n\n        return has_region?region:image;\n    }\n    \n    void cal(vector<vector<int>>& image, vector<vector<int>>& region, int m, int n, map<pair<int, int>, vector<int>>& mp){\n        int sum=0;\n        for(int i=m;i<m+3;++i){\n            for(int j=n;j<n+3;++j){\n                sum +=image[i][j];\n            }\n        }\n        \n        int avg=floor(sum/9);\n\n        for(int i=m;i<m+3;++i){\n            for(int j=n;j<n+3;++j){                \n                mp[{i, j}].push_back(avg);                \n            }\n        }        \n    }\n    \n    bool region_check(vector<vector<int>>& image, int m, int n, int threshold){             \n        for(int i=m;i<m+3;++i){\n            for(int j=n;j<n+2;++j){\n                if(abs(image[i][j]-image[i][j+1])<=threshold){\n                    continue;\n                }else{\n                    return false;\n                }\n            }\n        }\n        \n        for(int j=n;j<n+3;++j){\n            for(int i=m;i<m+2;++i){\n                if(abs(image[i][j]-image[i+1][j])<=threshold){\n                    continue;\n                }else{\n                    return false;\n                }\n            }\n        }\n        return true;\n    }\n};\n```
['C++']