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

Count Visited Nodes in a Directed Graph

Prompt:
"""
There is a directed graph consisting of n nodes numbered from 0 to n - 1 and n directed edges.

You are given a 0-indexed array edges where edges[i] indicates that there is an edge from node i to node edges[i].

Consider the following process on the graph:

 * You start from a node x and keep visiting other nodes through edges until you reach a node that you have already visited before on this same process.

Return an array answer where answer[i] is the number of different nodes that you will visit if you perform the process starting from node i.

Example 1:

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

Input: edges = [1,2,0,0]
Output: [3,3,3,4]
Explanation: We perform the process starting from each node in the following way:
- Starting from node 0, we visit the nodes 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 3.
- Starting from node 1, we visit the nodes 1 -> 2 -> 0 -> 1. The number of different nodes we visit is 3.
- Starting from node 2, we visit the nodes 2 -> 0 -> 1 -> 2. The number of different nodes we visit is 3.
- Starting from node 3, we visit the nodes 3 -> 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 4.

Example 2:

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

Input: edges = [1,2,3,4,0]
Output: [5,5,5,5,5]
Explanation: Starting from any node we can visit every node in the graph in the process.

Constraints:

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

There is a directed graph consisting of n nodes numbered from 0 to n - 1 and n directed edges.

You are given a 0-indexed array edges where edges[i] indicates that there is an edge from node i to node edges[i].

Consider the following process on the graph:

 * You start from a node x and keep visiting other nodes through edges until you reach a node that you have already visited before on this same process.

Return an array answer where answer[i] is the number of different nodes that you will visit if you perform the process starting from node i.

Example 1:

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

Input: edges = [1,2,0,0]
Output: [3,3,3,4]
Explanation: We perform the process starting from each node in the following way:
- Starting from node 0, we visit the nodes 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 3.
- Starting from node 1, we visit the nodes 1 -> 2 -> 0 -> 1. The number of different nodes we visit is 3.
- Starting from node 2, we visit the nodes 2 -> 0 -> 1 -> 2. The number of different nodes we visit is 3.
- Starting from node 3, we visit the nodes 3 -> 0 -> 1 -> 2 -> 0. The number of different nodes we visit is 4.

Example 2:

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

Input: edges = [1,2,3,4,0]
Output: [5,5,5,5,5]
Explanation: Starting from any node we can visit every node in the graph in the process.

Constraints:

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

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

```


minimum-operations-to-collect-elements

Minimum Operations to Collect Elements

Prompt:
"""
You are given an array nums of positive integers and an integer k.

In one operation, you can remove the last element of the array and add it to your collection.

Return the minimum number of operations needed to collect elements 1, 2, ..., k.

Example 1:

Input: nums = [3,1,5,4,2], k = 2
Output: 4
Explanation: After 4 operations, we collect elements 2, 4, 5, and 1, in this order. Our collection contains elements 1 and 2. Hence, the answer is 4.

Example 2:

Input: nums = [3,1,5,4,2], k = 5
Output: 5
Explanation: After 5 operations, we collect elements 2, 4, 5, 1, and 3, in this order. Our collection contains elements 1 through 5. Hence, the answer is 5.

Example 3:

Input: nums = [3,2,5,3,1], k = 3
Output: 4
Explanation: After 4 operations, we collect elements 1, 3, 5, and 2, in this order. Our collection contains elements 1 through 3. Hence, the answer is 4.

Constraints:

 * 1 <= nums.length <= 50
 * 1 <= nums[i] <= nums.length
 * 1 <= k <= nums.length
 * The input is generated such that you can collect elements 1, 2, ..., k.
