minimum-size-subarray-in-infinite-array

Minimum Size Subarray in Infinite Array

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

下标从 0 开始的数组 infinite_nums 是通过无限地将 nums 的元素追加到自己之后生成的。

请你从 infinite_nums 中找出满足 元素和 等于 target 的 最短 子数组，并返回该子数组的长度。如果不存在满足条件的子数组，返回 -1 。

示例 1：

输入：nums = [1,2,3], target = 5
输出：2
解释：在这个例子中 infinite_nums = [1,2,3,1,2,3,1,2,...] 。
区间 [1,2] 内的子数组的元素和等于 target = 5 ，且长度 length = 2 。
可以证明，当元素和等于目标值 target = 5 时，2 是子数组的最短长度。

示例 2：

输入：nums = [1,1,1,2,3], target = 4
输出：2
解释：在这个例子中 infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].
区间 [4,5] 内的子数组的元素和等于 target = 4 ，且长度 length = 2 。
可以证明，当元素和等于目标值 target = 4 时，2 是子数组的最短长度。

示例 3：

输入：nums = [2,4,6,8], target = 3
输出：-1
解释：在这个例子中 infinite_nums = [2,4,6,8,2,4,6,8,...] 。
可以证明，不存在元素和等于目标值 target = 3 的子数组。

提示：

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

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

下标从 0 开始的数组 infinite_nums 是通过无限地将 nums 的元素追加到自己之后生成的。

请你从 infinite_nums 中找出满足 元素和 等于 target 的 最短 子数组，并返回该子数组的长度。如果不存在满足条件的子数组，返回 -1 。

示例 1：

输入：nums = [1,2,3], target = 5
输出：2
解释：在这个例子中 infinite_nums = [1,2,3,1,2,3,1,2,...] 。
区间 [1,2] 内的子数组的元素和等于 target = 5 ，且长度 length = 2 。
可以证明，当元素和等于目标值 target = 5 时，2 是子数组的最短长度。

示例 2：

输入：nums = [1,1,1,2,3], target = 4
输出：2
解释：在这个例子中 infinite_nums = [1,1,1,2,3,1,1,1,2,3,1,1,...].
区间 [4,5] 内的子数组的元素和等于 target = 4 ，且长度 length = 2 。
可以证明，当元素和等于目标值 target = 4 时，2 是子数组的最短长度。

示例 3：

输入：nums = [2,4,6,8], target = 3
输出：-1
解释：在这个例子中 infinite_nums = [2,4,6,8,2,4,6,8,...] 。
可以证明，不存在元素和等于目标值 target = 3 的子数组。

提示：

 * 1 <= nums.length <= 105
 * 1 <= nums[i] <= 105
 * 1 <= target <= 109

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

