distribute-candies-among-children-ii

Distribute Candies Among Children II

Prompt:
"""
给你两个正整数 n 和 limit 。

请你将 n 颗糖果分给 3 位小朋友，确保没有任何小朋友得到超过 limit 颗糖果，请你返回满足此条件下的 总方案数 。

示例 1：

输入：n = 5, limit = 2
输出：3
解释：总共有 3 种方法分配 5 颗糖果，且每位小朋友的糖果数不超过 2 ：(1, 2, 2) ，(2, 1, 2) 和 (2, 2, 1) 。

示例 2：

输入：n = 3, limit = 3
输出：10
解释：总共有 10 种方法分配 3 颗糖果，且每位小朋友的糖果数不超过 3 ：(0, 0, 3) ，(0, 1, 2) ，(0, 2, 1) ，(0, 3, 0) ，(1, 0, 2) ，(1, 1, 1) ，(1, 2, 0) ，(2, 0, 1) ，(2, 1, 0) 和 (3, 0, 0) 。

提示：

 * 1 <= n <= 106
 * 1 <= limit <= 106
"""
class Solution:
    def distributeCandies(self, n: int, limit: int) -> int:

给你两个正整数 n 和 limit 。

请你将 n 颗糖果分给 3 位小朋友，确保没有任何小朋友得到超过 limit 颗糖果，请你返回满足此条件下的 总方案数 。

示例 1：

输入：n = 5, limit = 2
输出：3
解释：总共有 3 种方法分配 5 颗糖果，且每位小朋友的糖果数不超过 2 ：(1, 2, 2) ，(2, 1, 2) 和 (2, 2, 1) 。

示例 2：

输入：n = 3, limit = 3
输出：10
解释：总共有 10 种方法分配 3 颗糖果，且每位小朋友的糖果数不超过 3 ：(0, 0, 3) ，(0, 1, 2) ，(0, 2, 1) ，(0, 3, 0) ，(1, 0, 2) ，(1, 1, 1) ，(1, 2, 0) ，(2, 0, 1) ，(2, 1, 0) 和 (3, 0, 0) 。

提示：

 * 1 <= n <= 106
 * 1 <= limit <= 106

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

```

my_solution = Solution()

test_input = { "n": 5, "limit": 2 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 3, "limit": 3 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 1, "limit": 1 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 2 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 3 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 4 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 5 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 6 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 7 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 8 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 9 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 10 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 11 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 12 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 13 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 14 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 15 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 16 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 17 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 18 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 19 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 1, "limit": 20 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 2, "limit": 1 }
assert my_solution.distributeCandies(**test_input) == 3

test_input = { "n": 2, "limit": 2 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 3 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 4 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 5 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 6 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 7 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 8 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 9 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 10 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 11 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 12 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 13 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 14 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 15 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 16 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 17 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 18 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 19 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 2, "limit": 20 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 3, "limit": 1 }
assert my_solution.distributeCandies(**test_input) == 1

test_input = { "n": 3, "limit": 2 }
assert my_solution.distributeCandies(**test_input) == 7

test_input = { "n": 3, "limit": 4 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 5 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 6 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 7 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 8 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 9 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 10 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 11 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 12 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 13 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 14 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 15 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 16 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 17 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 18 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 19 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 3, "limit": 20 }
assert my_solution.distributeCandies(**test_input) == 10

test_input = { "n": 4, "limit": 1 }
assert my_solution.distributeCandies(**test_input) == 0

test_input = { "n": 4, "limit": 2 }
assert my_solution.distributeCandies(**test_input) == 6

test_input = { "n": 4, "limit": 3 }
assert my_solution.distributeCandies(**test_input) == 12

test_input = { "n": 4, "limit": 4 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 5 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 6 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 7 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 8 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 9 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 10 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 11 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 12 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 13 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 14 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 15 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 16 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 17 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 18 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 19 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 4, "limit": 20 }
assert my_solution.distributeCandies(**test_input) == 15

test_input = { "n": 5, "limit": 1 }
assert my_solution.distributeCandies(**test_input) == 0

test_input = { "n": 5, "limit": 3 }
assert my_solution.distributeCandies(**test_input) == 12

test_input = { "n": 5, "limit": 4 }
assert my_solution.distributeCandies(**test_input) == 18

test_input = { "n": 5, "limit": 5 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 6 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 7 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 8 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 9 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 10 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 11 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 12 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 13 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 14 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 15 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 16 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 17 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 18 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 19 }
assert my_solution.distributeCandies(**test_input) == 21

test_input = { "n": 5, "limit": 20 }
assert my_solution.distributeCandies(**test_input) == 21


number-of-strings-which-can-be-rearranged-to-contain-substring

Number of Strings Which Can Be Rearranged to Contain Substring

Prompt:
"""
给你一个整数 n 。

如果一个字符串 s 只包含小写英文字母，且 将 s 的字符重新排列后，新字符串包含 子字符串 "leet" ，那么我们称字符串 s 是一个 好 字符串。

比方说：

 * 字符串 "lteer" 是好字符串，因为重新排列后可以得到 "leetr" 。
 * "letl" 不是好字符串，因为无法重新排列并得到子字符串 "leet" 。

请你返回长度为 n 的好字符串 总 数目。

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

子字符串 是一个字符串中一段连续的字符序列。

示例 1：

输入：n = 4
输出：12
解释：总共有 12 个字符串重新排列后包含子字符串 "leet" ："eelt" ，"eetl" ，"elet" ，"elte" ，"etel" ，"etle" ，"leet" ，"lete" ，"ltee" ，"teel" ，"tele" 和 "tlee" 。

示例 2：

输入：n = 10
输出：83943898
解释：长度为 10 的字符串重新排列后包含子字符串 "leet" 的方案数为 526083947580 。所以答案为 526083947580 % (109 + 7) = 83943898 。

提示：

 * 1 <= n <= 105
"""
class Solution:
    def stringCount(self, n: int) -> int:

给你一个整数 n 。

如果一个字符串 s 只包含小写英文字母，且 将 s 的字符重新排列后，新字符串包含 子字符串 "leet" ，那么我们称字符串 s 是一个 好 字符串。

比方说：

 * 字符串 "lteer" 是好字符串，因为重新排列后可以得到 "leetr" 。
 * "letl" 不是好字符串，因为无法重新排列并得到子字符串 "leet" 。

请你返回长度为 n 的好字符串 总 数目。

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

子字符串 是一个字符串中一段连续的字符序列。

示例 1：

输入：n = 4
输出：12
解释：总共有 12 个字符串重新排列后包含子字符串 "leet" ："eelt" ，"eetl" ，"elet" ，"elte" ，"etel" ，"etle" ，"leet" ，"lete" ，"ltee" ，"teel" ，"tele" 和 "tlee" 。

示例 2：

输入：n = 10
输出：83943898
解释：长度为 10 的字符串重新排列后包含子字符串 "leet" 的方案数为 526083947580 。所以答案为 526083947580 % (109 + 7) = 83943898 。

提示：

 * 1 <= n <= 105

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

```

my_solution = Solution()

test_input = { "n": 4 }
assert my_solution.stringCount(**test_input) == 12

test_input = { "n": 10 }
assert my_solution.stringCount(**test_input) == 83943898

test_input = { "n": 1 }
assert my_solution.stringCount(**test_input) == 0

test_input = { "n": 2 }
assert my_solution.stringCount(**test_input) == 0

test_input = { "n": 3 }
assert my_solution.stringCount(**test_input) == 0

test_input = { "n": 5 }
assert my_solution.stringCount(**test_input) == 1460

test_input = { "n": 6 }
assert my_solution.stringCount(**test_input) == 106620

test_input = { "n": 7 }
assert my_solution.stringCount(**test_input) == 6058192

test_input = { "n": 8 }
assert my_solution.stringCount(**test_input) == 295164156

test_input = { "n": 9 }
assert my_solution.stringCount(**test_input) == 947613240

test_input = { "n": 11 }
assert my_solution.stringCount(**test_input) == 795234177

test_input = { "n": 12 }
assert my_solution.stringCount(**test_input) == 55396773

