Faster than 💯% and takes up less space than 💯% 🔥🔥
Intuition\n Describe your first thoughts on how to solve this problem. \nThis problem is mostly based on combinatronics.\n\n# Approach\n Describe your approach 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThis problem is mostly based on combinatronics.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nRegardless of the input array, the given set of houses can always be divided into three parts, namely, left side, the circle and the right side, we can treat these as separate entities because that\'s where the changes occur(i.e., the interaction between these three componenets).\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n$$O(n)$$\n\n# Code\n```\n#define ll long long\nclass Solution {\npublic:\n    void solve(ll out, ll in, ll minm, int n,vector<ll>&ans){\n        ll maxm = minm + out + in - 2;\n        ll gap = minm - 2;\n        for(ll i = minm;i<=maxm;i++){\n            ll k = min(out, in);\n            ll value = min({k, i - minm + 1, maxm - i + 1});\n            ans[i]-=2*value;\n            ans[i - gap]+=2*value;\n        }\n    }\n    \n    \n    void inside(vector<ll>&ans, ll x, ll n){\n        vector<ll>v(n + 1);\n        for(int i = 1;i<=x - 3;i++){\n            v[i] = (x - i - 2)*2;\n        }\n        for(ll i = 1;i<=n;i++){\n            ans[i]-=v[i];\n        }\n        for(ll i = 1;i<=x - 3;i++){\n            if(x - i < i){\n                v[x - i]+=v[i];\n                v[i] = 0;\n            }\n        }\n        for(ll i = 1;i<=n;i++){\n            ans[i]+=v[i];\n        }    \n        \n    }\n    \n    \n    vector<ll> countOfPairs(int n, int x, int y) {\n        vector<ll>ans(n + 1);\n        for(int i = 1;i<n;i++){\n            ans[i] = (n - i)*2;\n        }\n        if(abs(x - y) > 1){\n            int l = min(x, y), r = max(x, y);\n            for(ll i = r - l;i<=n - 1;i++){\n                ll k = min(l, n - r + 1);\n                ll value = min({k, i - r + l + 1, n - i});\n                ans[i]-=2*value;\n                ans[i - (r - l) + 1]+=2*value; \n            }\n            ll in = (r - l - 1)/2, minm = (r + l - 2*(l - 1))/2;\n            solve(l, in, minm, n, ans);\n            solve(n - r + 1, in, minm, n, ans);\n            if(r - l + 1 > 4){\n                inside(ans, r - l + 1, n);    \n            }\n        }\n        vector<ll>ans2(n);\n        for(int i = 0;i<n;i++){\n            ans2[i] = ans[i + 1];\n        }\n        return ans2;\n    }\n};\n```
['C++']