Algorithms
Hard
3017
3310
Count the Number of Houses at a Certain Distance II
count-the-number-of-houses-at-a-certain-distance-ii
"""
You are given three positive integers n, x, and y.
In a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.
For each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house1, house2) such that the minimum number of streets that need to be traveled to reach house2 from house1 is k.
Return a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.
Note that x and y can be equal.

Example 1:


Input: n = 3, x = 1, y = 3
Output: [6,0,0]
Explanation: Let's look at each pair of houses:
- For the pair (1, 2), we can go from house 1 to house 2 directly.
- For the pair (2, 1), we can go from house 2 to house 1 directly.
- For the pair (1, 3), we can go from house 1 to house 3 directly.
- For the pair (3, 1), we can go from house 3 to house 1 directly.
- For the pair (2, 3), we can go from house 2 to house 3 directly.
- For the pair (3, 2), we can go from house 3 to house 2 directly.

Example 2:


Input: n = 5, x = 2, y = 4
Output: [10,8,2,0,0]
Explanation: For each distance k the pairs are:
- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).
- For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).
- For k == 3, the pairs are (1, 5), and (5, 1).
- For k == 4 and k == 5, there are no pairs.

Example 3:


Input: n = 4, x = 1, y = 1
Output: [6,4,2,0]
Explanation: For each distance k the pairs are:
- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).
- For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).
- For k == 3, the pairs are (1, 4), and (4, 1).
- For k == 4, there are no pairs.


Constraints:

2 <= n <= 105
1 <= x, y <= n
"""
class Solution:
    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:
        
You are given three positive integers n, x, and y.
In a city, there exist houses numbered 1 to n connected by n streets. There is a street connecting the house numbered i with the house numbered i + 1 for all 1 <= i <= n - 1 . An additional street connects the house numbered x with the house numbered y.
For each k, such that 1 <= k <= n, you need to find the number of pairs of houses (house1, house2) such that the minimum number of streets that need to be traveled to reach house2 from house1 is k.
Return a 1-indexed array result of length n where result[k] represents the total number of pairs of houses such that the minimum streets required to reach one house from the other is k.
Note that x and y can be equal.

Example 1:


Input: n = 3, x = 1, y = 3
Output: [6,0,0]
Explanation: Let's look at each pair of houses:
- For the pair (1, 2), we can go from house 1 to house 2 directly.
- For the pair (2, 1), we can go from house 2 to house 1 directly.
- For the pair (1, 3), we can go from house 1 to house 3 directly.
- For the pair (3, 1), we can go from house 3 to house 1 directly.
- For the pair (2, 3), we can go from house 2 to house 3 directly.
- For the pair (3, 2), we can go from house 3 to house 2 directly.

Example 2:


Input: n = 5, x = 2, y = 4
Output: [10,8,2,0,0]
Explanation: For each distance k the pairs are:
- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (2, 4), (4, 2), (3, 4), (4, 3), (4, 5), and (5, 4).
- For k == 2, the pairs are (1, 3), (3, 1), (1, 4), (4, 1), (2, 5), (5, 2), (3, 5), and (5, 3).
- For k == 3, the pairs are (1, 5), and (5, 1).
- For k == 4 and k == 5, there are no pairs.

Example 3:


Input: n = 4, x = 1, y = 1
Output: [6,4,2,0]
Explanation: For each distance k the pairs are:
- For k == 1, the pairs are (1, 2), (2, 1), (2, 3), (3, 2), (3, 4), and (4, 3).
- For k == 2, the pairs are (1, 3), (3, 1), (2, 4), and (4, 2).
- For k == 3, the pairs are (1, 4), and (4, 1).
- For k == 4, there are no pairs.


Constraints:

2 <= n <= 105
1 <= x, y <= n


Please complete the code below to solve above prblem:
```python
class Solution:
    def countOfPairs(self, n: int, x: int, y: int) -> List[int]:
        
```

my_solution = Solution()

