Only sum "ranges". Time O(n). Space O(1)
\nclass Solution:\n    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n        if x == y:\n            return range((n-1)*2, -1, -2)\n        if x
```\nclass Solution:\n    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:\n        if x == y:\n            return range((n-1)*2, -1, -2)\n        if x > y:\n            y, x = x, y\n        l, m, r = x-1, y-x+1, n-y\n        m1 = m//2\n        m2 = m-m1\n    \n        line = (range((l+r+1)*2, -1, -2), range((l+m2-1)*2, -1, -2), range((l+m1)*2, -1, -2),\n                range((r+m2-1)*2, -1, -2), range((r+m1)*2, -1, -2),\n                range(l*2, -1, -2), range((l+1)*2, -1, -2), range(r*2, -1, -2), range((r+1)*2, -1, -2),\n                range(m1*2, -1, -2), range(m2*2, -1, -2), range((m1-1)*2, -1, -2), range((m2-1)*2, -1, -2))\n        cycle = repeat(m*2, (m-1)//2)\n\n        ans = [sum(k[:6])-sum(k[6:]) for k in zip_longest(cycle, *line, fillvalue = 0)]\n        ans[0] += 2\n        ans[m1] += 2 * (m1 != m2)\n        ans[m//2-1] += m * (m%2 == 0)\n        return ans + [0]*(n-len(ans))\n```
['Python3']