minimum-increment-operations-to-make-array-beautiful

Minimum Increment Operations to Make Array Beautiful

Prompt:
"""
给你一个下标从 0 开始、长度为 n 的整数数组 nums ，和一个整数 k 。

你可以执行下述 递增 运算 任意 次（可以是 0 次）：

 * 从范围 [0, n - 1] 中选择一个下标 i ，并将 nums[i] 的值加 1 。

如果数组中任何长度 大于或等于 3 的子数组，其 最大 元素都大于或等于 k ，则认为数组是一个 美丽数组 。

以整数形式返回使数组变为 美丽数组 需要执行的 最小 递增运算数。

子数组是数组中的一个连续 非空 元素序列。

示例 1：

输入：nums = [2,3,0,0,2], k = 4
输出：3
解释：可以执行下述递增运算，使 nums 变为美丽数组：
选择下标 i = 1 ，并且将 nums[1] 的值加 1 -> [2,4,0,0,2] 。
选择下标 i = 4 ，并且将 nums[4] 的值加 1 -> [2,4,0,0,3] 。
选择下标 i = 4 ，并且将 nums[4] 的值加 1 -> [2,4,0,0,4] 。
长度大于或等于 3 的子数组为 [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4] 。
在所有子数组中，最大元素都等于 k = 4 ，所以 nums 现在是美丽数组。
可以证明无法用少于 3 次递增运算使 nums 变为美丽数组。
因此，答案为 3 。

示例 2：

输入：nums = [0,1,3,3], k = 5
输出：2
解释：可以执行下述递增运算，使 nums 变为美丽数组：
选择下标 i = 2 ，并且将 nums[2] 的值加 1 -> [0,1,4,3] 。
选择下标 i = 2 ，并且将 nums[2] 的值加 1 -> [0,1,5,3] 。
长度大于或等于 3 的子数组为 [0,1,5]、[1,5,3]、[0,1,5,3] 。
在所有子数组中，最大元素都等于 k = 5 ，所以 nums 现在是美丽数组。
可以证明无法用少于 2 次递增运算使 nums 变为美丽数组。
因此，答案为 2 。

示例 3：

输入：nums = [1,1,2], k = 1
输出：0
解释：在这个示例中，只有一个长度大于或等于 3 的子数组 [1,1,2] 。
其最大元素 2 已经大于 k = 1 ，所以无需执行任何增量运算。
因此，答案为 0 。

提示：

 * 3 <= n == nums.length <= 105
 * 0 <= nums[i] <= 109
 * 0 <= k <= 109
"""
class Solution:
    def minIncrementOperations(self, nums: List[int], k: int) -> int:

给你一个下标从 0 开始、长度为 n 的整数数组 nums ，和一个整数 k 。

你可以执行下述 递增 运算 任意 次（可以是 0 次）：

 * 从范围 [0, n - 1] 中选择一个下标 i ，并将 nums[i] 的值加 1 。

如果数组中任何长度 大于或等于 3 的子数组，其 最大 元素都大于或等于 k ，则认为数组是一个 美丽数组 。

以整数形式返回使数组变为 美丽数组 需要执行的 最小 递增运算数。

子数组是数组中的一个连续 非空 元素序列。

示例 1：

输入：nums = [2,3,0,0,2], k = 4
输出：3
解释：可以执行下述递增运算，使 nums 变为美丽数组：
选择下标 i = 1 ，并且将 nums[1] 的值加 1 -> [2,4,0,0,2] 。
选择下标 i = 4 ，并且将 nums[4] 的值加 1 -> [2,4,0,0,3] 。
选择下标 i = 4 ，并且将 nums[4] 的值加 1 -> [2,4,0,0,4] 。
长度大于或等于 3 的子数组为 [2,4,0], [4,0,0], [0,0,4], [2,4,0,0], [4,0,0,4], [2,4,0,0,4] 。
在所有子数组中，最大元素都等于 k = 4 ，所以 nums 现在是美丽数组。
可以证明无法用少于 3 次递增运算使 nums 变为美丽数组。
因此，答案为 3 。

示例 2：

输入：nums = [0,1,3,3], k = 5
输出：2
解释：可以执行下述递增运算，使 nums 变为美丽数组：
选择下标 i = 2 ，并且将 nums[2] 的值加 1 -> [0,1,4,3] 。
选择下标 i = 2 ，并且将 nums[2] 的值加 1 -> [0,1,5,3] 。
长度大于或等于 3 的子数组为 [0,1,5]、[1,5,3]、[0,1,5,3] 。
在所有子数组中，最大元素都等于 k = 5 ，所以 nums 现在是美丽数组。
可以证明无法用少于 2 次递增运算使 nums 变为美丽数组。
因此，答案为 2 。

示例 3：

输入：nums = [1,1,2], k = 1
输出：0
解释：在这个示例中，只有一个长度大于或等于 3 的子数组 [1,1,2] 。
其最大元素 2 已经大于 k = 1 ，所以无需执行任何增量运算。
因此，答案为 0 。

提示：

 * 3 <= n == nums.length <= 105
 * 0 <= nums[i] <= 109
 * 0 <= k <= 109

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

