beautiful-towers-ii

Beautiful Towers II

Prompt:
"""
给你一个长度为 n 下标从 0 开始的整数数组 maxHeights 。

你的任务是在坐标轴上建 n 座塔。第 i 座塔的下标为 i ，高度为 heights[i] 。

如果以下条件满足，我们称这些塔是 美丽 的：

 1. 1 <= heights[i] <= maxHeights[i]
 2. heights 是一个 山状 数组。

如果存在下标 i 满足以下条件，那么我们称数组 heights 是一个 山状 数组：

 * 对于所有 0 < j <= i ，都有 heights[j - 1] <= heights[j]
 * 对于所有 i <= k < n - 1 ，都有 heights[k + 1] <= heights[k]

请你返回满足 美丽塔 要求的方案中，高度和的最大值 。

示例 1：

输入：maxHeights = [5,3,4,1,1]
输出：13
解释：和最大的美丽塔方案为 heights = [5,3,3,1,1] ，这是一个美丽塔方案，因为：
- 1 <= heights[i] <= maxHeights[i]
- heights 是个山状数组，峰值在 i = 0 处。
13 是所有美丽塔方案中的最大高度和。

示例 2：

输入：maxHeights = [6,5,3,9,2,7]
输出：22
解释： 和最大的美丽塔方案为 heights = [3,3,3,9,2,2] ，这是一个美丽塔方案，因为：
- 1 <= heights[i] <= maxHeights[i]
- heights 是个山状数组，峰值在 i = 3 处。
22 是所有美丽塔方案中的最大高度和。

示例 3：

输入：maxHeights = [3,2,5,5,2,3]
输出：18
解释：和最大的美丽塔方案为 heights = [2,2,5,5,2,2] ，这是一个美丽塔方案，因为：
- 1 <= heights[i] <= maxHeights[i]
- heights 是个山状数组，最大值在 i = 2 处。
注意，在这个方案中，i = 3 也是一个峰值。
18 是所有美丽塔方案中的最大高度和。

提示：

 * 1 <= n == maxHeights <= 105
 * 1 <= maxHeights[i] <= 109
"""
class Solution:
    def maximumSumOfHeights(self, maxHeights: List[int]) -> int:

给你一个长度为 n 下标从 0 开始的整数数组 maxHeights 。

你的任务是在坐标轴上建 n 座塔。第 i 座塔的下标为 i ，高度为 heights[i] 。

如果以下条件满足，我们称这些塔是 美丽 的：

 1. 1 <= heights[i] <= maxHeights[i]
 2. heights 是一个 山状 数组。

如果存在下标 i 满足以下条件，那么我们称数组 heights 是一个 山状 数组：

 * 对于所有 0 < j <= i ，都有 heights[j - 1] <= heights[j]
 * 对于所有 i <= k < n - 1 ，都有 heights[k + 1] <= heights[k]

请你返回满足 美丽塔 要求的方案中，高度和的最大值 。

示例 1：

输入：maxHeights = [5,3,4,1,1]
输出：13
解释：和最大的美丽塔方案为 heights = [5,3,3,1,1] ，这是一个美丽塔方案，因为：
- 1 <= heights[i] <= maxHeights[i]
- heights 是个山状数组，峰值在 i = 0 处。
13 是所有美丽塔方案中的最大高度和。

示例 2：

输入：maxHeights = [6,5,3,9,2,7]
输出：22
解释： 和最大的美丽塔方案为 heights = [3,3,3,9,2,2] ，这是一个美丽塔方案，因为：
- 1 <= heights[i] <= maxHeights[i]
- heights 是个山状数组，峰值在 i = 3 处。
22 是所有美丽塔方案中的最大高度和。

示例 3：

输入：maxHeights = [3,2,5,5,2,3]
输出：18
解释：和最大的美丽塔方案为 heights = [2,2,5,5,2,2] ，这是一个美丽塔方案，因为：
- 1 <= heights[i] <= maxHeights[i]
- heights 是个山状数组，最大值在 i = 2 处。
注意，在这个方案中，i = 3 也是一个峰值。
18 是所有美丽塔方案中的最大高度和。

提示：

 * 1 <= n == maxHeights <= 105
 * 1 <= maxHeights[i] <= 109

请完成下面的代码来解决上述问题:
```python
class Solution:
    def maximumSumOfHeights(self, maxHeights: List[int]) -> int:

```

my_solution = Solution()

