O(n) Line Sweep Python
Time: O(n)\nSpace: O(n)\n\ndef countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n    x,y = sorted([x, y])\n\n    aggr = [0]*(n+1)\n    def addRange(l, r
**Time: O(n)\nSpace: O(n)**\n```\ndef countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n    x,y = sorted([x, y])\n\n    aggr = [0]*(n+1)\n    def addRange(l, r):\n        if r < l: return\n        aggr[r] += 1\n        aggr[l-1] -= 1\n    \n    if y - x <= 1:\n        for i in range(1, n):\n            addRange(1, n-i)\n    else:\n        cycle_path = (y - x)//2\n        forward_path = (y - x + 1)//2\n        for i in range(1, n):\n            if i < (y+x)//2:\n                if i < x:\n                    addRange(1, (x-i)+cycle_path)\n                else:\n                    addRange(abs(i-x)+1, cycle_path)\n                addRange(max(x-i, 0)+1, max(x-i, 0)+forward_path)\n                addRange(abs(i-x)+1+1, abs(i-x)+1 + n-y)\n            else:\n                addRange(1, n-i)\n    \n    res = []\n    curr = 0\n    for i in range(n, 0, -1):\n        curr += aggr[i] + aggr[i]\n        res.append(curr)\n    return reversed(res)\n```
['Graph', 'Line Sweep', 'Prefix Sum', 'Python']