```

my_solution = Solution()

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

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

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

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

test_input = { "nums": [0,18,28], "k": 93 }
assert my_solution.minIncrementOperations(**test_input) == 65

test_input = { "nums": [0,24,14], "k": 7 }
assert my_solution.minIncrementOperations(**test_input) == 0

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

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

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

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

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

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

test_input = { "nums": [7,47,16], "k": 39 }
assert my_solution.minIncrementOperations(**test_input) == 0

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

test_input = { "nums": [41,44,37], "k": 55 }
assert my_solution.minIncrementOperations(**test_input) == 11

test_input = { "nums": [48,3,13], "k": 1 }
assert my_solution.minIncrementOperations(**test_input) == 0

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

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

test_input = { "nums": [2,35,41,20], "k": 4 }
assert my_solution.minIncrementOperations(**test_input) == 0

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

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

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

test_input = { "nums": [20,2,22,30], "k": 67 }
assert my_solution.minIncrementOperations(**test_input) == 45

test_input = { "nums": [22,49,0,20], "k": 52 }
assert my_solution.minIncrementOperations(**test_input) == 3

test_input = { "nums": [25,2,1,41], "k": 9 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [31,86,1,2], "k": 354 }
assert my_solution.minIncrementOperations(**test_input) == 268

test_input = { "nums": [43,31,14,4], "k": 73 }
assert my_solution.minIncrementOperations(**test_input) == 42

test_input = { "nums": [44,24,28,47], "k": 16 }
assert my_solution.minIncrementOperations(**test_input) == 0

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

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

test_input = { "nums": [5,9,0,10,3], "k": 3 }
assert my_solution.minIncrementOperations(**test_input) == 0

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

test_input = { "nums": [6,14,17,4,7], "k": 22 }
assert my_solution.minIncrementOperations(**test_input) == 5

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

test_input = { "nums": [20,38,29,34,6], "k": 95 }
assert my_solution.minIncrementOperations(**test_input) == 66

test_input = { "nums": [21,45,33,14,22], "k": 58 }
assert my_solution.minIncrementOperations(**test_input) == 25

test_input = { "nums": [32,14,31,43,29], "k": 46 }
assert my_solution.minIncrementOperations(**test_input) == 15

test_input = { "nums": [39,21,10,46,40], "k": 81 }
assert my_solution.minIncrementOperations(**test_input) == 71

test_input = { "nums": [42,7,32,19,4], "k": 66 }
assert my_solution.minIncrementOperations(**test_input) == 34

test_input = { "nums": [74,91,93,96,12], "k": 964 }
assert my_solution.minIncrementOperations(**test_input) == 871

test_input = { "nums": [84,17,58,61,72], "k": 432 }
assert my_solution.minIncrementOperations(**test_input) == 374

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

test_input = { "nums": [4,0,22,41,29,28], "k": 30 }
assert my_solution.minIncrementOperations(**test_input) == 8

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

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

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

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

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

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

test_input = { "nums": [9,5,0,10,9,0], "k": 8 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [13,34,0,13,9,19], "k": 82 }
assert my_solution.minIncrementOperations(**test_input) == 117

test_input = { "nums": [16,50,23,35,38,13], "k": 34 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [20,1,40,48,32,24], "k": 38 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [28,5,10,26,38,6], "k": 17 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [30,42,46,45,23,31], "k": 13 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [3,8,0,6,46,24,31], "k": 30 }
assert my_solution.minIncrementOperations(**test_input) == 22

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

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

test_input = { "nums": [10,7,2,5,9,6,3], "k": 2 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [10,24,21,42,6,10,43], "k": 55 }
assert my_solution.minIncrementOperations(**test_input) == 56

test_input = { "nums": [18,48,1,19,43,25,49], "k": 21 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [37,82,95,82,77,87,93], "k": 239 }
assert my_solution.minIncrementOperations(**test_input) == 296

test_input = { "nums": [40,17,28,38,41,32,9], "k": 97 }
assert my_solution.minIncrementOperations(**test_input) == 125

test_input = { "nums": [41,22,4,41,4,47,36], "k": 25 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [42,19,52,36,8,5,9], "k": 656 }
assert my_solution.minIncrementOperations(**test_input) == 1252

test_input = { "nums": [45,58,6,16,70,69,87], "k": 26 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [48,24,41,16,4,20,38], "k": 97 }
assert my_solution.minIncrementOperations(**test_input) == 133

test_input = { "nums": [50,3,17,36,16,10,2], "k": 19 }
assert my_solution.minIncrementOperations(**test_input) == 3

test_input = { "nums": [57,41,90,16,41,25,2], "k": 934 }
assert my_solution.minIncrementOperations(**test_input) == 1737

test_input = { "nums": [74,33,13,74,75,95,11], "k": 426 }
assert my_solution.minIncrementOperations(**test_input) == 744

test_input = { "nums": [83,54,75,22,32,59,30], "k": 298 }
assert my_solution.minIncrementOperations(**test_input) == 462

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

test_input = { "nums": [1,29,18,3,38,4,7,47], "k": 67 }
assert my_solution.minIncrementOperations(**test_input) == 87

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

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

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

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

test_input = { "nums": [5,10,8,7,6,7,1,10], "k": 3 }
assert my_solution.minIncrementOperations(**test_input) == 0

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

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

test_input = { "nums": [7,12,36,8,27,48,39,35], "k": 36 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [15,47,34,46,42,26,23,11], "k": 15 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [19,40,43,32,15,7,43,5], "k": 85 }
assert my_solution.minIncrementOperations(**test_input) == 120

test_input = { "nums": [22,45,6,7,7,23,6,3], "k": 43 }
assert my_solution.minIncrementOperations(**test_input) == 56

test_input = { "nums": [25,1,70,71,54,96,46,77], "k": 549 }
assert my_solution.minIncrementOperations(**test_input) == 932

test_input = { "nums": [33,41,14,18,43,20,49,23], "k": 25 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [39,26,16,36,19,5,6,28], "k": 98 }
assert my_solution.minIncrementOperations(**test_input) == 175

test_input = { "nums": [44,44,31,36,1,8,39,46], "k": 45 }
assert my_solution.minIncrementOperations(**test_input) == 16

test_input = { "nums": [2,17,43,26,33,12,37,28,34], "k": 3 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [3,1,6,1,0,5,4,5,7], "k": 10 }
assert my_solution.minIncrementOperations(**test_input) == 12

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

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

test_input = { "nums": [7,40,36,45,42,23,10,33,17], "k": 25 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [10,4,7,4,8,7,8,4,6], "k": 3 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [12,32,12,13,18,38,21,15,13], "k": 95 }
assert my_solution.minIncrementOperations(**test_input) == 214

test_input = { "nums": [17,50,14,27,10,37,24,35,23], "k": 45 }
assert my_solution.minIncrementOperations(**test_input) == 36

test_input = { "nums": [20,17,29,44,18,20,17,26,2], "k": 1 }
assert my_solution.minIncrementOperations(**test_input) == 0

test_input = { "nums": [28,4,38,38,37,13,47,48,49], "k": 61 }
assert my_solution.minIncrementOperations(**test_input) == 60

test_input = { "nums": [29,0,34,5,5,24,43,23,27], "k": 98 }
assert my_solution.minIncrementOperations(**test_input) == 193

test_input = { "nums": [41,53,77,44,79,66,2,46,64], "k": 204 }
assert my_solution.minIncrementOperations(**test_input) == 405


maximum-points-after-collecting-coins-from-all-nodes

Maximum Points After Collecting Coins From All Nodes

Prompt:
"""
有一棵由 n 个节点组成的无向树，以 0  为根节点，节点编号从 0 到 n - 1 。给你一个长度为 n - 1 的二维 整数 数组 edges ，其中 edges[i] = [ai, bi] 表示在树上的节点 ai 和 bi 之间存在一条边。另给你一个下标从 0 开始、长度为 n 的数组 coins 和一个整数 k ，其中 coins[i] 表示节点 i 处的金币数量。

从根节点开始，你必须收集所有金币。要想收集节点上的金币，必须先收集该节点的祖先节点上的金币。

节点 i 上的金币可以用下述方法之一进行收集：

 * 收集所有金币，得到共计 coins[i] - k 点积分。如果 coins[i] - k 是负数，你将会失去 abs(coins[i] - k) 点积分。
 * 收集所有金币，得到共计 floor(coins[i] / 2) 点积分。如果采用这种方法，节点 i 子树中所有节点 j 的金币数 coins[j] 将会减少至 floor(coins[j] / 2) 。

返回收集 所有 树节点的金币之后可以获得的最大积分。

示例 1：

[https://assets.leetcode.com/uploads/2023/09/18/ex1-copy.png]

输入：edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5
输出：11
解释：
使用第一种方法收集节点 0 上的所有金币。总积分 = 10 - 5 = 5 。
使用第一种方法收集节点 1 上的所有金币。总积分 = 5 + (10 - 5) = 10 。
使用第二种方法收集节点 2 上的所有金币。所以节点 3 上的金币将会变为 floor(3 / 2) = 1 ，总积分 = 10 + floor(3 / 2) = 11 。
使用第二种方法收集节点 3 上的所有金币。总积分 =  11 + floor(1 / 2) = 11.
可以证明收集所有节点上的金币能获得的最大积分是 11 。

示例 2：

[https://assets.leetcode.com/uploads/2023/09/18/ex2.png]

输入：edges = [[0,1],[0,2]], coins = [8,4,4], k = 0
输出：16
解释：
使用第一种方法收集所有节点上的金币，因此，总积分 = (8 - 0) + (4 - 0) + (4 - 0) = 16 。

提示：

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

有一棵由 n 个节点组成的无向树，以 0  为根节点，节点编号从 0 到 n - 1 。给你一个长度为 n - 1 的二维 整数 数组 edges ，其中 edges[i] = [ai, bi] 表示在树上的节点 ai 和 bi 之间存在一条边。另给你一个下标从 0 开始、长度为 n 的数组 coins 和一个整数 k ，其中 coins[i] 表示节点 i 处的金币数量。

从根节点开始，你必须收集所有金币。要想收集节点上的金币，必须先收集该节点的祖先节点上的金币。

节点 i 上的金币可以用下述方法之一进行收集：

 * 收集所有金币，得到共计 coins[i] - k 点积分。如果 coins[i] - k 是负数，你将会失去 abs(coins[i] - k) 点积分。
 * 收集所有金币，得到共计 floor(coins[i] / 2) 点积分。如果采用这种方法，节点 i 子树中所有节点 j 的金币数 coins[j] 将会减少至 floor(coins[j] / 2) 。

返回收集 所有 树节点的金币之后可以获得的最大积分。

示例 1：

[https://assets.leetcode.com/uploads/2023/09/18/ex1-copy.png]

输入：edges = [[0,1],[1,2],[2,3]], coins = [10,10,3,3], k = 5
输出：11
解释：
使用第一种方法收集节点 0 上的所有金币。总积分 = 10 - 5 = 5 。
使用第一种方法收集节点 1 上的所有金币。总积分 = 5 + (10 - 5) = 10 。
使用第二种方法收集节点 2 上的所有金币。所以节点 3 上的金币将会变为 floor(3 / 2) = 1 ，总积分 = 10 + floor(3 / 2) = 11 。
使用第二种方法收集节点 3 上的所有金币。总积分 =  11 + floor(1 / 2) = 11.
可以证明收集所有节点上的金币能获得的最大积分是 11 。

示例 2：

[https://assets.leetcode.com/uploads/2023/09/18/ex2.png]

输入：edges = [[0,1],[0,2]], coins = [8,4,4], k = 0
输出：16
解释：
使用第一种方法收集所有节点上的金币，因此，总积分 = (8 - 0) + (4 - 0) + (4 - 0) = 16 。

提示：

 * n == coins.length
 * 2 <= n <= 105
 * 0 <= coins[i] <= 104
 * edges.length == n - 1
 * 0 <= edges[i][0], edges[i][1] < n
 * 0 <= k <= 104

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

```