```

my_solution = Solution()

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

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

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

test_input = { "nums": [2,1,5,7,7,1,6,3], "target": 39 }
assert my_solution.minSizeSubarray(**test_input) == 9

test_input = { "nums": [17,4,3,14,17,6,15], "target": 85 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [18,3,11,19,7,16,6,7,3,6,18,9,9,1,14,17,15,14,12,10], "target": 7 }
assert my_solution.minSizeSubarray(**test_input) == 1

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

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

test_input = { "nums": [7,3,5], "target": 36 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [1,11,6,4,13], "target": 22 }
assert my_solution.minSizeSubarray(**test_input) == 4

test_input = { "nums": [1,2,2,2,1,2,1,2,1,2,1], "target": 83 }
assert my_solution.minSizeSubarray(**test_input) == 53

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

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

test_input = { "nums": [2,5,6,4], "target": 95 }
assert my_solution.minSizeSubarray(**test_input) == 22

test_input = { "nums": [6,6,4,5,2,8,1,8,7,6,6,7,4,1,9,6,8,8], "target": 55 }
assert my_solution.minSizeSubarray(**test_input) == 9

test_input = { "nums": [1,2,8,19,17,2,3,11,8,12,16,18,7], "target": 36 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [12,14,4,14,13,16,5], "target": 36 }
assert my_solution.minSizeSubarray(**test_input) == -1

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

test_input = { "nums": [5,7,2,6,4,1,6,7,1,4,7,6,7,7,6,6,4,6,8], "target": 90 }
assert my_solution.minSizeSubarray(**test_input) == 17

test_input = { "nums": [3,5,15,17,6,17,10,15,10,4,6], "target": 25 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [14,5], "target": 23 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [1,1,5,9], "target": 68 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [11,1,17,14,9,16,5,3,7,16,14,18,17,10], "target": 82 }
assert my_solution.minSizeSubarray(**test_input) == 6

test_input = { "nums": [9,6,8,4,3,4,6,4,7,2,6,9,2,4,5,4], "target": 71 }
assert my_solution.minSizeSubarray(**test_input) == 14

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

test_input = { "nums": [3,6], "target": 66 }
assert my_solution.minSizeSubarray(**test_input) == 15

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

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

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

test_input = { "nums": [2,2,1,3,2,2,2,3,3,2,1,3,3,2,3,3], "target": 93 }
assert my_solution.minSizeSubarray(**test_input) == 40

test_input = { "nums": [5,1,4,1,5,6], "target": 71 }
assert my_solution.minSizeSubarray(**test_input) == 19

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

test_input = { "nums": [12,15,9,3,3,12,13,14,7,11,7,15,12,5,11], "target": 18 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [3,11,10,12,9,13,9], "target": 19 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [3,4,4], "target": 35 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [4,5,2,5,5,5,1], "target": 87 }
assert my_solution.minSizeSubarray(**test_input) == 23

test_input = { "nums": [2,13,15,3,6,7,16,7,9,10,4,3,12,9,13,2,9,13,15], "target": 4 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [1,2,16,10,15,15,13,11,10,6,12,15,9], "target": 30 }
assert my_solution.minSizeSubarray(**test_input) == 2

test_input = { "nums": [3,5], "target": 85 }
assert my_solution.minSizeSubarray(**test_input) == 21

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

test_input = { "nums": [2,10,12,10,4,4,12,5,12,12,5], "target": 33 }
assert my_solution.minSizeSubarray(**test_input) == 4

test_input = { "nums": [5,9,7,10,4,7,9,11,6,3,1,8,6,1,11,1,1], "target": 72 }
assert my_solution.minSizeSubarray(**test_input) == 11

test_input = { "nums": [19,18,6], "target": 56 }
assert my_solution.minSizeSubarray(**test_input) == -1

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

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

test_input = { "nums": [1,1,1,1,1,1,1,1], "target": 22 }
assert my_solution.minSizeSubarray(**test_input) == 22

test_input = { "nums": [1,2], "target": 72 }
assert my_solution.minSizeSubarray(**test_input) == 48

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

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

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

test_input = { "nums": [18,12,13,9,17,11], "target": 82 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [13,3,1,5,13,7,12,5], "target": 35 }
assert my_solution.minSizeSubarray(**test_input) == 5

test_input = { "nums": [4,10,12,6,2,2,4,12,6,1,1,2,2,10,6,11,5,4,9], "target": 49 }
assert my_solution.minSizeSubarray(**test_input) == 7

test_input = { "nums": [8], "target": 68 }
assert my_solution.minSizeSubarray(**test_input) == -1

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

test_input = { "nums": [4,7,6,12,10,13,7,6,6,1,15,2,4,8,12], "target": 43 }
assert my_solution.minSizeSubarray(**test_input) == 6

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

test_input = { "nums": [4,3,2,4,5,3,7,12,2,2,10], "target": 43 }
assert my_solution.minSizeSubarray(**test_input) == 8

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1,1], "target": 58 }
assert my_solution.minSizeSubarray(**test_input) == 58

test_input = { "nums": [1,1,1,1,1], "target": 20 }
assert my_solution.minSizeSubarray(**test_input) == 20

test_input = { "nums": [4,3], "target": 23 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [3,2,1,3,2,1,3,1,1,1,2,1,2,1,2,3,3,1], "target": 78 }
assert my_solution.minSizeSubarray(**test_input) == 41

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

test_input = { "nums": [17], "target": 1 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [10,12,1,11,9,5,4,5,1,10,8,12,5,4], "target": 82 }
assert my_solution.minSizeSubarray(**test_input) == 10

test_input = { "nums": [6], "target": 44 }
assert my_solution.minSizeSubarray(**test_input) == -1

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

test_input = { "nums": [14,4,13,12,18,8,4,15,4,14,17,4,2], "target": 8 }
assert my_solution.minSizeSubarray(**test_input) == 1

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

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], "target": 28 }
assert my_solution.minSizeSubarray(**test_input) == 28

test_input = { "nums": [5,10,1,3,14,7,13,6,5,7,10,3,10,5,8,5,7,5,6,7], "target": 25 }
assert my_solution.minSizeSubarray(**test_input) == 4

test_input = { "nums": [12,3,4,10,5,8,12,7,12,7,5,8,4,8,11,11], "target": 48 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [3,11,5,5,3,10,12,12,12,3,10], "target": 88 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [8,2,10,5], "target": 28 }
assert my_solution.minSizeSubarray(**test_input) == -1

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

test_input = { "nums": [1,4,1,4,4], "target": 21 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [15,8,8,19,8,12,15,3,15,8,10,9], "target": 77 }
assert my_solution.minSizeSubarray(**test_input) == 7

test_input = { "nums": [4,4], "target": 80 }
assert my_solution.minSizeSubarray(**test_input) == 20

test_input = { "nums": [4,9,3,7,5,4,5,1,3,5], "target": 69 }
assert my_solution.minSizeSubarray(**test_input) == 14

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

test_input = { "nums": [7,11,14,12,3,16,11,9], "target": 10 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [2,1,2,1,3,2,1,1,2], "target": 17 }
assert my_solution.minSizeSubarray(**test_input) == 10

test_input = { "nums": [5,20,18,2,8], "target": 45 }
assert my_solution.minSizeSubarray(**test_input) == 4

test_input = { "nums": [2,1,2,1,2,1,1,1,2,2], "target": 58 }
assert my_solution.minSizeSubarray(**test_input) == 38

test_input = { "nums": [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1], "target": 17 }
assert my_solution.minSizeSubarray(**test_input) == 17

test_input = { "nums": [18,6,8,17,3,10,14,12,4,13,12,10,5,18,11], "target": 95 }
assert my_solution.minSizeSubarray(**test_input) == 9

test_input = { "nums": [19,12,14], "target": 57 }
assert my_solution.minSizeSubarray(**test_input) == 4

test_input = { "nums": [3,13,14], "target": 11 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [17,6,8,7,4,6,6,3,8,1,8,10,18,13,2], "target": 32 }
assert my_solution.minSizeSubarray(**test_input) == 3

test_input = { "nums": [3,12,4,9,5,2,2,9,9,6,9,11,9], "target": 41 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [3,14,2,9,5,14,15,4,3,4,17,11], "target": 3 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [2,5,3,6,3,6,1,1,5,1], "target": 37 }
assert my_solution.minSizeSubarray(**test_input) == -1

test_input = { "nums": [13,6,4,7,3,6,4,10,13,10,5,4,2,1,7,11,3,3,12], "target": 51 }
assert my_solution.minSizeSubarray(**test_input) == 7

test_input = { "nums": [1,10,9,16,3,10,2,5,1,10], "target": 83 }
assert my_solution.minSizeSubarray(**test_input) == 11

test_input = { "nums": [2,10,13,3,4,19,14,20,11,15,4,3,17,8,2,3,1,13,8], "target": 1 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [4,5,5,3,5,4,2,11,5,9,4,6], "target": 41 }
assert my_solution.minSizeSubarray(**test_input) == 7

test_input = { "nums": [2,8,9,6,11,17,3,6,9,7,2,8,9,11,19], "target": 39 }
assert my_solution.minSizeSubarray(**test_input) == 3

test_input = { "nums": [8,13,9,5,8,6,17,16,14,7,10,15,16], "target": 8 }
assert my_solution.minSizeSubarray(**test_input) == 1

test_input = { "nums": [10,20,16,1,11,18,13,6,13,6,9,14,16,12,13,7,19], "target": 59 }
assert my_solution.minSizeSubarray(**test_input) == 5

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


count-visited-nodes-in-a-directed-graph

Count Visited Nodes in a Directed Graph

Prompt:
"""
现有一个有向图，其中包含 n 个节点，节点编号从 0 到 n - 1 。此外，该图还包含了 n 条有向边。

给你一个下标从 0 开始的数组 edges ，其中 edges[i] 表示存在一条从节点 i 到节点 edges[i] 的边。

想象在图上发生以下过程：

 * 你从节点 x 开始，通过边访问其他节点，直到你在 此过程 中再次访问到之前已经访问过的节点。

返回数组 answer 作为答案，其中 answer[i] 表示如果从节点 i 开始执行该过程，你可以访问到的不同节点数。

示例 1：

[https://assets.leetcode.com/uploads/2023/08/31/graaphdrawio-1.png]

输入：edges = [1,2,0,0]
输出：[3,3,3,4]
解释：从每个节点开始执行该过程，记录如下：
- 从节点 0 开始，访问节点 0 -> 1 -> 2 -> 0 。访问的不同节点数是 3 。
- 从节点 1 开始，访问节点 1 -> 2 -> 0 -> 1 。访问的不同节点数是 3 。
- 从节点 2 开始，访问节点 2 -> 0 -> 1 -> 2 。访问的不同节点数是 3 。
- 从节点 3 开始，访问节点 3 -> 0 -> 1 -> 2 -> 0 。访问的不同节点数是 4 。

示例 2：

[https://assets.leetcode.com/uploads/2023/08/31/graaph2drawio.png]

输入：edges = [1,2,3,4,0]
输出：[5,5,5,5,5]
解释：无论从哪个节点开始，在这个过程中，都可以访问到图中的每一个节点。

提示：

 * n == edges.length
 * 2 <= n <= 105
 * 0 <= edges[i] <= n - 1
 * edges[i] != i
"""
class Solution:
    def countVisitedNodes(self, edges: List[int]) -> List[int]:

现有一个有向图，其中包含 n 个节点，节点编号从 0 到 n - 1 。此外，该图还包含了 n 条有向边。

给你一个下标从 0 开始的数组 edges ，其中 edges[i] 表示存在一条从节点 i 到节点 edges[i] 的边。

想象在图上发生以下过程：

 * 你从节点 x 开始，通过边访问其他节点，直到你在 此过程 中再次访问到之前已经访问过的节点。

返回数组 answer 作为答案，其中 answer[i] 表示如果从节点 i 开始执行该过程，你可以访问到的不同节点数。

示例 1：

[https://assets.leetcode.com/uploads/2023/08/31/graaphdrawio-1.png]

输入：edges = [1,2,0,0]
输出：[3,3,3,4]
解释：从每个节点开始执行该过程，记录如下：
- 从节点 0 开始，访问节点 0 -> 1 -> 2 -> 0 。访问的不同节点数是 3 。
- 从节点 1 开始，访问节点 1 -> 2 -> 0 -> 1 。访问的不同节点数是 3 。
- 从节点 2 开始，访问节点 2 -> 0 -> 1 -> 2 。访问的不同节点数是 3 。
- 从节点 3 开始，访问节点 3 -> 0 -> 1 -> 2 -> 0 。访问的不同节点数是 4 。

示例 2：

[https://assets.leetcode.com/uploads/2023/08/31/graaph2drawio.png]

输入：edges = [1,2,3,4,0]
输出：[5,5,5,5,5]
解释：无论从哪个节点开始，在这个过程中，都可以访问到图中的每一个节点。

提示：

 * n == edges.length
 * 2 <= n <= 105
 * 0 <= edges[i] <= n - 1
 * edges[i] != i

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

```