"""
class Solution:
    def minOperations(self, nums: List[int], k: int) -> int:

You are given an array nums of positive integers and an integer k.

In one operation, you can remove the last element of the array and add it to your collection.

Return the minimum number of operations needed to collect elements 1, 2, ..., k.

Example 1:

Input: nums = [3,1,5,4,2], k = 2
Output: 4
Explanation: After 4 operations, we collect elements 2, 4, 5, and 1, in this order. Our collection contains elements 1 and 2. Hence, the answer is 4.

Example 2:

Input: nums = [3,1,5,4,2], k = 5
Output: 5
Explanation: After 5 operations, we collect elements 2, 4, 5, 1, and 3, in this order. Our collection contains elements 1 through 5. Hence, the answer is 5.

Example 3:

Input: nums = [3,2,5,3,1], k = 3
Output: 4
Explanation: After 4 operations, we collect elements 1, 3, 5, and 2, in this order. Our collection contains elements 1 through 3. Hence, the answer is 4.

Constraints:

 * 1 <= nums.length <= 50
 * 1 <= nums[i] <= nums.length
 * 1 <= k <= nums.length
 * The input is generated such that you can collect elements 1, 2, ..., k.

Please complete the code below to solve above prblem:
```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:
"""
You are given a 0-indexed array nums consisting of positive integers.

There are two types of operations that you can apply on the array any number of times:

 * Choose two elements with equal values and delete them from the array.
 * Choose three elements with equal values and delete them from the array.

Return the minimum number of operations required to make the array empty, or -1 if it is not possible.

Example 1:

Input: nums = [2,3,3,2,2,4,2,3,4]
Output: 4
Explanation: We can apply the following operations to make the array empty:
- Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].
- Apply the first operation on the elements at indices 2 and 4. The resulting array is nums = [3,3,4,3,4].
- Apply the second operation on the elements at indices 0, 1, and 3. The resulting array is nums = [4,4].
- Apply the first operation on the elements at indices 0 and 1. The resulting array is nums = [].
It can be shown that we cannot make the array empty in less than 4 operations.

Example 2:

Input: nums = [2,1,2,2,3,3]
Output: -1
Explanation: It is impossible to empty the array.

Constraints:

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

You are given a 0-indexed array nums consisting of positive integers.

There are two types of operations that you can apply on the array any number of times:

 * Choose two elements with equal values and delete them from the array.
 * Choose three elements with equal values and delete them from the array.

Return the minimum number of operations required to make the array empty, or -1 if it is not possible.

Example 1:

Input: nums = [2,3,3,2,2,4,2,3,4]
Output: 4
Explanation: We can apply the following operations to make the array empty:
- Apply the first operation on the elements at indices 0 and 3. The resulting array is nums = [3,3,2,4,2,3,4].
- Apply the first operation on the elements at indices 2 and 4. The resulting array is nums = [3,3,4,3,4].
- Apply the second operation on the elements at indices 0, 1, and 3. The resulting array is nums = [4,4].
- Apply the first operation on the elements at indices 0 and 1. The resulting array is nums = [].
It can be shown that we cannot make the array empty in less than 4 operations.

Example 2:

Input: nums = [2,1,2,2,3,3]
Output: -1
Explanation: It is impossible to empty the array.

Constraints:

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