subarrays-distinct-element-sum-of-squares-i

Subarrays Distinct Element Sum of Squares I

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

定义 nums 一个子数组的 不同计数 值如下：

 * 令 nums[i..j] 表示 nums 中所有下标在 i 到 j 范围内的元素构成的子数组（满足 0 <= i <= j < nums.length ），那么我们称子数组 nums[i..j] 中不同值的数目为 nums[i..j] 的不同计数。

请你返回 nums 中所有子数组的 不同计数 的 平方 和。

由于答案可能会很大，请你将它对 109 + 7 取余 后返回。

子数组指的是一个数组里面一段连续 非空 的元素序列。

示例 1：

输入：nums = [1,2,1]
输出：15
解释：六个子数组分别为：
[1]: 1 个互不相同的元素。
[2]: 1 个互不相同的元素。
[1]: 1 个互不相同的元素。
[1,2]: 2 个互不相同的元素。
[2,1]: 2 个互不相同的元素。
[1,2,1]: 2 个互不相同的元素。
所有不同计数的平方和为 12 + 12 + 12 + 22 + 22 + 22 = 15 。

示例 2：

输入：nums = [2,2]
输出：3
解释：三个子数组分别为：
[2]: 1 个互不相同的元素。
[2]: 1 个互不相同的元素。
[2,2]: 1 个互不相同的元素。
所有不同计数的平方和为 12 + 12 + 12 = 3 。