minimum-operations-to-collect-elements

Minimum Operations to Collect Elements

Prompt:
"""
给你一个正整数数组 nums 和一个整数 k 。

一次操作中，你可以将数组的最后一个元素删除，将该元素添加到一个集合中。

请你返回收集元素 1, 2, ..., k 需要的 最少操作次数 。

示例 1：

输入：nums = [3,1,5,4,2], k = 2
输出：4
解释：4 次操作后，集合中的元素依次添加了 2 ，4 ，5 和 1 。此时集合中包含元素 1 和 2 ，所以答案为 4 。

示例 2：

输入：nums = [3,1,5,4,2], k = 5
输出：5
解释：5 次操作后，集合中的元素依次添加了 2 ，4 ，5 ，1 和 3 。此时集合中包含元素 1 到 5 ，所以答案为 5 。

示例 3：

输入：nums = [3,2,5,3,1], k = 3
输出：4
解释：4 次操作后，集合中的元素依次添加了 1 ，3 ，5 和 2 。此时集合中包含元素 1 到 3  ，所以答案为 4 。

提示：

 * 1 <= nums.length <= 50
 * 1 <= nums[i] <= nums.length
 * 1 <= k <= nums.length
 * 输入保证你可以收集到元素 1, 2, ..., k 。
"""
class Solution:
    def minOperations(self, nums: List[int], k: int) -> int:

给你一个正整数数组 nums 和一个整数 k 。

一次操作中，你可以将数组的最后一个元素删除，将该元素添加到一个集合中。

请你返回收集元素 1, 2, ..., k 需要的 最少操作次数 。

示例 1：

输入：nums = [3,1,5,4,2], k = 2
输出：4
解释：4 次操作后，集合中的元素依次添加了 2 ，4 ，5 和 1 。此时集合中包含元素 1 和 2 ，所以答案为 4 。

示例 2：

输入：nums = [3,1,5,4,2], k = 5
输出：5
解释：5 次操作后，集合中的元素依次添加了 2 ，4 ，5 ，1 和 3 。此时集合中包含元素 1 到 5 ，所以答案为 5 。

示例 3：

输入：nums = [3,2,5,3,1], k = 3
输出：4
解释：4 次操作后，集合中的元素依次添加了 1 ，3 ，5 和 2 。此时集合中包含元素 1 到 3  ，所以答案为 4 。

提示：

 * 1 <= nums.length <= 50
 * 1 <= nums[i] <= nums.length
 * 1 <= k <= nums.length
 * 输入保证你可以收集到元素 1, 2, ..., k 。

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

```

my_solution = Solution()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


minimum-number-of-operations-to-make-array-empty

Minimum Number of Operations to Make Array Empty

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

你可以对数组执行以下两种操作 任意次 ：

 * 从数组中选择 两个 值 相等 的元素，并将它们从数组中 删除 。
 * 从数组中选择 三个 值 相等 的元素，并将它们从数组中 删除 。

请你返回使数组为空的 最少 操作次数，如果无法达成，请返回 -1 。

示例 1：

输入：nums = [2,3,3,2,2,4,2,3,4]
输出：4
解释：我们可以执行以下操作使数组为空：
- 对下标为 0 和 3 的元素执行第一种操作，得到 nums = [3,3,2,4,2,3,4] 。
- 对下标为 2 和 4 的元素执行第一种操作，得到 nums = [3,3,4,3,4] 。
- 对下标为 0 ，1 和 3 的元素执行第二种操作，得到 nums = [4,4] 。
- 对下标为 0 和 1 的元素执行第一种操作，得到 nums = [] 。
至少需要 4 步操作使数组为空。

示例 2：

输入：nums = [2,1,2,2,3,3]
输出：-1
解释：无法使数组为空。

提示：

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

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

你可以对数组执行以下两种操作 任意次 ：

 * 从数组中选择 两个 值 相等 的元素，并将它们从数组中 删除 。
 * 从数组中选择 三个 值 相等 的元素，并将它们从数组中 删除 。

请你返回使数组为空的 最少 操作次数，如果无法达成，请返回 -1 。

示例 1：

输入：nums = [2,3,3,2,2,4,2,3,4]
输出：4
解释：我们可以执行以下操作使数组为空：
- 对下标为 0 和 3 的元素执行第一种操作，得到 nums = [3,3,2,4,2,3,4] 。
- 对下标为 2 和 4 的元素执行第一种操作，得到 nums = [3,3,4,3,4] 。
- 对下标为 0 ，1 和 3 的元素执行第二种操作，得到 nums = [4,4] 。
- 对下标为 0 和 1 的元素执行第一种操作，得到 nums = [] 。
至少需要 4 步操作使数组为空。

示例 2：

输入：nums = [2,1,2,2,3,3]
输出：-1
解释：无法使数组为空。

提示：

 * 2 <= nums.length <= 105
 * 1 <= nums[i] <= 106

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

```

my_solution = Solution()

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

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

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

test_input = { "nums": [14,12,14,14,12,14,14,12,12,12,12,14,14,12,14,14,14,12,12] }
assert my_solution.minOperations(**test_input) == 7

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

test_input = { "nums": [15,3,3,15,15,13,8,15,6,15,3,1,8,8,15] }
assert my_solution.minOperations(**test_input) == -1

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

test_input = { "nums": [13,7,13,7,13,7,13,13,7] }
assert my_solution.minOperations(**test_input) == 4

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

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

test_input = { "nums": [3,14,3,14,3,14,14,3,3,14,14,14,3,14,14,3,14,14,14,3] }
assert my_solution.minOperations(**test_input) == 7

test_input = { "nums": [16,16,16,19,16,3,16,8,16,16,16,19,3,16,16] }
assert my_solution.minOperations(**test_input) == -1

test_input = { "nums": [11,11,11,11,19,11,11,11,11,11,19,11,11,11,11,11,19] }
assert my_solution.minOperations(**test_input) == 6

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

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

test_input = { "nums": [14,4,4,19,19] }
assert my_solution.minOperations(**test_input) == -1

test_input = { "nums": [1,14,1,1,1] }
assert my_solution.minOperations(**test_input) == -1

test_input = { "nums": [3,10,11,3,3,11,3,3,3,3,3,3,3,3,10,3,3,3] }
assert my_solution.minOperations(**test_input) == 7

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

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

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

test_input = { "nums": [9,19,19,19,9,9,19,19,19,9,9,19,9,19,19,19] }
assert my_solution.minOperations(**test_input) == 6

test_input = { "nums": [9,4,9,20,20,4,20] }
assert my_solution.minOperations(**test_input) == 3

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

test_input = { "nums": [11,18,11,18,11,18,11] }
assert my_solution.minOperations(**test_input) == 3

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

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

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

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

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

test_input = { "nums": [13,13,16,4,16,13,2,16,16,16,2,16,6,16,13,18,9] }
assert my_solution.minOperations(**test_input) == -1

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

test_input = { "nums": [20,20,19,19,20,19,20,20,20,19,20,20,20,20,20,20,20,20,20] }
assert my_solution.minOperations(**test_input) == 7

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

test_input = { "nums": [16,17,17,8,17,17,16,8,17,16,17] }
assert my_solution.minOperations(**test_input) == 4

test_input = { "nums": [10,10,10,9,10,10,10,9,10,18,10,4,20,2,10,10] }
assert my_solution.minOperations(**test_input) == -1