Please complete the code below to solve above prblem:
```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:
"""
You are given an array nums consisting of non-negative integers.

We define the score of subarray nums[l..r] such that l <= r as nums[l] AND nums[l + 1] AND ... AND nums[r] where AND is the bitwise AND operation.

Consider splitting the array into one or more subarrays such that the following conditions are satisfied:

 * Each element of the array belongs to exactly one subarray.
 * The sum of scores of the subarrays is the minimum possible.

Return the maximum number of subarrays in a split that satisfies the conditions above.

A subarray is a contiguous part of an array.

Example 1:

Input: nums = [1,0,2,0,1,2]
Output: 3
Explanation: We can split the array into the following subarrays:
- [1,0]. The score of this subarray is 1 AND 0 = 0.
- [2,0]. The score of this subarray is 2 AND 0 = 0.
- [1,2]. The score of this subarray is 1 AND 2 = 0.
The sum of scores is 0 + 0 + 0 = 0, which is the minimum possible score that we can obtain.
It can be shown that we cannot split the array into more than 3 subarrays with a total score of 0. So we return 3.

Example 2:

Input: nums = [5,7,1,3]
Output: 1
Explanation: We can split the array into one subarray: [5,7,1,3] with a score of 1, which is the minimum possible score that we can obtain.
It can be shown that we cannot split the array into more than 1 subarray with a total score of 1. So we return 1.

Constraints:

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

You are given an array nums consisting of non-negative integers.

We define the score of subarray nums[l..r] such that l <= r as nums[l] AND nums[l + 1] AND ... AND nums[r] where AND is the bitwise AND operation.

Consider splitting the array into one or more subarrays such that the following conditions are satisfied:

 * Each element of the array belongs to exactly one subarray.
 * The sum of scores of the subarrays is the minimum possible.

Return the maximum number of subarrays in a split that satisfies the conditions above.

A subarray is a contiguous part of an array.

Example 1:

Input: nums = [1,0,2,0,1,2]
Output: 3
Explanation: We can split the array into the following subarrays:
- [1,0]. The score of this subarray is 1 AND 0 = 0.
- [2,0]. The score of this subarray is 2 AND 0 = 0.
- [1,2]. The score of this subarray is 1 AND 2 = 0.
The sum of scores is 0 + 0 + 0 = 0, which is the minimum possible score that we can obtain.
It can be shown that we cannot split the array into more than 3 subarrays with a total score of 0. So we return 3.

Example 2:

Input: nums = [5,7,1,3]
Output: 1
Explanation: We can split the array into one subarray: [5,7,1,3] with a score of 1, which is the minimum possible score that we can obtain.
It can be shown that we cannot split the array into more than 1 subarray with a total score of 1. So we return 1.

Constraints:

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

Please complete the code below to solve above prblem:
```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:
"""
There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.

You are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node, and an integer k.

A valid split of the tree is obtained by removing any set of edges, possibly empty, from the tree such that the resulting components all have values that are divisible by k, where the value of a connected component is the sum of the values of its nodes.

Return the maximum number of components in any valid split.

Example 1:

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

Input: n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6
Output: 2
Explanation: We remove the edge connecting node 1 with 2. The resulting split is valid because:
- The value of the component containing nodes 1 and 3 is values[1] + values[3] = 12.
- The value of the component containing nodes 0, 2, and 4 is values[0] + values[2] + values[4] = 6.
It can be shown that no other valid split has more than 2 connected components.

Example 2:

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

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
Output: 3
Explanation: We remove the edge connecting node 0 with 2, and the edge connecting node 0 with 1. The resulting split is valid because:
- The value of the component containing node 0 is values[0] = 3.
- The value of the component containing nodes 2, 5, and 6 is values[2] + values[5] + values[6] = 9.
- The value of the component containing nodes 1, 3, and 4 is values[1] + values[3] + values[4] = 6.
It can be shown that no other valid split has more than 3 connected components.

Constraints:

 * 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
 * Sum of values is divisible by k.
 * The input is generated such that edges represents a valid tree.
"""
class Solution:
    def maxKDivisibleComponents(self, n: int, edges: List[List[int]], values: List[int], k: int) -> int:

There is an undirected tree with n nodes labeled from 0 to n - 1. You are given the integer n and a 2D integer array edges of length n - 1, where edges[i] = [ai, bi] indicates that there is an edge between nodes ai and bi in the tree.

You are also given a 0-indexed integer array values of length n, where values[i] is the value associated with the ith node, and an integer k.

A valid split of the tree is obtained by removing any set of edges, possibly empty, from the tree such that the resulting components all have values that are divisible by k, where the value of a connected component is the sum of the values of its nodes.

Return the maximum number of components in any valid split.

Example 1:

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

Input: n = 5, edges = [[0,2],[1,2],[1,3],[2,4]], values = [1,8,1,4,4], k = 6
Output: 2
Explanation: We remove the edge connecting node 1 with 2. The resulting split is valid because:
- The value of the component containing nodes 1 and 3 is values[1] + values[3] = 12.
- The value of the component containing nodes 0, 2, and 4 is values[0] + values[2] + values[4] = 6.
It can be shown that no other valid split has more than 2 connected components.

Example 2:

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

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
Output: 3
Explanation: We remove the edge connecting node 0 with 2, and the edge connecting node 0 with 1. The resulting split is valid because:
- The value of the component containing node 0 is values[0] = 3.
- The value of the component containing nodes 2, 5, and 6 is values[2] + values[5] + values[6] = 9.
- The value of the component containing nodes 1, 3, and 4 is values[1] + values[3] + values[4] = 6.
It can be shown that no other valid split has more than 3 connected components.