提示：

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

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

定义 nums 一个子数组的 不同计数 值如下：

 * 令 nums[i..j] 表示 nums 中所有下标在 i 到 j 范围内的元素构成的子数组（满足 0 <= i <= j < nums.length ），那么我们称子数组 nums[i..j] 中不同值的数目为 nums[i..j] 的不同计数。

请你返回 nums 中所有子数组的 不同计数 的 平方 和。

由于答案可能会很大，请你将它对 109 + 7 取余 后返回。

子数组指的是一个数组里面一段连续 非空 的元素序列。

示例 1：

输入：nums = [1,2,1]
输出：15
解释：六个子数组分别为：
[1]: 1 个互不相同的元素。
[2]: 1 个互不相同的元素。
[1]: 1 个互不相同的元素。
[1,2]: 2 个互不相同的元素。
[2,1]: 2 个互不相同的元素。
[1,2,1]: 2 个互不相同的元素。
所有不同计数的平方和为 12 + 12 + 12 + 22 + 22 + 22 = 15 。

示例 2：

输入：nums = [2,2]
输出：3
解释：三个子数组分别为：
[2]: 1 个互不相同的元素。
[2]: 1 个互不相同的元素。
[2,2]: 1 个互不相同的元素。
所有不同计数的平方和为 12 + 12 + 12 = 3 。

提示：

 * 1 <= nums.length <= 100
 * 1 <= nums[i] <= 100

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

```

my_solution = Solution()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


minimum-number-of-changes-to-make-binary-string-beautiful

Minimum Number of Changes to Make Binary String Beautiful

Prompt:
"""
给你一个长度为偶数下标从 0 开始的二进制字符串 s 。

如果可以将一个字符串分割成一个或者更多满足以下条件的子字符串，那么我们称这个字符串是 美丽的 ：

 * 每个子字符串的长度都是 偶数 。
 * 每个子字符串都 只 包含 1 或 只 包含 0 。

你可以将 s 中任一字符改成 0 或者 1 。

请你返回让字符串 s 美丽的 最少 字符修改次数。

示例 1：

输入：s = "1001"
输出：2
解释：我们将 s[1] 改为 1 ，且将 s[3] 改为 0 ，得到字符串 "1100" 。
字符串 "1100" 是美丽的，因为我们可以将它分割成 "11|00" 。
将字符串变美丽最少需要 2 次修改。

示例 2：

输入：s = "10"
输出：1
解释：我们将 s[1] 改为 1 ，得到字符串 "11" 。
字符串 "11" 是美丽的，因为它已经是美丽的。
将字符串变美丽最少需要 1 次修改。

示例 3：

输入：s = "0000"
输出：0
解释：不需要进行任何修改，字符串 "0000" 已经是美丽字符串。

提示：

 * 2 <= s.length <= 105
 * s 的长度为偶数。
 * s[i] 要么是 '0' ，要么是 '1' 。
"""
class Solution:
    def minChanges(self, s: str) -> int:

给你一个长度为偶数下标从 0 开始的二进制字符串 s 。

如果可以将一个字符串分割成一个或者更多满足以下条件的子字符串，那么我们称这个字符串是 美丽的 ：

 * 每个子字符串的长度都是 偶数 。
 * 每个子字符串都 只 包含 1 或 只 包含 0 。

你可以将 s 中任一字符改成 0 或者 1 。

请你返回让字符串 s 美丽的 最少 字符修改次数。

示例 1：

输入：s = "1001"
输出：2
解释：我们将 s[1] 改为 1 ，且将 s[3] 改为 0 ，得到字符串 "1100" 。
字符串 "1100" 是美丽的，因为我们可以将它分割成 "11|00" 。
将字符串变美丽最少需要 2 次修改。

示例 2：

输入：s = "10"
输出：1
解释：我们将 s[1] 改为 1 ，得到字符串 "11" 。
字符串 "11" 是美丽的，因为它已经是美丽的。
将字符串变美丽最少需要 1 次修改。

示例 3：

输入：s = "0000"
输出：0
解释：不需要进行任何修改，字符串 "0000" 已经是美丽字符串。

提示：

 * 2 <= s.length <= 105
 * s 的长度为偶数。
 * s[i] 要么是 '0' ，要么是 '1' 。

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

```

my_solution = Solution()

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

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

test_input = { "s": "0000" }
assert my_solution.minChanges(**test_input) == 0

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

test_input = { "s": "01010001" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "010010" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "111111111110010001" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "01010000011001001101" }
assert my_solution.minChanges(**test_input) == 6

test_input = { "s": "011011100001110111" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "1001000010111010" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "0011" }
assert my_solution.minChanges(**test_input) == 0

test_input = { "s": "11100100010010" }
assert my_solution.minChanges(**test_input) == 4

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

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

test_input = { "s": "10110010" }
assert my_solution.minChanges(**test_input) == 2

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