test_input = { "n": 13 }
assert my_solution.stringCount(**test_input) == 968092561

test_input = { "n": 14 }
assert my_solution.stringCount(**test_input) == 715599898

test_input = { "n": 15 }
assert my_solution.stringCount(**test_input) == 430509685

test_input = { "n": 16 }
assert my_solution.stringCount(**test_input) == 462719236

test_input = { "n": 17 }
assert my_solution.stringCount(**test_input) == 155543310

test_input = { "n": 18 }
assert my_solution.stringCount(**test_input) == 159683962

test_input = { "n": 19 }
assert my_solution.stringCount(**test_input) == 808507313

test_input = { "n": 20 }
assert my_solution.stringCount(**test_input) == 291395991

test_input = { "n": 21 }
assert my_solution.stringCount(**test_input) == 461951930

test_input = { "n": 22 }
assert my_solution.stringCount(**test_input) == 871561520

test_input = { "n": 23 }
assert my_solution.stringCount(**test_input) == 993268925

test_input = { "n": 24 }
assert my_solution.stringCount(**test_input) == 871982505

test_input = { "n": 25 }
assert my_solution.stringCount(**test_input) == 935610434

test_input = { "n": 26 }
assert my_solution.stringCount(**test_input) == 867518559

test_input = { "n": 27 }
assert my_solution.stringCount(**test_input) == 3067523

test_input = { "n": 28 }
assert my_solution.stringCount(**test_input) == 716801469

test_input = { "n": 29 }
assert my_solution.stringCount(**test_input) == 452206104

test_input = { "n": 30 }
assert my_solution.stringCount(**test_input) == 52805056

test_input = { "n": 31 }
assert my_solution.stringCount(**test_input) == 61992724

test_input = { "n": 32 }
assert my_solution.stringCount(**test_input) == 76928250

test_input = { "n": 33 }
assert my_solution.stringCount(**test_input) == 257967635

test_input = { "n": 34 }
assert my_solution.stringCount(**test_input) == 549347744

test_input = { "n": 35 }
assert my_solution.stringCount(**test_input) == 290653839

test_input = { "n": 36 }
assert my_solution.stringCount(**test_input) == 123906995

test_input = { "n": 37 }
assert my_solution.stringCount(**test_input) == 41253530

test_input = { "n": 38 }
assert my_solution.stringCount(**test_input) == 828924891

test_input = { "n": 39 }
assert my_solution.stringCount(**test_input) == 60893212

test_input = { "n": 40 }
assert my_solution.stringCount(**test_input) == 618599272

test_input = { "n": 41 }
assert my_solution.stringCount(**test_input) == 840600409

test_input = { "n": 42 }
assert my_solution.stringCount(**test_input) == 995406621

test_input = { "n": 43 }
assert my_solution.stringCount(**test_input) == 991833054

test_input = { "n": 44 }
assert my_solution.stringCount(**test_input) == 403185520

test_input = { "n": 45 }
assert my_solution.stringCount(**test_input) == 904195428

test_input = { "n": 46 }
assert my_solution.stringCount(**test_input) == 643609894

test_input = { "n": 47 }
assert my_solution.stringCount(**test_input) == 177947842

test_input = { "n": 48 }
assert my_solution.stringCount(**test_input) == 826753905

test_input = { "n": 49 }
assert my_solution.stringCount(**test_input) == 855443295

test_input = { "n": 50 }
assert my_solution.stringCount(**test_input) == 232825199

test_input = { "n": 51 }
assert my_solution.stringCount(**test_input) == 227116084

test_input = { "n": 52 }
assert my_solution.stringCount(**test_input) == 417264566

test_input = { "n": 53 }
assert my_solution.stringCount(**test_input) == 468973861

test_input = { "n": 54 }
assert my_solution.stringCount(**test_input) == 999145386

test_input = { "n": 55 }
assert my_solution.stringCount(**test_input) == 721276317

test_input = { "n": 56 }
assert my_solution.stringCount(**test_input) == 385673910

test_input = { "n": 57 }
assert my_solution.stringCount(**test_input) == 7891114

test_input = { "n": 58 }
assert my_solution.stringCount(**test_input) == 85081065

test_input = { "n": 59 }
assert my_solution.stringCount(**test_input) == 194677227

test_input = { "n": 60 }
assert my_solution.stringCount(**test_input) == 759126147

test_input = { "n": 61 }
assert my_solution.stringCount(**test_input) == 273111337

test_input = { "n": 62 }
assert my_solution.stringCount(**test_input) == 166598301

test_input = { "n": 63 }
assert my_solution.stringCount(**test_input) == 955460796

test_input = { "n": 64 }
assert my_solution.stringCount(**test_input) == 685704195

test_input = { "n": 65 }
assert my_solution.stringCount(**test_input) == 821093882

test_input = { "n": 66 }
assert my_solution.stringCount(**test_input) == 172674695

test_input = { "n": 67 }
assert my_solution.stringCount(**test_input) == 464621746

test_input = { "n": 68 }
assert my_solution.stringCount(**test_input) == 432202634

test_input = { "n": 69 }
assert my_solution.stringCount(**test_input) == 465445347

test_input = { "n": 70 }
assert my_solution.stringCount(**test_input) == 654273613

test_input = { "n": 71 }
assert my_solution.stringCount(**test_input) == 366864502

test_input = { "n": 72 }
assert my_solution.stringCount(**test_input) == 124689502

test_input = { "n": 73 }
assert my_solution.stringCount(**test_input) == 419691288

test_input = { "n": 74 }
assert my_solution.stringCount(**test_input) == 987033948

test_input = { "n": 75 }
assert my_solution.stringCount(**test_input) == 842828500

test_input = { "n": 76 }
assert my_solution.stringCount(**test_input) == 409614634

test_input = { "n": 77 }
assert my_solution.stringCount(**test_input) == 73844796

test_input = { "n": 78 }
assert my_solution.stringCount(**test_input) == 584672527

test_input = { "n": 79 }
assert my_solution.stringCount(**test_input) == 113476429

test_input = { "n": 80 }
assert my_solution.stringCount(**test_input) == 974106352

test_input = { "n": 81 }
assert my_solution.stringCount(**test_input) == 646239862

test_input = { "n": 82 }
assert my_solution.stringCount(**test_input) == 420253116

test_input = { "n": 83 }
assert my_solution.stringCount(**test_input) == 817573615

test_input = { "n": 84 }
assert my_solution.stringCount(**test_input) == 471199144

test_input = { "n": 85 }
assert my_solution.stringCount(**test_input) == 567239979

test_input = { "n": 86 }
assert my_solution.stringCount(**test_input) == 221534816

test_input = { "n": 87 }
assert my_solution.stringCount(**test_input) == 707218848

test_input = { "n": 88 }
assert my_solution.stringCount(**test_input) == 687360104

test_input = { "n": 89 }
assert my_solution.stringCount(**test_input) == 551986596

test_input = { "n": 90 }
assert my_solution.stringCount(**test_input) == 122933939

test_input = { "n": 91 }
assert my_solution.stringCount(**test_input) == 427294641

test_input = { "n": 92 }
assert my_solution.stringCount(**test_input) == 14022454

test_input = { "n": 93 }
assert my_solution.stringCount(**test_input) == 568729284

test_input = { "n": 94 }
assert my_solution.stringCount(**test_input) == 653568519

test_input = { "n": 95 }
assert my_solution.stringCount(**test_input) == 15509440

test_input = { "n": 96 }
assert my_solution.stringCount(**test_input) == 991824044

test_input = { "n": 97 }
assert my_solution.stringCount(**test_input) == 690441338

test_input = { "n": 98 }
assert my_solution.stringCount(**test_input) == 600462833

test_input = { "n": 99 }
assert my_solution.stringCount(**test_input) == 880019356

test_input = { "n": 100 }
assert my_solution.stringCount(**test_input) == 86731066


maximum-spending-after-buying-items

Maximum Spending After Buying Items