test_input = { "n": 3, "x": 1, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [6,0,0]

test_input = { "n": 5, "x": 2, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]

test_input = { "n": 4, "x": 1, "y": 1 }
assert my_solution.countOfPairs(**test_input) == [6,4,2,0]

test_input = { "n": 2, "x": 1, "y": 1 }
assert my_solution.countOfPairs(**test_input) == [2,0]

test_input = { "n": 2, "x": 1, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [2,0]

test_input = { "n": 2, "x": 2, "y": 1 }
assert my_solution.countOfPairs(**test_input) == [2,0]

test_input = { "n": 2, "x": 2, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [2,0]

test_input = { "n": 3, "x": 1, "y": 1 }
assert my_solution.countOfPairs(**test_input) == [4,2,0]

test_input = { "n": 3, "x": 1, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [4,2,0]

test_input = { "n": 3, "x": 2, "y": 1 }
assert my_solution.countOfPairs(**test_input) == [4,2,0]

test_input = { "n": 3, "x": 2, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [4,2,0]

test_input = { "n": 3, "x": 2, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [4,2,0]

test_input = { "n": 3, "x": 3, "y": 1 }
assert my_solution.countOfPairs(**test_input) == [6,0,0]

test_input = { "n": 3, "x": 3, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [4,2,0]

test_input = { "n": 3, "x": 3, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [4,2,0]

test_input = { "n": 4, "x": 1, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [6,4,2,0]

test_input = { "n": 4, "x": 1, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [8,4,0,0]

test_input = { "n": 4, "x": 1, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [8,4,0,0]

test_input = { "n": 4, "x": 2, "y": 1 }
assert my_solution.countOfPairs(**test_input) == [6,4,2,0]

test_input = { "n": 4, "x": 2, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [6,4,2,0]

test_input = { "n": 4, "x": 2, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [6,4,2,0]

test_input = { "n": 4, "x": 2, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [8,4,0,0]

test_input = { "n": 4, "x": 3, "y": 1 }
assert my_solution.countOfPairs(**test_input) == [8,4,0,0]

test_input = { "n": 4, "x": 3, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [6,4,2,0]

test_input = { "n": 4, "x": 3, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [6,4,2,0]

test_input = { "n": 4, "x": 3, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [6,4,2,0]

test_input = { "n": 4, "x": 4, "y": 1 }
assert my_solution.countOfPairs(**test_input) == [8,4,0,0]

test_input = { "n": 4, "x": 4, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [8,4,0,0]

test_input = { "n": 4, "x": 4, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [6,4,2,0]

test_input = { "n": 4, "x": 4, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [6,4,2,0]

test_input = { "n": 5, "x": 1, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]

test_input = { "n": 5, "x": 1, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]

test_input = { "n": 5, "x": 2, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]

test_input = { "n": 5, "x": 2, "y": 5 }
assert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]

test_input = { "n": 5, "x": 3, "y": 5 }
assert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]

test_input = { "n": 5, "x": 4, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [10,8,2,0,0]

test_input = { "n": 5, "x": 4, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]

test_input = { "n": 5, "x": 5, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [10,6,4,0,0]

test_input = { "n": 5, "x": 5, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]

test_input = { "n": 5, "x": 5, "y": 5 }
assert my_solution.countOfPairs(**test_input) == [8,6,4,2,0]

test_input = { "n": 6, "x": 1, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]

test_input = { "n": 6, "x": 1, "y": 5 }
assert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]

test_input = { "n": 6, "x": 1, "y": 6 }
assert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]

test_input = { "n": 6, "x": 3, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]

test_input = { "n": 6, "x": 3, "y": 5 }
assert my_solution.countOfPairs(**test_input) == [12,10,6,2,0,0]

test_input = { "n": 6, "x": 4, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]

test_input = { "n": 6, "x": 4, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]

test_input = { "n": 6, "x": 4, "y": 5 }
assert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]

test_input = { "n": 6, "x": 4, "y": 6 }
assert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]

test_input = { "n": 6, "x": 5, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [12,12,6,0,0,0]

test_input = { "n": 6, "x": 5, "y": 5 }
assert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]

test_input = { "n": 6, "x": 6, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [12,14,4,0,0,0]

test_input = { "n": 6, "x": 6, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [12,8,6,4,0,0]

test_input = { "n": 6, "x": 6, "y": 5 }
assert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]

test_input = { "n": 6, "x": 6, "y": 6 }
assert my_solution.countOfPairs(**test_input) == [10,8,6,4,2,0]

test_input = { "n": 7, "x": 1, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [14,14,14,0,0,0,0]

test_input = { "n": 7, "x": 2, "y": 6 }
assert my_solution.countOfPairs(**test_input) == [14,18,10,0,0,0,0]

test_input = { "n": 7, "x": 3, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]

test_input = { "n": 7, "x": 3, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]

test_input = { "n": 7, "x": 3, "y": 6 }
assert my_solution.countOfPairs(**test_input) == [14,14,10,4,0,0,0]

test_input = { "n": 7, "x": 4, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]

test_input = { "n": 7, "x": 4, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]

test_input = { "n": 7, "x": 4, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [14,12,8,6,2,0,0]

test_input = { "n": 7, "x": 5, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [14,12,10,4,2,0,0]

test_input = { "n": 7, "x": 5, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]

test_input = { "n": 7, "x": 5, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [14,10,8,6,4,0,0]

test_input = { "n": 7, "x": 6, "y": 6 }
assert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]

test_input = { "n": 7, "x": 6, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [12,10,8,6,4,2,0]

test_input = { "n": 7, "x": 7, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [14,12,8,6,2,0,0]

test_input = { "n": 8, "x": 1, "y": 2 }
assert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]

test_input = { "n": 8, "x": 2, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [16,20,16,4,0,0,0,0]

test_input = { "n": 8, "x": 3, "y": 5 }
assert my_solution.countOfPairs(**test_input) == [16,14,12,8,4,2,0,0]

test_input = { "n": 8, "x": 3, "y": 6 }
assert my_solution.countOfPairs(**test_input) == [16,16,14,8,2,0,0,0]

test_input = { "n": 8, "x": 4, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]

test_input = { "n": 8, "x": 4, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]

test_input = { "n": 8, "x": 4, "y": 8 }
assert my_solution.countOfPairs(**test_input) == [16,18,10,8,4,0,0,0]

test_input = { "n": 8, "x": 5, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [16,14,12,8,4,2,0,0]

test_input = { "n": 8, "x": 5, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [16,14,10,8,6,2,0,0]

test_input = { "n": 8, "x": 6, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [16,16,14,8,2,0,0,0]

test_input = { "n": 8, "x": 6, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]

test_input = { "n": 8, "x": 6, "y": 8 }
assert my_solution.countOfPairs(**test_input) == [16,12,10,8,6,4,0,0]

test_input = { "n": 8, "x": 7, "y": 8 }
assert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]

test_input = { "n": 8, "x": 8, "y": 1 }
assert my_solution.countOfPairs(**test_input) == [16,16,16,8,0,0,0,0]

test_input = { "n": 8, "x": 8, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]

test_input = { "n": 8, "x": 8, "y": 8 }
assert my_solution.countOfPairs(**test_input) == [14,12,10,8,6,4,2,0]

test_input = { "n": 9, "x": 1, "y": 3 }
assert my_solution.countOfPairs(**test_input) == [18,14,12,10,8,6,4,0,0]

test_input = { "n": 9, "x": 4, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]

test_input = { "n": 9, "x": 4, "y": 6 }
assert my_solution.countOfPairs(**test_input) == [18,16,14,12,6,4,2,0,0]

test_input = { "n": 9, "x": 4, "y": 9 }
assert my_solution.countOfPairs(**test_input) == [18,20,16,10,6,2,0,0,0]

test_input = { "n": 9, "x": 5, "y": 5 }
assert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]

test_input = { "n": 9, "x": 5, "y": 9 }
assert my_solution.countOfPairs(**test_input) == [18,20,12,10,8,4,0,0,0]

test_input = { "n": 9, "x": 6, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]

test_input = { "n": 9, "x": 7, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]

test_input = { "n": 9, "x": 8, "y": 4 }
assert my_solution.countOfPairs(**test_input) == [18,22,16,10,6,0,0,0,0]

test_input = { "n": 9, "x": 8, "y": 6 }
assert my_solution.countOfPairs(**test_input) == [18,16,12,10,8,6,2,0,0]

test_input = { "n": 9, "x": 8, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]

test_input = { "n": 9, "x": 8, "y": 9 }
assert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]

test_input = { "n": 9, "x": 9, "y": 5 }
assert my_solution.countOfPairs(**test_input) == [18,20,12,10,8,4,0,0,0]

test_input = { "n": 9, "x": 9, "y": 7 }
assert my_solution.countOfPairs(**test_input) == [18,14,12,10,8,6,4,0,0]

test_input = { "n": 9, "x": 9, "y": 8 }
assert my_solution.countOfPairs(**test_input) == [16,14,12,10,8,6,4,2,0]