test_input = { "s": "01000011000111" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "0001110001" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "000000001010100011" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "100001" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "10010010" }
assert my_solution.minChanges(**test_input) == 3

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

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

test_input = { "s": "011011000001100011" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "01101111" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "000000011101" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "011011011111111011" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "110011" }
assert my_solution.minChanges(**test_input) == 0

test_input = { "s": "1111101111101011" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "11000101011001100110" }
assert my_solution.minChanges(**test_input) == 8

test_input = { "s": "101101101110110010" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "11011110" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "1011100101" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "0011000101001000" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "00" }
assert my_solution.minChanges(**test_input) == 0

test_input = { "s": "10110111010001000010" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "0101" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "0010101100" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "11001110101001" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "010101000011011111" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "0010111010000001" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "0000010101" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "10100011101010" }
assert my_solution.minChanges(**test_input) == 5

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

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

test_input = { "s": "110110" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "001001110111010101" }
assert my_solution.minChanges(**test_input) == 6

test_input = { "s": "11110011" }
assert my_solution.minChanges(**test_input) == 0

test_input = { "s": "1100000101101110" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "111010" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "100000100010011100" }
assert my_solution.minChanges(**test_input) == 4

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

test_input = { "s": "0100110011111101" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "010111" }
assert my_solution.minChanges(**test_input) == 2

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

test_input = { "s": "00110111000111110001" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "01010010" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "01110101001001" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "00111100010111" }
assert my_solution.minChanges(**test_input) == 2

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

test_input = { "s": "00010101111101" }
assert my_solution.minChanges(**test_input) == 4

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

test_input = { "s": "011110" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "1010" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "011101010011101011" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "1001110001111100" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "011000101100" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "1110111000111111" }
assert my_solution.minChanges(**test_input) == 2

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

test_input = { "s": "10110110" }
assert my_solution.minChanges(**test_input) == 3

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

test_input = { "s": "0111110110" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "011000011101" }
assert my_solution.minChanges(**test_input) == 4

test_input = { "s": "0100101000010101" }
assert my_solution.minChanges(**test_input) == 6

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

test_input = { "s": "100010010010110001" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "101001111001111001" }
assert my_solution.minChanges(**test_input) == 7

test_input = { "s": "111001" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "111010001000" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "0110" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "11011010" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "100111" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "11000110000001" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "010111010011011000" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "000101" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "000010101010101011" }
assert my_solution.minChanges(**test_input) == 6

test_input = { "s": "11011000" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "010101" }
assert my_solution.minChanges(**test_input) == 3

test_input = { "s": "10011010110110101100" }
assert my_solution.minChanges(**test_input) == 7

test_input = { "s": "10100011" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "11010100000000" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "101100101111010011" }
assert my_solution.minChanges(**test_input) == 3

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

test_input = { "s": "111110110100" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "011110110101010100" }
assert my_solution.minChanges(**test_input) == 6

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

test_input = { "s": "00000010001101" }
assert my_solution.minChanges(**test_input) == 2

test_input = { "s": "01111001101001" }
assert my_solution.minChanges(**test_input) == 6

test_input = { "s": "010110011101" }
assert my_solution.minChanges(**test_input) == 5

test_input = { "s": "0111011101" }
assert my_solution.minChanges(**test_input) == 3


length-of-the-longest-subsequence-that-sums-to-target

Length of the Longest Subsequence That Sums to Target

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

返回和为 target 的 nums 子序列中，子序列 长度的最大值 。如果不存在和为 target 的子序列，返回 -1 。

子序列 指的是从原数组中删除一些或者不删除任何元素后，剩余元素保持原来的顺序构成的数组。

示例 1：

输入：nums = [1,2,3,4,5], target = 9
输出：3
解释：总共有 3 个子序列的和为 9 ：[4,5] ，[1,3,5] 和 [2,3,4] 。最长的子序列是 [1,3,5] 和 [2,3,4] 。所以答案为 3 。

示例 2：

输入：nums = [4,1,3,2,1,5], target = 7
输出：4
解释：总共有 5 个子序列的和为 7 ：[4,3] ，[4,1,2] ，[4,2,1] ，[1,1,5] 和 [1,3,2,1] 。最长子序列为 [1,3,2,1] 。所以答案为 4 。

示例 3：

输入：nums = [1,1,5,4,5], target = 3
输出：-1
解释：无法得到和为 3 的子序列。

提示：

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

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

返回和为 target 的 nums 子序列中，子序列 长度的最大值 。如果不存在和为 target 的子序列，返回 -1 。

子序列 指的是从原数组中删除一些或者不删除任何元素后，剩余元素保持原来的顺序构成的数组。

示例 1：

输入：nums = [1,2,3,4,5], target = 9
输出：3
解释：总共有 3 个子序列的和为 9 ：[4,5] ，[1,3,5] 和 [2,3,4] 。最长的子序列是 [1,3,5] 和 [2,3,4] 。所以答案为 3 。

示例 2：

输入：nums = [4,1,3,2,1,5], target = 7
输出：4
解释：总共有 5 个子序列的和为 7 ：[4,3] ，[4,1,2] ，[4,2,1] ，[1,1,5] 和 [1,3,2,1] 。最长子序列为 [1,3,2,1] 。所以答案为 4 。

示例 3：

输入：nums = [1,1,5,4,5], target = 3
输出：-1
解释：无法得到和为 3 的子序列。

提示：

 * 1 <= nums.length <= 1000
 * 1 <= nums[i] <= 1000
 * 1 <= target <= 1000

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