Prompt:
"""
给你一个下标从 0 开始大小为 m * n 的整数矩阵 values ，表示 m 个不同商店里 m * n 件不同的物品。每个商店有 n 件物品，第 i 个商店的第 j 件物品的价值为 values[i][j] 。除此以外，第 i 个商店的物品已经按照价值非递增排好序了，也就是说对于所有 0 <= j < n - 1 都有 values[i][j] >= values[i][j + 1] 。

每一天，你可以在一个商店里购买一件物品。具体来说，在第 d 天，你可以：

 * 选择商店 i 。
 * 购买数组中最右边的物品 j ，开销为 values[i][j] * d 。换句话说，选择该商店中还没购买过的物品中最大的下标 j ，并且花费 values[i][j] * d 去购买。

注意，所有物品都视为不同的物品。比方说如果你已经从商店 1 购买了物品 0 ，你还可以在别的商店里购买其他商店的物品 0 。

请你返回购买所有 m * n 件物品需要的 最大开销 。

示例 1：

输入：values = [[8,5,2],[6,4,1],[9,7,3]]
输出：285
解释：第一天，从商店 1 购买物品 2 ，开销为 values[1][2] * 1 = 1 。
第二天，从商店 0 购买物品 2 ，开销为 values[0][2] * 2 = 4 。
第三天，从商店 2 购买物品 2 ，开销为 values[2][2] * 3 = 9 。
第四天，从商店 1 购买物品 1 ，开销为 values[1][1] * 4 = 16 。
第五天，从商店 0 购买物品 1 ，开销为 values[0][1] * 5 = 25 。
第六天，从商店 1 购买物品 0 ，开销为 values[1][0] * 6 = 36 。
第七天，从商店 2 购买物品 1 ，开销为 values[2][1] * 7 = 49 。
第八天，从商店 0 购买物品 0 ，开销为 values[0][0] * 8 = 64 。
第九天，从商店 2 购买物品 0 ，开销为 values[2][0] * 9 = 81 。
所以总开销为 285 。
285 是购买所有 m * n 件物品的最大总开销。

示例 2：

输入：values = [[10,8,6,4,2],[9,7,5,3,2]]
输出：386
解释：第一天，从商店 0 购买物品 4 ，开销为 values[0][4] * 1 = 2 。
第二天，从商店 1 购买物品 4 ，开销为 values[1][4] * 2 = 4 。
第三天，从商店 1 购买物品 3 ，开销为 values[1][3] * 3 = 9 。
第四天，从商店 0 购买物品 3 ，开销为 values[0][3] * 4 = 16 。
第五天，从商店 1 购买物品 2 ，开销为 values[1][2] * 5 = 25 。
第六天，从商店 0 购买物品 2 ，开销为 values[0][2] * 6 = 36 。
第七天，从商店 1 购买物品 1 ，开销为 values[1][1] * 7 = 49 。
第八天，从商店 0 购买物品 1 ，开销为 values[0][1] * 8 = 64 。
第九天，从商店 1 购买物品 0 ，开销为 values[1][0] * 9 = 81 。
第十天，从商店 0 购买物品 0 ，开销为 values[0][0] * 10 = 100 。
所以总开销为 386 。
386 是购买所有 m * n 件物品的最大总开销。

提示：

 * 1 <= m == values.length <= 10
 * 1 <= n == values[i].length <= 104
 * 1 <= values[i][j] <= 106
 * values[i] 按照非递增顺序排序。
"""
class Solution:
    def maxSpending(self, values: List[List[int]]) -> int:

给你一个下标从 0 开始大小为 m * n 的整数矩阵 values ，表示 m 个不同商店里 m * n 件不同的物品。每个商店有 n 件物品，第 i 个商店的第 j 件物品的价值为 values[i][j] 。除此以外，第 i 个商店的物品已经按照价值非递增排好序了，也就是说对于所有 0 <= j < n - 1 都有 values[i][j] >= values[i][j + 1] 。

每一天，你可以在一个商店里购买一件物品。具体来说，在第 d 天，你可以：

 * 选择商店 i 。
 * 购买数组中最右边的物品 j ，开销为 values[i][j] * d 。换句话说，选择该商店中还没购买过的物品中最大的下标 j ，并且花费 values[i][j] * d 去购买。

注意，所有物品都视为不同的物品。比方说如果你已经从商店 1 购买了物品 0 ，你还可以在别的商店里购买其他商店的物品 0 。

请你返回购买所有 m * n 件物品需要的 最大开销 。

示例 1：

输入：values = [[8,5,2],[6,4,1],[9,7,3]]
输出：285
解释：第一天，从商店 1 购买物品 2 ，开销为 values[1][2] * 1 = 1 。
第二天，从商店 0 购买物品 2 ，开销为 values[0][2] * 2 = 4 。
第三天，从商店 2 购买物品 2 ，开销为 values[2][2] * 3 = 9 。
第四天，从商店 1 购买物品 1 ，开销为 values[1][1] * 4 = 16 。
第五天，从商店 0 购买物品 1 ，开销为 values[0][1] * 5 = 25 。
第六天，从商店 1 购买物品 0 ，开销为 values[1][0] * 6 = 36 。
第七天，从商店 2 购买物品 1 ，开销为 values[2][1] * 7 = 49 。
第八天，从商店 0 购买物品 0 ，开销为 values[0][0] * 8 = 64 。
第九天，从商店 2 购买物品 0 ，开销为 values[2][0] * 9 = 81 。
所以总开销为 285 。
285 是购买所有 m * n 件物品的最大总开销。

示例 2：

输入：values = [[10,8,6,4,2],[9,7,5,3,2]]
输出：386
解释：第一天，从商店 0 购买物品 4 ，开销为 values[0][4] * 1 = 2 。
第二天，从商店 1 购买物品 4 ，开销为 values[1][4] * 2 = 4 。
第三天，从商店 1 购买物品 3 ，开销为 values[1][3] * 3 = 9 。
第四天，从商店 0 购买物品 3 ，开销为 values[0][3] * 4 = 16 。
第五天，从商店 1 购买物品 2 ，开销为 values[1][2] * 5 = 25 。
第六天，从商店 0 购买物品 2 ，开销为 values[0][2] * 6 = 36 。
第七天，从商店 1 购买物品 1 ，开销为 values[1][1] * 7 = 49 。
第八天，从商店 0 购买物品 1 ，开销为 values[0][1] * 8 = 64 。
第九天，从商店 1 购买物品 0 ，开销为 values[1][0] * 9 = 81 。
第十天，从商店 0 购买物品 0 ，开销为 values[0][0] * 10 = 100 。
所以总开销为 386 。
386 是购买所有 m * n 件物品的最大总开销。

提示：

 * 1 <= m == values.length <= 10
 * 1 <= n == values[i].length <= 104
 * 1 <= values[i][j] <= 106
 * values[i] 按照非递增顺序排序。

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