test_input = { "nums": [11,20,20,11,11,20,14,20,11,11,20,1] }
assert my_solution.minOperations(**test_input) == -1

test_input = { "nums": [14,14,14,14,15,20,15] }
assert my_solution.minOperations(**test_input) == -1

test_input = { "nums": [17,7,17,5,17,17,17,7,17,17,17,17,5,17,17,7,5] }
assert my_solution.minOperations(**test_input) == 6

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

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

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

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

test_input = { "nums": [12,4,9,10,17,12,5,17,4,12,12,12,4,10,4] }
assert my_solution.minOperations(**test_input) == -1

test_input = { "nums": [7,7,7,7,7,7,7,16,7,7,7,16,7,16,7,16,16,16,16,7] }
assert my_solution.minOperations(**test_input) == 8

test_input = { "nums": [20,20,20,20,19] }
assert my_solution.minOperations(**test_input) == -1

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

test_input = { "nums": [15,12,18,18,15,15,15,12,12,12,12,12,12,15,18] }
assert my_solution.minOperations(**test_input) == 6

test_input = { "nums": [14,14,14,1] }
assert my_solution.minOperations(**test_input) == -1

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

test_input = { "nums": [10,16,6,6,10,6] }
assert my_solution.minOperations(**test_input) == -1

test_input = { "nums": [18,17,3,18,6,13,3,6,14,6,15,3] }
assert my_solution.minOperations(**test_input) == -1

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

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

test_input = { "nums": [11,4,4,18,11,12,18,18,12,4,4,12,4] }
assert my_solution.minOperations(**test_input) == 5

test_input = { "nums": [2,5,20,20,5,20,20,16,20,20,20,20,20,20,3,20,20,20] }
assert my_solution.minOperations(**test_input) == -1

test_input = { "nums": [12,13,13,13,12,13,13,13,13,13,11,13,13,13] }
assert my_solution.minOperations(**test_input) == -1

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

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

test_input = { "nums": [7,14,7,7,2,2,7] }
assert my_solution.minOperations(**test_input) == -1

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

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

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

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

test_input = { "nums": [19,19,19,19,18,19,15,7,19,19,15,5] }
assert my_solution.minOperations(**test_input) == -1

test_input = { "nums": [2,12,12,12,17,12,12,12,12,12,12,12,12,12,12] }
assert my_solution.minOperations(**test_input) == -1

test_input = { "nums": [19,16,19,19,16,16,16,16] }
assert my_solution.minOperations(**test_input) == 3

test_input = { "nums": [15,15,15,15,15,15,11,13,15,15,11,15,13,15,11,13] }
assert my_solution.minOperations(**test_input) == 6

test_input = { "nums": [15,16,16,15,16] }
assert my_solution.minOperations(**test_input) == 2

test_input = { "nums": [9,7,14,9,14,7,7,9,9,9,9,9,9,14,14] }
assert my_solution.minOperations(**test_input) == 6

test_input = { "nums": [12,16,5,5,7,10,2,16,12,7,2,12,5,16,2,11] }
assert my_solution.minOperations(**test_input) == -1

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

test_input = { "nums": [18,13,13,18,18,13,13,18,13,13] }
assert my_solution.minOperations(**test_input) == 4

test_input = { "nums": [4,4,8,10,8,10,19,19,19,19,8,8,19,4] }
assert my_solution.minOperations(**test_input) == 6

test_input = { "nums": [1,18,14,16,14] }
assert my_solution.minOperations(**test_input) == -1

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

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

test_input = { "nums": [6,11,6,8,6,13,17,14] }
assert my_solution.minOperations(**test_input) == -1

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

test_input = { "nums": [19,17,17,17,17,17,17,17,19,19,19,17,19,17] }
assert my_solution.minOperations(**test_input) == 5

test_input = { "nums": [4,16,12,7,16,16,16] }
assert my_solution.minOperations(**test_input) == -1

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

test_input = { "nums": [6,6,6,13,6,18,13,18,5,18,12,3,12,12,18,6,18,3,18,6] }
assert my_solution.minOperations(**test_input) == -1

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

test_input = { "nums": [11,11,11,11,9,11,9,9,11,11,9,9,11,11,9] }
assert my_solution.minOperations(**test_input) == 5

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

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

test_input = { "nums": [17,16,16,17,16,16,16] }
assert my_solution.minOperations(**test_input) == 3

test_input = { "nums": [10,18,10,10] }
assert my_solution.minOperations(**test_input) == -1

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

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

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

test_input = { "nums": [19,3,3,3,3,3,3,15,17,3,3,18,10,17,17,15,17,3,3] }
assert my_solution.minOperations(**test_input) == -1

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

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

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

test_input = { "nums": [16,18,18,20] }
assert my_solution.minOperations(**test_input) == -1

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

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

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


split-array-into-maximum-number-of-subarrays

Split Array Into Maximum Number of Subarrays