Constraints:

 * 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
 * Sum of values is divisible by k.
 * The input is generated such that edges represents a valid tree.

Please complete the code below to solve above prblem:
```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:
"""
You are given a binary string s that contains at least one '1'.

You have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.

Return a string representing the maximum odd binary number that can be created from the given combination.

Note that the resulting string can have leading zeros.

Example 1:

Input: s = "010"
Output: "001"
Explanation: Because there is just one '1', it must be in the last position. So the answer is "001".

Example 2:

Input: s = "0101"
Output: "1001"
Explanation: One of the '1's must be in the last position. The maximum number that can be made with the remaining digits is "100". So the answer is "1001".

Constraints:

 * 1 <= s.length <= 100
 * s consists only of '0' and '1'.
 * s contains at least one '1'.
"""
class Solution:
    def maximumOddBinaryNumber(self, s: str) -> str:

You are given a binary string s that contains at least one '1'.

You have to rearrange the bits in such a way that the resulting binary number is the maximum odd binary number that can be created from this combination.

Return a string representing the maximum odd binary number that can be created from the given combination.

Note that the resulting string can have leading zeros.

Example 1:

Input: s = "010"
Output: "001"
Explanation: Because there is just one '1', it must be in the last position. So the answer is "001".

Example 2:

Input: s = "0101"
Output: "1001"
Explanation: One of the '1's must be in the last position. The maximum number that can be made with the remaining digits is "100". So the answer is "1001".

Constraints:

 * 1 <= s.length <= 100
 * s consists only of '0' and '1'.
 * s contains at least one '1'.

Please complete the code below to solve above prblem:
```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:
"""
You are given a 0-indexed array maxHeights of n integers.

You are tasked with building n towers in the coordinate line. The ith tower is built at coordinate i and has a height of heights[i].

A configuration of towers is beautiful if the following conditions hold:

 1. 1 <= heights[i] <= maxHeights[i]
 2. heights is a mountain array.

Array heights is a mountain if there exists an index i such that:

 * For all 0 < j <= i, heights[j - 1] <= heights[j]
 * For all i <= k < n - 1, heights[k + 1] <= heights[k]

Return the maximum possible sum of heights of a beautiful configuration of towers.

Example 1:

Input: maxHeights = [5,3,4,1,1]
Output: 13
Explanation: One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 0.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.

Example 2:

Input: maxHeights = [6,5,3,9,2,7]
Output: 22
Explanation: One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 3.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.

Example 3:

Input: maxHeights = [3,2,5,5,2,3]
Output: 18
Explanation: One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 2.
Note that, for this configuration, i = 3 can also be considered a peak.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.

Constraints:

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

You are given a 0-indexed array maxHeights of n integers.

You are tasked with building n towers in the coordinate line. The ith tower is built at coordinate i and has a height of heights[i].

A configuration of towers is beautiful if the following conditions hold:

 1. 1 <= heights[i] <= maxHeights[i]
 2. heights is a mountain array.

Array heights is a mountain if there exists an index i such that:

 * For all 0 < j <= i, heights[j - 1] <= heights[j]
 * For all i <= k < n - 1, heights[k + 1] <= heights[k]

Return the maximum possible sum of heights of a beautiful configuration of towers.

Example 1:

Input: maxHeights = [5,3,4,1,1]
Output: 13
Explanation: One beautiful configuration with a maximum sum is heights = [5,3,3,1,1]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 0.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 13.

Example 2:

Input: maxHeights = [6,5,3,9,2,7]
Output: 22
Explanation: One beautiful configuration with a maximum sum is heights = [3,3,3,9,2,2]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 3.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 22.

Example 3:

Input: maxHeights = [3,2,5,5,2,3]
Output: 18
Explanation: One beautiful configuration with a maximum sum is heights = [2,2,5,5,2,2]. This configuration is beautiful since:
- 1 <= heights[i] <= maxHeights[i]
- heights is a mountain of peak i = 2.
Note that, for this configuration, i = 3 can also be considered a peak.
It can be shown that there exists no other beautiful configuration with a sum of heights greater than 18.

Constraints:

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

Please complete the code below to solve above prblem:
```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