```

my_solution = Solution()

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

test_input = { "values": [[10,8,6,4,2],[9,7,5,3,2]] }
assert my_solution.maxSpending(**test_input) == 386

test_input = { "values": [[1000000]] }
assert my_solution.maxSpending(**test_input) == 1000000

test_input = { "values": [[1]] }
assert my_solution.maxSpending(**test_input) == 1

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

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

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

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

test_input = { "values": [[5,5]] }
assert my_solution.maxSpending(**test_input) == 15

test_input = { "values": [[7,5]] }
assert my_solution.maxSpending(**test_input) == 19

test_input = { "values": [[3,2,1]] }
assert my_solution.maxSpending(**test_input) == 14

test_input = { "values": [[2,2,1]] }
assert my_solution.maxSpending(**test_input) == 11

test_input = { "values": [[3,3,2]] }
assert my_solution.maxSpending(**test_input) == 17

test_input = { "values": [[3],[2],[1]] }
assert my_solution.maxSpending(**test_input) == 14

test_input = { "values": [[2],[10],[1]] }
assert my_solution.maxSpending(**test_input) == 35

test_input = { "values": [[1000000,1000000,1000000]] }
assert my_solution.maxSpending(**test_input) == 6000000

test_input = { "values": [[1000000,1000000,1000000,1000000]] }
assert my_solution.maxSpending(**test_input) == 10000000

test_input = { "values": [[1000000],[1000000],[1000000],[1000000]] }
assert my_solution.maxSpending(**test_input) == 10000000

test_input = { "values": [[1000000,1000000],[1000000,1000000]] }
assert my_solution.maxSpending(**test_input) == 10000000

test_input = { "values": [[2,1],[4,3]] }
assert my_solution.maxSpending(**test_input) == 30

test_input = { "values": [[3,1],[4,2]] }
assert my_solution.maxSpending(**test_input) == 30

test_input = { "values": [[4,1],[3,2]] }
assert my_solution.maxSpending(**test_input) == 30

test_input = { "values": [[15,13,13,12,12,12,12,11,11,11,11,9,9,8,7,5,5,5,1]] }
assert my_solution.maxSpending(**test_input) == 2162

test_input = { "values": [[13,13,11,7,2,1],[13,10,10,6,3,3]] }
assert my_solution.maxSpending(**test_input) == 776

test_input = { "values": [[12,6],[13,5],[13,3],[6,6],[15,6],[5,4],[6,1]] }
assert my_solution.maxSpending(**test_input) == 971

test_input = { "values": [[15,15,14,14,14,10,10,9,9,8,8,8,7,7,7,4]] }
assert my_solution.maxSpending(**test_input) == 1585

test_input = { "values": [[11,10],[10,1],[14,6],[13,5],[7,3],[10,10],[10,5]] }
assert my_solution.maxSpending(**test_input) == 1061

test_input = { "values": [[15,13,12,7,6,4,1]] }
assert my_solution.maxSpending(**test_input) == 298

test_input = { "values": [[8,2],[4,1],[10,4]] }
assert my_solution.maxSpending(**test_input) == 133

test_input = { "values": [[10,4],[13,2],[7,5],[15,11]] }
assert my_solution.maxSpending(**test_input) == 380

test_input = { "values": [[13,10,10,9,8,5,5,2,1,1]] }
assert my_solution.maxSpending(**test_input) == 465

test_input = { "values": [[15,14,8,7,5,5,1]] }
assert my_solution.maxSpending(**test_input) == 283

test_input = { "values": [[15,15,14,14,14,14,13,11,10,10,10,9,7,7,6,6,4,4,2,1]] }
assert my_solution.maxSpending(**test_input) == 2449

test_input = { "values": [[15,14,11,10,10,6,2],[13,8,8,6,6,3,2]] }
assert my_solution.maxSpending(**test_input) == 1084

test_input = { "values": [[15,15,14,13,13,12,11,9,9,9,8,6,5,5,4,3,2,1,1]] }
assert my_solution.maxSpending(**test_input) == 2030

test_input = { "values": [[15,10,7],[14,2,2],[14,13,12],[13,13,10]] }
assert my_solution.maxSpending(**test_input) == 975

test_input = { "values": [[10,9,3,3],[11,8,7,2],[14,14,13,1],[14,14,11,4],[13,11,9,5]] }
assert my_solution.maxSpending(**test_input) == 2338

test_input = { "values": [[11,7,5,2],[15,5,5,3]] }
assert my_solution.maxSpending(**test_input) == 307

test_input = { "values": [[15,10,10,9,8,7,4,2,2]] }
assert my_solution.maxSpending(**test_input) == 425

test_input = { "values": [[15,13,12,12,10,5,4,3,1]] }
assert my_solution.maxSpending(**test_input) == 484

test_input = { "values": [[12,12,12,11,10,10,7,7,6,5,5,3,2,1]] }
assert my_solution.maxSpending(**test_input) == 979

test_input = { "values": [[15,13,13,13,12,12,11,11,10,9,9,9,8,6,6,4,4,3,2,1]] }
assert my_solution.maxSpending(**test_input) == 2253

test_input = { "values": [[14,11],[11,8],[10,4],[4,3],[9,6],[8,4],[7,7],[10,4],[14,4]] }
assert my_solution.maxSpending(**test_input) == 1621

test_input = { "values": [[14,13,13,11,11,8,8,7,6,4,3,2,1]] }
assert my_solution.maxSpending(**test_input) == 912

test_input = { "values": [[15,14,14,10,10,9,9,7,7,7,7,7,6,6,6,4,4,3,3]] }
assert my_solution.maxSpending(**test_input) == 1823

test_input = { "values": [[14,13,11,10,10,1,1],[15,12,8,6,6,5,5]] }
assert my_solution.maxSpending(**test_input) == 1120

test_input = { "values": [[15,14,13,12,11,10,10,10,9,7,6,6,4,3,3,3,2,2,1]] }
assert my_solution.maxSpending(**test_input) == 1860

test_input = { "values": [[12,6,5,4,2]] }
assert my_solution.maxSpending(**test_input) == 109

test_input = { "values": [[15,15,14,13,12,12,12,11,10,10,9,9,9,8,7,6,3,2]] }
assert my_solution.maxSpending(**test_input) == 2006

test_input = { "values": [[15,14,12,11,10,10,7,6,2,1]] }
assert my_solution.maxSpending(**test_input) == 610

test_input = { "values": [[15,13,12,11,8,6,5]] }
assert my_solution.maxSpending(**test_input) == 328

test_input = { "values": [[15,15,12,10,9,7,7,6,6,5,4,2,1]] }
assert my_solution.maxSpending(**test_input) == 896

test_input = { "values": [[15,15,12,12,10,10,9,7,6,4,4,4,1]] }
assert my_solution.maxSpending(**test_input) == 969

test_input = { "values": [[15,14,14,13,8,7,7,4,3,3,2,1]] }
assert my_solution.maxSpending(**test_input) == 792

test_input = { "values": [[15,15,14,14,14,13,10,8,6,6,5,5,3,3,2,2,1]] }
assert my_solution.maxSpending(**test_input) == 1634

test_input = { "values": [[14,12,11,10,10,8,7,7,5,5,3,3,3]] }
assert my_solution.maxSpending(**test_input) == 855

test_input = { "values": [[14,14,9,9,4,4,1],[12,12,9,8,7,6,3]] }
assert my_solution.maxSpending(**test_input) == 1060

test_input = { "values": [[15,15,15,13,12,12,10,9,9,9,9,7,6,4,4,4,1]] }
assert my_solution.maxSpending(**test_input) == 1727

test_input = { "values": [[9,4],[13,4],[13,9],[6,5],[8,2],[13,1]] }
assert my_solution.maxSpending(**test_input) == 732

test_input = { "values": [[14,9,9,9,8,7,5],[15,14,10,8,5,3,1]] }
assert my_solution.maxSpending(**test_input) == 1094

test_input = { "values": [[15,15,14,13,10,3,1]] }
assert my_solution.maxSpending(**test_input) == 354

test_input = { "values": [[13,12],[13,12],[11,8],[14,3]] }
assert my_solution.maxSpending(**test_input) == 441

test_input = { "values": [[13,12,11,10,7,5,5,1]] }
assert my_solution.maxSpending(**test_input) == 358

test_input = { "values": [[15,10,9,8,8,7,7,5,4,3,1]] }
assert my_solution.maxSpending(**test_input) == 582

test_input = { "values": [[10,10,6,4,1],[14,13,13,11,9],[14,11,7,4,3]] }
assert my_solution.maxSpending(**test_input) == 1302

test_input = { "values": [[15,14,12,12,11,11,10,9,9,8,8,6,6,4,2,2,1]] }
assert my_solution.maxSpending(**test_input) == 1596

test_input = { "values": [[12,5,4,3,3,2,1,1],[13,11,9,9,6,4,3,1]] }
assert my_solution.maxSpending(**test_input) == 1019

test_input = { "values": [[15,15,13,11,10,10,7,1,1]] }
assert my_solution.maxSpending(**test_input) == 526

test_input = { "values": [[14,12,10,4,3,1],[12,12,8,7,6,2],[15,13,8,5,4,1]] }
assert my_solution.maxSpending(**test_input) == 1719

test_input = { "values": [[13,8,8,8,5,4,3],[15,13,9,8,7,3,2]] }
assert my_solution.maxSpending(**test_input) == 1006

test_input = { "values": [[13,13,12,12,9]] }
assert my_solution.maxSpending(**test_input) == 186

test_input = { "values": [[10,3],[11,9],[10,5],[8,7],[6,1]] }
assert my_solution.maxSpending(**test_input) == 472

test_input = { "values": [[15,15,12,12,11,10,9,8,2,2,1,1,1]] }
assert my_solution.maxSpending(**test_input) == 941

test_input = { "values": [[14,14,13,13,11,11,10,10,10,9,8,8,7,7,6,6,5,4,3]] }
assert my_solution.maxSpending(**test_input) == 2023

test_input = { "values": [[11,10,9,7,6,5,3,1],[14,14,10,9,7,4,4,3]] }
assert my_solution.maxSpending(**test_input) == 1270

test_input = { "values": [[6,2],[10,2],[13,5],[8,7],[10,3],[13,2],[13,6]] }
assert my_solution.maxSpending(**test_input) == 972

test_input = { "values": [[15,15,15,14,13,12,6,5,5,4]] }
assert my_solution.maxSpending(**test_input) == 694

test_input = { "values": [[11,9],[8,1],[2,1],[15,13],[12,4],[14,5],[13,4]] }
assert my_solution.maxSpending(**test_input) == 1113

test_input = { "values": [[15,14,14,13,12,11,10,10,5,4,2]] }
assert my_solution.maxSpending(**test_input) == 800

test_input = { "values": [[13,12,12,6,5,5,4,2,2,2,1]] }
assert my_solution.maxSpending(**test_input) == 523

test_input = { "values": [[13,8],[15,1],[9,1],[13,1]] }
assert my_solution.maxSpending(**test_input) == 372

test_input = { "values": [[12,8,4,1],[14,8,8,3]] }
assert my_solution.maxSpending(**test_input) == 335

test_input = { "values": [[15,14,14,13,13,13,12,12,9,9,8,7,6,5,5,5,4,3,1]] }
assert my_solution.maxSpending(**test_input) == 2113

test_input = { "values": [[13,9,8,2,1],[9,4,3,2,1],[10,8,6,3,1]] }
assert my_solution.maxSpending(**test_input) == 877

test_input = { "values": [[8,6],[13,1],[12,8],[8,7]] }
assert my_solution.maxSpending(**test_input) == 342

test_input = { "values": [[9,7],[15,15],[9,8],[6,1],[11,4]] }
assert my_solution.maxSpending(**test_input) == 585

test_input = { "values": [[14,9,9,8,6,4,2]] }
assert my_solution.maxSpending(**test_input) == 257

test_input = { "values": [[15,13,11,11,10,9,5,5,4,4,4,4,3,2]] }
assert my_solution.maxSpending(**test_input) == 968

test_input = { "values": [[13,7,7,4],[8,8,6,6]] }
assert my_solution.maxSpending(**test_input) == 305

test_input = { "values": [[15,13,12,10,10,10,9,9,9,8,7,6,6,5,4,4,2,1,1]] }
assert my_solution.maxSpending(**test_input) == 1805

test_input = { "values": [[13,13,1],[11,5,4],[14,5,1],[15,5,2],[10,1,1],[15,12,1]] }
assert my_solution.maxSpending(**test_input) == 1714

test_input = { "values": [[15,15,14,14,11,10,10,8,8,8,3,1,1]] }
assert my_solution.maxSpending(**test_input) == 1050

test_input = { "values": [[3,3],[15,10],[14,9]] }
assert my_solution.maxSpending(**test_input) == 236

test_input = { "values": [[14,13,11,10,9,7,2]] }
assert my_solution.maxSpending(**test_input) == 314

test_input = { "values": [[11,7],[5,3],[11,6],[6,1],[15,13]] }
assert my_solution.maxSpending(**test_input) == 550

test_input = { "values": [[14,13,13,12,12,12,11,11,9,8,8,6,5,5,5,5,3,3,2]] }
assert my_solution.maxSpending(**test_input) == 1962

test_input = { "values": [[14,14,13,13,13,12,12,11,10,9,9,8,8,7,3,2,2]] }
assert my_solution.maxSpending(**test_input) == 1750

test_input = { "values": [[15,8],[12,2],[15,10],[9,3],[5,4],[14,2],[7,6]] }
assert my_solution.maxSpending(**test_input) == 1091

test_input = { "values": [[15,9,7,3,3],[7,6,4,3,2],[15,9,8,4,4],[15,10,9,7,4]] }
assert my_solution.maxSpending(**test_input) == 1952

test_input = { "values": [[12,12,10,8,8,8,8,6,2,2,1]] }
assert my_solution.maxSpending(**test_input) == 585


find-champion-i

Find Champion I

Prompt:
"""
一场比赛中共有 n 支队伍，按从 0 到  n - 1 编号。

给你一个下标从 0 开始、大小为 n * n 的二维布尔矩阵 grid 。对于满足 0 <= i, j <= n - 1 且 i != j 的所有 i, j ：如果 grid[i][j] == 1，那么 i 队比 j 队 强 ；否则，j 队比 i 队 强 。

在这场比赛中，如果不存在某支强于 a 队的队伍，则认为 a 队将会是 冠军 。

返回这场比赛中将会成为冠军的队伍。

示例 1：

输入：grid = [[0,1],[0,0]]
输出：0
解释：比赛中有两支队伍。
grid[0][1] == 1 表示 0 队比 1 队强。所以 0 队是冠军。

示例 2：

输入：grid = [[0,0,1],[1,0,1],[0,0,0]]
输出：1
解释：比赛中有三支队伍。
grid[1][0] == 1 表示 1 队比 0 队强。
grid[1][2] == 1 表示 1 队比 2 队强。
所以 1 队是冠军。

提示：

 * n == grid.length
 * n == grid[i].length
 * 2 <= n <= 100
 * grid[i][j] 的值为 0 或 1
 * 对于所有 i， grid[i][i] 等于 0.
 * 对于满足 i != j 的所有 i, j ，grid[i][j] != grid[j][i] 均成立
 * 生成的输入满足：如果 a 队比 b 队强，b 队比 c 队强，那么 a 队比 c 队强
"""
class Solution:
    def findChampion(self, grid: List[List[int]]) -> int:

一场比赛中共有 n 支队伍，按从 0 到  n - 1 编号。

给你一个下标从 0 开始、大小为 n * n 的二维布尔矩阵 grid 。对于满足 0 <= i, j <= n - 1 且 i != j 的所有 i, j ：如果 grid[i][j] == 1，那么 i 队比 j 队 强 ；否则，j 队比 i 队 强 。

在这场比赛中，如果不存在某支强于 a 队的队伍，则认为 a 队将会是 冠军 。

返回这场比赛中将会成为冠军的队伍。

示例 1：

输入：grid = [[0,1],[0,0]]
输出：0
解释：比赛中有两支队伍。
grid[0][1] == 1 表示 0 队比 1 队强。所以 0 队是冠军。

示例 2：

输入：grid = [[0,0,1],[1,0,1],[0,0,0]]
输出：1
解释：比赛中有三支队伍。
grid[1][0] == 1 表示 1 队比 0 队强。
grid[1][2] == 1 表示 1 队比 2 队强。
所以 1 队是冠军。

提示：

 * n == grid.length
 * n == grid[i].length
 * 2 <= n <= 100
 * grid[i][j] 的值为 0 或 1
 * 对于所有 i， grid[i][i] 等于 0.
 * 对于满足 i != j 的所有 i, j ，grid[i][j] != grid[j][i] 均成立
 * 生成的输入满足：如果 a 队比 b 队强，b 队比 c 队强，那么 a 队比 c 队强

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

```