Prompt:
"""
给你一个只包含 非负 整数的数组 nums 。

我们定义满足 l <= r 的子数组 nums[l..r] 的分数为 nums[l] AND nums[l + 1] AND ... AND nums[r] ，其中 AND 是按位与运算。

请你将数组分割成一个或者更多子数组，满足：

 * 每个 元素都 只 属于一个子数组。
 * 子数组分数之和尽可能 小 。

请你在满足以上要求的条件下，返回 最多 可以得到多少个子数组。

一个 子数组 是一个数组中一段连续的元素。

示例 1：

输入：nums = [1,0,2,0,1,2]
输出：3
解释：我们可以将数组分割成以下子数组：
- [1,0] 。子数组分数为 1 AND 0 = 0 。
- [2,0] 。子数组分数为 2 AND 0 = 0 。
- [1,2] 。子数组分数为 1 AND 2 = 0 。
分数之和为 0 + 0 + 0 = 0 ，是我们可以得到的最小分数之和。
在分数之和为 0 的前提下，最多可以将数组分割成 3 个子数组。所以返回 3 。

示例 2：

输入：nums = [5,7,1,3]
输出：1
解释：我们可以将数组分割成一个子数组：[5,7,1,3] ，分数为 1 ，这是可以得到的最小总分数。
在总分数为 1 的前提下，最多可以将数组分割成 1 个子数组。所以返回 1 。

提示：

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

给你一个只包含 非负 整数的数组 nums 。

我们定义满足 l <= r 的子数组 nums[l..r] 的分数为 nums[l] AND nums[l + 1] AND ... AND nums[r] ，其中 AND 是按位与运算。

请你将数组分割成一个或者更多子数组，满足：

 * 每个 元素都 只 属于一个子数组。
 * 子数组分数之和尽可能 小 。

请你在满足以上要求的条件下，返回 最多 可以得到多少个子数组。

一个 子数组 是一个数组中一段连续的元素。

示例 1：

输入：nums = [1,0,2,0,1,2]
输出：3
解释：我们可以将数组分割成以下子数组：
- [1,0] 。子数组分数为 1 AND 0 = 0 。
- [2,0] 。子数组分数为 2 AND 0 = 0 。
- [1,2] 。子数组分数为 1 AND 2 = 0 。
分数之和为 0 + 0 + 0 = 0 ，是我们可以得到的最小分数之和。
在分数之和为 0 的前提下，最多可以将数组分割成 3 个子数组。所以返回 3 。

示例 2：

输入：nums = [5,7,1,3]
输出：1
解释：我们可以将数组分割成一个子数组：[5,7,1,3] ，分数为 1 ，这是可以得到的最小总分数。
在总分数为 1 的前提下，最多可以将数组分割成 1 个子数组。所以返回 1 。

提示：

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

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

```

my_solution = Solution()

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

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

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

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

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

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

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

test_input = { "nums": [30,18,19,20,11,21,12,22,26] }
assert my_solution.maxSubarrays(**test_input) == 2

test_input = { "nums": [0,8,0,0,0,23] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [8,10,23,26,21,28,21,14,21,14,9,16,24,29,7,26] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [18,12,16,28,7,15,24,7,8,26,22,6,23,7,17,1,16] }
assert my_solution.maxSubarrays(**test_input) == 6

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

test_input = { "nums": [15,24,20,28,11,16,0,0,0,22,7,18] }
assert my_solution.maxSubarrays(**test_input) == 5

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

test_input = { "nums": [18,7,20,10,0,14,0,28,7,0,0,9,12,0] }
assert my_solution.maxSubarrays(**test_input) == 6

test_input = { "nums": [0,29,16,0,6,17] }
assert my_solution.maxSubarrays(**test_input) == 3

test_input = { "nums": [4,7,13,0,23,6,4] }
assert my_solution.maxSubarrays(**test_input) == 1

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

test_input = { "nums": [29,5,0,25,0,15,19,24,20,0,23] }
assert my_solution.maxSubarrays(**test_input) == 4

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

test_input = { "nums": [13,20,16,16,27,0,7,18,3,0,23,16,25,0,5,1,4] }
assert my_solution.maxSubarrays(**test_input) == 5

test_input = { "nums": [0,0,30,20,6,13] }
assert my_solution.maxSubarrays(**test_input) == 2

test_input = { "nums": [21,24,8,8,20,12,24,28,17,9,17] }
assert my_solution.maxSubarrays(**test_input) == 3

test_input = { "nums": [0,0,18,0,0,4,5,25,0,0,0,30,0,18,0,0,12,21,21,18] }
assert my_solution.maxSubarrays(**test_input) == 12

test_input = { "nums": [12,3,0,27,23,0,29,18,0,0,0,20,29,0,2,0,17,10,0,0] }
assert my_solution.maxSubarrays(**test_input) == 11

test_input = { "nums": [26,28,7,14,24,15,1,16,5,24,4,10,24] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [30,11,0,9,15,0,0,0] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [16,18,14,6,25,30,7,0,22,0,15,0] }
assert my_solution.maxSubarrays(**test_input) == 5

test_input = { "nums": [16,12,6,21,26,25,2,0,6,0,13] }
assert my_solution.maxSubarrays(**test_input) == 5

test_input = { "nums": [13,1,13,18,2,15,15,27,3,3,14,12,23,8,29,10,29,15,10] }
assert my_solution.maxSubarrays(**test_input) == 3

test_input = { "nums": [0,29,0,28,20,0,21,8,0,0,26,8,0,0,8,12] }
assert my_solution.maxSubarrays(**test_input) == 8

test_input = { "nums": [0,18,0,0,0,22,0,15] }
assert my_solution.maxSubarrays(**test_input) == 5

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

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

test_input = { "nums": [0,10,11,14,0,19,1,0,28,10,27,27,25,17,0,25,19] }
assert my_solution.maxSubarrays(**test_input) == 5

test_input = { "nums": [18,4,0,6,0,10,23,3,26,0] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [11,22,22,22,18,15,8,8,19,12,20,11] }
assert my_solution.maxSubarrays(**test_input) == 3

test_input = { "nums": [0,23,0,0,0,17,0,0] }
assert my_solution.maxSubarrays(**test_input) == 6

test_input = { "nums": [0,23,0,14,4,5,23,23,8,8,15,0,0,13,6,26,0] }
assert my_solution.maxSubarrays(**test_input) == 7

test_input = { "nums": [0,3,0,16,15,0,1,0,24,16,27,0,23,15,0,13,0,0] }
assert my_solution.maxSubarrays(**test_input) == 9

test_input = { "nums": [12,0,16,0,0,0,29,18] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [0,27,15,13] }
assert my_solution.maxSubarrays(**test_input) == 1

test_input = { "nums": [15,10,0,2,0,3,8,0,0,26,25,27,0,0,0,28,0,10,27,3] }
assert my_solution.maxSubarrays(**test_input) == 9

test_input = { "nums": [11,10,12,6,15,25,17,21,22] }
assert my_solution.maxSubarrays(**test_input) == 2

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

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

test_input = { "nums": [0,0,12,0,7,0,18,26,9,29,0,4,30,21,0,1] }
assert my_solution.maxSubarrays(**test_input) == 7

test_input = { "nums": [6,8,0,0,25,0,30,18,18,0] }
assert my_solution.maxSubarrays(**test_input) == 5

test_input = { "nums": [21,5,18,18,18,0,0,17,0] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [25,29,23,27] }
assert my_solution.maxSubarrays(**test_input) == 1

test_input = { "nums": [28,28,0,16,21,27,12,3,10,0,19,0,0] }
assert my_solution.maxSubarrays(**test_input) == 5

test_input = { "nums": [9,2,22,14,17,3,21,1,29,3,30,13,16,17,25,26,17] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [0,9,4,25,21,0,25,11,13,9,0,0,19,0,16,8,17,26,0,0] }
assert my_solution.maxSubarrays(**test_input) == 9

test_input = { "nums": [11,0,0,2,3,0,9,26,0,0,25,7,1,12,16,14] }
assert my_solution.maxSubarrays(**test_input) == 7

test_input = { "nums": [7,11,27,13,23,16,13,5,27,5,16] }
assert my_solution.maxSubarrays(**test_input) == 2

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

test_input = { "nums": [20,19,2,20,26,1,17,6,23,25,7,14,16,8] }
assert my_solution.maxSubarrays(**test_input) == 5

test_input = { "nums": [28,0,29,9,0,11,13,22,10,16,21,30,18,19,0,0,0] }
assert my_solution.maxSubarrays(**test_input) == 7

test_input = { "nums": [20,26,0,0,0,11,30] }
assert my_solution.maxSubarrays(**test_input) == 3

test_input = { "nums": [16,12,0,2,15,30,0,16,7,25] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [0,7,16,17,29,0,18,0,14,21,17,2,28,7,26,0,14] }
assert my_solution.maxSubarrays(**test_input) == 7

test_input = { "nums": [29,0,19,23,13] }
assert my_solution.maxSubarrays(**test_input) == 1

test_input = { "nums": [0,13,1,12,18,24,11,26,7] }
assert my_solution.maxSubarrays(**test_input) == 3

test_input = { "nums": [7,26,28,12,24,10,11,26,19,29,1,26] }
assert my_solution.maxSubarrays(**test_input) == 3

test_input = { "nums": [28,15,24,9,0] }
assert my_solution.maxSubarrays(**test_input) == 1

test_input = { "nums": [22,6,21,16,24,7,18,25,25,26,15,10,26,22,23,15] }
assert my_solution.maxSubarrays(**test_input) == 3

test_input = { "nums": [0,23,0,1,26,5,18,12,25,23,5,19] }
assert my_solution.maxSubarrays(**test_input) == 5

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

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

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

test_input = { "nums": [0,0,0,11,0,24,8,0,0,17,21,7,0,25,25] }
assert my_solution.maxSubarrays(**test_input) == 7

test_input = { "nums": [0,0,10,0,0,30,5,0] }
assert my_solution.maxSubarrays(**test_input) == 5

test_input = { "nums": [29,22,30,22,19,26] }
assert my_solution.maxSubarrays(**test_input) == 1

test_input = { "nums": [17,15,14,24,30,14,25,28,10,11] }
assert my_solution.maxSubarrays(**test_input) == 1

test_input = { "nums": [0,0,13,2,12,2,27] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [0,18,9,0,20,0,30,22,0] }
assert my_solution.maxSubarrays(**test_input) == 5

test_input = { "nums": [2,6,23,0,0,6,12,22,0,19,18,0,0,14,19,3,11,28,0,17] }
assert my_solution.maxSubarrays(**test_input) == 7

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

test_input = { "nums": [0,22,0,0,0,26,7] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [0,19,5,25,0,0,4,0,0,1,0,10,25,2,3] }
assert my_solution.maxSubarrays(**test_input) == 7

test_input = { "nums": [7,8,18,14,4,6,22,22,7] }
assert my_solution.maxSubarrays(**test_input) == 2

test_input = { "nums": [8,9,13,0,0,20] }
assert my_solution.maxSubarrays(**test_input) == 2

test_input = { "nums": [29,20,13,11,19,27,20,4,24,20,10,21,18,26,3,23,15,18,23,25] }
assert my_solution.maxSubarrays(**test_input) == 5

test_input = { "nums": [25,0,18,13,22,5,0,0] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [9,3,0,2,18,11,15,1,10,0,0,16,0,11] }
assert my_solution.maxSubarrays(**test_input) == 5

test_input = { "nums": [9,0,0,11,14,0,23,0] }
assert my_solution.maxSubarrays(**test_input) == 4

test_input = { "nums": [6,3,22,28,0,0,25,2,23,0,0,23,15,0] }
assert my_solution.maxSubarrays(**test_input) == 7

test_input = { "nums": [0,10,11,25,14] }
assert my_solution.maxSubarrays(**test_input) == 1

test_input = { "nums": [26,9,27,25,30,25,10,3,14,29,2,6,5,7,8,18] }
assert my_solution.maxSubarrays(**test_input) == 3

test_input = { "nums": [5,9,0,28,23,11,1,3] }
assert my_solution.maxSubarrays(**test_input) == 2

test_input = { "nums": [0,22,3,0,15,0,11,3,20,23,0,7,13,20,11,6,19] }
assert my_solution.maxSubarrays(**test_input) == 6

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

test_input = { "nums": [26,9,20,26,22,12,18,21,23,30,3,9,12,19,16] }
assert my_solution.maxSubarrays(**test_input) == 4

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

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

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

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

test_input = { "nums": [16,4,29,17,0,0,13,22,1,6,0,29,1,3,0,7] }
assert my_solution.maxSubarrays(**test_input) == 6

test_input = { "nums": [5,0,0,9,0,0,19,0,0,0,0,7,19,14,3,0,10,29] }
assert my_solution.maxSubarrays(**test_input) == 9

test_input = { "nums": [16,22,0,0,0,0,27,0,0,0,24,22,0,0] }
assert my_solution.maxSubarrays(**test_input) == 9


maximum-number-of-k-divisible-components

Maximum Number of K-Divisible Components

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

同时给你一个下标从 0 开始长度为 n 的整数数组 values ，其中 values[i] 是第 i 个节点的 值 。再给你一个整数 k 。

你可以从树中删除一些边，也可以一条边也不删，得到若干连通块。一个 连通块的值 定义为连通块中所有节点值之和。如果所有连通块的值都可以被 k 整除，那么我们说这是一个 合法分割 。

请你返回所有合法分割中，连通块数目的最大值 。

示例 1：

[https://assets.leetcode.com/uploads/2023/08/07/example12-cropped2svg.jpg]

输入：n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6
输出：2
解释：我们删除节点 1 和 2 之间的边。这是一个合法分割，因为：
- 节点 1 和 3 所在连通块的值为 values[1] + values[3] = 12 。
- 节点 0 ，2 和 4 所在连通块的值为 values[0] + values[2] + values[4] = 6 。
最多可以得到 2 个连通块的合法分割。

示例 2：

[https://assets.leetcode.com/uploads/2023/08/07/example21svg-1.jpg]

输入：n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3
输出：3
解释：我们删除节点 0 和 2 ，以及节点 0 和 1 之间的边。这是一个合法分割，因为：
- 节点 0 的连通块的值为 values[0] = 3 。
- 节点 2 ，5 和 6 所在连通块的值为 values[2] + values[5] + values[6] = 9 。
- 节点 1 ，3 和 4 的连通块的值为 values[1] + values[3] + values[4] = 6 。
最多可以得到 3 个连通块的合法分割。

提示：

 * 1 <= n <= 3 * 104
 * edges.length == n - 1
 * edges[i].length == 2
 * 0 <= ai, bi < n
 * values.length == n
 * 0 <= values[i] <= 109
 * 1 <= k <= 109
 * values 之和可以被 k 整除。
 * 输入保证 edges 是一棵无向树。
"""
class Solution:
    def maxKDivisibleComponents(self, n: int, edges: List[List[int]], values: List[int], k: int) -> int:

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