```

my_solution = Solution()

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

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

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

test_input = { "nums": [1000], "target": 12 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == -1

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

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

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

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

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

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

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

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

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

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

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

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

test_input = { "nums": [9,12,8,4,11,13,15,7,5], "target": 84 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

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

test_input = { "nums": [9,11,11,15,4,14,3,2,13,7], "target": 89 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 10

test_input = { "nums": [11,13,6,13,10], "target": 53 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 5

test_input = { "nums": [10,3,5,11,6,12], "target": 47 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [13,3,6,6,6,15,4], "target": 53 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [1,6,15,6,14,13,14], "target": 69 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [10,7,8,14,15], "target": 54 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 5

test_input = { "nums": [14,15,8,10,8,7], "target": 62 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [7,9,14,14,9,14,5,12,10], "target": 94 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

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

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

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

test_input = { "nums": [10,14,11,13,2,11], "target": 61 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [10,2,13,5,7,15], "target": 52 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [3,1,10,1,10,1,2,9,5,13], "target": 55 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 10

test_input = { "nums": [5,13,2,13,9,4,5,7], "target": 58 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 8

test_input = { "nums": [1,15,5,12,13,10,14,8], "target": 78 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 8

test_input = { "nums": [7,4,14,10,13], "target": 48 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 5

test_input = { "nums": [6,14,14,6,2,9,1,4,10], "target": 66 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [14,15,7,5,7,10,6,14,10,11], "target": 99 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 10

test_input = { "nums": [15,13,8,8,6], "target": 50 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 5

test_input = { "nums": [2,6,8,9,13,3], "target": 41 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [13,15,9,3,8,1,9,2,15,5], "target": 80 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 10

test_input = { "nums": [5,13,9,11,6,1], "target": 45 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [7,10,15,7,14,2], "target": 55 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [12,14,13,13,13], "target": 65 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 5

test_input = { "nums": [12,8,7,9,3,10,3,8,2], "target": 62 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [11,1,14,13,14,4,14,11], "target": 82 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 8

test_input = { "nums": [5,9,11,2,5,2,7,11,5,3], "target": 60 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 10

test_input = { "nums": [5,15,3,13,14,15,10], "target": 75 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [10,8,2,2,9], "target": 31 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 5

test_input = { "nums": [7,15,4,3,9,15,12,1,12], "target": 78 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [3,1,12,15,5,10], "target": 46 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [5,3,12,7,5,2,12,10,12,5], "target": 73 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 10

test_input = { "nums": [6,10,3,1,7,11,9,8,13,12], "target": 80 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 10

test_input = { "nums": [11,3,4,11,9], "target": 38 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 5

test_input = { "nums": [15,12,12,13,6,6,4,1], "target": 69 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 8

test_input = { "nums": [9,2,10,7,10,11,14,11,8], "target": 82 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [4,4,3,9,6,8,4,7,7], "target": 52 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [10,14,4,15,9,5], "target": 57 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [4,13,2,3,13,11,8,6], "target": 60 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 8

test_input = { "nums": [1,7,8,14,15,9,8,10,13,7], "target": 92 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 10

test_input = { "nums": [7,7,6,14,7,4], "target": 45 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [9,10,9,7,14,3,6,4,6], "target": 68 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [15,13,14,5,7,13,11,14], "target": 92 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 8

test_input = { "nums": [1,1,10,12,5,6,15,6,8], "target": 64 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [14,13,13,11,14,13,8], "target": 86 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [3,14,4,2,10,3,7], "target": 43 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [6,1,3,11,9,2,10,6,12], "target": 60 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

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

test_input = { "nums": [7,11,15,1,9,9,11], "target": 63 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [7,12,10,15,6,15,14,2], "target": 81 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 8

test_input = { "nums": [12,3,10,12,13,3,4,7,15], "target": 79 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [14,6,11,2,10,1,12,9,2], "target": 67 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [5,8,12,6,15,13,11], "target": 70 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [11,6,1,6,2,6,15], "target": 47 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [12,7,15,10,5,4,7,12,12], "target": 84 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [11,4,4,9,10,7,12], "target": 57 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [4,12,15,6,15,1,4,4,2], "target": 63 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [3,13,4,15,1], "target": 36 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 5

test_input = { "nums": [14,3,7,14,7,7,1,6], "target": 59 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 8

test_input = { "nums": [15,13,1,14,6,8], "target": 57 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [14,2,3,10,15], "target": 44 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 5

test_input = { "nums": [5,5,3,7,12,10,11], "target": 53 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [3,7,3,5,3,14,8], "target": 43 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

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

test_input = { "nums": [12,7,8,6,3,9,7,3,4,4], "target": 63 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 10

test_input = { "nums": [9,12,1,4,9,6,15,9,7], "target": 72 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [9,13,12,10,4,9,9,4,4,13], "target": 87 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 10

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

test_input = { "nums": [7,9,8,9,9,3,5], "target": 50 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [15,1,14,8,2,1,10,15,15], "target": 81 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [13,14,1,9,12,2], "target": 51 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [13,12,12,13,8,11,3,14,13], "target": 99 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

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

test_input = { "nums": [13,10,3,4,10,3], "target": 43 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 6

test_input = { "nums": [8,9,1,5,8,7,6,8], "target": 52 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 8

test_input = { "nums": [10,1,4,10,9,13,14], "target": 61 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 7

test_input = { "nums": [3,14,11,4,7,9,7,6,8,11], "target": 80 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 10

test_input = { "nums": [4,11,6,6,14,12,2,9,1], "target": 65 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 9

test_input = { "nums": [9,2,15,12,15,6,4,12], "target": 75 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 8

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

test_input = { "nums": [4,3,13,6,9], "target": 35 }
assert my_solution.lengthOfLongestSubsequence(**test_input) == 5


subarrays-distinct-element-sum-of-squares-ii

Subarrays Distinct Element Sum of Squares II

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

定义 nums 一个子数组的 不同计数 值如下：

 * 令 nums[i..j] 表示 nums 中所有下标在 i 到 j 范围内的元素构成的子数组（满足 0 <= i <= j < nums.length ），那么我们称子数组 nums[i..j] 中不同值的数目为 nums[i..j] 的不同计数。

请你返回 nums 中所有子数组的 不同计数 的 平方 和。

由于答案可能会很大，请你将它对 109 + 7 取余 后返回。

子数组指的是一个数组里面一段连续 非空 的元素序列。

示例 1：

输入：nums = [1,2,1]
输出：15
解释：六个子数组分别为：
[1]: 1 个互不相同的元素。
[2]: 1 个互不相同的元素。
[1]: 1 个互不相同的元素。
[1,2]: 2 个互不相同的元素。
[2,1]: 2 个互不相同的元素。
[1,2,1]: 2 个互不相同的元素。
所有不同计数的平方和为 12 + 12 + 12 + 22 + 22 + 22 = 15 。

示例 2：

输入：nums = [2,2]
输出：3
解释：三个子数组分别为：
[2]: 1 个互不相同的元素。
[2]: 1 个互不相同的元素。
[2,2]: 1 个互不相同的元素。
所有不同计数的平方和为 12 + 12 + 12 = 3 。

提示：

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

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

定义 nums 一个子数组的 不同计数 值如下：

 * 令 nums[i..j] 表示 nums 中所有下标在 i 到 j 范围内的元素构成的子数组（满足 0 <= i <= j < nums.length ），那么我们称子数组 nums[i..j] 中不同值的数目为 nums[i..j] 的不同计数。

请你返回 nums 中所有子数组的 不同计数 的 平方 和。

由于答案可能会很大，请你将它对 109 + 7 取余 后返回。

子数组指的是一个数组里面一段连续 非空 的元素序列。

示例 1：

输入：nums = [1,2,1]
输出：15
解释：六个子数组分别为：
[1]: 1 个互不相同的元素。
[2]: 1 个互不相同的元素。
[1]: 1 个互不相同的元素。
[1,2]: 2 个互不相同的元素。
[2,1]: 2 个互不相同的元素。
[1,2,1]: 2 个互不相同的元素。
所有不同计数的平方和为 12 + 12 + 12 + 22 + 22 + 22 = 15 。

示例 2：

输入：nums = [2,2]
输出：3
解释：三个子数组分别为：
[2]: 1 个互不相同的元素。
[2]: 1 个互不相同的元素。
[2,2]: 1 个互不相同的元素。
所有不同计数的平方和为 12 + 12 + 12 = 3 。

提示：

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

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

```