my_solution = Solution()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


find-champion-ii

Find Champion II

Prompt:
"""
一场比赛中共有 n 支队伍，按从 0 到  n - 1 编号。每支队伍也是 有向无环图（DAG） 上的一个节点。

给你一个整数 n 和一个下标从 0 开始、长度为 m 的二维整数数组 edges 表示这个有向无环图，其中 edges[i] = [ui, vi] 表示图中存在一条从 ui 队到 vi 队的有向边。

从 a 队到 b 队的有向边意味着 a 队比 b 队 强 ，也就是 b 队比 a 队 弱 。

在这场比赛中，如果不存在某支强于 a 队的队伍，则认为 a 队将会是 冠军 。

如果这场比赛存在 唯一 一个冠军，则返回将会成为冠军的队伍。否则，返回 -1 。

注意

 * 环 是形如 a1, a2, ..., an, an+1 的一个序列，且满足：节点 a1 与节点 an+1 是同一个节点；节点 a1, a2, ..., an 互不相同；对于范围 [1, n] 中的每个 i ，均存在一条从节点 ai 到节点 ai+1 的有向边。
 * 有向无环图 是不存在任何环的有向图。

示例 1：

[https://assets.leetcode.com/uploads/2023/10/19/graph-3.png]

输入：n = 3, edges = [[0,1],[1,2]]
输出：0
解释：1 队比 0 队弱。2 队比 1 队弱。所以冠军是 0 队。

示例 2：

[https://assets.leetcode.com/uploads/2023/10/19/graph-4.png]

输入：n = 4, edges = [[0,2],[1,3],[1,2]]
输出：-1
解释：2 队比 0 队和 1 队弱。3 队比 1 队弱。但是 1 队和 0 队之间不存在强弱对比。所以答案是 -1 。

提示：

 * 1 <= n <= 100
 * m == edges.length
 * 0 <= m <= n * (n - 1) / 2
 * edges[i].length == 2
 * 0 <= edge[i][j] <= n - 1
 * edges[i][0] != edges[i][1]
 * 生成的输入满足：如果 a 队比 b 队强，就不存在 b 队比 a 队强
 * 生成的输入满足：如果 a 队比 b 队强，b 队比 c 队强，那么 a 队比 c 队强
"""
class Solution:
    def findChampion(self, n: int, edges: List[List[int]]) -> int:

一场比赛中共有 n 支队伍，按从 0 到  n - 1 编号。每支队伍也是 有向无环图（DAG） 上的一个节点。

给你一个整数 n 和一个下标从 0 开始、长度为 m 的二维整数数组 edges 表示这个有向无环图，其中 edges[i] = [ui, vi] 表示图中存在一条从 ui 队到 vi 队的有向边。

从 a 队到 b 队的有向边意味着 a 队比 b 队 强 ，也就是 b 队比 a 队 弱 。

在这场比赛中，如果不存在某支强于 a 队的队伍，则认为 a 队将会是 冠军 。

如果这场比赛存在 唯一 一个冠军，则返回将会成为冠军的队伍。否则，返回 -1 。

注意

 * 环 是形如 a1, a2, ..., an, an+1 的一个序列，且满足：节点 a1 与节点 an+1 是同一个节点；节点 a1, a2, ..., an 互不相同；对于范围 [1, n] 中的每个 i ，均存在一条从节点 ai 到节点 ai+1 的有向边。
 * 有向无环图 是不存在任何环的有向图。

示例 1：

[https://assets.leetcode.com/uploads/2023/10/19/graph-3.png]

输入：n = 3, edges = [[0,1],[1,2]]
输出：0
解释：1 队比 0 队弱。2 队比 1 队弱。所以冠军是 0 队。

示例 2：

[https://assets.leetcode.com/uploads/2023/10/19/graph-4.png]

输入：n = 4, edges = [[0,2],[1,3],[1,2]]
输出：-1
解释：2 队比 0 队和 1 队弱。3 队比 1 队弱。但是 1 队和 0 队之间不存在强弱对比。所以答案是 -1 。

提示：

 * 1 <= n <= 100
 * m == edges.length
 * 0 <= m <= n * (n - 1) / 2
 * edges[i].length == 2
 * 0 <= edge[i][j] <= n - 1
 * edges[i][0] != edges[i][1]
 * 生成的输入满足：如果 a 队比 b 队强，就不存在 b 队比 a 队强
 * 生成的输入满足：如果 a 队比 b 队强，b 队比 c 队强，那么 a 队比 c 队强

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

```

my_solution = Solution()

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

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

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

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

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

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

test_input = { "n": 3, "edges": [] }
assert my_solution.findChampion(**test_input) == -1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

test_input = { "n": 4, "edges": [] }
assert my_solution.findChampion(**test_input) == -1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

test_input = { "n": 5, "edges": [] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[0,2]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[2,0]] }
assert my_solution.findChampion(**test_input) == -1

test_input = { "n": 5, "edges": [[4,0]] }
assert my_solution.findChampion(**test_input) == -1

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

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

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

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

test_input = { "n": 5, "edges": [[0,4],[1,4],[0,1]] }
assert my_solution.findChampion(**test_input) == -1

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

test_input = { "n": 6, "edges": [] }
assert my_solution.findChampion(**test_input) == -1

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

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

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

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

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

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

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

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

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

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

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

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

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


maximum-score-after-applying-operations-on-a-tree

Maximum Score After Applying Operations on a Tree

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

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

一开始你的分数为 0 ，每次操作中，你将执行：

 * 选择节点 i 。
 * 将 values[i] 加入你的分数。
 * 将 values[i] 变为 0 。

如果从根节点出发，到任意叶子节点经过的路径上的节点值之和都不等于 0 ，那么我们称这棵树是 健康的 。

你可以对这棵树执行任意次操作，但要求执行完所有操作以后树是 健康的 ，请你返回你可以获得的 最大分数 。

示例 1：

[https://assets.leetcode.com/uploads/2023/10/11/graph-13-1.png]

输入：edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1]
输出：11
解释：我们可以选择节点 1 ，2 ，3 ，4 和 5 。根节点的值是非 0 的。所以从根出发到任意叶子节点路径上节点值之和都不为 0 。所以树是健康的。你的得分之和为 values[1] + values[2] + values[3] + values[4] + values[5] = 11 。
11 是你对树执行任意次操作以后可以获得的最大得分之和。

示例 2：

[https://assets.leetcode.com/uploads/2023/10/11/graph-14-2.png]

输入：edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5]
输出：40
解释：我们选择节点 0 ，2 ，3 和 4 。
- 从 0 到 4 的节点值之和为 10 。
- 从 0 到 3 的节点值之和为 10 。
- 从 0 到 5 的节点值之和为 3 。
- 从 0 到 6 的节点值之和为 5 。
所以树是健康的。你的得分之和为 values[0] + values[2] + values[3] + values[4] = 40 。
40 是你对树执行任意次操作以后可以获得的最大得分之和。

提示：

 * 2 <= n <= 2 * 104
 * edges.length == n - 1
 * edges[i].length == 2
 * 0 <= ai, bi < n
 * values.length == n
 * 1 <= values[i] <= 109
 * 输入保证 edges 构成一棵合法的树。
"""
class Solution:
    def maximumScoreAfterOperations(self, edges: List[List[int]], values: List[int]) -> int:

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

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

一开始你的分数为 0 ，每次操作中，你将执行：

 * 选择节点 i 。
 * 将 values[i] 加入你的分数。
 * 将 values[i] 变为 0 。

如果从根节点出发，到任意叶子节点经过的路径上的节点值之和都不等于 0 ，那么我们称这棵树是 健康的 。

你可以对这棵树执行任意次操作，但要求执行完所有操作以后树是 健康的 ，请你返回你可以获得的 最大分数 。

示例 1：

[https://assets.leetcode.com/uploads/2023/10/11/graph-13-1.png]

输入：edges = [[0,1],[0,2],[0,3],[2,4],[4,5]], values = [5,2,5,2,1,1]
输出：11
解释：我们可以选择节点 1 ，2 ，3 ，4 和 5 。根节点的值是非 0 的。所以从根出发到任意叶子节点路径上节点值之和都不为 0 。所以树是健康的。你的得分之和为 values[1] + values[2] + values[3] + values[4] + values[5] = 11 。
11 是你对树执行任意次操作以后可以获得的最大得分之和。

示例 2：

[https://assets.leetcode.com/uploads/2023/10/11/graph-14-2.png]

输入：edges = [[0,1],[0,2],[1,3],[1,4],[2,5],[2,6]], values = [20,10,9,7,4,3,5]
输出：40
解释：我们选择节点 0 ，2 ，3 和 4 。
- 从 0 到 4 的节点值之和为 10 。
- 从 0 到 3 的节点值之和为 10 。
- 从 0 到 5 的节点值之和为 3 。
- 从 0 到 6 的节点值之和为 5 。
所以树是健康的。你的得分之和为 values[0] + values[2] + values[3] + values[4] = 40 。
40 是你对树执行任意次操作以后可以获得的最大得分之和。

提示：

 * 2 <= n <= 2 * 104
 * edges.length == n - 1
 * edges[i].length == 2
 * 0 <= ai, bi < n
 * values.length == n
 * 1 <= values[i] <= 109
 * 输入保证 edges 构成一棵合法的树。

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

```


maximum-balanced-subsequence-sum

Maximum Balanced Subsequence Sum

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

nums 一个长度为 k 的 子序列 指的是选出 k 个 下标 i0 < i1 < ... < ik-1 ，如果这个子序列满足以下条件，我们说它是 平衡的 ：

 * 对于范围 [1, k - 1] 内的所有 j ，nums[ij] - nums[ij-1] >= ij - ij-1 都成立。

nums 长度为 1 的 子序列 是平衡的。

请你返回一个整数，表示 nums 平衡 子序列里面的 最大元素和 。

一个数组的 子序列 指的是从原数组中删除一些元素（也可能一个元素也不删除）后，剩余元素保持相对顺序得到的 非空 新数组。

示例 1：

输入：nums = [3,3,5,6]
输出：14
解释：这个例子中，选择子序列 [3,5,6] ，下标为 0 ，2 和 3 的元素被选中。
nums[2] - nums[0] >= 2 - 0 。
nums[3] - nums[2] >= 3 - 2 。
所以，这是一个平衡子序列，且它的和是所有平衡子序列里最大的。
包含下标 1 ，2 和 3 的子序列也是一个平衡的子序列。
最大平衡子序列和为 14 。

示例 2：

输入：nums = [5,-1,-3,8]
输出：13
解释：这个例子中，选择子序列 [5,8] ，下标为 0 和 3 的元素被选中。
nums[3] - nums[0] >= 3 - 0 。
所以，这是一个平衡子序列，且它的和是所有平衡子序列里最大的。
最大平衡子序列和为 13 。

示例 3：

输入：nums = [-2,-1]
输出：-1
解释：这个例子中，选择子序列 [-1] 。
这是一个平衡子序列，而且它的和是 nums 所有平衡子序列里最大的。

提示：

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

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

nums 一个长度为 k 的 子序列 指的是选出 k 个 下标 i0 < i1 < ... < ik-1 ，如果这个子序列满足以下条件，我们说它是 平衡的 ：

 * 对于范围 [1, k - 1] 内的所有 j ，nums[ij] - nums[ij-1] >= ij - ij-1 都成立。

nums 长度为 1 的 子序列 是平衡的。

请你返回一个整数，表示 nums 平衡 子序列里面的 最大元素和 。

一个数组的 子序列 指的是从原数组中删除一些元素（也可能一个元素也不删除）后，剩余元素保持相对顺序得到的 非空 新数组。

示例 1：

输入：nums = [3,3,5,6]
输出：14
解释：这个例子中，选择子序列 [3,5,6] ，下标为 0 ，2 和 3 的元素被选中。
nums[2] - nums[0] >= 2 - 0 。
nums[3] - nums[2] >= 3 - 2 。
所以，这是一个平衡子序列，且它的和是所有平衡子序列里最大的。
包含下标 1 ，2 和 3 的子序列也是一个平衡的子序列。
最大平衡子序列和为 14 。

示例 2：

输入：nums = [5,-1,-3,8]
输出：13
解释：这个例子中，选择子序列 [5,8] ，下标为 0 和 3 的元素被选中。
nums[3] - nums[0] >= 3 - 0 。
所以，这是一个平衡子序列，且它的和是所有平衡子序列里最大的。
最大平衡子序列和为 13 。

示例 3：

输入：nums = [-2,-1]
输出：-1
解释：这个例子中，选择子序列 [-1] 。
这是一个平衡子序列，而且它的和是 nums 所有平衡子序列里最大的。

提示：

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

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

```

my_solution = Solution()

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

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

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

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

test_input = { "nums": [-47] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -47

test_input = { "nums": [-8] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -8

test_input = { "nums": [-7] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -7

test_input = { "nums": [-6] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -6

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

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

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

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

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

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

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

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

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

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

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

test_input = { "nums": [45] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 45

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

test_input = { "nums": [-43,23,-49] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 23

test_input = { "nums": [-9,-6,-5] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == -5

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

test_input = { "nums": [-9,5,-6] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 5

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

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

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

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

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

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

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

test_input = { "nums": [0,-6,-4] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 0

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

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

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

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

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

test_input = { "nums": [6,-3,9] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 15

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

test_input = { "nums": [7,-6,0] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 7

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

test_input = { "nums": [14,-21,-18] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 14

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

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

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

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

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

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

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

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

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

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

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

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

test_input = { "nums": [3,-7,9,-3] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 12

test_input = { "nums": [3,-7,9,2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 12

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

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

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

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

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

test_input = { "nums": [34,34,32,33] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 65

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

test_input = { "nums": [2,9,-4,4,2] }
assert my_solution.maxBalancedSubsequenceSum(**test_input) == 11

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

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


find-the-k-or-of-an-array

Find the K-or of an Array

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

nums 中的 K-or 是一个满足以下条件的非负整数：

 * 只有在 nums 中，至少存在 k 个元素的第 i 位值为 1 ，那么 K-or 中的第 i 位的值才是 1 。

返回 nums 的 K-or 值。

注意 ：对于整数 x ，如果 (2i AND x) == 2i ，则 x 中的第 i 位值为 1 ，其中 AND 为按位与运算符。

示例 1：

输入：nums = [7,12,9,8,9,15], k = 4
输出：9
解释：nums[0]、nums[2]、nums[4] 和 nums[5] 的第 0 位的值为 1 。
nums[0] 和 nums[5] 的第 1 位的值为 1 。
nums[0]、nums[1] 和 nums[5] 的第 2 位的值为 1 。
nums[1]、nums[2]、nums[3]、nums[4] 和 nums[5] 的第 3 位的值为 1 。
只有第 0 位和第 3 位满足数组中至少存在 k 个元素在对应位上的值为 1 。因此，答案为 2^0 + 2^3 = 9 。

示例 2：

输入：nums = [2,12,1,11,4,5], k = 6
输出：0
解释：因为 k == 6 == nums.length ，所以数组的 6-or 等于其中所有元素按位与运算的结果。因此，答案为 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0 。

示例 3：

输入：nums = [10,8,5,9,11,6,8], k = 1
输出：15
解释：因为 k == 1 ，数组的 1-or 等于其中所有元素按位或运算的结果。因此，答案为 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15 。

提示：

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

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

nums 中的 K-or 是一个满足以下条件的非负整数：

 * 只有在 nums 中，至少存在 k 个元素的第 i 位值为 1 ，那么 K-or 中的第 i 位的值才是 1 。

返回 nums 的 K-or 值。

注意 ：对于整数 x ，如果 (2i AND x) == 2i ，则 x 中的第 i 位值为 1 ，其中 AND 为按位与运算符。

示例 1：

输入：nums = [7,12,9,8,9,15], k = 4
输出：9
解释：nums[0]、nums[2]、nums[4] 和 nums[5] 的第 0 位的值为 1 。
nums[0] 和 nums[5] 的第 1 位的值为 1 。
nums[0]、nums[1] 和 nums[5] 的第 2 位的值为 1 。
nums[1]、nums[2]、nums[3]、nums[4] 和 nums[5] 的第 3 位的值为 1 。
只有第 0 位和第 3 位满足数组中至少存在 k 个元素在对应位上的值为 1 。因此，答案为 2^0 + 2^3 = 9 。

示例 2：

输入：nums = [2,12,1,11,4,5], k = 6
输出：0
解释：因为 k == 6 == nums.length ，所以数组的 6-or 等于其中所有元素按位与运算的结果。因此，答案为 2 AND 12 AND 1 AND 11 AND 4 AND 5 = 0 。

示例 3：

输入：nums = [10,8,5,9,11,6,8], k = 1
输出：15
解释：因为 k == 1 ，数组的 1-or 等于其中所有元素按位或运算的结果。因此，答案为 10 OR 8 OR 5 OR 9 OR 11 OR 6 OR 8 = 15 。

提示：

 * 1 <= nums.length <= 50
 * 0 <= nums[i] < 231
 * 1 <= k <= nums.length

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

```

my_solution = Solution()

test_input = { "nums": [7,12,9,8,9,15], "k": 4 }
assert my_solution.findKOr(**test_input) == 9

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

test_input = { "nums": [10,8,5,9,11,6,8], "k": 1 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [14,7,12,9,8,9,1,15], "k": 4 }
assert my_solution.findKOr(**test_input) == 13

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

test_input = { "nums": [10,8,5,10,11,11,6,8], "k": 1 }
assert my_solution.findKOr(**test_input) == 15

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

test_input = { "nums": [22,7,27,30,15,30,28], "k": 4 }
assert my_solution.findKOr(**test_input) == 30

test_input = { "nums": [24,18,3,23,16,11,27,18,5,29], "k": 6 }
assert my_solution.findKOr(**test_input) == 19

test_input = { "nums": [14,1,2,28,4,15,3,12], "k": 2 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [7,18,25,11,2], "k": 5 }
assert my_solution.findKOr(**test_input) == 0

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

test_input = { "nums": [17,5,14,16,24,30,3,19,31], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,20,23,7,1,12,24,19], "k": 7 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [5,31,29,22,8,6,23], "k": 4 }
assert my_solution.findKOr(**test_input) == 23

test_input = { "nums": [9,10,30,0,7,19,14,19,20,3], "k": 4 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [25,6,5,30,27,11,10,30], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [0,15,16,6,19,5,24,17], "k": 3 }
assert my_solution.findKOr(**test_input) == 23

test_input = { "nums": [19,8,2,28,4,5], "k": 5 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [13,9,1,15,9,2,19,19], "k": 3 }
assert my_solution.findKOr(**test_input) == 11

test_input = { "nums": [16,6,16,22,8,2,25,30], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,28,23,22], "k": 2 }
assert my_solution.findKOr(**test_input) == 30

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