同时给你一个下标从 0 开始长度为 n 的整数数组 values ，其中 values[i] 是第 i 个节点的 值 。再给你一个整数 k 。

你可以从树中删除一些边，也可以一条边也不删，得到若干连通块。一个 连通块的值 定义为连通块中所有节点值之和。如果所有连通块的值都可以被 k 整除，那么我们说这是一个 合法分割 。

请你返回所有合法分割中，连通块数目的最大值 。

示例 1：

[https://assets.leetcode.com/uploads/2023/08/07/example12-cropped2svg.jpg]

输入：n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6
输出：2
解释：我们删除节点 1 和 2 之间的边。这是一个合法分割，因为：
- 节点 1 和 3 所在连通块的值为 values[1] + values[3] = 12 。
- 节点 0 ，2 和 4 所在连通块的值为 values[0] + values[2] + values[4] = 6 。
最多可以得到 2 个连通块的合法分割。

示例 2：

[https://assets.leetcode.com/uploads/2023/08/07/example21svg-1.jpg]

输入：n = 7, edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [3,0,6,1,5,2,1], k = 3
输出：3
解释：我们删除节点 0 和 2 ，以及节点 0 和 1 之间的边。这是一个合法分割，因为：
- 节点 0 的连通块的值为 values[0] = 3 。
- 节点 2 ，5 和 6 所在连通块的值为 values[2] + values[5] + values[6] = 9 。
- 节点 1 ，3 和 4 的连通块的值为 values[1] + values[3] + values[4] = 6 。
最多可以得到 3 个连通块的合法分割。

提示：

 * 1 <= n <= 3 * 104
 * edges.length == n - 1
 * edges[i].length == 2
 * 0 <= ai, bi < n
 * values.length == n
 * 0 <= values[i] <= 109
 * 1 <= k <= 109
 * values 之和可以被 k 整除。
 * 输入保证 edges 是一棵无向树。

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

```

my_solution = Solution()

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

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

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

test_input = { "n": 1, "edges": [], "values": [10000], "k": 100 }
assert my_solution.maxKDivisibleComponents(**test_input) == 1

test_input = { "n": 2, "edges": [[1,0]], "values": [0,0], "k": 100000000 }
assert my_solution.maxKDivisibleComponents(**test_input) == 2

test_input = { "n": 2, "edges": [[0,1]], "values": [1,2], "k": 1 }
assert my_solution.maxKDivisibleComponents(**test_input) == 2

test_input = { "n": 2, "edges": [[1,0]], "values": [10000,10000], "k": 4 }
assert my_solution.maxKDivisibleComponents(**test_input) == 2

test_input = { "n": 3, "edges": [[0,2],[2,1]], "values": [0,0,0], "k": 1 }
assert my_solution.maxKDivisibleComponents(**test_input) == 3

test_input = { "n": 3, "edges": [[1,0],[2,0]], "values": [1,1,2], "k": 2 }
assert my_solution.maxKDivisibleComponents(**test_input) == 2

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

test_input = { "n": 3, "edges": [[1,0],[0,2]], "values": [0,1,2], "k": 3 }
assert my_solution.maxKDivisibleComponents(**test_input) == 1

test_input = { "n": 4, "edges": [[0,1],[1,2],[2,3]], "values": [0,0,0,0], "k": 9999999 }
assert my_solution.maxKDivisibleComponents(**test_input) == 4

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

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

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

test_input = { "n": 4, "edges": [[0,3],[1,2],[0,2]], "values": [12,6,0,18], "k": 6 }
assert my_solution.maxKDivisibleComponents(**test_input) == 4

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

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

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

test_input = { "n": 7, "edges": [[0,3],[3,2],[3,5],[0,6],[0,1],[6,4]], "values": [12,6,6,12,18,18,12], "k": 6 }
assert my_solution.maxKDivisibleComponents(**test_input) == 7

test_input = { "n": 4, "edges": [[1,3],[0,2],[1,0]], "values": [2,6,1,9], "k": 3 }
assert my_solution.maxKDivisibleComponents(**test_input) == 3

test_input = { "n": 5, "edges": [[2,0],[0,1],[2,3],[2,4]], "values": [0,2,10,0,18], "k": 6 }
assert my_solution.maxKDivisibleComponents(**test_input) == 3

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

test_input = { "n": 10, "edges": [[9,5],[4,9],[5,8],[3,6],[8,6],[0,1],[9,0],[6,2],[3,7]], "values": [10,14,12,4,12,1,8,36,12,11], "k": 12 }
assert my_solution.maxKDivisibleComponents(**test_input) == 7

test_input = { "n": 7, "edges": [[3,0],[0,4],[2,6],[3,6],[2,1],[1,5]], "values": [5,36,21,7,36,36,15], "k": 12 }
assert my_solution.maxKDivisibleComponents(**test_input) == 5

test_input = { "n": 5, "edges": [[2,3],[2,0],[2,4],[3,1]], "values": [3,0,3,15,3], "k": 8 }
assert my_solution.maxKDivisibleComponents(**test_input) == 2

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

test_input = { "n": 4, "edges": [[2,1],[2,0],[2,3]], "values": [2,0,8,10], "k": 5 }
assert my_solution.maxKDivisibleComponents(**test_input) == 3

test_input = { "n": 5, "edges": [[2,4],[4,0],[0,1],[0,3]], "values": [10,20,10,30,30], "k": 10 }
assert my_solution.maxKDivisibleComponents(**test_input) == 5

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

test_input = { "n": 9, "edges": [[5,6],[5,1],[6,0],[6,8],[8,2],[7,3],[8,3],[8,4]], "values": [33,11,33,6,11,11,33,16,33], "k": 11 }
assert my_solution.maxKDivisibleComponents(**test_input) == 8

test_input = { "n": 4, "edges": [[3,0],[0,2],[3,1]], "values": [8,8,12,4], "k": 4 }
assert my_solution.maxKDivisibleComponents(**test_input) == 4

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

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

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

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

test_input = { "n": 4, "edges": [[2,1],[2,3],[2,0]], "values": [3,6,9,6], "k": 3 }
assert my_solution.maxKDivisibleComponents(**test_input) == 4

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

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

test_input = { "n": 5, "edges": [[0,4],[0,1],[1,3],[0,2]], "values": [2,12,14,0,0], "k": 7 }
assert my_solution.maxKDivisibleComponents(**test_input) == 4

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

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

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

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

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

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

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

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

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

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

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

test_input = { "n": 8, "edges": [[4,3],[3,6],[6,1],[6,7],[1,2],[7,0],[4,5]], "values": [30,10,10,20,10,10,30,10], "k": 10 }
assert my_solution.maxKDivisibleComponents(**test_input) == 8

test_input = { "n": 4, "edges": [[2,1],[1,0],[0,3]], "values": [9,6,6,9], "k": 3 }
assert my_solution.maxKDivisibleComponents(**test_input) == 4

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

test_input = { "n": 5, "edges": [[1,3],[3,4],[4,2],[2,0]], "values": [27,14,0,0,4], "k": 9 }
assert my_solution.maxKDivisibleComponents(**test_input) == 3

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

test_input = { "n": 7, "edges": [[6,1],[6,4],[1,3],[3,0],[2,5],[4,2]], "values": [33,18,7,22,11,4,4], "k": 11 }
assert my_solution.maxKDivisibleComponents(**test_input) == 5

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

test_input = { "n": 8, "edges": [[6,1],[0,5],[5,7],[5,2],[5,4],[1,4],[0,3]], "values": [15,24,9,12,0,3,24,9], "k": 12 }
assert my_solution.maxKDivisibleComponents(**test_input) == 5

test_input = { "n": 6, "edges": [[3,1],[3,5],[1,4],[1,0],[3,2]], "values": [12,12,36,12,24,36], "k": 12 }
assert my_solution.maxKDivisibleComponents(**test_input) == 6

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

test_input = { "n": 8, "edges": [[6,1],[2,0],[0,7],[1,2],[4,5],[7,5],[1,3]], "values": [1,14,5,21,18,3,7,1], "k": 7 }
assert my_solution.maxKDivisibleComponents(**test_input) == 5

test_input = { "n": 4, "edges": [[1,3],[1,0],[1,2]], "values": [18,18,9,27], "k": 9 }
assert my_solution.maxKDivisibleComponents(**test_input) == 4

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

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

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

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

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

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

test_input = { "n": 5, "edges": [[2,4],[2,0],[0,3],[2,1]], "values": [36,24,10,24,2], "k": 12 }
assert my_solution.maxKDivisibleComponents(**test_input) == 4

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

test_input = { "n": 4, "edges": [[3,2],[2,1],[2,0]], "values": [6,2,2,6], "k": 8 }
assert my_solution.maxKDivisibleComponents(**test_input) == 1

test_input = { "n": 10, "edges": [[7,4],[7,2],[4,1],[6,5],[6,0],[7,6],[1,8],[9,3],[7,9]], "values": [12,4,3,2,1,18,3,3,22,20], "k": 11 }
assert my_solution.maxKDivisibleComponents(**test_input) == 4

test_input = { "n": 5, "edges": [[0,3],[3,2],[3,1],[0,4]], "values": [12,36,36,36,12], "k": 12 }
assert my_solution.maxKDivisibleComponents(**test_input) == 5

test_input = { "n": 5, "edges": [[0,1],[1,2],[2,3],[3,4]], "values": [3,0,0,18,3], "k": 8 }
assert my_solution.maxKDivisibleComponents(**test_input) == 1

test_input = { "n": 4, "edges": [[3,2],[3,0],[3,1]], "values": [9,0,15,3], "k": 9 }
assert my_solution.maxKDivisibleComponents(**test_input) == 3

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

test_input = { "n": 5, "edges": [[1,4],[1,3],[0,3],[1,2]], "values": [10,2,15,2,1], "k": 5 }
assert my_solution.maxKDivisibleComponents(**test_input) == 3

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

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

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

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

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

test_input = { "n": 6, "edges": [[4,1],[4,5],[4,2],[4,0],[3,1]], "values": [0,6,6,22,2,8], "k": 11 }
assert my_solution.maxKDivisibleComponents(**test_input) == 3

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

test_input = { "n": 5, "edges": [[0,3],[0,1],[0,2],[0,4]], "values": [3,3,0,18,0], "k": 8 }
assert my_solution.maxKDivisibleComponents(**test_input) == 3

test_input = { "n": 4, "edges": [[2,0],[2,1],[0,3]], "values": [10,15,5,15], "k": 5 }
assert my_solution.maxKDivisibleComponents(**test_input) == 4

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

test_input = { "n": 8, "edges": [[5,2],[2,4],[5,1],[5,3],[1,0],[2,6],[2,7]], "values": [18,9,9,9,27,9,9,18], "k": 9 }
assert my_solution.maxKDivisibleComponents(**test_input) == 8

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

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

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

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

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

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

test_input = { "n": 7, "edges": [[4,2],[6,4],[5,3],[3,1],[4,5],[2,0]], "values": [9,3,0,9,9,15,18], "k": 9 }
assert my_solution.maxKDivisibleComponents(**test_input) == 5

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

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

test_input = { "n": 6, "edges": [[2,3],[4,5],[4,1],[2,4],[2,0]], "values": [20,0,30,30,12,8], "k": 10 }
assert my_solution.maxKDivisibleComponents(**test_input) == 5

test_input = { "n": 9, "edges": [[5,7],[5,4],[5,6],[7,2],[7,1],[4,3],[2,0],[3,8]], "values": [6,6,6,18,6,12,18,6,6], "k": 6 }
assert my_solution.maxKDivisibleComponents(**test_input) == 9


maximum-odd-binary-number

Maximum Odd Binary Number

Prompt:
"""
给你一个 二进制 字符串 s ，其中至少包含一个 '1' 。

你必须按某种方式 重新排列 字符串中的位，使得到的二进制数字是可以由该组合生成的 最大二进制奇数 。

以字符串形式，表示并返回可以由给定组合生成的最大二进制奇数。

注意 返回的结果字符串 可以 含前导零。

示例 1：

输入：s = "010"
输出："001"
解释：因为字符串 s 中仅有一个 '1' ，其必须出现在最后一位上。所以答案是 "001" 。

示例 2：

输入：s = "0101"
输出："1001"
解释：其中一个 '1' 必须出现在最后一位上。而由剩下的数字可以生产的最大数字是 "100" 。所以答案是 "1001" 。

提示：

 * 1 <= s.length <= 100
 * s 仅由 '0' 和 '1' 组成
 * s 中至少包含一个 '1'
"""
class Solution:
    def maximumOddBinaryNumber(self, s: str) -> str:

给你一个 二进制 字符串 s ，其中至少包含一个 '1' 。

你必须按某种方式 重新排列 字符串中的位，使得到的二进制数字是可以由该组合生成的 最大二进制奇数 。

以字符串形式，表示并返回可以由给定组合生成的最大二进制奇数。

注意 返回的结果字符串 可以 含前导零。

示例 1：

输入：s = "010"
输出："001"
解释：因为字符串 s 中仅有一个 '1' ，其必须出现在最后一位上。所以答案是 "001" 。

示例 2：

输入：s = "0101"
输出："1001"
解释：其中一个 '1' 必须出现在最后一位上。而由剩下的数字可以生产的最大数字是 "100" 。所以答案是 "1001" 。

提示：

 * 1 <= s.length <= 100
 * s 仅由 '0' 和 '1' 组成
 * s 中至少包含一个 '1'

请完成下面的代码来解决上述问题:
```python
class Solution:
    def maximumOddBinaryNumber(self, s: str) -> str:

```

my_solution = Solution()

test_input = { "s": "010" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "001"

test_input = { "s": "0101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1001"

test_input = { "s": "1" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1"

test_input = { "s": "01" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "01"

test_input = { "s": "10" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "01"

test_input = { "s": "11" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "11"

test_input = { "s": "001" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "001"

test_input = { "s": "011" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "101"

test_input = { "s": "100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "001"

test_input = { "s": "101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "101"

test_input = { "s": "110" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "101"

test_input = { "s": "111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111"

test_input = { "s": "0010" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "0001"

test_input = { "s": "0011" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1001"

test_input = { "s": "0100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "0001"

test_input = { "s": "0111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1101"

test_input = { "s": "1000" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "0001"

test_input = { "s": "1001" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1001"

test_input = { "s": "1011" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1101"

test_input = { "s": "1100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1001"

test_input = { "s": "1101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1101"

test_input = { "s": "1111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1111"

test_input = { "s": "00001" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "00001"

test_input = { "s": "00011" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "10001"

test_input = { "s": "00100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "00001"

test_input = { "s": "00101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "10001"

test_input = { "s": "00111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "11001"

test_input = { "s": "01011" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "11001"

test_input = { "s": "01100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "10001"

test_input = { "s": "01110" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "11001"

test_input = { "s": "01111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "11101"

test_input = { "s": "10000" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "00001"

test_input = { "s": "10100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "10001"

test_input = { "s": "11010" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "11001"

test_input = { "s": "11011" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "11101"

test_input = { "s": "11110" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "11101"

test_input = { "s": "000001" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "000001"

test_input = { "s": "000100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "000001"

test_input = { "s": "000101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "100001"

test_input = { "s": "000110" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "100001"

test_input = { "s": "000111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "110001"

test_input = { "s": "001100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "100001"

test_input = { "s": "001110" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "110001"

test_input = { "s": "001111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111001"

test_input = { "s": "010001" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "100001"

test_input = { "s": "010101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "110001"

test_input = { "s": "010111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111001"

test_input = { "s": "011010" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "110001"

test_input = { "s": "011100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "110001"

test_input = { "s": "011111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111101"

test_input = { "s": "100100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "100001"

test_input = { "s": "100101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "110001"

test_input = { "s": "100111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111001"

test_input = { "s": "101010" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "110001"

test_input = { "s": "101100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "110001"

test_input = { "s": "101101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111001"

test_input = { "s": "110000" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "100001"

test_input = { "s": "110010" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "110001"

test_input = { "s": "110011" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111001"

test_input = { "s": "110100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "110001"

test_input = { "s": "110101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111001"

test_input = { "s": "110110" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111001"

test_input = { "s": "111000" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "110001"

test_input = { "s": "111010" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111001"

test_input = { "s": "111101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111101"

test_input = { "s": "111111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "111111"

test_input = { "s": "0000010" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "0000001"

test_input = { "s": "0000100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "0000001"

test_input = { "s": "0001001" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1000001"

test_input = { "s": "0001110" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1100001"

test_input = { "s": "0010000" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "0000001"

test_input = { "s": "0010101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1100001"

test_input = { "s": "0010110" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1100001"

test_input = { "s": "0010111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1110001"

test_input = { "s": "0011101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1110001"

test_input = { "s": "0011111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1111001"

test_input = { "s": "0100100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1000001"

test_input = { "s": "0101001" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1100001"

test_input = { "s": "0110010" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1100001"

test_input = { "s": "0110110" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1110001"

test_input = { "s": "0110111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1111001"

test_input = { "s": "0111011" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1111001"

test_input = { "s": "0111101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1111001"

test_input = { "s": "1000011" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1100001"

test_input = { "s": "1000100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1000001"

test_input = { "s": "1000101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1100001"

test_input = { "s": "1000111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1110001"

test_input = { "s": "1001100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1100001"

test_input = { "s": "1001101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1110001"

test_input = { "s": "1010000" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1000001"

test_input = { "s": "1010100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1100001"

test_input = { "s": "1010111" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1111001"

test_input = { "s": "1011000" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1100001"

test_input = { "s": "1011010" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1110001"

test_input = { "s": "1011011" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1111001"

test_input = { "s": "1100100" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1100001"

test_input = { "s": "1100101" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1110001"

test_input = { "s": "1101010" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1110001"

test_input = { "s": "1101011" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1111001"

test_input = { "s": "1101110" }
assert my_solution.maximumOddBinaryNumber(**test_input) == "1111001"


beautiful-towers-i

Beautiful Towers I

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 <= 103
 * 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 <= 103
 * 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": [933754743] }
assert my_solution.maximumSumOfHeights(**test_input) == 933754743

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": [30,1] }
assert my_solution.maximumSumOfHeights(**test_input) == 31

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

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,4,3,3,3,6] }
assert my_solution.maximumSumOfHeights(**test_input) == 20

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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