my_solution = Solution()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


minimum-sum-of-mountain-triplets-i

Minimum Sum of Mountain Triplets I

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

如果下标三元组 (i, j, k) 满足下述全部条件，则认为它是一个 山形三元组 ：

 * i < j < k
 * nums[i] < nums[j] 且 nums[k] < nums[j]

请你找出 nums 中 元素和最小 的山形三元组，并返回其 元素和 。如果不存在满足条件的三元组，返回 -1 。

示例 1：

输入：nums = [8,6,1,5,3]
输出：9
解释：三元组 (2, 3, 4) 是一个元素和等于 9 的山形三元组，因为：
- 2 < 3 < 4
- nums[2] < nums[3] 且 nums[4] < nums[3]
这个三元组的元素和等于 nums[2] + nums[3] + nums[4] = 9 。可以证明不存在元素和小于 9 的山形三元组。

示例 2：

输入：nums = [5,4,8,7,10,2]
输出：13
解释：三元组 (1, 3, 5) 是一个元素和等于 13 的山形三元组，因为：
- 1 < 3 < 5
- nums[1] < nums[3] 且 nums[5] < nums[3]
这个三元组的元素和等于 nums[1] + nums[3] + nums[5] = 13 。可以证明不存在元素和小于 13 的山形三元组。

示例 3：

输入：nums = [6,5,4,3,4,5]
输出：-1
解释：可以证明 nums 中不存在山形三元组。

提示：

 * 3 <= nums.length <= 50
 * 1 <= nums[i] <= 50