test_input = { "maxHeights": [5,3,4,1,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 13

test_input = { "maxHeights": [6,5,3,9,2,7] }
assert my_solution.maximumSumOfHeights(**test_input) == 22

test_input = { "maxHeights": [3,2,5,5,2,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 18

test_input = { "maxHeights": [1000000000] }
assert my_solution.maximumSumOfHeights(**test_input) == 1000000000

test_input = { "maxHeights": [1] }
assert my_solution.maximumSumOfHeights(**test_input) == 1

test_input = { "maxHeights": [352939501] }
assert my_solution.maximumSumOfHeights(**test_input) == 352939501

test_input = { "maxHeights": [1,1000000000] }
assert my_solution.maximumSumOfHeights(**test_input) == 1000000001

test_input = { "maxHeights": [1000000000,1000000000] }
assert my_solution.maximumSumOfHeights(**test_input) == 2000000000

test_input = { "maxHeights": [999999999,1000000000] }
assert my_solution.maximumSumOfHeights(**test_input) == 1999999999

test_input = { "maxHeights": [1000000000,999999999] }
assert my_solution.maximumSumOfHeights(**test_input) == 1999999999

test_input = { "maxHeights": [2,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 3

test_input = { "maxHeights": [26,30,30] }
assert my_solution.maximumSumOfHeights(**test_input) == 86

test_input = { "maxHeights": [1000000000,1000000000,1000000000] }
assert my_solution.maximumSumOfHeights(**test_input) == 3000000000

test_input = { "maxHeights": [999999999,1000000000,999999999] }
assert my_solution.maximumSumOfHeights(**test_input) == 2999999998

test_input = { "maxHeights": [1000000000,999999999,999999998] }
assert my_solution.maximumSumOfHeights(**test_input) == 2999999997

test_input = { "maxHeights": [999999998,999999999,1000000000] }
assert my_solution.maximumSumOfHeights(**test_input) == 2999999997

test_input = { "maxHeights": [1,1,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 3

test_input = { "maxHeights": [1,1,5,6,2,2,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 19

test_input = { "maxHeights": [3,5,3,5,1,5,4,4,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 22

test_input = { "maxHeights": [4,2,4,2,1,5,4,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 19

test_input = { "maxHeights": [5,3,2,4,6,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 21

test_input = { "maxHeights": [6,5,2,1,5,4,4,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 19

test_input = { "maxHeights": [4,3,2,4,6,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 19

test_input = { "maxHeights": [2,6,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 13

test_input = { "maxHeights": [6,5,3,4,6,1,2,3,2,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 25

test_input = { "maxHeights": [2,1,6,2,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 12

test_input = { "maxHeights": [6,5,1,5,4,3,4,2,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 22

test_input = { "maxHeights": [1,1,6,4,2,2,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 18

test_input = { "maxHeights": [2,2,2,5,6,1,4,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 20

test_input = { "maxHeights": [3,1,5,3,6,5,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 20

test_input = { "maxHeights": [1,4,6,1,4,6,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 15

test_input = { "maxHeights": [4,4,2,3,3,2,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 18

test_input = { "maxHeights": [4,4,1,6,2,1,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 13

test_input = { "maxHeights": [6,3,3,5,4,1,5,2,4,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 23

test_input = { "maxHeights": [3,2,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 8

test_input = { "maxHeights": [3,1,4,3,2,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 13

test_input = { "maxHeights": [3,1,4,5,4,4,6,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 28

test_input = { "maxHeights": [1,2,5,5,5,6,5,6,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 37

test_input = { "maxHeights": [6,1,1,6,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 14

test_input = { "maxHeights": [1,6,6,6,2,6,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 25

test_input = { "maxHeights": [4,1,4,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 11

test_input = { "maxHeights": [1,5,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 12

test_input = { "maxHeights": [1,4,4,5,6,6,2,4,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 31

test_input = { "maxHeights": [2,6,6,4,6,1,6,2,1,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 27

test_input = { "maxHeights": [2,4,6,4,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 20

test_input = { "maxHeights": [5,2,6,1,6,6,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 21

test_input = { "maxHeights": [3,6,1,4,5,5,2,5,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 22

test_input = { "maxHeights": [3,2,6,5,6,6,2,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 29

test_input = { "maxHeights": [1,4,2,1,6,3,2,1,2,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 18

test_input = { "maxHeights": [3,3,4,3,5,6,1,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 25

test_input = { "maxHeights": [4,4,2,4,1,4,5,5,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 25

test_input = { "maxHeights": [6,5,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 14

test_input = { "maxHeights": [2,2,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 8

test_input = { "maxHeights": [6,2,6,5,3,6,2,5,1,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 27

test_input = { "maxHeights": [4,6,3,4,6,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 25

test_input = { "maxHeights": [6,4,6,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 17

test_input = { "maxHeights": [4,3,5,1,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 13

test_input = { "maxHeights": [3,5,6,6,3,6,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 27

test_input = { "maxHeights": [6,1,6,5,5,1,1,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 21

test_input = { "maxHeights": [4,3,3,1,5,3,3,6,3,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 25

test_input = { "maxHeights": [1,4,6,1,6,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 14

test_input = { "maxHeights": [6,2,1,4,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 11

test_input = { "maxHeights": [1,4,6,4,2,6,6,5,5,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 36

test_input = { "maxHeights": [6,1,2,1,3,3,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 12

test_input = { "maxHeights": [6,4,3,3,6,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 20

test_input = { "maxHeights": [3,1,4,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 10

test_input = { "maxHeights": [2,4,1,6,5,3,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 19

test_input = { "maxHeights": [2,5,5,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 18

test_input = { "maxHeights": [5,2,1,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 9

test_input = { "maxHeights": [5,5,3,3,3,3,1,3,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 25

test_input = { "maxHeights": [5,6,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 16

test_input = { "maxHeights": [1,1,6,2,3,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 13

test_input = { "maxHeights": [2,4,2,2,2,6,1,4,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 19

test_input = { "maxHeights": [6,2,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 10

test_input = { "maxHeights": [5,6,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 12

test_input = { "maxHeights": [6,6,4,3,6,3,6,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 31

test_input = { "maxHeights": [3,2,4,2,3,2,3,6,1,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 23

test_input = { "maxHeights": [6,3,3,3,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 18

test_input = { "maxHeights": [5,5,2,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 13

test_input = { "maxHeights": [3,5,4,5,5,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 25

test_input = { "maxHeights": [3,4,6,3,1,5,5,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 20

test_input = { "maxHeights": [4,3,6,6,5,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 28

test_input = { "maxHeights": [3,5,5,2,2,3,4,1,1,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 24

test_input = { "maxHeights": [5,6,1,2,5,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 15

test_input = { "maxHeights": [6,3,3,6,4,4,2,1,6,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 28

test_input = { "maxHeights": [1,5,3,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 13

test_input = { "maxHeights": [5,2,3,5,3,2,5,5,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 28

test_input = { "maxHeights": [5,4,2,6,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 18

test_input = { "maxHeights": [5,5,4,4,1,4,3,1,4,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 24

test_input = { "maxHeights": [4,4,4,6,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 22

test_input = { "maxHeights": [3,3,3,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 14

test_input = { "maxHeights": [2,2,2] }
assert my_solution.maximumSumOfHeights(**test_input) == 6

test_input = { "maxHeights": [4,4,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 13

test_input = { "maxHeights": [1,1,6,5,4,6,6,2,5] }
assert my_solution.maximumSumOfHeights(**test_input) == 30

test_input = { "maxHeights": [6,6,3,3,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 21

test_input = { "maxHeights": [1,3,2,5,2,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 13

test_input = { "maxHeights": [1,5,3,3,1,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 14

test_input = { "maxHeights": [4,2,4,3] }
assert my_solution.maximumSumOfHeights(**test_input) == 11

test_input = { "maxHeights": [6,4,5,1,2,3,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 18

test_input = { "maxHeights": [4,4,1,6,1,4] }
assert my_solution.maximumSumOfHeights(**test_input) == 12


count-valid-paths-in-a-tree

Count Valid Paths in a Tree

Prompt:
"""
给你一棵 n 个节点的无向树，节点编号为 1 到 n 。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ，其中 edges[i] = [ui, vi] 表示节点 ui 和 vi 在树中有一条边。

请你返回树中的 合法路径数目 。

如果在节点 a 到节点 b 之间 恰好有一个 节点的编号是质数，那么我们称路径 (a, b) 是 合法的 。

注意：

 * 路径 (a, b) 指的是一条从节点 a 开始到节点 b 结束的一个节点序列，序列中的节点 互不相同 ，且相邻节点之间在树上有一条边。
 * 路径 (a, b) 和路径 (b, a) 视为 同一条 路径，且只计入答案 一次 。

示例 1：

[https://assets.leetcode.com/uploads/2023/08/27/example1.png]

输入：n = 5, edges = [[1,2],[1,3],[2,4],[2,5]]
输出：4
解释：恰好有一个质数编号的节点路径有：
- (1, 2) 因为路径 1 到 2 只包含一个质数 2 。
- (1, 3) 因为路径 1 到 3 只包含一个质数 3 。
- (1, 4) 因为路径 1 到 4 只包含一个质数 2 。
- (2, 4) 因为路径 2 到 4 只包含一个质数 2 。
只有 4 条合法路径。

示例 2：

[https://assets.leetcode.com/uploads/2023/08/27/example2.png]

输入：n = 6, edges = [[1,2],[1,3],[2,4],[3,5],[3,6]]
输出：6
解释：恰好有一个质数编号的节点路径有：
- (1, 2) 因为路径 1 到 2 只包含一个质数 2 。
- (1, 3) 因为路径 1 到 3 只包含一个质数 3 。
- (1, 4) 因为路径 1 到 4 只包含一个质数 2 。
- (1, 6) 因为路径 1 到 6 只包含一个质数 3 。
- (2, 4) 因为路径 2 到 4 只包含一个质数 2 。
- (3, 6) 因为路径 3 到 6 只包含一个质数 3 。
只有 6 条合法路径。

提示：

 * 1 <= n <= 105
 * edges.length == n - 1
 * edges[i].length == 2
 * 1 <= ui, vi <= n
 * 输入保证 edges 形成一棵合法的树。
"""
class Solution:
    def countPaths(self, n: int, edges: List[List[int]]) -> int:

给你一棵 n 个节点的无向树，节点编号为 1 到 n 。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ，其中 edges[i] = [ui, vi] 表示节点 ui 和 vi 在树中有一条边。

请你返回树中的 合法路径数目 。

如果在节点 a 到节点 b 之间 恰好有一个 节点的编号是质数，那么我们称路径 (a, b) 是 合法的 。

注意：

 * 路径 (a, b) 指的是一条从节点 a 开始到节点 b 结束的一个节点序列，序列中的节点 互不相同 ，且相邻节点之间在树上有一条边。
 * 路径 (a, b) 和路径 (b, a) 视为 同一条 路径，且只计入答案 一次 。

示例 1：

[https://assets.leetcode.com/uploads/2023/08/27/example1.png]

输入：n = 5, edges = [[1,2],[1,3],[2,4],[2,5]]
输出：4
解释：恰好有一个质数编号的节点路径有：
- (1, 2) 因为路径 1 到 2 只包含一个质数 2 。
- (1, 3) 因为路径 1 到 3 只包含一个质数 3 。
- (1, 4) 因为路径 1 到 4 只包含一个质数 2 。
- (2, 4) 因为路径 2 到 4 只包含一个质数 2 。
只有 4 条合法路径。

示例 2：

[https://assets.leetcode.com/uploads/2023/08/27/example2.png]

输入：n = 6, edges = [[1,2],[1,3],[2,4],[3,5],[3,6]]
输出：6
解释：恰好有一个质数编号的节点路径有：
- (1, 2) 因为路径 1 到 2 只包含一个质数 2 。
- (1, 3) 因为路径 1 到 3 只包含一个质数 3 。
- (1, 4) 因为路径 1 到 4 只包含一个质数 2 。
- (1, 6) 因为路径 1 到 6 只包含一个质数 3 。
- (2, 4) 因为路径 2 到 4 只包含一个质数 2 。
- (3, 6) 因为路径 3 到 6 只包含一个质数 3 。
只有 6 条合法路径。

提示：

 * 1 <= n <= 105
 * edges.length == n - 1
 * edges[i].length == 2
 * 1 <= ui, vi <= n
 * 输入保证 edges 形成一棵合法的树。

请完成下面的代码来解决上述问题:
```python
class Solution:
    def countPaths(self, n: int, edges: List[List[int]]) -> int:

```

my_solution = Solution()

test_input = { "n": 5, "edges": [[1,2],[1,3],[2,4],[2,5]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 6, "edges": [[1,2],[1,3],[2,4],[3,5],[3,6]] }
assert my_solution.countPaths(**test_input) == 6

test_input = { "n": 1, "edges": [] }
assert my_solution.countPaths(**test_input) == 0

test_input = { "n": 2, "edges": [[2,1]] }
assert my_solution.countPaths(**test_input) == 1

test_input = { "n": 4, "edges": [[1,2],[4,1],[3,4]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 5, "edges": [[1,3],[4,3],[2,3],[5,2]] }
assert my_solution.countPaths(**test_input) == 3

test_input = { "n": 5, "edges": [[1,5],[2,1],[4,5],[3,2]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 5, "edges": [[2,3],[4,2],[1,3],[5,1]] }
assert my_solution.countPaths(**test_input) == 3

test_input = { "n": 5, "edges": [[4,1],[5,4],[2,1],[3,4]] }
assert my_solution.countPaths(**test_input) == 6

test_input = { "n": 5, "edges": [[3,5],[1,5],[4,3],[2,5]] }
assert my_solution.countPaths(**test_input) == 2

test_input = { "n": 4, "edges": [[2,1],[4,2],[3,2]] }
assert my_solution.countPaths(**test_input) == 3

test_input = { "n": 5, "edges": [[1,4],[2,4],[3,2],[5,4]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 5, "edges": [[5,4],[3,4],[1,4],[2,4]] }
assert my_solution.countPaths(**test_input) == 6

test_input = { "n": 4, "edges": [[3,4],[1,3],[2,4]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 10, "edges": [[10,9],[2,10],[1,10],[3,2],[6,10],[4,3],[8,6],[5,8],[7,6]] }
assert my_solution.countPaths(**test_input) == 16

test_input = { "n": 8, "edges": [[7,2],[6,2],[5,2],[1,2],[4,7],[8,1],[3,6]] }
assert my_solution.countPaths(**test_input) == 7

test_input = { "n": 5, "edges": [[3,2],[4,3],[5,4],[1,4]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 9, "edges": [[7,4],[3,4],[5,4],[1,5],[6,4],[9,5],[8,7],[2,8]] }
assert my_solution.countPaths(**test_input) == 17

test_input = { "n": 9, "edges": [[1,8],[5,8],[4,8],[6,5],[3,1],[9,1],[7,4],[2,8]] }
assert my_solution.countPaths(**test_input) == 21

test_input = { "n": 10, "edges": [[2,9],[7,2],[10,9],[5,7],[4,5],[6,7],[8,2],[1,5],[3,10]] }
assert my_solution.countPaths(**test_input) == 11

test_input = { "n": 8, "edges": [[6,1],[8,1],[3,6],[4,1],[7,3],[2,8],[5,1]] }
assert my_solution.countPaths(**test_input) == 12

test_input = { "n": 10, "edges": [[9,1],[8,9],[5,9],[10,8],[7,5],[2,8],[3,8],[6,7],[4,1]] }
assert my_solution.countPaths(**test_input) == 16

test_input = { "n": 5, "edges": [[5,3],[4,5],[2,5],[1,4]] }
assert my_solution.countPaths(**test_input) == 2

test_input = { "n": 7, "edges": [[7,6],[2,6],[5,2],[3,5],[4,5],[1,6]] }
assert my_solution.countPaths(**test_input) == 5

test_input = { "n": 8, "edges": [[4,5],[8,4],[6,4],[2,5],[1,6],[3,1],[7,8]] }
assert my_solution.countPaths(**test_input) == 12

test_input = { "n": 10, "edges": [[9,6],[5,6],[10,6],[8,5],[4,8],[3,9],[1,3],[2,6],[7,1]] }
assert my_solution.countPaths(**test_input) == 22

test_input = { "n": 5, "edges": [[1,4],[2,4],[5,4],[3,4]] }
assert my_solution.countPaths(**test_input) == 6

test_input = { "n": 10, "edges": [[9,4],[7,9],[10,9],[6,7],[8,7],[2,7],[3,2],[1,9],[5,10]] }
assert my_solution.countPaths(**test_input) == 19

test_input = { "n": 7, "edges": [[4,7],[6,7],[1,7],[3,7],[2,6],[5,6]] }
assert my_solution.countPaths(**test_input) == 8

test_input = { "n": 5, "edges": [[1,4],[2,1],[5,2],[3,1]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 5, "edges": [[4,5],[2,5],[1,4],[3,1]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 10, "edges": [[4,3],[5,3],[1,4],[7,5],[6,3],[8,3],[9,1],[10,8],[2,10]] }
assert my_solution.countPaths(**test_input) == 19

test_input = { "n": 5, "edges": [[1,3],[4,1],[2,1],[5,1]] }
assert my_solution.countPaths(**test_input) == 6

test_input = { "n": 7, "edges": [[5,2],[3,5],[4,5],[1,2],[6,2],[7,2]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 5, "edges": [[3,4],[1,4],[5,3],[2,5]] }
assert my_solution.countPaths(**test_input) == 2

test_input = { "n": 8, "edges": [[1,8],[2,1],[6,8],[3,6],[4,3],[5,8],[7,2]] }
assert my_solution.countPaths(**test_input) == 13

test_input = { "n": 9, "edges": [[2,1],[6,1],[8,2],[9,8],[4,9],[7,9],[3,1],[5,2]] }
assert my_solution.countPaths(**test_input) == 16

test_input = { "n": 5, "edges": [[4,3],[5,4],[1,5],[2,3]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 8, "edges": [[2,4],[3,4],[6,4],[7,3],[8,7],[5,6],[1,5]] }
assert my_solution.countPaths(**test_input) == 10

test_input = { "n": 6, "edges": [[3,6],[1,3],[2,3],[5,2],[4,5]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 10, "edges": [[7,5],[4,7],[10,5],[6,5],[8,6],[2,8],[9,4],[3,10],[1,9]] }
assert my_solution.countPaths(**test_input) == 11

test_input = { "n": 8, "edges": [[3,2],[8,3],[7,3],[6,2],[4,7],[5,6],[1,8]] }
assert my_solution.countPaths(**test_input) == 5

test_input = { "n": 8, "edges": [[2,6],[3,6],[5,2],[1,6],[7,2],[8,1],[4,1]] }
assert my_solution.countPaths(**test_input) == 8

test_input = { "n": 9, "edges": [[3,7],[6,7],[4,7],[1,6],[8,4],[9,1],[2,7],[5,2]] }
assert my_solution.countPaths(**test_input) == 11

test_input = { "n": 6, "edges": [[6,2],[5,6],[1,2],[3,2],[4,3]] }
assert my_solution.countPaths(**test_input) == 5

test_input = { "n": 6, "edges": [[6,2],[1,6],[3,1],[5,3],[4,3]] }
assert my_solution.countPaths(**test_input) == 7

test_input = { "n": 8, "edges": [[2,3],[8,3],[5,3],[6,3],[4,3],[7,8],[1,2]] }
assert my_solution.countPaths(**test_input) == 8

test_input = { "n": 7, "edges": [[4,6],[5,6],[7,6],[3,4],[2,6],[1,5]] }
assert my_solution.countPaths(**test_input) == 11

test_input = { "n": 6, "edges": [[4,2],[5,4],[1,5],[6,1],[3,1]] }
assert my_solution.countPaths(**test_input) == 8

test_input = { "n": 6, "edges": [[4,1],[6,1],[5,4],[3,5],[2,1]] }
assert my_solution.countPaths(**test_input) == 6

test_input = { "n": 7, "edges": [[6,7],[1,6],[4,6],[2,7],[3,2],[5,7]] }
assert my_solution.countPaths(**test_input) == 3

test_input = { "n": 6, "edges": [[4,3],[5,3],[6,5],[2,4],[1,5]] }
assert my_solution.countPaths(**test_input) == 5

test_input = { "n": 10, "edges": [[2,5],[3,5],[10,2],[8,3],[7,5],[4,3],[1,8],[9,5],[6,8]] }
assert my_solution.countPaths(**test_input) == 9

test_input = { "n": 8, "edges": [[2,8],[1,8],[5,2],[4,5],[6,5],[7,2],[3,5]] }
assert my_solution.countPaths(**test_input) == 5

test_input = { "n": 8, "edges": [[7,2],[6,7],[5,7],[8,6],[1,7],[3,5],[4,2]] }
assert my_solution.countPaths(**test_input) == 6

test_input = { "n": 7, "edges": [[5,7],[3,5],[2,7],[4,3],[6,3],[1,4]] }
assert my_solution.countPaths(**test_input) == 5

test_input = { "n": 7, "edges": [[2,3],[1,3],[7,3],[4,1],[6,3],[5,1]] }
assert my_solution.countPaths(**test_input) == 7

test_input = { "n": 7, "edges": [[4,2],[6,4],[1,6],[7,6],[5,2],[3,7]] }
assert my_solution.countPaths(**test_input) == 6

test_input = { "n": 6, "edges": [[3,4],[6,3],[1,4],[5,4],[2,6]] }
assert my_solution.countPaths(**test_input) == 8

test_input = { "n": 10, "edges": [[2,7],[1,2],[8,7],[4,2],[6,8],[10,7],[5,4],[9,8],[3,6]] }
assert my_solution.countPaths(**test_input) == 14

test_input = { "n": 8, "edges": [[6,2],[7,2],[5,6],[8,2],[3,6],[1,8],[4,2]] }
assert my_solution.countPaths(**test_input) == 11

test_input = { "n": 10, "edges": [[9,6],[1,9],[2,1],[8,1],[10,6],[7,6],[3,8],[4,3],[5,3]] }
assert my_solution.countPaths(**test_input) == 21

test_input = { "n": 8, "edges": [[4,6],[1,6],[7,6],[2,1],[8,7],[5,6],[3,5]] }
assert my_solution.countPaths(**test_input) == 13

test_input = { "n": 7, "edges": [[3,7],[6,7],[4,6],[1,3],[5,3],[2,3]] }
assert my_solution.countPaths(**test_input) == 3

test_input = { "n": 10, "edges": [[2,9],[3,9],[8,9],[10,3],[1,9],[4,8],[7,10],[6,1],[5,10]] }
assert my_solution.countPaths(**test_input) == 18

test_input = { "n": 8, "edges": [[5,6],[3,6],[7,5],[4,6],[8,6],[2,3],[1,3]] }
assert my_solution.countPaths(**test_input) == 10

test_input = { "n": 9, "edges": [[9,3],[4,3],[2,9],[7,3],[8,7],[1,7],[5,4],[6,2]] }
assert my_solution.countPaths(**test_input) == 10

test_input = { "n": 6, "edges": [[5,1],[2,1],[4,2],[6,5],[3,4]] }
assert my_solution.countPaths(**test_input) == 7

test_input = { "n": 7, "edges": [[3,6],[2,6],[5,6],[7,2],[1,6],[4,2]] }
assert my_solution.countPaths(**test_input) == 9

test_input = { "n": 5, "edges": [[1,5],[3,5],[4,3],[2,5]] }
assert my_solution.countPaths(**test_input) == 2

test_input = { "n": 8, "edges": [[2,8],[6,2],[1,2],[4,1],[7,2],[3,2],[5,7]] }
assert my_solution.countPaths(**test_input) == 9

test_input = { "n": 9, "edges": [[5,3],[1,3],[7,3],[4,5],[6,7],[8,7],[9,5],[2,5]] }
assert my_solution.countPaths(**test_input) == 7

test_input = { "n": 10, "edges": [[8,10],[3,10],[1,8],[7,8],[6,10],[2,3],[5,8],[9,5],[4,6]] }
assert my_solution.countPaths(**test_input) == 21

test_input = { "n": 10, "edges": [[4,8],[6,8],[9,4],[1,6],[5,8],[2,8],[10,9],[7,6],[3,5]] }
assert my_solution.countPaths(**test_input) == 18

test_input = { "n": 9, "edges": [[4,6],[9,4],[3,6],[7,6],[1,4],[5,9],[2,7],[8,4]] }
assert my_solution.countPaths(**test_input) == 15

test_input = { "n": 7, "edges": [[7,6],[2,6],[1,7],[3,2],[5,2],[4,5]] }
assert my_solution.countPaths(**test_input) == 5

test_input = { "n": 9, "edges": [[1,8],[5,8],[3,8],[2,1],[9,2],[7,1],[6,5],[4,9]] }
assert my_solution.countPaths(**test_input) == 17

test_input = { "n": 7, "edges": [[3,5],[4,3],[6,5],[2,4],[7,3],[1,4]] }
assert my_solution.countPaths(**test_input) == 5

test_input = { "n": 10, "edges": [[5,2],[8,5],[10,5],[3,8],[4,2],[1,4],[9,10],[7,5],[6,8]] }
assert my_solution.countPaths(**test_input) == 12

test_input = { "n": 8, "edges": [[7,4],[1,4],[5,7],[6,1],[8,5],[3,8],[2,6]] }
assert my_solution.countPaths(**test_input) == 8

test_input = { "n": 10, "edges": [[8,2],[7,8],[9,2],[4,2],[6,4],[3,9],[5,4],[1,9],[10,8]] }
assert my_solution.countPaths(**test_input) == 24

test_input = { "n": 8, "edges": [[3,8],[2,8],[1,8],[6,8],[4,3],[7,6],[5,2]] }
assert my_solution.countPaths(**test_input) == 13

test_input = { "n": 9, "edges": [[5,4],[2,4],[9,5],[3,2],[7,3],[1,4],[8,2],[6,4]] }
assert my_solution.countPaths(**test_input) == 14

test_input = { "n": 10, "edges": [[10,8],[5,10],[1,10],[3,10],[7,3],[2,10],[6,8],[9,6],[4,6]] }
assert my_solution.countPaths(**test_input) == 18

test_input = { "n": 9, "edges": [[6,7],[5,7],[8,7],[9,6],[2,5],[4,5],[1,8],[3,6]] }
assert my_solution.countPaths(**test_input) == 11

test_input = { "n": 10, "edges": [[1,6],[9,1],[5,9],[10,6],[4,9],[8,9],[7,8],[2,1],[3,1]] }
assert my_solution.countPaths(**test_input) == 24

test_input = { "n": 8, "edges": [[4,5],[3,4],[6,5],[1,4],[2,3],[8,4],[7,3]] }
assert my_solution.countPaths(**test_input) == 10

test_input = { "n": 7, "edges": [[7,4],[6,4],[2,6],[5,6],[3,2],[1,5]] }
assert my_solution.countPaths(**test_input) == 9

test_input = { "n": 10, "edges": [[3,2],[5,3],[1,2],[9,5],[7,5],[6,3],[4,3],[8,6],[10,1]] }
assert my_solution.countPaths(**test_input) == 8

test_input = { "n": 8, "edges": [[2,8],[5,2],[4,2],[7,4],[3,2],[1,3],[6,3]] }
assert my_solution.countPaths(**test_input) == 7

test_input = { "n": 6, "edges": [[6,3],[2,3],[4,2],[5,2],[1,6]] }
assert my_solution.countPaths(**test_input) == 3

test_input = { "n": 9, "edges": [[7,3],[5,3],[4,3],[9,7],[6,5],[8,3],[2,4],[1,5]] }
assert my_solution.countPaths(**test_input) == 8

test_input = { "n": 5, "edges": [[1,2],[5,1],[4,5],[3,4]] }
assert my_solution.countPaths(**test_input) == 5

test_input = { "n": 9, "edges": [[8,3],[6,8],[2,8],[4,3],[5,4],[7,5],[9,4],[1,5]] }
assert my_solution.countPaths(**test_input) == 15

test_input = { "n": 5, "edges": [[2,1],[4,2],[5,1],[3,2]] }
assert my_solution.countPaths(**test_input) == 4

test_input = { "n": 6, "edges": [[4,2],[6,2],[3,2],[1,6],[5,2]] }
assert my_solution.countPaths(**test_input) == 5

test_input = { "n": 10, "edges": [[10,5],[3,10],[4,3],[8,3],[7,4],[1,7],[6,5],[9,1],[2,5]] }
assert my_solution.countPaths(**test_input) == 14

test_input = { "n": 9, "edges": [[4,7],[6,4],[8,4],[2,8],[5,2],[9,7],[1,6],[3,7]] }
assert my_solution.countPaths(**test_input) == 13

test_input = { "n": 10, "edges": [[7,3],[1,3],[2,3],[10,2],[4,2],[8,1],[9,4],[5,3],[6,3]] }
assert my_solution.countPaths(**test_input) == 10

test_input = { "n": 7, "edges": [[4,7],[2,7],[3,4],[1,7],[6,4],[5,4]] }
assert my_solution.countPaths(**test_input) == 9


sum-of-values-at-indices-with-k-set-bits

Sum of Values at Indices With K Set Bits

Prompt:
"""
给你一个下标从 0 开始的整数数组 nums 和一个整数 k 。

请你用整数形式返回 nums 中的特定元素之 和 ，这些特定元素满足：其对应下标的二进制表示中恰存在 k 个置位。

整数的二进制表示中的 1 就是这个整数的 置位 。

例如，21 的二进制表示为 10101 ，其中有 3 个置位。

示例 1：

输入：nums = [5,10,1,5,2], k = 1
输出：13
解释：下标的二进制表示是：
0 = 0002
1 = 0012
2 = 0102
3 = 0112
4 = 1002
下标 1、2 和 4 在其二进制表示中都存在 k = 1 个置位。
因此，答案为 nums[1] + nums[2] + nums[4] = 13 。

示例 2：

输入：nums = [4,3,2,1], k = 2
输出：1
解释：下标的二进制表示是：
0 = 002
1 = 012
2 = 102
3 = 112
只有下标 3 的二进制表示中存在 k = 2 个置位。
因此，答案为 nums[3] = 1 。

提示：

 * 1 <= nums.length <= 1000
 * 1 <= nums[i] <= 105
 * 0 <= k <= 10
"""
class Solution:
    def sumIndicesWithKSetBits(self, nums: List[int], k: int) -> int:

给你一个下标从 0 开始的整数数组 nums 和一个整数 k 。

请你用整数形式返回 nums 中的特定元素之 和 ，这些特定元素满足：其对应下标的二进制表示中恰存在 k 个置位。

整数的二进制表示中的 1 就是这个整数的 置位 。

例如，21 的二进制表示为 10101 ，其中有 3 个置位。

示例 1：

输入：nums = [5,10,1,5,2], k = 1
输出：13
解释：下标的二进制表示是：
0 = 0002
1 = 0012
2 = 0102
3 = 0112
4 = 1002
下标 1、2 和 4 在其二进制表示中都存在 k = 1 个置位。
因此，答案为 nums[1] + nums[2] + nums[4] = 13 。

示例 2：

输入：nums = [4,3,2,1], k = 2
输出：1
解释：下标的二进制表示是：
0 = 002
1 = 012
2 = 102
3 = 112
只有下标 3 的二进制表示中存在 k = 2 个置位。
因此，答案为 nums[3] = 1 。

提示：

 * 1 <= nums.length <= 1000
 * 1 <= nums[i] <= 105
 * 0 <= k <= 10

请完成下面的代码来解决上述问题:
```python
class Solution:
    def sumIndicesWithKSetBits(self, nums: List[int], k: int) -> int:

```

my_solution = Solution()

test_input = { "nums": [5,10,1,5,2], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 13

test_input = { "nums": [4,3,2,1], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 1

test_input = { "nums": [1], "k": 0 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 1

test_input = { "nums": [100000], "k": 0 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 100000

test_input = { "nums": [2,2], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 2

test_input = { "nums": [2,4], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 4

test_input = { "nums": [2,7], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 7

test_input = { "nums": [3,3], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 3

test_input = { "nums": [3,9], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 9

test_input = { "nums": [4,7], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 7

test_input = { "nums": [4,8], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 8

test_input = { "nums": [6,6], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 6

test_input = { "nums": [7,2], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 2

test_input = { "nums": [7,4], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 4

test_input = { "nums": [8,4], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 4

test_input = { "nums": [8,9], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 9

test_input = { "nums": [9,9], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 9

test_input = { "nums": [15,43], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 43

test_input = { "nums": [35,86], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 86

test_input = { "nums": [36,14], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 14

test_input = { "nums": [47,61], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 61

test_input = { "nums": [60,46], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 46

test_input = { "nums": [70,7], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 7

test_input = { "nums": [1,51,55], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 106

test_input = { "nums": [2,2,5], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 7

test_input = { "nums": [2,3,2], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 5

test_input = { "nums": [3,2,5], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 7

test_input = { "nums": [3,7,5], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 12

test_input = { "nums": [4,5,9], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 14

test_input = { "nums": [5,5,5], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 10

test_input = { "nums": [5,7,7], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 14

test_input = { "nums": [6,2,1], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 3

test_input = { "nums": [6,9,8], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 17

test_input = { "nums": [7,1,2], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 3

test_input = { "nums": [7,9,1], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 10

test_input = { "nums": [8,5,4], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 9

test_input = { "nums": [9,1,6], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 7

test_input = { "nums": [9,3,5], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 8

test_input = { "nums": [57,48,69], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 117

test_input = { "nums": [78,37,59], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 96

test_input = { "nums": [96,71,53], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 124

test_input = { "nums": [900,914,367], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 1281

test_input = { "nums": [1,4,9,2], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 2

test_input = { "nums": [1,5,9,5], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 5

test_input = { "nums": [1,8,5,6], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 13

test_input = { "nums": [2,2,1,2], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 3

test_input = { "nums": [2,4,5,2], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 2

test_input = { "nums": [2,5,8,1], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 13

test_input = { "nums": [2,7,3,9], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 10

test_input = { "nums": [3,5,4,2], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 2

test_input = { "nums": [4,1,6,3], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 3

test_input = { "nums": [6,3,8,8], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 8

test_input = { "nums": [6,6,1,4], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 4

test_input = { "nums": [7,1,9,6], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 6

test_input = { "nums": [7,5,2,1], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 7

test_input = { "nums": [7,5,3,4], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 8

test_input = { "nums": [7,8,6,2], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 14

test_input = { "nums": [8,3,9,8], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 8

test_input = { "nums": [8,7,3,2], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 2

test_input = { "nums": [9,4,2,2], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 6

test_input = { "nums": [9,6,8,8], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 14

test_input = { "nums": [9,7,8,9], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 9

test_input = { "nums": [9,40,73,19], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 19

test_input = { "nums": [41,51,58,2], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 109

test_input = { "nums": [44,96,36,56], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 56

test_input = { "nums": [1,1,3,1,6], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 1

test_input = { "nums": [2,1,1,3,5], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 7

test_input = { "nums": [2,5,4,3,1], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 3

test_input = { "nums": [3,2,7,1,5], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 14

test_input = { "nums": [4,2,8,8,2], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 8

test_input = { "nums": [4,3,7,8,8], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 8

test_input = { "nums": [4,6,2,2,7], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 15

test_input = { "nums": [4,7,5,1,1], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 1

test_input = { "nums": [5,6,6,6,3], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 15

test_input = { "nums": [6,4,8,4,2], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 4

test_input = { "nums": [7,7,9,5,8], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 24

test_input = { "nums": [7,9,1,3,2], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 3

test_input = { "nums": [8,5,6,9,7], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 9

test_input = { "nums": [8,6,9,4,4], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 4

test_input = { "nums": [8,8,2,9,2], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 12

test_input = { "nums": [9,3,7,9,6], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 16

test_input = { "nums": [9,5,5,5,5], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 15

test_input = { "nums": [27,73,37,82,78], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 188

test_input = { "nums": [36,28,94,49,79], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 49

test_input = { "nums": [48,54,75,72,77], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 206

test_input = { "nums": [574,419,838,216,442], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 1699

test_input = { "nums": [1,1,1,2,5,7], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 9

test_input = { "nums": [2,6,6,8,6,4], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 12

test_input = { "nums": [2,8,2,9,2,8], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 17

test_input = { "nums": [2,9,1,6,5,7], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 13

test_input = { "nums": [2,9,1,6,6,7], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 13

test_input = { "nums": [3,5,4,5,8,9], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 17

test_input = { "nums": [5,5,3,7,9,7], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 17

test_input = { "nums": [5,9,4,8,7,2], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 10

test_input = { "nums": [5,9,6,6,4,5], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 11

test_input = { "nums": [6,4,7,8,4,7], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 15

test_input = { "nums": [6,8,6,2,7,3], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 5

test_input = { "nums": [7,2,5,4,4,4], "k": 1 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 11

test_input = { "nums": [7,2,9,7,8,7], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 14

test_input = { "nums": [7,6,6,7,6,1], "k": 2 }
assert my_solution.sumIndicesWithKSetBits(**test_input) == 8


happy-students

Happy Students

Prompt:
"""
给你一个下标从 0 开始、长度为 n 的整数数组 nums ，其中 n 是班级中学生的总数。班主任希望能够在让所有学生保持开心的情况下选出一组学生：

如果能够满足下述两个条件之一，则认为第 i 位学生将会保持开心：

 * 这位学生被选中，并且被选中的学生人数 严格大于 nums[i] 。
 * 这位学生没有被选中，并且被选中的学生人数 严格小于 nums[i] 。

返回能够满足让所有学生保持开心的分组方法的数目。

示例 1：

输入：nums = [1,1]
输出：2
解释：
有两种可行的方法：
班主任没有选中学生。
班主任选中所有学生形成一组。
如果班主任仅选中一个学生来完成分组，那么两个学生都无法保持开心。因此，仅存在两种可行的方法。

示例 2：

输入：nums = [6,0,3,3,6,7,2,7]
输出：3
解释：
存在三种可行的方法：
班主任选中下标为 1 的学生形成一组。
班主任选中下标为 1、2、3、6 的学生形成一组。
班主任选中所有学生形成一组。

提示：

 * 1 <= nums.length <= 105
 * 0 <= nums[i] < nums.length
"""
class Solution:
    def countWays(self, nums: List[int]) -> int:

给你一个下标从 0 开始、长度为 n 的整数数组 nums ，其中 n 是班级中学生的总数。班主任希望能够在让所有学生保持开心的情况下选出一组学生：

如果能够满足下述两个条件之一，则认为第 i 位学生将会保持开心：

 * 这位学生被选中，并且被选中的学生人数 严格大于 nums[i] 。
 * 这位学生没有被选中，并且被选中的学生人数 严格小于 nums[i] 。

返回能够满足让所有学生保持开心的分组方法的数目。

示例 1：

输入：nums = [1,1]
输出：2
解释：
有两种可行的方法：
班主任没有选中学生。
班主任选中所有学生形成一组。
如果班主任仅选中一个学生来完成分组，那么两个学生都无法保持开心。因此，仅存在两种可行的方法。

示例 2：

输入：nums = [6,0,3,3,6,7,2,7]
输出：3
解释：
存在三种可行的方法：
班主任选中下标为 1 的学生形成一组。
班主任选中下标为 1、2、3、6 的学生形成一组。
班主任选中所有学生形成一组。

提示：

 * 1 <= nums.length <= 105
 * 0 <= nums[i] < nums.length

请完成下面的代码来解决上述问题:
```python
class Solution:
    def countWays(self, nums: List[int]) -> int:

```

my_solution = Solution()

test_input = { "nums": [1,1] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [6,0,3,3,6,7,2,7] }
assert my_solution.countWays(**test_input) == 3

test_input = { "nums": [1,1,0,1] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [5,0,3,4,2,1,2,4] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [0,4,4,4,4,4,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,1,5,6,8,7,4,7,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [2,2,7,1,2,2,4,7] }
assert my_solution.countWays(**test_input) == 3

test_input = { "nums": [0,2,2,2,3,3,3,3] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [7,7,7,7,7,7,7,7,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [4,2,3,6,6,0,6,8,3] }
assert my_solution.countWays(**test_input) == 3

test_input = { "nums": [0,0,1,7,2,0,6,5] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [6,6,6,6,6,6,6,7,1,7] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,2,4,5,0,1,4,4,7] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [4,4,4,4,4] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,4,0,3,4] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [6,5,5,8,4,2,6,4,8] }
assert my_solution.countWays(**test_input) == 3

test_input = { "nums": [0,9,4,6,8,8,1,7,4,7] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,0,0] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [1,1,2,2,2,3,3,3,3] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [4,5,0,4,2,0,2] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [8,1,2,1,2,1,2,4,0] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [0,1] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [8,4,1,8,8,7,4,5,3] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,1,0,2,5,5,4] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [6,3,1,5,5,4,5] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,1,1,5,5,5,5,5,5] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,3,5,3,0,3] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,2,2,0,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,1,1] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [7,7,7,7,7,7,7,7,4,5] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,2,2,2,4] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [3,3,3,3] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,0] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [6,6,6,6,6,6,6,0,4,9] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [4,4,4,4,4,5] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,3,2,1] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [3,3,3,3,2,2,2,2,1] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,5,3,0,3,6,2] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [1,1,1,1,1] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,0] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [4,4,4,4,4,0,1] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [4,3,1,5,1,4,2,1,6] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [6,4,0,7,5,7,5,6,0] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [5,5,5,5,5,5] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,3,4,3,4,1] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,1,1,3] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,1,0] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [1,1,0] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [1,7,6,4,1,2,1,6,4] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,2,2,4,4,4,4,4] }
assert my_solution.countWays(**test_input) == 3

test_input = { "nums": [1,3,5,2,4,6,7,5,6] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,1,1,1,2,2,2,3] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [3,5,3,2,0,3,3,7] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [6,6,6,6,6,6,6] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [7,9,0,3,6,9,4,0,8,7] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,0,0] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [2,2,2,2,1,3,3,6] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,2,2,2,2,2,6] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [5,3,9,2,4,2,1,2,8,6] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,2,2,0,0,6,6,2,5,4] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [2,0,1] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [2,2,0] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,2,2,2,1,0] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [2,2,2,2,4,5,0] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,1,2] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [1,1,3,3,3,3,7,8,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,2,0,4,4] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,1,0,0] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [1,7,8,7,1,0,7,3,8] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,2,2,1] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,8,6,3,3,4,3,2,3] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [8,1,6,4,1,2,2,3,3] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,2,2,1,1,5] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,3,3,3,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,3,2,3] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,1,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,3,6,3,0,2,3] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [7,7,7,7,7,7,7,7,2,0] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [5,4,4,4,4,7,1,4] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [3,3,3,3,0] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [7,7,4,0,2,1,5,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,2,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [7,7,7,7,7,7,7,7] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,2,0,3] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [3,3,3,3,0,5] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [4,4,4,2,5,0] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,1,3,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,3,0,2,4] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [0,3,3,3,3,1,1] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [0,4,1,2,0,6,6] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [4,4,4,4,4,5,3,6,5,5] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,0,1,0] }
assert my_solution.countWays(**test_input) == 1

test_input = { "nums": [0,5,5,5,5,5,5] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [0,5,4,4,3,5] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [6,6,6,6,6,6,6,2,7] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [1,5,3,7,2,3,1,2,8] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [3,3,3,3,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [3,3,3,3,0,2] }
assert my_solution.countWays(**test_input) == 2

test_input = { "nums": [2,3,9,0,1,3,9,2,6,1] }
assert my_solution.countWays(**test_input) == 2


maximum-number-of-alloys

Maximum Number of Alloys

Prompt:
"""
假设你是一家合金制造公司的老板，你的公司使用多种金属来制造合金。现在共有 n 种不同类型的金属可以使用，并且你可以使用 k 台机器来制造合金。每台机器都需要特定数量的每种金属来创建合金。

对于第 i 台机器而言，创建合金需要 composition[i][j] 份 j 类型金属。最初，你拥有 stock[i] 份 i 类型金属，而每购入一份 i 类型金属需要花费 cost[i] 的金钱。

给你整数 n、k、budget，下标从 1 开始的二维数组 composition，两个下标从 1 开始的数组 stock 和 cost，请你在预算不超过 budget 金钱的前提下，最大化 公司制造合金的数量。

所有合金都需要由同一台机器制造。

返回公司可以制造的最大合金数。

示例 1：

输入：n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,0], cost = [1,2,3]
输出：2
解释：最优的方法是使用第 1 台机器来制造合金。
要想制造 2 份合金，我们需要购买：
- 2 份第 1 类金属。
- 2 份第 2 类金属。
- 2 份第 3 类金属。
总共需要 2 * 1 + 2 * 2 + 2 * 3 = 12 的金钱，小于等于预算 15 。
注意，我们最开始时候没有任何一类金属，所以必须买齐所有需要的金属。
可以证明在示例条件下最多可以制造 2 份合金。

示例 2：

输入：n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,100], cost = [1,2,3]
输出：5
解释：最优的方法是使用第 2 台机器来制造合金。
要想制造 5 份合金，我们需要购买：
- 5 份第 1 类金属。
- 5 份第 2 类金属。
- 0 份第 3 类金属。
总共需要 5 * 1 + 5 * 2 + 0 * 3 = 15 的金钱，小于等于预算 15 。
可以证明在示例条件下最多可以制造 5 份合金。

示例 3：

输入：n = 2, k = 3, budget = 10, composition = [[2,1],[1,2],[1,1]], stock = [1,1], cost = [5,5]
输出：2
解释：最优的方法是使用第 3 台机器来制造合金。
要想制造 2 份合金，我们需要购买：
- 1 份第 1 类金属。
- 1 份第 2 类金属。
总共需要 1 * 5 + 1 * 5 = 10 的金钱，小于等于预算 10 。
可以证明在示例条件下最多可以制造 2 份合金。

提示：

 * 1 <= n, k <= 100
 * 0 <= budget <= 108
 * composition.length == k
 * composition[i].length == n
 * 1 <= composition[i][j] <= 100
 * stock.length == cost.length == n
 * 0 <= stock[i] <= 108
 * 1 <= cost[i] <= 100
"""
class Solution:
    def maxNumberOfAlloys(self, n: int, k: int, budget: int, composition: List[List[int]], stock: List[int], cost: List[int]) -> int:

假设你是一家合金制造公司的老板，你的公司使用多种金属来制造合金。现在共有 n 种不同类型的金属可以使用，并且你可以使用 k 台机器来制造合金。每台机器都需要特定数量的每种金属来创建合金。

对于第 i 台机器而言，创建合金需要 composition[i][j] 份 j 类型金属。最初，你拥有 stock[i] 份 i 类型金属，而每购入一份 i 类型金属需要花费 cost[i] 的金钱。

给你整数 n、k、budget，下标从 1 开始的二维数组 composition，两个下标从 1 开始的数组 stock 和 cost，请你在预算不超过 budget 金钱的前提下，最大化 公司制造合金的数量。

所有合金都需要由同一台机器制造。

返回公司可以制造的最大合金数。

示例 1：

输入：n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,0], cost = [1,2,3]
输出：2
解释：最优的方法是使用第 1 台机器来制造合金。
要想制造 2 份合金，我们需要购买：
- 2 份第 1 类金属。
- 2 份第 2 类金属。
- 2 份第 3 类金属。
总共需要 2 * 1 + 2 * 2 + 2 * 3 = 12 的金钱，小于等于预算 15 。
注意，我们最开始时候没有任何一类金属，所以必须买齐所有需要的金属。
可以证明在示例条件下最多可以制造 2 份合金。

示例 2：

输入：n = 3, k = 2, budget = 15, composition = [[1,1,1],[1,1,10]], stock = [0,0,100], cost = [1,2,3]
输出：5
解释：最优的方法是使用第 2 台机器来制造合金。
要想制造 5 份合金，我们需要购买：
- 5 份第 1 类金属。
- 5 份第 2 类金属。
- 0 份第 3 类金属。
总共需要 5 * 1 + 5 * 2 + 0 * 3 = 15 的金钱，小于等于预算 15 。
可以证明在示例条件下最多可以制造 5 份合金。

示例 3：

输入：n = 2, k = 3, budget = 10, composition = [[2,1],[1,2],[1,1]], stock = [1,1], cost = [5,5]
输出：2
解释：最优的方法是使用第 3 台机器来制造合金。
要想制造 2 份合金，我们需要购买：
- 1 份第 1 类金属。
- 1 份第 2 类金属。
总共需要 1 * 5 + 1 * 5 = 10 的金钱，小于等于预算 10 。
可以证明在示例条件下最多可以制造 2 份合金。

提示：

 * 1 <= n, k <= 100
 * 0 <= budget <= 108
 * composition.length == k
 * composition[i].length == n
 * 1 <= composition[i][j] <= 100
 * stock.length == cost.length == n
 * 0 <= stock[i] <= 108
 * 1 <= cost[i] <= 100

请完成下面的代码来解决上述问题:
```python
class Solution:
    def maxNumberOfAlloys(self, n: int, k: int, budget: int, composition: List[List[int]], stock: List[int], cost: List[int]) -> int:

```


maximum-element-sum-of-a-complete-subset-of-indices

Maximum Element-Sum of a Complete Subset of Indices

Prompt:
"""
给你一个下标从 1 开始、由 n 个整数组成的数组。

如果一组数字中每对元素的乘积都是一个完全平方数，则称这组数字是一个 完全集 。

下标集 {1, 2, ..., n} 的子集可以表示为 {i1, i2, ..., ik}，我们定义对应该子集的 元素和 为 nums[i1] + nums[i2] + ... + nums[ik] 。

返回下标集 {1, 2, ..., n} 的 完全子集 所能取到的 最大元素和 。

完全平方数是指可以表示为一个整数和其自身相乘的数。

示例 1：

输入：nums = [8,7,3,5,7,2,4,9]
输出：16
解释：除了由单个下标组成的子集之外，还有两个下标集的完全子集：{1,4} 和 {2,8} 。
与下标 1 和 4 对应的元素和等于 nums[1] + nums[4] = 8 + 5 = 13 。
与下标 2 和 8 对应的元素和等于 nums[2] + nums[8] = 7 + 9 = 16 。
因此，下标集的完全子集可以取到的最大元素和为 16 。

示例 2：

输入：nums = [5,10,3,10,1,13,7,9,4]
输出：19
解释：除了由单个下标组成的子集之外，还有四个下标集的完全子集：{1,4}、{1,9}、{2,8}、{4,9} 和 {1,4,9} 。
与下标 1 和 4 对应的元素和等于 nums[1] + nums[4] = 5 + 10 = 15 。
与下标 1 和 9 对应的元素和等于 nums[1] + nums[9] = 5 + 4 = 9 。
与下标 2 和 8 对应的元素和等于 nums[2] + nums[8] = 10 + 9 = 19 。
与下标 4 和 9 对应的元素和等于 nums[4] + nums[9] = 10 + 4 = 14 。
与下标 1、4 和 9 对应的元素和等于 nums[1] + nums[4] + nums[9] = 5 + 10 + 4 = 19 。
因此，下标集的完全子集可以取到的最大元素和为 19 。

提示：

 * 1 <= n == nums.length <= 104
 * 1 <= nums[i] <= 109
"""
class Solution:
    def maximumSum(self, nums: List[int]) -> int:

给你一个下标从 1 开始、由 n 个整数组成的数组。

如果一组数字中每对元素的乘积都是一个完全平方数，则称这组数字是一个 完全集 。

下标集 {1, 2, ..., n} 的子集可以表示为 {i1, i2, ..., ik}，我们定义对应该子集的 元素和 为 nums[i1] + nums[i2] + ... + nums[ik] 。

返回下标集 {1, 2, ..., n} 的 完全子集 所能取到的 最大元素和 。

完全平方数是指可以表示为一个整数和其自身相乘的数。

示例 1：

输入：nums = [8,7,3,5,7,2,4,9]
输出：16
解释：除了由单个下标组成的子集之外，还有两个下标集的完全子集：{1,4} 和 {2,8} 。
与下标 1 和 4 对应的元素和等于 nums[1] + nums[4] = 8 + 5 = 13 。
与下标 2 和 8 对应的元素和等于 nums[2] + nums[8] = 7 + 9 = 16 。
因此，下标集的完全子集可以取到的最大元素和为 16 。

示例 2：

输入：nums = [5,10,3,10,1,13,7,9,4]
输出：19
解释：除了由单个下标组成的子集之外，还有四个下标集的完全子集：{1,4}、{1,9}、{2,8}、{4,9} 和 {1,4,9} 。
与下标 1 和 4 对应的元素和等于 nums[1] + nums[4] = 5 + 10 = 15 。
与下标 1 和 9 对应的元素和等于 nums[1] + nums[9] = 5 + 4 = 9 。
与下标 2 和 8 对应的元素和等于 nums[2] + nums[8] = 10 + 9 = 19 。
与下标 4 和 9 对应的元素和等于 nums[4] + nums[9] = 10 + 4 = 14 。
与下标 1、4 和 9 对应的元素和等于 nums[1] + nums[4] + nums[9] = 5 + 10 + 4 = 19 。
因此，下标集的完全子集可以取到的最大元素和为 19 。

提示：

 * 1 <= n == nums.length <= 104
 * 1 <= nums[i] <= 109

请完成下面的代码来解决上述问题:
```python
class Solution:
    def maximumSum(self, nums: List[int]) -> int:

```

my_solution = Solution()

test_input = { "nums": [8,7,3,5,7,2,4,9] }
assert my_solution.maximumSum(**test_input) == 16

test_input = { "nums": [5,10,3,10,1,13,7,9,4] }
assert my_solution.maximumSum(**test_input) == 19

test_input = { "nums": [1,1,1,1] }
assert my_solution.maximumSum(**test_input) == 2

test_input = { "nums": [1,100,100,1] }
assert my_solution.maximumSum(**test_input) == 100

test_input = { "nums": [998244353,998244353,998244353,998244353] }
assert my_solution.maximumSum(**test_input) == 1996488706

test_input = { "nums": [1000000000,1,1,1000000000] }
assert my_solution.maximumSum(**test_input) == 2000000000

test_input = { "nums": [1,1,1000000000,1] }
assert my_solution.maximumSum(**test_input) == 1000000000

test_input = { "nums": [5,10,3,10,1,13,7,20,4] }
assert my_solution.maximumSum(**test_input) == 30

test_input = { "nums": [5,3,3,10,1,13,7,67,4] }
assert my_solution.maximumSum(**test_input) == 70

test_input = { "nums": [35,45,29,16,42,49,25,19,46] }
assert my_solution.maximumSum(**test_input) == 97

test_input = { "nums": [34,43,47,50,45] }
assert my_solution.maximumSum(**test_input) == 84

test_input = { "nums": [4,31,45,34,44] }
assert my_solution.maximumSum(**test_input) == 45

test_input = { "nums": [12,5,49,26] }
assert my_solution.maximumSum(**test_input) == 49

test_input = { "nums": [41] }
assert my_solution.maximumSum(**test_input) == 41

test_input = { "nums": [38,9,37,11,20,43] }
assert my_solution.maximumSum(**test_input) == 49

test_input = { "nums": [47,50,17,49,12,22] }
assert my_solution.maximumSum(**test_input) == 96

test_input = { "nums": [23,13,17,3,21,23] }
assert my_solution.maximumSum(**test_input) == 26

test_input = { "nums": [38,28] }
assert my_solution.maximumSum(**test_input) == 38

test_input = { "nums": [16,31,37,29,28,34,25,36] }
assert my_solution.maximumSum(**test_input) == 67

test_input = { "nums": [19,46,37,44,4,40,24,17,49] }
assert my_solution.maximumSum(**test_input) == 112

test_input = { "nums": [28,40,37] }
assert my_solution.maximumSum(**test_input) == 40

test_input = { "nums": [19,6,30,23,25,45,15,2,3,46] }
assert my_solution.maximumSum(**test_input) == 46

test_input = { "nums": [5,16,4,13,37,44,49,7] }
assert my_solution.maximumSum(**test_input) == 49

test_input = { "nums": [40,8,19,26] }
assert my_solution.maximumSum(**test_input) == 66

test_input = { "nums": [3,37,2] }
assert my_solution.maximumSum(**test_input) == 37

test_input = { "nums": [1,5,35,20,32,18,6,49,34,15] }
assert my_solution.maximumSum(**test_input) == 55

test_input = { "nums": [25,31,4,20,45] }
assert my_solution.maximumSum(**test_input) == 45

test_input = { "nums": [32,3,25,15,37,37,21,24,8,33] }
assert my_solution.maximumSum(**test_input) == 55

test_input = { "nums": [13] }
assert my_solution.maximumSum(**test_input) == 13

test_input = { "nums": [41,25,20,28,40,22,37,43,6,32] }
assert my_solution.maximumSum(**test_input) == 75

test_input = { "nums": [23,9,7,24,30,34,10,47] }
assert my_solution.maximumSum(**test_input) == 56

test_input = { "nums": [11,31,1,34,8,20,15,20,49] }
assert my_solution.maximumSum(**test_input) == 94

test_input = { "nums": [41,21,4,15,25,38,26,7,6] }
assert my_solution.maximumSum(**test_input) == 62

test_input = { "nums": [46,31,28,34,12,40,11,31,8,25] }
assert my_solution.maximumSum(**test_input) == 88

test_input = { "nums": [50] }
assert my_solution.maximumSum(**test_input) == 50

test_input = { "nums": [41,43,17,35] }
assert my_solution.maximumSum(**test_input) == 76

test_input = { "nums": [20,6] }
assert my_solution.maximumSum(**test_input) == 20

test_input = { "nums": [43,18,10,19,20,9,49] }
assert my_solution.maximumSum(**test_input) == 62

test_input = { "nums": [3,39,29,5,6,36,38,26,14,10] }
assert my_solution.maximumSum(**test_input) == 65

test_input = { "nums": [47,2,48,16,10,3,45,20,39] }
assert my_solution.maximumSum(**test_input) == 102

test_input = { "nums": [11,47,27,17,7] }
assert my_solution.maximumSum(**test_input) == 47

test_input = { "nums": [48,17,41,23,40,9,3,26,44,34] }
assert my_solution.maximumSum(**test_input) == 115

test_input = { "nums": [47,2,42,10,15,44,35,50] }
assert my_solution.maximumSum(**test_input) == 57

test_input = { "nums": [45,48,50,24,23,14,2,33] }
assert my_solution.maximumSum(**test_input) == 81

test_input = { "nums": [7,39,27,39,43,42,31,37,15] }
assert my_solution.maximumSum(**test_input) == 76

test_input = { "nums": [10,36,23,31] }
assert my_solution.maximumSum(**test_input) == 41

test_input = { "nums": [27,27,13,37] }
assert my_solution.maximumSum(**test_input) == 64

test_input = { "nums": [34,17,26,13] }
assert my_solution.maximumSum(**test_input) == 47

test_input = { "nums": [9,42] }
assert my_solution.maximumSum(**test_input) == 42

test_input = { "nums": [23,42,4,28,30,36,30,39] }
assert my_solution.maximumSum(**test_input) == 81

test_input = { "nums": [10,28,28,21,25,14,38] }
assert my_solution.maximumSum(**test_input) == 38

test_input = { "nums": [40,34,26,9,23,15,23,27,49] }
assert my_solution.maximumSum(**test_input) == 98

test_input = { "nums": [27,42,40,2,1] }
assert my_solution.maximumSum(**test_input) == 42

test_input = { "nums": [48,19,21,21,32,20,50,41,49,30] }
assert my_solution.maximumSum(**test_input) == 118

test_input = { "nums": [10,13,6,39,9] }
assert my_solution.maximumSum(**test_input) == 49

test_input = { "nums": [50,37,24,4,10,43,35] }
assert my_solution.maximumSum(**test_input) == 54

test_input = { "nums": [39,24] }
assert my_solution.maximumSum(**test_input) == 39

test_input = { "nums": [21] }
assert my_solution.maximumSum(**test_input) == 21

test_input = { "nums": [20,15] }
assert my_solution.maximumSum(**test_input) == 20

test_input = { "nums": [23,27,42,3,33,36,43,32,27,48,40,22,5,36,48] }
assert my_solution.maximumSum(**test_input) == 64

test_input = { "nums": [39,46,12,14,25,37,24,44,6,38,4] }
assert my_solution.maximumSum(**test_input) == 90

test_input = { "nums": [36,5,23,17,32,47,23,41,18,44,21,4,22,6,21] }
assert my_solution.maximumSum(**test_input) == 71

test_input = { "nums": [46,26,37,17,15,26,45,45,17,42,16,14,36,40] }
assert my_solution.maximumSum(**test_input) == 80

test_input = { "nums": [46,40,16,48,24,1,13,15,6,5,12,15,4] }
assert my_solution.maximumSum(**test_input) == 100

test_input = { "nums": [11,27,28,26,4,22,10,49,4,23,30,6,5] }
assert my_solution.maximumSum(**test_input) == 76

test_input = { "nums": [37,17,17,18,10,28,47,38,43,20,10] }
assert my_solution.maximumSum(**test_input) == 98

test_input = { "nums": [12,17,9,30,38,20,28,36,34,15,4,15,48] }
assert my_solution.maximumSum(**test_input) == 76

test_input = { "nums": [28,32,22,9,33,26,10,15,15,37,33,48,2,14,35] }
assert my_solution.maximumSum(**test_input) == 70

test_input = { "nums": [35,28,45,34,49,45,38,15,36,33,15,16] }
assert my_solution.maximumSum(**test_input) == 105

test_input = { "nums": [50,18,24,30,6,49,3,20,22,19,25,35,30,33] }
assert my_solution.maximumSum(**test_input) == 102

test_input = { "nums": [10,19,37,1,31,6,2,37,10,1,36,48,7,40] }
assert my_solution.maximumSum(**test_input) == 85

test_input = { "nums": [45,49,32,44,12,39,8,7,3,48,37,27,41,20,18] }
assert my_solution.maximumSum(**test_input) == 92

test_input = { "nums": [40,9,16,40,9,28,29,36,4,17,29] }
assert my_solution.maximumSum(**test_input) == 84

test_input = { "nums": [21,32,24,39,2,13,37,33,50,43,9,43,14] }
assert my_solution.maximumSum(**test_input) == 110

test_input = { "nums": [36,25,21,29,42,40,16,41,22,24,45,7,33] }
assert my_solution.maximumSum(**test_input) == 87

test_input = { "nums": [32,33,7,45,23,13,45,4,15,12] }
assert my_solution.maximumSum(**test_input) == 92

test_input = { "nums": [10,7,1,15,12,22,34,3,36,44,10,12] }
assert my_solution.maximumSum(**test_input) == 61

test_input = { "nums": [26,4,44,3,37,50,27,22,48,14,12,3,39,31] }
assert my_solution.maximumSum(**test_input) == 77

test_input = { "nums": [47,48,8,24,1,17,32,13,19,25,15,30,12] }
assert my_solution.maximumSum(**test_input) == 90

test_input = { "nums": [31,18,11,28,7,34,32,38,47,44,1,13,46] }
assert my_solution.maximumSum(**test_input) == 106

test_input = { "nums": [47,12,35,10,37,36,44,38,19,31,28,21,3,34] }
assert my_solution.maximumSum(**test_input) == 76

test_input = { "nums": [19,47,46,5,7,42,35,3,39,2,1,31] }
assert my_solution.maximumSum(**test_input) == 77

test_input = { "nums": [15,50,14,27,37,44,11,38,23,39,27,36,22] }
assert my_solution.maximumSum(**test_input) == 88

test_input = { "nums": [31,31,18,24,9,27,33,10,23,38,44,4,17,11,14] }
assert my_solution.maximumSum(**test_input) == 78

test_input = { "nums": [38,27,13,20,36,23,6,7,37,20,49,31,25,12] }
assert my_solution.maximumSum(**test_input) == 95

test_input = { "nums": [6,21,11,15,17,47,50,14,24,18,38,19,48,43] }
assert my_solution.maximumSum(**test_input) == 50

test_input = { "nums": [31,4,1,5,50,46,14,17,13,14,17,39,46,18] }
assert my_solution.maximumSum(**test_input) == 50

test_input = { "nums": [39,13,6,45,44,14,44,37,24,20,21,47,6,6,5] }
assert my_solution.maximumSum(**test_input) == 108

test_input = { "nums": [17,16,48,41,7,39,50,29,2,33] }
assert my_solution.maximumSum(**test_input) == 60

test_input = { "nums": [3,8,19,47,29,4,16,31,11,30] }
assert my_solution.maximumSum(**test_input) == 61

test_input = { "nums": [20,1,46,36,35,32,49,14,48,25,17,50,22] }
assert my_solution.maximumSum(**test_input) == 104

test_input = { "nums": [49,20,12,42,33,21,29,30,35,4,5,50] }
assert my_solution.maximumSum(**test_input) == 126

test_input = { "nums": [36,1,8,14,39,2,31,23,10,46,42] }
assert my_solution.maximumSum(**test_input) == 60

test_input = { "nums": [33,29,23,4,48,31,31,26,11,39] }
assert my_solution.maximumSum(**test_input) == 55

test_input = { "nums": [33,36,31,21,2,41,14,36,6,1,22,13,34] }
assert my_solution.maximumSum(**test_input) == 72

test_input = { "nums": [35,32,43,20,4,13,6,19,36,20] }
assert my_solution.maximumSum(**test_input) == 91

test_input = { "nums": [16,41,16,41,11,39,40,7,24,28,13] }
assert my_solution.maximumSum(**test_input) == 81

test_input = { "nums": [32,24,29,24,29,45,10,37,22,35,37,28,15] }
assert my_solution.maximumSum(**test_input) == 78

test_input = { "nums": [45,8,19,1,33,2,32,40,16,33,44,27] }
assert my_solution.maximumSum(**test_input) == 62

test_input = { "nums": [3,42,14,18,1,20,19,7,37,3,2,3,48] }
assert my_solution.maximumSum(**test_input) == 58


minimum-right-shifts-to-sort-the-array

Minimum Right Shifts to Sort the Array

Prompt:
"""
给你一个长度为 n 下标从 0 开始的数组 nums ，数组中的元素为 互不相同 的正整数。请你返回让 nums 成为递增数组的 最少右移 次数，如果无法得到递增数组，返回 -1 。

一次 右移 指的是同时对所有下标进行操作，将下标为 i 的元素移动到下标 (i + 1) % n 处。

示例 1：

输入：nums = [3,4,5,1,2]
输出：2
解释：
第一次右移后，nums = [2,3,4,5,1] 。
第二次右移后，nums = [1,2,3,4,5] 。
现在 nums 是递增数组了，所以答案为 2 。

示例 2：

输入：nums = [1,3,5]
输出：0
解释：nums 已经是递增数组了，所以答案为 0 。

示例 3：

输入：nums = [2,1,4]
输出：-1
解释：无法将数组变为递增数组。

提示：

 * 1 <= nums.length <= 100
 * 1 <= nums[i] <= 100
 * nums 中的整数互不相同。
"""
class Solution:
    def minimumRightShifts(self, nums: List[int]) -> int:

给你一个长度为 n 下标从 0 开始的数组 nums ，数组中的元素为 互不相同 的正整数。请你返回让 nums 成为递增数组的 最少右移 次数，如果无法得到递增数组，返回 -1 。

一次 右移 指的是同时对所有下标进行操作，将下标为 i 的元素移动到下标 (i + 1) % n 处。

示例 1：

输入：nums = [3,4,5,1,2]
输出：2
解释：
第一次右移后，nums = [2,3,4,5,1] 。
第二次右移后，nums = [1,2,3,4,5] 。
现在 nums 是递增数组了，所以答案为 2 。

示例 2：

输入：nums = [1,3,5]
输出：0
解释：nums 已经是递增数组了，所以答案为 0 。

示例 3：

输入：nums = [2,1,4]
输出：-1
解释：无法将数组变为递增数组。

提示：

 * 1 <= nums.length <= 100
 * 1 <= nums[i] <= 100
 * nums 中的整数互不相同。

请完成下面的代码来解决上述问题:
```python
class Solution:
    def minimumRightShifts(self, nums: List[int]) -> int:

```

my_solution = Solution()

test_input = { "nums": [3,4,5,1,2] }
assert my_solution.minimumRightShifts(**test_input) == 2

test_input = { "nums": [1,3,5] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [2,1,4] }
assert my_solution.minimumRightShifts(**test_input) == -1

test_input = { "nums": [31,72,79,25] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [27,33,42,58,81,8,9,17] }
assert my_solution.minimumRightShifts(**test_input) == 3

test_input = { "nums": [72,13,21,35,52] }
assert my_solution.minimumRightShifts(**test_input) == 4

test_input = { "nums": [65,73,77,1] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [100,8,14,68,80,84] }
assert my_solution.minimumRightShifts(**test_input) == 5

test_input = { "nums": [53,60,64,69,98,40] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [21] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [78,12,18,21,23,36,64,70] }
assert my_solution.minimumRightShifts(**test_input) == 7

test_input = { "nums": [25,26,53,91,92,99,10,24] }
assert my_solution.minimumRightShifts(**test_input) == 2

test_input = { "nums": [63,51,65,87,6,17,32,14,42,46] }
assert my_solution.minimumRightShifts(**test_input) == -1

test_input = { "nums": [43,46,75,76,85,96,9,19,25] }
assert my_solution.minimumRightShifts(**test_input) == 3

test_input = { "nums": [5] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [35,72,76,82,96,97,24,26] }
assert my_solution.minimumRightShifts(**test_input) == 2

test_input = { "nums": [82,30,94,55,76,51,3,89,52,96] }
assert my_solution.minimumRightShifts(**test_input) == -1

test_input = { "nums": [57,59,88,97,6,27,41,46,52] }
assert my_solution.minimumRightShifts(**test_input) == 5

test_input = { "nums": [17] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [62] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [24,46,55,61,71,78,1,4] }
assert my_solution.minimumRightShifts(**test_input) == 2

test_input = { "nums": [83,2,21,42,73,77,80] }
assert my_solution.minimumRightShifts(**test_input) == 6

test_input = { "nums": [83,94,14,43,50,62,63] }
assert my_solution.minimumRightShifts(**test_input) == 5

test_input = { "nums": [38,46,66,77,7,15,17,35] }
assert my_solution.minimumRightShifts(**test_input) == 4

test_input = { "nums": [35,68,82,90,9,18,29,34] }
assert my_solution.minimumRightShifts(**test_input) == 4

test_input = { "nums": [71] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [71,73,88,12,49,55,59,70] }
assert my_solution.minimumRightShifts(**test_input) == 5

test_input = { "nums": [54,65,75,81,24,37] }
assert my_solution.minimumRightShifts(**test_input) == 2

test_input = { "nums": [57,67,73,78,79,2,45,48,51] }
assert my_solution.minimumRightShifts(**test_input) == 4

test_input = { "nums": [36,62,65,85,95,9,21] }
assert my_solution.minimumRightShifts(**test_input) == 2

test_input = { "nums": [68,12] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [34,9,86,20,67,94,65,82,40,79] }
assert my_solution.minimumRightShifts(**test_input) == -1

test_input = { "nums": [92,84,37,19,16,85,20,79,25,89] }
assert my_solution.minimumRightShifts(**test_input) == -1

test_input = { "nums": [3,16,38,44,67,79,84] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [14,24,58,69,71,94,13] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [100,18] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [13] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [94,30,53,56,67,72,82] }
assert my_solution.minimumRightShifts(**test_input) == 6

test_input = { "nums": [92,14,65,80,85] }
assert my_solution.minimumRightShifts(**test_input) == 4

test_input = { "nums": [43,53,81,87,93,19,31,39] }
assert my_solution.minimumRightShifts(**test_input) == 3

test_input = { "nums": [80,38] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [52,72,78,83,85,99,20] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [3,6,89] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [3] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [55,56,63,91,3,46] }
assert my_solution.minimumRightShifts(**test_input) == 2

test_input = { "nums": [58,10,31,37,41] }
assert my_solution.minimumRightShifts(**test_input) == 4

test_input = { "nums": [17,33,53,58,78] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [82,44] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [89,96,35,48,57,71] }
assert my_solution.minimumRightShifts(**test_input) == 4

test_input = { "nums": [43,69,4,29,37] }
assert my_solution.minimumRightShifts(**test_input) == 3

test_input = { "nums": [65,88] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [42,44,59,76,86] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [29,56,78,96,1,10,27] }
assert my_solution.minimumRightShifts(**test_input) == 3

test_input = { "nums": [48,100] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [4,33,17,3,8,91,28,13,72,42] }
assert my_solution.minimumRightShifts(**test_input) == -1

test_input = { "nums": [5,35,53,56] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [65,67,70,27,41,50,52,57,60] }
assert my_solution.minimumRightShifts(**test_input) == 6

test_input = { "nums": [94,32,45,62] }
assert my_solution.minimumRightShifts(**test_input) == 3

test_input = { "nums": [23,25,34,47,61,65,6,21] }
assert my_solution.minimumRightShifts(**test_input) == 2

test_input = { "nums": [99,11,12,21,22,55,62,83] }
assert my_solution.minimumRightShifts(**test_input) == 7

test_input = { "nums": [92,13,33,58,61,85] }
assert my_solution.minimumRightShifts(**test_input) == 5

test_input = { "nums": [46] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [12,27,30,36] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [33,44,57,16,22,26,30] }
assert my_solution.minimumRightShifts(**test_input) == 4

test_input = { "nums": [67,24] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [12,44,83,87] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [19,52,3,8,12] }
assert my_solution.minimumRightShifts(**test_input) == 3

test_input = { "nums": [82,86,88,6,35,47,52,58,62] }
assert my_solution.minimumRightShifts(**test_input) == 6

test_input = { "nums": [48] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [60,11] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [69,60] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [22,28,36,16,82,77,41,85,44,97] }
assert my_solution.minimumRightShifts(**test_input) == -1

test_input = { "nums": [63,94,2,14] }
assert my_solution.minimumRightShifts(**test_input) == 2

test_input = { "nums": [41,45,74,84,90,93,100,18,31] }
assert my_solution.minimumRightShifts(**test_input) == 2

test_input = { "nums": [21,38,57,64,12] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [99,2,9,17,33,58,59,72] }
assert my_solution.minimumRightShifts(**test_input) == 7

test_input = { "nums": [36,89,90,98,11,14,23] }
assert my_solution.minimumRightShifts(**test_input) == 3

test_input = { "nums": [84,90,5,57,78] }
assert my_solution.minimumRightShifts(**test_input) == 3

test_input = { "nums": [48,73,76,30] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [74] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [21,84,35,65,12,74,30,95,46,23] }
assert my_solution.minimumRightShifts(**test_input) == -1

test_input = { "nums": [64,76,46,53,54] }
assert my_solution.minimumRightShifts(**test_input) == 3

test_input = { "nums": [77,84,89,47,52,74] }
assert my_solution.minimumRightShifts(**test_input) == 3

test_input = { "nums": [12,29,31,52,88,89,10] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [20,25,28,41,57,89] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [1,28,51,59] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [59,76,2,26,49,78,36,70,64,24] }
assert my_solution.minimumRightShifts(**test_input) == -1

test_input = { "nums": [35,43,49,63,21] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [1,35,38,47,54,56,58,74] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [49,94,97] }
assert my_solution.minimumRightShifts(**test_input) == 0

test_input = { "nums": [32,30] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [37,36] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [31,41,65,14] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [45,57,73,77,17,30,42,43] }
assert my_solution.minimumRightShifts(**test_input) == 4

test_input = { "nums": [17,65,11] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [32,84,93,31,61,78,15,52,100,65] }
assert my_solution.minimumRightShifts(**test_input) == -1

test_input = { "nums": [61,72,90,3,8,17,23,55] }
assert my_solution.minimumRightShifts(**test_input) == 5

test_input = { "nums": [19,30,44,95,13] }
assert my_solution.minimumRightShifts(**test_input) == 1

test_input = { "nums": [42,46,66,71,87,3,4,5,14] }
assert my_solution.minimumRightShifts(**test_input) == 4

test_input = { "nums": [13,57,7] }
assert my_solution.minimumRightShifts(**test_input) == 1


minimum-array-length-after-pair-removals

Minimum Array Length After Pair Removals

Prompt:
"""
给你一个下标从 0 开始的 非递减 整数数组 nums 。

你可以执行以下操作任意次：

 * 选择 两个 下标 i 和 j ，满足 i < j 且 nums[i] < nums[j] 。
 * 将 nums 中下标在 i 和 j 处的元素删除。剩余元素按照原来的顺序组成新的数组，下标也重新从 0 开始编号。

请你返回一个整数，表示执行以上操作任意次后（可以执行 0 次），nums 数组的 最小 数组长度。

请注意，nums 数组是按 非降序 排序的。

示例 1：

输入：nums = [1,3,4,9]
输出：0
解释：一开始，nums = [1, 3, 4, 9] 。
第一次操作，我们选择下标 0 和 1 ，满足 nums[0] < nums[1] <=> 1 < 3 。
删除下标 0 和 1 处的元素，nums 变成 [4, 9] 。
下一次操作，我们选择下标 0 和 1 ，满足 nums[0] < nums[1] <=> 4 < 9 。
删除下标 0 和 1 处的元素，nums 变成空数组 [] 。
所以，可以得到的最小数组长度为 0 。

示例 2：

输入：nums = [2,3,6,9]
输出：0
解释：一开始，nums = [2, 3, 6, 9] 。
第一次操作，我们选择下标 0 和 2 ，满足 nums[0] < nums[2] <=> 2 < 6 。
删除下标 0 和 2 处的元素，nums 变成 [3, 9] 。
下一次操作，我们选择下标 0 和 1 ，满足 nums[0] < nums[1] <=> 3 < 9 。
删除下标 0 和 1 处的元素，nums 变成空数组 [] 。
所以，可以得到的最小数组长度为 0 。

示例 3：

输入：nums = [1,1,2]
输出：1
解释：一开始，nums = [1, 1, 2] 。
第一次操作，我们选择下标 0 和 2 ，满足 nums[0] < nums[2] <=> 1 < 2 。
删除下标 0 和 2 处的元素，nums 变成 [1] 。
无法对数组再执行操作。
所以，可以得到的最小数组长度为 1 。

提示：

 * 1 <= nums.length <= 105
 * 1 <= nums[i] <= 109
 * nums 是 非递减 数组。
"""
class Solution:
    def minLengthAfterRemovals(self, nums: List[int]) -> int:

给你一个下标从 0 开始的 非递减 整数数组 nums 。

你可以执行以下操作任意次：

 * 选择 两个 下标 i 和 j ，满足 i < j 且 nums[i] < nums[j] 。
 * 将 nums 中下标在 i 和 j 处的元素删除。剩余元素按照原来的顺序组成新的数组，下标也重新从 0 开始编号。

请你返回一个整数，表示执行以上操作任意次后（可以执行 0 次），nums 数组的 最小 数组长度。

请注意，nums 数组是按 非降序 排序的。

示例 1：

输入：nums = [1,3,4,9]
输出：0
解释：一开始，nums = [1, 3, 4, 9] 。
第一次操作，我们选择下标 0 和 1 ，满足 nums[0] < nums[1] <=> 1 < 3 。
删除下标 0 和 1 处的元素，nums 变成 [4, 9] 。
下一次操作，我们选择下标 0 和 1 ，满足 nums[0] < nums[1] <=> 4 < 9 。
删除下标 0 和 1 处的元素，nums 变成空数组 [] 。
所以，可以得到的最小数组长度为 0 。

示例 2：

输入：nums = [2,3,6,9]
输出：0
解释：一开始，nums = [2, 3, 6, 9] 。
第一次操作，我们选择下标 0 和 2 ，满足 nums[0] < nums[2] <=> 2 < 6 。
删除下标 0 和 2 处的元素，nums 变成 [3, 9] 。
下一次操作，我们选择下标 0 和 1 ，满足 nums[0] < nums[1] <=> 3 < 9 。
删除下标 0 和 1 处的元素，nums 变成空数组 [] 。
所以，可以得到的最小数组长度为 0 。

示例 3：

输入：nums = [1,1,2]
输出：1
解释：一开始，nums = [1, 1, 2] 。
第一次操作，我们选择下标 0 和 2 ，满足 nums[0] < nums[2] <=> 1 < 2 。
删除下标 0 和 2 处的元素，nums 变成 [1] 。
无法对数组再执行操作。
所以，可以得到的最小数组长度为 1 。

提示：

 * 1 <= nums.length <= 105
 * 1 <= nums[i] <= 109
 * nums 是 非递减 数组。

请完成下面的代码来解决上述问题:
```python
class Solution:
    def minLengthAfterRemovals(self, nums: List[int]) -> int:

```

my_solution = Solution()

test_input = { "nums": [1,3,4,9] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [2,3,6,9] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 2

test_input = { "nums": [1,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,4] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [2,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 2

test_input = { "nums": [4,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 3

test_input = { "nums": [1,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 3

test_input = { "nums": [2,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [2,3,4] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [3,4,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 4

test_input = { "nums": [1,1,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [2,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 2

test_input = { "nums": [1,1,1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 5

test_input = { "nums": [1,1,2,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,2,5,6] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,3,3,3,4] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [2,3,4,4,4] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 6

test_input = { "nums": [1,1,2,3,4,4] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,4,4,5,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,2,2,2,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,2,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 2

test_input = { "nums": [3,4,7,8,9,9] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,1,1,1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 7

test_input = { "nums": [1,1,1,1,2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,1,2,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,2,2,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,2,2,3,3,4] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,2,3,4,5,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,2,3,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 3

test_input = { "nums": [2,2,2,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,1,1,1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 8

test_input = { "nums": [1,1,1,1,2,2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,2,2,3,3,4,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,3,4,4,4,5,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,2,2,2,4,4,4,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [2,3,3,3,4,4,5,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,1,1,1,1,1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 9

test_input = { "nums": [1,1,1,1,1,1,1,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 5

test_input = { "nums": [1,1,1,1,2,2,2,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,2,2,2,2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 3

test_input = { "nums": [1,1,1,5,5,5,5,5,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 3

test_input = { "nums": [1,1,2,2,2,2,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,2,2,2,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,2,4,4,5,5,5,6,6] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 10

test_input = { "nums": [1,1,1,1,1,2,2,2,3,4] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,1,1,2,2,2,2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 2

test_input = { "nums": [1,1,2,2,2,3,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,2,2,2,3,3,3,3,4] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,2,2,4,5,6,6,7,7,8] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 11

test_input = { "nums": [1,1,1,1,1,1,2,2,2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,2,2,2,2,2,2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 5

test_input = { "nums": [1,1,1,2,2,2,3,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,2,2,3,4,6,6,8,8] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,2,2,2,2,2,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,2,2,2,2,3,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,2,2,2,2,3,3,3,4,4] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,2,2,2,3,3,4,5,5,6,6] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 12

test_input = { "nums": [1,1,1,1,1,1,1,1,1,2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 6

test_input = { "nums": [1,1,1,1,1,2,2,3,3,4,4,4] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,1,2,2,2,2,2,2,2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 6

test_input = { "nums": [1,1,1,2,2,3,3,3,4,5,5,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,1,2,4,4,4,4,4,5,6,6] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,2,2,2,2,2,2,2,2,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 4

test_input = { "nums": [1,1,2,2,2,2,2,3,3,3,5,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,2,2,2,3,3,4,4,4,5,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 13

test_input = { "nums": [1,1,1,1,1,1,1,2,2,4,4,4,4] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,1,1,2,3,3,3,3,3,3,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,1,2,2,2,2,2,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,2,2,3,3,3,3,4,4,4,6,7] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,2,2,2,2,2,2,3,3,4,6,7,7] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1,1,1,1] }
assert my_solution.minLengthAfterRemovals(**test_input) == 14

test_input = { "nums": [1,1,1,1,1,1,2,2,2,2,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,1,1,1,2,2,2,2,2,2,2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 4

test_input = { "nums": [1,1,1,2,2,2,3,3,3,4,4,4,5,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,1,2,2,3,3,3,3,4,4,5,5,6] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,2,2,2,3,3,3,5,6,7,9,9,10] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,3,3,3,3,3,3,3,4,4,4,4,5,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [2,2,2,2,2,2,2,3,3,3,3,3,3,3] }
assert my_solution.minLengthAfterRemovals(**test_input) == 0

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,2,2,2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 5

test_input = { "nums": [1,1,1,1,1,1,1,1,1,2,2,2,2,2,2] }
assert my_solution.minLengthAfterRemovals(**test_input) == 3

test_input = { "nums": [1,1,1,1,1,1,2,2,2,4,4,4,5,5,5] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1

test_input = { "nums": [1,1,1,3,5,6,6,7,7,8,8,8,8,9,9] }
assert my_solution.minLengthAfterRemovals(**test_input) == 1


count-pairs-of-points-with-distance-k

Count Pairs of Points With Distance k

Prompt:
"""
给你一个 二维 整数数组 coordinates 和一个整数 k ，其中 coordinates[i] = [xi, yi] 是第 i 个点在二维平面里的坐标。

我们定义两个点 (x1, y1) 和 (x2, y2) 的 距离 为 (x1 XOR x2) + (y1 XOR y2) ，XOR 指的是按位异或运算。

请你返回满足 i < j 且点 i 和点 j之间距离为 k 的点对数目。

示例 1：

输入：coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5
输出：2
解释：以下点对距离为 k ：
- (0, 1)：(1 XOR 4) + (2 XOR 2) = 5 。
- (2, 3)：(1 XOR 5) + (3 XOR 2) = 5 。

示例 2：

输入：coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0
输出：10
解释：任何两个点之间的距离都为 0 ，所以总共有 10 组点对。

提示：

 * 2 <= coordinates.length <= 50000
 * 0 <= xi, yi <= 106
 * 0 <= k <= 100
"""
class Solution:
    def countPairs(self, coordinates: List[List[int]], k: int) -> int:

给你一个 二维 整数数组 coordinates 和一个整数 k ，其中 coordinates[i] = [xi, yi] 是第 i 个点在二维平面里的坐标。

我们定义两个点 (x1, y1) 和 (x2, y2) 的 距离 为 (x1 XOR x2) + (y1 XOR y2) ，XOR 指的是按位异或运算。

请你返回满足 i < j 且点 i 和点 j之间距离为 k 的点对数目。

示例 1：

输入：coordinates = [[1,2],[4,2],[1,3],[5,2]], k = 5
输出：2
解释：以下点对距离为 k ：
- (0, 1)：(1 XOR 4) + (2 XOR 2) = 5 。
- (2, 3)：(1 XOR 5) + (3 XOR 2) = 5 。

示例 2：

输入：coordinates = [[1,3],[1,3],[1,3],[1,3],[1,3]], k = 0
输出：10
解释：任何两个点之间的距离都为 0 ，所以总共有 10 组点对。

提示：

 * 2 <= coordinates.length <= 50000
 * 0 <= xi, yi <= 106
 * 0 <= k <= 100

请完成下面的代码来解决上述问题:
```python
class Solution:
    def countPairs(self, coordinates: List[List[int]], k: int) -> int:

```