test_input = { "nums": [14,9,22,30,15], "k": 4 }
assert my_solution.findKOr(**test_input) == 14

test_input = { "nums": [12,13,16,25,12,4,8,29], "k": 6 }
assert my_solution.findKOr(**test_input) == 8

test_input = { "nums": [27,29], "k": 2 }
assert my_solution.findKOr(**test_input) == 25

test_input = { "nums": [9,27,27,20,24,13,25,8], "k": 6 }
assert my_solution.findKOr(**test_input) == 8

test_input = { "nums": [22,26,18,26,1], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [20,20,31,19,29,19], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [5,8,27,23,3], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [4,23,0,20,4,19,14,22,26,2], "k": 9 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [31,26,21,4,9,11,13,24,23,5], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

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

test_input = { "nums": [22,17,20,3,21,5,20,25,16], "k": 4 }
assert my_solution.findKOr(**test_input) == 21

test_input = { "nums": [16,15,13,26,15,23,0,12], "k": 4 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [4,11,14], "k": 1 }
assert my_solution.findKOr(**test_input) == 15

test_input = { "nums": [10,26,27,25,3,21,9,3,22], "k": 8 }
assert my_solution.findKOr(**test_input) == 0

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

test_input = { "nums": [9,27,19,9,24,11], "k": 3 }
assert my_solution.findKOr(**test_input) == 27

test_input = { "nums": [29,19,27,14], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [27,31,21,8,25], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,1,13,22,27], "k": 5 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [14,15,17,23,29], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [19,21], "k": 2 }
assert my_solution.findKOr(**test_input) == 17

