Spent 3 hours. Simplest easy to understand 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<long long> countOfPairs(int n, int x, int y) {\n        \n        \n        // connections are directed. method flopped.\n        \n        \n        \n        if(x > y) swap(x, y);\n        \n        // for node i find answer for each j from i + 1 to n.\n       \n        \n        \n        if(x == y || y == x + 1) {\n            vector<long long> v;\n            \n            for(int i = 1; i <= n; i ++) {\n                v.push_back(2 * (n - i));\n            }\n            \n            return v;\n        }\n        \n        int radius = (y - x + 1) / 2;\n        \n        vector<long long > ans(n + 2);\n        \n        // cout << "colaveri " << x << " " << y << endl;\n        \n        for(int i = 1; i <= n; i ++) {\n            \n            if(i <= x) {\n                // left side of the loop\n                \n                // i to x\n                \n                \n                if(i < x) {\n                    ans[1] ++;\n                    ans[x - i + 1] --;   \n                }\n                \n                // i to nodes in (x, y) on the bridge\n                // left part of the loop\n                int ll = x - i + 1;\n                int rr = x - i + radius;\n                \n                ans[rr + 1] --;\n                ans[ll] ++;\n                \n                // right part of the loop\n                int num_loop_nodes = y - x - 1;\n                int covered_nodes = rr - ll + 1;\n                int rem_nodes = num_loop_nodes - covered_nodes;\n                \n                if(rem_nodes > 0) {\n                    int lly = x - i + 1 + 1;\n                    int rry = x - i + 1 + rem_nodes + 1;\n                \n                    ans[lly] ++;\n                    ans[rry] --;\n                }\n                \n                    \n                // i to nodes >= y crossing the bridge\n                \n                int l = (x - i + 1); // time to reach y\n                int r = (l + n - y);\n                ans[l] ++;\n                ans[r + 1] --;\n                \n                // for(auto it: ans)  {\n                //     cout << it << " ";\n                // }\n                // cout << endl;\n                \n            } else if(i >= y) {\n                // right side of the loop\n                // this is pretty simple case\n                \n                // increment each distance from 1 to n - i;\n                \n                if(i == n) continue;\n                \n                ans[1] ++;\n                ans[n - i + 1] --;\n                \n            } else {\n                \n                // cout << "fuck " << i << endl;\n                \n                // most complex is in the middle of the loop.\n                // part 1 => count contributions after the right end of the loop\n                // find minimal distance between node i and node y.\n                \n                \n                int l = min(i - x + 1, y - i);\n                int r = l + n - y;\n                \n                ans[l] ++;\n                ans[r + 1] --;\n                \n                \n                // part 2 => count contributions within the loop.\n                \n                // simple case.\n                if(i >= x + radius) {\n                    int l = 1;\n                    int r = y - 1 - i;\n                \n                    \n                    ans[l] ++;\n                    ans[r + 1] --;\n                } else {\n                    // hardest.\n                    \n                    \n                    int l = 1;\n                    int r = min(y - 1, i + radius) - i;\n                    \n                    // i to i + radius is covered.\n                    \n                    ans[l] ++;\n                    \n                    ans[r + 1] --;\n                    \n                    int diff = (y - i) - (r + 1); // these nodes have to be covered.\n                    \n                    if(diff > 0) {\n                        l = i - x + 1 + 1;\n                        r = i - x + 1 + diff;\n                        ans[l] ++;\n                        ans[r + 1] --;\n                    }\n                    \n                    \n                }\n            }\n        }\n        \n        for(int i = 1; i <= n; i ++) {\n            ans [i] += ans[i - 1];\n        }\n        \n        vector<long long> v;\n        for(int i = 1; i <= n; i ++) v.push_back(2 * ans[i]);\n        \n        return v;\n    }\n};\n```
['C++']