"""
class Solution:
    def minimumSum(self, nums: List[int]) -> int:

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

如果下标三元组 (i, j, k) 满足下述全部条件，则认为它是一个 山形三元组 ：

 * i < j < k
 * nums[i] < nums[j] 且 nums[k] < nums[j]

请你找出 nums 中 元素和最小 的山形三元组，并返回其 元素和 。如果不存在满足条件的三元组，返回 -1 。

示例 1：

输入：nums = [8,6,1,5,3]
输出：9
解释：三元组 (2, 3, 4) 是一个元素和等于 9 的山形三元组，因为：
- 2 < 3 < 4
- nums[2] < nums[3] 且 nums[4] < nums[3]
这个三元组的元素和等于 nums[2] + nums[3] + nums[4] = 9 。可以证明不存在元素和小于 9 的山形三元组。

示例 2：

输入：nums = [5,4,8,7,10,2]
输出：13
解释：三元组 (1, 3, 5) 是一个元素和等于 13 的山形三元组，因为：
- 1 < 3 < 5
- nums[1] < nums[3] 且 nums[5] < nums[3]
这个三元组的元素和等于 nums[1] + nums[3] + nums[5] = 13 。可以证明不存在元素和小于 13 的山形三元组。

示例 3：

输入：nums = [6,5,4,3,4,5]
输出：-1
解释：可以证明 nums 中不存在山形三元组。

提示：

 * 3 <= nums.length <= 50
 * 1 <= nums[i] <= 50

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

```

my_solution = Solution()

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

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

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

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

test_input = { "nums": [49,50,48] }
assert my_solution.minimumSum(**test_input) == 147

test_input = { "nums": [48,50,49] }
assert my_solution.minimumSum(**test_input) == 147

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


minimum-sum-of-mountain-triplets-ii

Minimum Sum of Mountain Triplets II

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

如果下标三元组 (i, j, k) 满足下述全部条件，则认为它是一个 山形三元组 ：

 * i < j < k
 * nums[i] < nums[j] 且 nums[k] < nums[j]

请你找出 nums 中 元素和最小 的山形三元组，并返回其 元素和 。如果不存在满足条件的三元组，返回 -1 。

示例 1：

输入：nums = [8,6,1,5,3]
输出：9
解释：三元组 (2, 3, 4) 是一个元素和等于 9 的山形三元组，因为：
- 2 < 3 < 4
- nums[2] < nums[3] 且 nums[4] < nums[3]
这个三元组的元素和等于 nums[2] + nums[3] + nums[4] = 9 。可以证明不存在元素和小于 9 的山形三元组。

示例 2：

输入：nums = [5,4,8,7,10,2]
输出：13
解释：三元组 (1, 3, 5) 是一个元素和等于 13 的山形三元组，因为：
- 1 < 3 < 5
- nums[1] < nums[3] 且 nums[5] < nums[3]
这个三元组的元素和等于 nums[1] + nums[3] + nums[5] = 13 。可以证明不存在元素和小于 13 的山形三元组。

示例 3：

输入：nums = [6,5,4,3,4,5]
输出：-1
解释：可以证明 nums 中不存在山形三元组。

提示：

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

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

如果下标三元组 (i, j, k) 满足下述全部条件，则认为它是一个 山形三元组 ：

 * i < j < k
 * nums[i] < nums[j] 且 nums[k] < nums[j]

请你找出 nums 中 元素和最小 的山形三元组，并返回其 元素和 。如果不存在满足条件的三元组，返回 -1 。

示例 1：

输入：nums = [8,6,1,5,3]
输出：9
解释：三元组 (2, 3, 4) 是一个元素和等于 9 的山形三元组，因为：
- 2 < 3 < 4
- nums[2] < nums[3] 且 nums[4] < nums[3]
这个三元组的元素和等于 nums[2] + nums[3] + nums[4] = 9 。可以证明不存在元素和小于 9 的山形三元组。

示例 2：

输入：nums = [5,4,8,7,10,2]
输出：13
解释：三元组 (1, 3, 5) 是一个元素和等于 13 的山形三元组，因为：
- 1 < 3 < 5
- nums[1] < nums[3] 且 nums[5] < nums[3]
这个三元组的元素和等于 nums[1] + nums[3] + nums[5] = 13 。可以证明不存在元素和小于 13 的山形三元组。

示例 3：

输入：nums = [6,5,4,3,4,5]
输出：-1
解释：可以证明 nums 中不存在山形三元组。

提示：

 * 3 <= nums.length <= 105
 * 1 <= nums[i] <= 108

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

```

my_solution = Solution()

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

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

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

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

test_input = { "nums": [49,50,48] }
assert my_solution.minimumSum(**test_input) == 147

test_input = { "nums": [48,50,49] }
assert my_solution.minimumSum(**test_input) == 147

test_input = { "nums": [99999999,100000000,99999999] }
assert my_solution.minimumSum(**test_input) == 299999998

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


minimum-number-of-groups-to-create-a-valid-assignment

Minimum Number of Groups to Create a Valid Assignment

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

我们想将下标进行分组，使得 [0, n - 1] 内所有下标 i 都 恰好 被分到其中一组。

如果以下条件成立，我们说这个分组方案是合法的：

 * 对于每个组 g ，同一组内所有下标在 nums 中对应的数值都相等。
 * 对于任意两个组 g1 和 g2 ，两个组中 下标数量 的 差值不超过 1 。

请你返回一个整数，表示得到一个合法分组方案的 最少 组数。

示例 1：

输入：nums = [3,2,3,2,3]
输出：2
解释：一个得到 2 个分组的方案如下，中括号内的数字都是下标：
组 1 -> [0,2,4]
组 2 -> [1,3]
所有下标都只属于一个组。
组 1 中，nums[0] == nums[2] == nums[4] ，所有下标对应的数值都相等。
组 2 中，nums[1] == nums[3] ，所有下标对应的数值都相等。
组 1 中下标数目为 3 ，组 2 中下标数目为 2 。
两者之差不超过 1 。
无法得到一个小于 2 组的答案，因为如果只有 1 组，组内所有下标对应的数值都要相等。
所以答案为 2 。

示例 2：

输入：nums = [10,10,10,3,1,1]
输出：4
解释：一个得到 2 个分组的方案如下，中括号内的数字都是下标：
组 1 -> [0]
组 2 -> [1,2]
组 3 -> [3]
组 4 -> [4,5]
分组方案满足题目要求的两个条件。
无法得到一个小于 4 组的答案。
所以答案为 4 。

提示：

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

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

我们想将下标进行分组，使得 [0, n - 1] 内所有下标 i 都 恰好 被分到其中一组。

如果以下条件成立，我们说这个分组方案是合法的：

 * 对于每个组 g ，同一组内所有下标在 nums 中对应的数值都相等。
 * 对于任意两个组 g1 和 g2 ，两个组中 下标数量 的 差值不超过 1 。

请你返回一个整数，表示得到一个合法分组方案的 最少 组数。

示例 1：

输入：nums = [3,2,3,2,3]
输出：2
解释：一个得到 2 个分组的方案如下，中括号内的数字都是下标：
组 1 -> [0,2,4]
组 2 -> [1,3]
所有下标都只属于一个组。
组 1 中，nums[0] == nums[2] == nums[4] ，所有下标对应的数值都相等。
组 2 中，nums[1] == nums[3] ，所有下标对应的数值都相等。
组 1 中下标数目为 3 ，组 2 中下标数目为 2 。
两者之差不超过 1 。
无法得到一个小于 2 组的答案，因为如果只有 1 组，组内所有下标对应的数值都要相等。
所以答案为 2 。

示例 2：

输入：nums = [10,10,10,3,1,1]
输出：4
解释：一个得到 2 个分组的方案如下，中括号内的数字都是下标：
组 1 -> [0]
组 2 -> [1,2]
组 3 -> [3]
组 4 -> [4,5]
分组方案满足题目要求的两个条件。
无法得到一个小于 4 组的答案。
所以答案为 4 。

提示：

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

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

```

my_solution = Solution()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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