test_input = { "nums": [29,9,18,0,30,5,1,9], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [6,31,11,7,6,2,26,19,17,13], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [15,8,27,28], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [28,24,20,31,23,1], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [8,13,27,24,20,28,15,21,23,6], "k": 9 }
assert my_solution.findKOr(**test_input) == 0

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

test_input = { "nums": [3,14,11,17,9], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [14,11], "k": 2 }
assert my_solution.findKOr(**test_input) == 10

test_input = { "nums": [2,9,11,25,3,2,26,21,13,11], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [26,7,23,0,16,31,12,18,24], "k": 4 }
assert my_solution.findKOr(**test_input) == 30

test_input = { "nums": [11,30,30,17,10,27,6,31,0], "k": 4 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [11,9,18,30,27,20,2,17,18,4], "k": 2 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [2,1,0,30,29,14,13,26,10,22], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [21,30,30,17,23,8,26,9], "k": 6 }
assert my_solution.findKOr(**test_input) == 16

test_input = { "nums": [16,10], "k": 1 }
assert my_solution.findKOr(**test_input) == 26

test_input = { "nums": [26,12,19,22,5,6,19,30,24,11], "k": 10 }
assert my_solution.findKOr(**test_input) == 0

test_input = { "nums": [20,10,14], "k": 2 }
assert my_solution.findKOr(**test_input) == 14

test_input = { "nums": [23,17,18,30,3], "k": 1 }
assert my_solution.findKOr(**test_input) == 31

test_input = { "nums": [13,16,12], "k": 1 }
assert my_solution.findKOr(**test_input) == 29

test_input = { "nums": [17,12,5,13,23,19], "k": 3 }
assert my_solution.findKOr(**test_input) == 21

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

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

test_input = { "nums": [28,3,15,30,10,29], "k": 4 }
assert my_solution.findKOr(**test_input) == 14

test_input = { "nums": [0,31,13,24,16,21], "k": 3 }
assert my_solution.findKOr(**test_input) == 29

test_input = { "nums": [11,20,28,29,3,4], "k": 2 }
assert my_solution.findKOr(**test_input) == 31


minimum-equal-sum-of-two-arrays-after-replacing-zeros

Minimum Equal Sum of Two Arrays After Replacing Zeros

Prompt:
"""
给你两个由正整数和 0 组成的数组 nums1 和 nums2 。

你必须将两个数组中的 所有 0 替换为 严格 正整数，并且满足两个数组中所有元素的和 相等 。

返回 最小 相等和 ，如果无法使两数组相等，则返回 -1 。

示例 1：

输入：nums1 = [3,2,0,1,0], nums2 = [6,5,0]
输出：12
解释：可以按下述方式替换数组中的 0 ：
- 用 2 和 4 替换 nums1 中的两个 0 。得到 nums1 = [3,2,2,1,4] 。
- 用 1 替换 nums2 中的一个 0 。得到 nums2 = [6,5,1] 。
两个数组的元素和相等，都等于 12 。可以证明这是可以获得的最小相等和。

示例 2：

输入：nums1 = [2,0,2,0], nums2 = [1,4]
输出：-1
解释：无法使两个数组的和相等。

提示：

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

给你两个由正整数和 0 组成的数组 nums1 和 nums2 。

你必须将两个数组中的 所有 0 替换为 严格 正整数，并且满足两个数组中所有元素的和 相等 。

返回 最小 相等和 ，如果无法使两数组相等，则返回 -1 。

示例 1：

输入：nums1 = [3,2,0,1,0], nums2 = [6,5,0]
输出：12
解释：可以按下述方式替换数组中的 0 ：
- 用 2 和 4 替换 nums1 中的两个 0 。得到 nums1 = [3,2,2,1,4] 。
- 用 1 替换 nums2 中的一个 0 。得到 nums2 = [6,5,1] 。
两个数组的元素和相等，都等于 12 。可以证明这是可以获得的最小相等和。

示例 2：

输入：nums1 = [2,0,2,0], nums2 = [1,4]
输出：-1
解释：无法使两个数组的和相等。

提示：

 * 1 <= nums1.length, nums2.length <= 105
 * 0 <= nums1[i], nums2[i] <= 106

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

```