[Python] 3 Cases
There are 2 lines and 1 cycle:\n\n\n\n3 cases:\n1. Both ends on the lines (but not on the cycle).\n2. Both ends on the cycle.\n3. One end on the lines and the o
There are 2 lines and 1 cycle:\n\n![Weekly Contest 381 Q4.drawio.png](https://assets.leetcode.com/users/images/56ed4978-7986-4624-b832-dea6340d59c8_1705809828.4879057.png)\n\n3 cases:\n1. Both ends on the lines (but not on the cycle).\n2. Both ends on the cycle.\n3. One end on the lines and the other end on the cycle.\n\nSpecial cases of no cycle are handled separately. \n\nTime complexity: $$O(n)$$\n\n\n# Code\n```python3\nclass Solution:\n    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n        res = [0] * n\n        if abs(x - y) <= 1:  # no cycle\n            for k in range(1, n):\n                res[k-1] += n - k\n            for i in range(n): res[i] *= 2\n            return res\n\n        if x > y: x, y = y, x\n        n1, nc, n2 = x - 1, y - x + 1 , n - y\n\n        def flc(k, nc, nl): # ends on line and cycle\n            p = k + 1  # num of points\n            t = 1 <= p - 1 <= nl\n            t += nc % 2 == 0 and 1 <= p - (nc // 2 + 1) <= nl\n            t += max(0, min((nc+1)//2, p-1) - max(2, p-nl) + 1) * 2\n            return t\n        \n        for k in range(1, n):\n            # both ends on lines\n            if k < n1 + n2 + 2:\n                res[k-1] += n1 + n2 + 2 - k\n                res[k-1] -= (k == 1) + (1 <= k <= n1) + (1 <= k-1 <= n1) + (1 <= k <= n2) + (1 <= k-1 <= n2)\n\n            # both ends on cycle\n            if k <= (nc - 1) // 2:\n                res[k-1] += nc\n            elif nc % 2 == 0 and k == nc // 2:\n                res[k-1] += nc // 2\n\n            # ends on line and cycle\n            res[k-1] += flc(k, nc, n1) + flc(k, nc, n2)\n            \n            if res[k-1] == 0: break\n        \n        for i in range(n): res[i] *= 2\n        return res\n```
['Python3']