Video Explanation (Breaking the problems and solving each version incrementally)
Explanation\n\nClick here for the video\n\n# Code\n\ntypedef long long int ll;\n\nclass Solution {\npublic:\n    vector<long long> countOfPairs(int n, int x, in
# Explanation\n\n[Click here for the video](https://youtu.be/Jt9Mf-5cnow)\n\n# Code\n```\ntypedef long long int ll;\n\nclass Solution {\npublic:\n    vector<long long> countOfPairs(int n, int x, int y) {\n        vector<ll> prefix(n+2, 0);\n        \n        if (x > y) swap(x, y);\n        \n        if (x == y || x+1 == y) {\n            for (int i = 1; i <= n; i ++) \n                prefix[1] ++, prefix[n-i+1] --;\n        }\n        else {\n            for (int i = y; i <= n; i ++) \n                prefix[1] ++, prefix[n-i+1] --;\n\n            int m = y - (y-x)/2;\n            \n            for (int i = m; i < y; i ++)\n                prefix[1] ++, prefix[n-i+1] --;\n\n            for (int i = x, to = m; i < m; i ++, to ++) {\n                // i ... to\n                prefix[1] ++, prefix[to-i+1] --;\n                \n                if (to+1 <= y) {\n                    // to+1 ... y\n                    prefix[(i-x) + 1] ++, prefix[(i-x) + (y-to+1)] --;\n                }\n                \n                if (to+1 <= n) {\n                    // y+1 ... n\n                    prefix[(i-x+1) + 1] ++, prefix[(i-x+1) + n-y+1] --;\n                }\n            }\n\n            for (int i = 1; i < x; i ++) {\n                // i ... m\n                prefix[1] ++, prefix[m-i+1] --;\n\n                if (m+1 <= y-1) {\n                    // m+1 ... y-1\n                    prefix[(x-i+1) + 1] ++, prefix[(x-i+1) + (y-m)] --;\n                }\n            \n                // y ... n\n                prefix[(x-i) + 1] ++, prefix[(x-i) + (n-y+2)] --;\n            }\n        }\n        \n        vector<ll> result(n, 0);\n        for (int j = 1; j <= n; j++) {\n            prefix[j] += prefix[j-1];\n            result[j-1] = prefix[j]*2;\n        }\n        \n        return result;\n    }\n};\n```
['C++']