☕ Java solution
![Screenshot_4.png](https://assets.leetcode.com/users/images/d1376a79-e1d8-4123-be81-79f32f83db7b_1737007731.7817147.png)

```java []
class Solution {
    public long[] countOfPairs(int n, int x, int y) {
        long[] result = new long[n];
        boolean isLineOnly = false;

        if (x > y) {
            int temp = x;
            x = y;
            y = temp;
        }

        int circleLength = 0;
        int lineLength = 0;

        if (x != y && y - x > 1) {
            int a = x;
            int b = n - y + 1;
            lineLength = a + b;
        } else {
            isLineOnly = true;
            lineLength = n;
        }

        for (int d = 1; d <= lineLength; d++) {
            result[d - 1] = (lineLength - d) * 2;
        }

        if (!isLineOnly) {
            for (int i = 1; i < x; i++) {
                result[x - i] -= 2;
            }
            result[0] -= 2;
            for (int i = y + 1; i <= n; i++) {
                result[i - y] -= 2;
            }
        }

        if (isLineOnly) {
            return result;
        }

        long[] circleDP = new long[n];
        long[] prefixSum = new long[n];

        if (x != y && y - x > 1) {
            int l = y - x + 1;
            circleLength = l;
            int half = (l - 1) / 2;

            for (int i = 0; i < half; i++) {
                circleDP[i] = l * 2;
                result[i] += circleDP[i];
            }

            if ((l - 1) % 2 == 1) {
                circleDP[half] += l;
                result[half] += l;
            }

            for (int i = 0; i <= half; i++) {
                circleDP[i] /= l;
            }

            long sum = 0;
            for (int i = 0; i < n; i++) {
                prefixSum[i] = circleDP[i] + sum;
                sum = prefixSum[i];
            }
        }

        if (x > 1) {
            int len = x - 1;
            for (int i = n - 1; i >= 0; i--) {
                int left = i - len;
                int right = i - 1;
                if (right < 0) break;
                result[i] += rangeSum(prefixSum, left, right) * 2;
            }
        }

        if (y < n) {
            int len = n - y;
            for (int i = n - 1; i >= 0; i--) {
                int left = i - len;
                int right = i - 1;
                if (right < 0) break;
                result[i] += rangeSum(prefixSum, left, right) * 2;
            }
        }

        return result;
    }

    private long rangeSum(long[] prefix, int l, int r) {
        long pre = l - 1 >= 0 ? prefix[l - 1] : 0;
        return prefix[r] - pre;
    }
}
```
['Java']