max-pair-sum-in-an-array

Max Pair Sum in an Array

Prompt:
"""
给你一个下标从 0 开始的整数数组 nums 。请你从 nums 中找出和 最大 的一对数，且这两个数数位上最大的数字相等。

返回最大和，如果不存在满足题意的数字对，返回 -1 。

示例 1：

输入：nums = [51,71,17,24,42]
输出：88
解释：
i = 1 和 j = 2 ，nums[i] 和 nums[j] 数位上最大的数字相等，且这一对的总和 71 + 17 = 88 。
i = 3 和 j = 4 ，nums[i] 和 nums[j] 数位上最大的数字相等，且这一对的总和 24 + 42 = 66 。
可以证明不存在其他数对满足数位上最大的数字相等，所以答案是 88 。

示例 2：

输入：nums = [1,2,3,4]
输出：-1
解释：不存在数对满足数位上最大的数字相等。

提示：

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

给你一个下标从 0 开始的整数数组 nums 。请你从 nums 中找出和 最大 的一对数，且这两个数数位上最大的数字相等。

返回最大和，如果不存在满足题意的数字对，返回 -1 。

示例 1：

输入：nums = [51,71,17,24,42]
输出：88
解释：
i = 1 和 j = 2 ，nums[i] 和 nums[j] 数位上最大的数字相等，且这一对的总和 71 + 17 = 88 。
i = 3 和 j = 4 ，nums[i] 和 nums[j] 数位上最大的数字相等，且这一对的总和 24 + 42 = 66 。
可以证明不存在其他数对满足数位上最大的数字相等，所以答案是 88 。

示例 2：

输入：nums = [1,2,3,4]
输出：-1
解释：不存在数对满足数位上最大的数字相等。

提示：

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

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

```

my_solution = Solution()

test_input = { "nums": [51,71,17,24,42] }
assert my_solution.maxSum(**test_input) == 88

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

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

test_input = { "nums": [84,91,18,59,27,9,81,33,17,58] }
assert my_solution.maxSum(**test_input) == 165

test_input = { "nums": [8,75,28,35,21,13,21] }
assert my_solution.maxSum(**test_input) == 42

test_input = { "nums": [35,52,74,92,25,65,77,1,73,32] }
assert my_solution.maxSum(**test_input) == 151

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

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

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

test_input = { "nums": [99,63,23,70,18,64] }
assert my_solution.maxSum(**test_input) == 127

test_input = { "nums": [21,21,78] }
assert my_solution.maxSum(**test_input) == 42

test_input = { "nums": [58,88,58,99,26,92] }
assert my_solution.maxSum(**test_input) == 191

test_input = { "nums": [10,24,25,20,92,73,63,51] }
assert my_solution.maxSum(**test_input) == 76

test_input = { "nums": [87,6,17,32,14,42,46,65,43,9] }
assert my_solution.maxSum(**test_input) == 111

test_input = { "nums": [96,46,85,19,29] }
assert my_solution.maxSum(**test_input) == 125

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

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

test_input = { "nums": [77,82,30,94] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [76,94,51,82,3,89,52,96] }
assert my_solution.maxSum(**test_input) == 190

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

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

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

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

test_input = { "nums": [55,46,4,61,78,21,85,52,83,77] }
assert my_solution.maxSum(**test_input) == 168

test_input = { "nums": [21,73,2,80,99,98,89] }
assert my_solution.maxSum(**test_input) == 197

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

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

test_input = { "nums": [61,90,34,29,68,35] }
assert my_solution.maxSum(**test_input) == 119

test_input = { "nums": [18,82,78] }
assert my_solution.maxSum(**test_input) == 160

test_input = { "nums": [8,71,2,59,70,12] }
assert my_solution.maxSum(**test_input) == 141

test_input = { "nums": [55,88,59] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [49,47,46,65,37,24,75,81,54,39] }
assert my_solution.maxSum(**test_input) == 122

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

test_input = { "nums": [2,82,80,74,34,54,65] }
assert my_solution.maxSum(**test_input) == 162

test_input = { "nums": [9,62,85,95,36,62,21,38,16,12] }
assert my_solution.maxSum(**test_input) == 124

test_input = { "nums": [50,80,34,9,86,20,67,94,65,82] }
assert my_solution.maxSum(**test_input) == 168

test_input = { "nums": [79,74,92,84,37,19] }
assert my_solution.maxSum(**test_input) == 171

test_input = { "nums": [85,20,79] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [89,55,67,84,3] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [16,44,2,54,58,94] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [71,14,24,13,21,14,100,18,84,37] }
assert my_solution.maxSum(**test_input) == 108

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

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

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

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

test_input = { "nums": [27,12,80,38,94,92,67,54,56,20] }
assert my_solution.maxSum(**test_input) == 186

test_input = { "nums": [52,32,24,6,3,89,100,3,5,3] }
assert my_solution.maxSum(**test_input) == 57

test_input = { "nums": [93,1,13,88,47,48,46,63] }
assert my_solution.maxSum(**test_input) == 136

test_input = { "nums": [3,55,40,93,97,37,31,31] }
assert my_solution.maxSum(**test_input) == 190

test_input = { "nums": [58,41,10,74,40,17] }
assert my_solution.maxSum(**test_input) == 91

test_input = { "nums": [58,33,78,53,88,1,15,44,82] }
assert my_solution.maxSum(**test_input) == 170

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

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

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

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

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

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

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

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

test_input = { "nums": [91,13,72,42,28] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [5,53,35,88,77,1,66,57] }
assert my_solution.maxSum(**test_input) == 134

test_input = { "nums": [50,27,52,70,67,60,65] }
assert my_solution.maxSum(**test_input) == 137

test_input = { "nums": [84,82,31,45,94,62,45,32] }
assert my_solution.maxSum(**test_input) == 166

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

test_input = { "nums": [60,21,11,99] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [22,83,62,12,63,100,41,33] }
assert my_solution.maxSum(**test_input) == 125

test_input = { "nums": [92,58,85] }
assert my_solution.maxSum(**test_input) == 143

test_input = { "nums": [93,5,46,26,25,36,27,12,30] }
assert my_solution.maxSum(**test_input) == 82

test_input = { "nums": [52,30,16] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [22,57,33,26,76,14,67] }
assert my_solution.maxSum(**test_input) == 143

test_input = { "nums": [90,72,37,30] }
assert my_solution.maxSum(**test_input) == 109

test_input = { "nums": [44,87,16] }
assert my_solution.maxSum(**test_input) == -1

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

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

test_input = { "nums": [84,1,48,76,16,10,11,60] }
assert my_solution.maxSum(**test_input) == 132

test_input = { "nums": [12,60,69,63,78,22,28] }
assert my_solution.maxSum(**test_input) == 123

test_input = { "nums": [16,28,82,77,41,22] }
assert my_solution.maxSum(**test_input) == 110

test_input = { "nums": [97,31,63,2,94,14,47] }
assert my_solution.maxSum(**test_input) == 191

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

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

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

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

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

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

test_input = { "nums": [2,74,37,75] }
assert my_solution.maxSum(**test_input) == 149

test_input = { "nums": [84,35,65,12] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [95,46,23,81,35] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [64,76,46,54,64,94,90,95] }
assert my_solution.maxSum(**test_input) == 189

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

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

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

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

test_input = { "nums": [51,1,98,73,84,11,100,100,75] }
assert my_solution.maxSum(**test_input) == 200

test_input = { "nums": [76,2,26,49,78,36,2,70,64] }
assert my_solution.maxSum(**test_input) == 146

test_input = { "nums": [34,63,21,49] }
assert my_solution.maxSum(**test_input) == -1

test_input = { "nums": [35,19,1,21,11,59,38] }
assert my_solution.maxSum(**test_input) == 78

test_input = { "nums": [1,35,74,58,56,54,75] }
assert my_solution.maxSum(**test_input) == 149

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

test_input = { "nums": [97,92,13,30] }
assert my_solution.maxSum(**test_input) == 189

test_input = { "nums": [89,49,10,36,37] }
assert my_solution.maxSum(**test_input) == 138


double-a-number-represented-as-a-linked-list

Double a Number Represented as a Linked List

Prompt:
"""
给你一个 非空 链表的头节点 head ，表示一个不含前导零的非负数整数。

将链表 翻倍 后，返回头节点 head 。

示例 1：

[https://assets.leetcode.com/uploads/2023/05/28/example.png]

输入：head = [1,8,9]
输出：[3,7,8]
解释：上图中给出的链表，表示数字 189 。返回的链表表示数字 189 * 2 = 378 。

示例 2：

[https://assets.leetcode.com/uploads/2023/05/28/example2.png]

输入：head = [9,9,9]
输出：[1,9,9,8]
解释：上图中给出的链表，表示数字 999 。返回的链表表示数字 999 * 2 = 1998 。

提示：

 * 链表中节点的数目在范围 [1, 104] 内
 * 0 <= Node.val <= 9
 * 生成的输入满足：链表表示一个不含前导零的数字，除了数字 0 本身。
"""
# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution:
    def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:

给你一个 非空 链表的头节点 head ，表示一个不含前导零的非负数整数。

将链表 翻倍 后，返回头节点 head 。

示例 1：

[https://assets.leetcode.com/uploads/2023/05/28/example.png]

输入：head = [1,8,9]
输出：[3,7,8]
解释：上图中给出的链表，表示数字 189 。返回的链表表示数字 189 * 2 = 378 。

示例 2：

[https://assets.leetcode.com/uploads/2023/05/28/example2.png]

输入：head = [9,9,9]
输出：[1,9,9,8]
解释：上图中给出的链表，表示数字 999 。返回的链表表示数字 999 * 2 = 1998 。

提示：

 * 链表中节点的数目在范围 [1, 104] 内
 * 0 <= Node.val <= 9
 * 生成的输入满足：链表表示一个不含前导零的数字，除了数字 0 本身。

请完成下面的代码来解决上述问题:
```python
# Definition for singly-linked list.
class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next
class Solution:
    def doubleIt(self, head: Optional[ListNode]) -> Optional[ListNode]:

```

my_solution = Solution()

_f1 = lambda lst: ListNode(lst[0], _f1(lst[1:])) if lst else None
_f2 = lambda node: [node.val] + _f2(node.next) if node else []

test_input = { "head": _f1([1,8,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,7,8]

test_input = { "head": _f1([9,9,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,9,9,8]

test_input = { "head": _f1([0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [0]

test_input = { "head": _f1([1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2]

test_input = { "head": _f1([2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4]

test_input = { "head": _f1([3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6]

test_input = { "head": _f1([4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8]

test_input = { "head": _f1([5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0]

test_input = { "head": _f1([6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2]

test_input = { "head": _f1([7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4]

test_input = { "head": _f1([8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6]

test_input = { "head": _f1([9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8]

test_input = { "head": _f1([1,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2,0]

test_input = { "head": _f1([1,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2,2]

test_input = { "head": _f1([1,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2,4]

test_input = { "head": _f1([1,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2,6]

test_input = { "head": _f1([1,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [2,8]

test_input = { "head": _f1([1,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,0]

test_input = { "head": _f1([1,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,2]

test_input = { "head": _f1([1,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,4]

test_input = { "head": _f1([1,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,6]

test_input = { "head": _f1([1,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [3,8]

test_input = { "head": _f1([2,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4,0]

test_input = { "head": _f1([2,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4,2]

test_input = { "head": _f1([2,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4,4]

test_input = { "head": _f1([2,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4,6]

test_input = { "head": _f1([2,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [4,8]

test_input = { "head": _f1([2,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [5,0]

test_input = { "head": _f1([2,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [5,2]

test_input = { "head": _f1([2,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [5,4]

test_input = { "head": _f1([2,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [5,6]

test_input = { "head": _f1([2,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [5,8]

test_input = { "head": _f1([3,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6,0]

test_input = { "head": _f1([3,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6,2]

test_input = { "head": _f1([3,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6,4]

test_input = { "head": _f1([3,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6,6]

test_input = { "head": _f1([3,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [6,8]

test_input = { "head": _f1([3,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [7,0]

test_input = { "head": _f1([3,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [7,2]

test_input = { "head": _f1([3,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [7,4]

test_input = { "head": _f1([3,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [7,6]

test_input = { "head": _f1([3,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [7,8]

test_input = { "head": _f1([4,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8,0]

test_input = { "head": _f1([4,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8,2]

test_input = { "head": _f1([4,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8,4]

test_input = { "head": _f1([4,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8,6]

test_input = { "head": _f1([4,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [8,8]

test_input = { "head": _f1([4,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [9,0]

test_input = { "head": _f1([4,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [9,2]

test_input = { "head": _f1([4,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [9,4]

test_input = { "head": _f1([4,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [9,6]

test_input = { "head": _f1([4,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [9,8]

test_input = { "head": _f1([5,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0,0]

test_input = { "head": _f1([5,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0,2]

test_input = { "head": _f1([5,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0,4]

test_input = { "head": _f1([5,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0,6]

test_input = { "head": _f1([5,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,0,8]

test_input = { "head": _f1([5,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,1,0]

test_input = { "head": _f1([5,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,1,2]

test_input = { "head": _f1([5,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,1,4]

test_input = { "head": _f1([5,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,1,6]

test_input = { "head": _f1([5,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,1,8]

test_input = { "head": _f1([6,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2,0]

test_input = { "head": _f1([6,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2,2]

test_input = { "head": _f1([6,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2,4]

test_input = { "head": _f1([6,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2,6]

test_input = { "head": _f1([6,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,2,8]

test_input = { "head": _f1([6,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,3,0]

test_input = { "head": _f1([6,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,3,2]

test_input = { "head": _f1([6,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,3,4]

test_input = { "head": _f1([6,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,3,6]

test_input = { "head": _f1([6,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,3,8]

test_input = { "head": _f1([7,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4,0]

test_input = { "head": _f1([7,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4,2]

test_input = { "head": _f1([7,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4,4]

test_input = { "head": _f1([7,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4,6]

test_input = { "head": _f1([7,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,4,8]

test_input = { "head": _f1([7,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,5,0]

test_input = { "head": _f1([7,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,5,2]

test_input = { "head": _f1([7,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,5,4]

test_input = { "head": _f1([7,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,5,6]

test_input = { "head": _f1([7,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,5,8]

test_input = { "head": _f1([8,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6,0]

test_input = { "head": _f1([8,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6,2]

test_input = { "head": _f1([8,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6,4]

test_input = { "head": _f1([8,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6,6]

test_input = { "head": _f1([8,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,6,8]

test_input = { "head": _f1([8,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,7,0]

test_input = { "head": _f1([8,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,7,2]

test_input = { "head": _f1([8,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,7,4]

test_input = { "head": _f1([8,8]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,7,6]

test_input = { "head": _f1([8,9]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,7,8]

test_input = { "head": _f1([9,0]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8,0]

test_input = { "head": _f1([9,1]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8,2]

test_input = { "head": _f1([9,2]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8,4]

test_input = { "head": _f1([9,3]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8,6]

test_input = { "head": _f1([9,4]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,8,8]

test_input = { "head": _f1([9,5]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,9,0]

test_input = { "head": _f1([9,6]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,9,2]

test_input = { "head": _f1([9,7]) }
assert _f2(my_solution.doubleIt(**test_input)) == [1,9,4]


minimum-absolute-difference-between-elements-with-constraint

Minimum Absolute Difference Between Elements With Constraint

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

请你找到数组中下标距离至少为 x 的两个元素的 差值绝对值 的 最小值 。

换言之，请你找到两个下标 i 和 j ，满足 abs(i - j) >= x 且 abs(nums[i] - nums[j]) 的值最小。

请你返回一个整数，表示下标距离至少为 x 的两个元素之间的差值绝对值的 最小值 。

示例 1：

输入：nums = [4,3,2,4], x = 2
输出：0
解释：我们选择 nums[0] = 4 和 nums[3] = 4 。
它们下标距离满足至少为 2 ，差值绝对值为最小值 0 。
0 是最优解。

示例 2：

输入：nums = [5,3,2,10,15], x = 1
输出：1
解释：我们选择 nums[1] = 3 和 nums[2] = 2 。
它们下标距离满足至少为 1 ，差值绝对值为最小值 1 。
1 是最优解。

示例 3：

输入：nums = [1,2,3,4], x = 3
输出：3
解释：我们选择 nums[0] = 1 和 nums[3] = 4 。
它们下标距离满足至少为 3 ，差值绝对值为最小值 3 。
3 是最优解。

提示：

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

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

请你找到数组中下标距离至少为 x 的两个元素的 差值绝对值 的 最小值 。

换言之，请你找到两个下标 i 和 j ，满足 abs(i - j) >= x 且 abs(nums[i] - nums[j]) 的值最小。

请你返回一个整数，表示下标距离至少为 x 的两个元素之间的差值绝对值的 最小值 。

示例 1：

输入：nums = [4,3,2,4], x = 2
输出：0
解释：我们选择 nums[0] = 4 和 nums[3] = 4 。
它们下标距离满足至少为 2 ，差值绝对值为最小值 0 。
0 是最优解。

示例 2：

输入：nums = [5,3,2,10,15], x = 1
输出：1
解释：我们选择 nums[1] = 3 和 nums[2] = 2 。
它们下标距离满足至少为 1 ，差值绝对值为最小值 1 。
1 是最优解。

示例 3：

输入：nums = [1,2,3,4], x = 3
输出：3
解释：我们选择 nums[0] = 1 和 nums[3] = 4 。
它们下标距离满足至少为 3 ，差值绝对值为最小值 3 。
3 是最优解。

提示：

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

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

```

my_solution = Solution()

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

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

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

test_input = { "nums": [1,67], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 66

test_input = { "nums": [7,398], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 391

test_input = { "nums": [12,141], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 129

test_input = { "nums": [21,75], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 54

test_input = { "nums": [22,147], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 125

test_input = { "nums": [25,197], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 172

test_input = { "nums": [27,275], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 248

test_input = { "nums": [37,192], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 155

test_input = { "nums": [41,163], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 122

test_input = { "nums": [45,49], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 4

test_input = { "nums": [48,195], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 147

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

test_input = { "nums": [71,4], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 67

test_input = { "nums": [72,169], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 97

test_input = { "nums": [74,62], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 12

test_input = { "nums": [75,1], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 74

test_input = { "nums": [76,49], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 27

test_input = { "nums": [88,72], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 16

test_input = { "nums": [99,370], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 271

test_input = { "nums": [103,39], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 64

test_input = { "nums": [109,99], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 10

test_input = { "nums": [111,161], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 50

test_input = { "nums": [113,117], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 4

test_input = { "nums": [119,184], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 65

test_input = { "nums": [122,118], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 4

test_input = { "nums": [123,13], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 110

test_input = { "nums": [123,162], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 39

test_input = { "nums": [126,69], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 57

test_input = { "nums": [127,18], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 109

test_input = { "nums": [127,346], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 219

test_input = { "nums": [132,110], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 22

test_input = { "nums": [134,23], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 111

test_input = { "nums": [136,150], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 14

test_input = { "nums": [139,215], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 76

test_input = { "nums": [153,3], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 150

test_input = { "nums": [156,67], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 89

test_input = { "nums": [160,168], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 8

test_input = { "nums": [161,93], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 68

test_input = { "nums": [164,81], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 83

test_input = { "nums": [167,83], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 84

test_input = { "nums": [174,58], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 116

test_input = { "nums": [174,102], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 72

test_input = { "nums": [175,137], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 38

test_input = { "nums": [176,99], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 77

test_input = { "nums": [178,179], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 1

test_input = { "nums": [228,359], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 131

test_input = { "nums": [243,280], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 37

test_input = { "nums": [283,62], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 221

test_input = { "nums": [288,149], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 139

test_input = { "nums": [293,278], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 15

test_input = { "nums": [327,425], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 98

test_input = { "nums": [337,187], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 150

test_input = { "nums": [346,160], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 186

test_input = { "nums": [347,369], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 22

test_input = { "nums": [355,199], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 156

test_input = { "nums": [413,311], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 102

test_input = { "nums": [417,320], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 97

test_input = { "nums": [418,131], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 287

test_input = { "nums": [3274,71], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 3203

test_input = { "nums": [5,14,81], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 76

test_input = { "nums": [9,25,15], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 6

test_input = { "nums": [9,113,136], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 23

test_input = { "nums": [13,19,12], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 1

test_input = { "nums": [13,94,59], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 46

test_input = { "nums": [14,111,16], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 2

test_input = { "nums": [17,173,69], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 52

test_input = { "nums": [24,39,28], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 4

test_input = { "nums": [32,129,93], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 36

test_input = { "nums": [33,18,131], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 15

test_input = { "nums": [36,19,27], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 9

test_input = { "nums": [40,18,17], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 1

test_input = { "nums": [43,49,20], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 23

test_input = { "nums": [44,186,163], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 119

test_input = { "nums": [56,23,158], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 33

test_input = { "nums": [62,37,182], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 120

test_input = { "nums": [63,116,12], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 51

test_input = { "nums": [66,345,278], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 212

test_input = { "nums": [67,81,165], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 98

test_input = { "nums": [70,184,70], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 0

test_input = { "nums": [73,106,172], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 33

test_input = { "nums": [74,199,57], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 17

test_input = { "nums": [83,14,14], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 0

test_input = { "nums": [86,1,129], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 43

test_input = { "nums": [87,194,107], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 20

test_input = { "nums": [88,75,122], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 34

test_input = { "nums": [93,96,28], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 3

test_input = { "nums": [95,86,132], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 37

test_input = { "nums": [96,41,24], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 17

test_input = { "nums": [116,6,3], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 3

test_input = { "nums": [120,102,184], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 18

test_input = { "nums": [123,113,20], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 10

test_input = { "nums": [125,14,141], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 16

test_input = { "nums": [126,2,180], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 54

test_input = { "nums": [136,24,114], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 22

test_input = { "nums": [136,177,98], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 38

test_input = { "nums": [136,177,123], "x": 1 }
assert my_solution.minAbsoluteDifference(**test_input) == 13

test_input = { "nums": [136,178,18], "x": 2 }
assert my_solution.minAbsoluteDifference(**test_input) == 118


apply-operations-to-maximize-score

Apply Operations to Maximize Score

Prompt:
"""
给你一个长度为 n 的正整数数组 nums 和一个整数 k 。

一开始，你的分数为 1 。你可以进行以下操作至多 k 次，目标是使你的分数最大：

 * 选择一个之前没有选过的 非空 子数组 nums[l, ..., r] 。
 * 从 nums[l, ..., r] 里面选择一个 质数分数 最高的元素 x 。如果多个元素质数分数相同且最高，选择下标最小的一个。
 * 将你的分数乘以 x 。

nums[l, ..., r] 表示 nums 中起始下标为 l ，结束下标为 r 的子数组，两个端点都包含。

一个整数的 质数分数 等于 x 不同质因子的数目。比方说， 300 的质数分数为 3 ，因为 300 = 2 * 2 * 3 * 5 * 5 。

请你返回进行至多 k 次操作后，可以得到的 最大分数 。

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

示例 1：

输入：nums = [8,3,9,3,8], k = 2
输出：81
解释：进行以下操作可以得到分数 81 ：
- 选择子数组 nums[2, ..., 2] 。nums[2] 是子数组中唯一的元素。所以我们将分数乘以 nums[2] ，分数变为 1 * 9 = 9 。
- 选择子数组 nums[2, ..., 3] 。nums[2] 和 nums[3] 质数分数都为 1 ，但是 nums[2] 下标更小。所以我们将分数乘以 nums[2] ，分数变为 9 * 9 = 81 。
81 是可以得到的最高得分。

示例 2：

输入：nums = [19,12,14,6,10,18], k = 3
输出：4788
解释：进行以下操作可以得到分数 4788 ：
- 选择子数组 nums[0, ..., 0] 。nums[0] 是子数组中唯一的元素。所以我们将分数乘以 nums[0] ，分数变为 1 * 19 = 19 。
- 选择子数组 nums[5, ..., 5] 。nums[5] 是子数组中唯一的元素。所以我们将分数乘以 nums[5] ，分数变为 19 * 18 = 342 。
- 选择子数组 nums[2, ..., 3] 。nums[2] 和 nums[3] 质数分数都为 2，但是 nums[2] 下标更小。所以我们将分数乘以 nums[2] ，分数变为  342 * 14 = 4788 。
4788 是可以得到的最高的分。

提示：

 * 1 <= nums.length == n <= 105
 * 1 <= nums[i] <= 105
 * 1 <= k <= min(n * (n + 1) / 2, 109)
"""
class Solution:
    def maximumScore(self, nums: List[int], k: int) -> int:

给你一个长度为 n 的正整数数组 nums 和一个整数 k 。

一开始，你的分数为 1 。你可以进行以下操作至多 k 次，目标是使你的分数最大：

 * 选择一个之前没有选过的 非空 子数组 nums[l, ..., r] 。
 * 从 nums[l, ..., r] 里面选择一个 质数分数 最高的元素 x 。如果多个元素质数分数相同且最高，选择下标最小的一个。
 * 将你的分数乘以 x 。

nums[l, ..., r] 表示 nums 中起始下标为 l ，结束下标为 r 的子数组，两个端点都包含。

一个整数的 质数分数 等于 x 不同质因子的数目。比方说， 300 的质数分数为 3 ，因为 300 = 2 * 2 * 3 * 5 * 5 。

请你返回进行至多 k 次操作后，可以得到的 最大分数 。

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

示例 1：

输入：nums = [8,3,9,3,8], k = 2
输出：81
解释：进行以下操作可以得到分数 81 ：
- 选择子数组 nums[2, ..., 2] 。nums[2] 是子数组中唯一的元素。所以我们将分数乘以 nums[2] ，分数变为 1 * 9 = 9 。
- 选择子数组 nums[2, ..., 3] 。nums[2] 和 nums[3] 质数分数都为 1 ，但是 nums[2] 下标更小。所以我们将分数乘以 nums[2] ，分数变为 9 * 9 = 81 。
81 是可以得到的最高得分。

示例 2：

输入：nums = [19,12,14,6,10,18], k = 3
输出：4788
解释：进行以下操作可以得到分数 4788 ：
- 选择子数组 nums[0, ..., 0] 。nums[0] 是子数组中唯一的元素。所以我们将分数乘以 nums[0] ，分数变为 1 * 19 = 19 。
- 选择子数组 nums[5, ..., 5] 。nums[5] 是子数组中唯一的元素。所以我们将分数乘以 nums[5] ，分数变为 19 * 18 = 342 。
- 选择子数组 nums[2, ..., 3] 。nums[2] 和 nums[3] 质数分数都为 2，但是 nums[2] 下标更小。所以我们将分数乘以 nums[2] ，分数变为  342 * 14 = 4788 。
4788 是可以得到的最高的分。

提示：

 * 1 <= nums.length == n <= 105
 * 1 <= nums[i] <= 105
 * 1 <= k <= min(n * (n + 1) / 2, 109)

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

```

my_solution = Solution()

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

test_input = { "nums": [19,12,14,6,10,18], "k": 3 }
assert my_solution.maximumScore(**test_input) == 4788

test_input = { "nums": [3289,2832,14858,22011], "k": 6 }
assert my_solution.maximumScore(**test_input) == 256720975

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

test_input = { "nums": [1,1,2,18,1,9,3,1], "k": 32 }
assert my_solution.maximumScore(**test_input) == 346264255

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

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

test_input = { "nums": [12,5,1,6,9,1,17,14], "k": 12 }
assert my_solution.maximumScore(**test_input) == 62996359

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

test_input = { "nums": [1,10,15,1,3], "k": 13 }
assert my_solution.maximumScore(**test_input) == 499978741

test_input = { "nums": [6,1,13,10,1,17,6], "k": 27 }
assert my_solution.maximumScore(**test_input) == 630596200

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

test_input = { "nums": [2,1,14,5,18,1,8,5], "k": 34 }
assert my_solution.maximumScore(**test_input) == 799392504

test_input = { "nums": [5,12,11,15,10,18], "k": 18 }
assert my_solution.maximumScore(**test_input) == 557423913

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

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

test_input = { "nums": [13,16,12,15,12,1,13,1,18,1], "k": 46 }
assert my_solution.maximumScore(**test_input) == 912532739

test_input = { "nums": [10,11], "k": 3 }
assert my_solution.maximumScore(**test_input) == 1100

test_input = { "nums": [15,16,12,1,10,14], "k": 19 }
assert my_solution.maximumScore(**test_input) == 311972352

test_input = { "nums": [14,12,5,2,14], "k": 6 }
assert my_solution.maximumScore(**test_input) == 7529536

test_input = { "nums": [1,13,12,1,9,12,1,18], "k": 31 }
assert my_solution.maximumScore(**test_input) == 846374420

test_input = { "nums": [1,6,14,10,16], "k": 4 }
assert my_solution.maximumScore(**test_input) == 43904

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

test_input = { "nums": [13,1,1,15,9,1,1], "k": 22 }
assert my_solution.maximumScore(**test_input) == 925331761

test_input = { "nums": [1,17,3,9,10,17,1,1,1,11], "k": 22 }
assert my_solution.maximumScore(**test_input) == 407065837

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

test_input = { "nums": [1,13,4,1,1], "k": 14 }
assert my_solution.maximumScore(**test_input) == 206765780

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

test_input = { "nums": [1,2,1,1,16,8,11,6], "k": 27 }
assert my_solution.maximumScore(**test_input) == 33977400

test_input = { "nums": [1,10,13,1,9,15,1], "k": 2 }
assert my_solution.maximumScore(**test_input) == 225

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

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

test_input = { "nums": [14,6,18,10,1,8,1,17], "k": 25 }
assert my_solution.maximumScore(**test_input) == 677968714

test_input = { "nums": [15,16,12], "k": 6 }
assert my_solution.maximumScore(**test_input) == 7776000

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

test_input = { "nums": [13,1,10,1,15,6,1,12,6], "k": 10 }
assert my_solution.maximumScore(**test_input) == 650386593

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

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

test_input = { "nums": [13,8,14,6,3,14,13,10,1], "k": 21 }
assert my_solution.maximumScore(**test_input) == 247566578

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

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

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

test_input = { "nums": [3,6,17,1,1,17,18,12,16,5], "k": 9 }
assert my_solution.maximumScore(**test_input) == 359288982

test_input = { "nums": [2,2,15,2,15,15], "k": 10 }
assert my_solution.maximumScore(**test_input) == 650386593

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

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

test_input = { "nums": [11,15,18,4,11,7,1,1], "k": 32 }
assert my_solution.maximumScore(**test_input) == 179964426

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

test_input = { "nums": [10,1,1,9,14,6,4,18,8], "k": 10 }
assert my_solution.maximumScore(**test_input) == 420565606

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

test_input = { "nums": [13,1,10,6], "k": 4 }
assert my_solution.maximumScore(**test_input) == 16900

test_input = { "nums": [8,10,16,1,1,1], "k": 2 }
assert my_solution.maximumScore(**test_input) == 256

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

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

test_input = { "nums": [5,5,16,12,8,1,1,7,12], "k": 34 }
assert my_solution.maximumScore(**test_input) == 15762264

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

test_input = { "nums": [3,18,12,8,1,3,6], "k": 23 }
assert my_solution.maximumScore(**test_input) == 18966086

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

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

test_input = { "nums": [6,2,1,17,9,14,1], "k": 25 }
assert my_solution.maximumScore(**test_input) == 808455901

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

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

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

test_input = { "nums": [18,13,12,1,11], "k": 8 }
assert my_solution.maximumScore(**test_input) == 537271275

test_input = { "nums": [10,14,18,6,12,14,3,13], "k": 23 }
assert my_solution.maximumScore(**test_input) == 795923147

test_input = { "nums": [16,1,14,13,3,1], "k": 6 }
assert my_solution.maximumScore(**test_input) == 9834496

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

test_input = { "nums": [2,4,1,5,14,13,13,17], "k": 19 }
assert my_solution.maximumScore(**test_input) == 241329678

test_input = { "nums": [6,1,15,1,13], "k": 12 }
assert my_solution.maximumScore(**test_input) == 820232542

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

test_input = { "nums": [10,4,12,12,16,9,1,18], "k": 36 }
assert my_solution.maximumScore(**test_input) == 892891506

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

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

test_input = { "nums": [10,17,17,15,1,15,1], "k": 19 }
assert my_solution.maximumScore(**test_input) == 301460564

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

test_input = { "nums": [10,12], "k": 3 }
assert my_solution.maximumScore(**test_input) == 1200

test_input = { "nums": [9,10,2,3,2,1,11,1,1,13], "k": 49 }
assert my_solution.maximumScore(**test_input) == 900432644

test_input = { "nums": [1,10,18,18,3,1,8,1,15,15], "k": 18 }
assert my_solution.maximumScore(**test_input) == 38759446

test_input = { "nums": [15,1,11,13,16], "k": 14 }
assert my_solution.maximumScore(**test_input) == 753886562

test_input = { "nums": [12,1,6,1,1,4,8,17,18,1], "k": 2 }
assert my_solution.maximumScore(**test_input) == 324

test_input = { "nums": [1,1,1,17,8,18,8,1], "k": 14 }
assert my_solution.maximumScore(**test_input) == 958387476

test_input = { "nums": [7,1,6,9,11,7,13,12,1], "k": 39 }
assert my_solution.maximumScore(**test_input) == 21295572

test_input = { "nums": [12,1,1,15,2,1,1,16,1,1], "k": 8 }
assert my_solution.maximumScore(**test_input) == 294967268

test_input = { "nums": [3,14,13,1,11,1,1,1], "k": 22 }
assert my_solution.maximumScore(**test_input) == 810815174

test_input = { "nums": [14,3,6,6,1,7,13,16], "k": 28 }
assert my_solution.maximumScore(**test_input) == 312142986

test_input = { "nums": [3,4,4,15,18,12,6], "k": 8 }
assert my_solution.maximumScore(**test_input) == 428674972

test_input = { "nums": [6,15,17,9,9,17], "k": 5 }
assert my_solution.maximumScore(**test_input) == 1419857

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

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

test_input = { "nums": [7,11,3,1,12,10], "k": 15 }
assert my_solution.maximumScore(**test_input) == 784368200

test_input = { "nums": [18,1,11,15,16,18,18,13,10,10], "k": 41 }
assert my_solution.maximumScore(**test_input) == 911212578

test_input = { "nums": [11,15,2,14,6,15], "k": 2 }
assert my_solution.maximumScore(**test_input) == 225

test_input = { "nums": [11,2,15,1,1,11,7,1], "k": 16 }
assert my_solution.maximumScore(**test_input) == 734032462

test_input = { "nums": [1,6,12,4,10,13,7,6,17,1], "k": 50 }
assert my_solution.maximumScore(**test_input) == 377786273

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

test_input = { "nums": [5,1,17,10,12], "k": 9 }
assert my_solution.maximumScore(**test_input) == 467999979

test_input = { "nums": [6,1,1,4,10,15,16,8], "k": 12 }
assert my_solution.maximumScore(**test_input) == 999939527

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

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

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


faulty-keyboard

Faulty Keyboard

Prompt:
"""
你的笔记本键盘存在故障，每当你在上面输入字符 'i' 时，它会反转你所写的字符串。而输入其他字符则可以正常工作。

给你一个下标从 0 开始的字符串 s ，请你用故障键盘依次输入每个字符。

返回最终笔记本屏幕上输出的字符串。

示例 1：

输入：s = "string"
输出："rtsng"
解释：
输入第 1 个字符后，屏幕上的文本是："s" 。
输入第 2 个字符后，屏幕上的文本是："st" 。
输入第 3 个字符后，屏幕上的文本是："str" 。
因为第 4 个字符是 'i' ，屏幕上的文本被反转，变成 "rts" 。
输入第 5 个字符后，屏幕上的文本是："rtsn" 。
输入第 6 个字符后，屏幕上的文本是： "rtsng" 。
因此，返回 "rtsng" 。

示例 2：

输入：s = "poiinter"
输出："ponter"
解释：
输入第 1 个字符后，屏幕上的文本是："p" 。
输入第 2 个字符后，屏幕上的文本是："po" 。
因为第 3 个字符是 'i' ，屏幕上的文本被反转，变成 "op" 。
因为第 4 个字符是 'i' ，屏幕上的文本被反转，变成 "po" 。
输入第 5 个字符后，屏幕上的文本是："pon" 。
输入第 6 个字符后，屏幕上的文本是："pont" 。
输入第 7 个字符后，屏幕上的文本是："ponte" 。
输入第 8 个字符后，屏幕上的文本是："ponter" 。
因此，返回 "ponter" 。

提示：

 * 1 <= s.length <= 100
 * s 由小写英文字母组成
 * s[0] != 'i'
"""
class Solution:
    def finalString(self, s: str) -> str:

你的笔记本键盘存在故障，每当你在上面输入字符 'i' 时，它会反转你所写的字符串。而输入其他字符则可以正常工作。

给你一个下标从 0 开始的字符串 s ，请你用故障键盘依次输入每个字符。

返回最终笔记本屏幕上输出的字符串。

示例 1：

输入：s = "string"
输出："rtsng"
解释：
输入第 1 个字符后，屏幕上的文本是："s" 。
输入第 2 个字符后，屏幕上的文本是："st" 。
输入第 3 个字符后，屏幕上的文本是："str" 。
因为第 4 个字符是 'i' ，屏幕上的文本被反转，变成 "rts" 。
输入第 5 个字符后，屏幕上的文本是："rtsn" 。
输入第 6 个字符后，屏幕上的文本是： "rtsng" 。
因此，返回 "rtsng" 。

示例 2：

输入：s = "poiinter"
输出："ponter"
解释：
输入第 1 个字符后，屏幕上的文本是："p" 。
输入第 2 个字符后，屏幕上的文本是："po" 。
因为第 3 个字符是 'i' ，屏幕上的文本被反转，变成 "op" 。
因为第 4 个字符是 'i' ，屏幕上的文本被反转，变成 "po" 。
输入第 5 个字符后，屏幕上的文本是："pon" 。
输入第 6 个字符后，屏幕上的文本是："pont" 。
输入第 7 个字符后，屏幕上的文本是："ponte" 。
输入第 8 个字符后，屏幕上的文本是："ponter" 。
因此，返回 "ponter" 。

提示：

 * 1 <= s.length <= 100
 * s 由小写英文字母组成
 * s[0] != 'i'

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

```

my_solution = Solution()

test_input = { "s": "string" }
assert my_solution.finalString(**test_input) == "rtsng"

test_input = { "s": "poiinter" }
assert my_solution.finalString(**test_input) == "ponter"

test_input = { "s": "goci" }
assert my_solution.finalString(**test_input) == "cog"

test_input = { "s": "ksi" }
assert my_solution.finalString(**test_input) == "sk"

test_input = { "s": "fii" }
assert my_solution.finalString(**test_input) == "f"

test_input = { "s": "qskyviiiii" }
assert my_solution.finalString(**test_input) == "vyksq"

test_input = { "s": "pft" }
assert my_solution.finalString(**test_input) == "pft"

test_input = { "s": "viwif" }
assert my_solution.finalString(**test_input) == "wvf"

test_input = { "s": "wiie" }
assert my_solution.finalString(**test_input) == "we"

test_input = { "s": "kiis" }
assert my_solution.finalString(**test_input) == "ks"

test_input = { "s": "xihbosxitx" }
assert my_solution.finalString(**test_input) == "xsobhxtx"

test_input = { "s": "uwioili" }
assert my_solution.finalString(**test_input) == "lwuo"

test_input = { "s": "aapziai" }
assert my_solution.finalString(**test_input) == "aaapz"

test_input = { "s": "pviist" }
assert my_solution.finalString(**test_input) == "pvst"

test_input = { "s": "miiuiei" }
assert my_solution.finalString(**test_input) == "emu"

test_input = { "s": "diiiiq" }
assert my_solution.finalString(**test_input) == "dq"

test_input = { "s": "eirov" }
assert my_solution.finalString(**test_input) == "erov"

test_input = { "s": "niiiiisiii" }
assert my_solution.finalString(**test_input) == "sn"

test_input = { "s": "siiuii" }
assert my_solution.finalString(**test_input) == "su"

test_input = { "s": "piijciivq" }
assert my_solution.finalString(**test_input) == "pjcvq"

test_input = { "s": "tidtwitik" }
assert my_solution.finalString(**test_input) == "ttdtwk"

test_input = { "s": "z" }
assert my_solution.finalString(**test_input) == "z"

test_input = { "s": "ffyuidnn" }
assert my_solution.finalString(**test_input) == "uyffdnn"

test_input = { "s": "xitiiinix" }
assert my_solution.finalString(**test_input) == "nxtx"

test_input = { "s": "ciiiuifab" }
assert my_solution.finalString(**test_input) == "ucfab"

test_input = { "s": "x" }
assert my_solution.finalString(**test_input) == "x"

test_input = { "s": "v" }
assert my_solution.finalString(**test_input) == "v"

test_input = { "s": "liinii" }
assert my_solution.finalString(**test_input) == "ln"

test_input = { "s": "ziii" }
assert my_solution.finalString(**test_input) == "z"

test_input = { "s": "ei" }
assert my_solution.finalString(**test_input) == "e"

test_input = { "s": "tidiiiii" }
assert my_solution.finalString(**test_input) == "dt"

test_input = { "s": "krjiqjii" }
assert my_solution.finalString(**test_input) == "jrkqj"

test_input = { "s": "mxczii" }
assert my_solution.finalString(**test_input) == "mxcz"

test_input = { "s": "bz" }
assert my_solution.finalString(**test_input) == "bz"

test_input = { "s": "zbwri" }
assert my_solution.finalString(**test_input) == "rwbz"

test_input = { "s": "biiq" }
assert my_solution.finalString(**test_input) == "bq"

test_input = { "s": "mmiiliir" }
assert my_solution.finalString(**test_input) == "mmlr"

test_input = { "s": "plibeici" }
assert my_solution.finalString(**test_input) == "clpbe"

test_input = { "s": "cii" }
assert my_solution.finalString(**test_input) == "c"

test_input = { "s": "wiilg" }
assert my_solution.finalString(**test_input) == "wlg"

test_input = { "s": "cdidi" }
assert my_solution.finalString(**test_input) == "dcd"

test_input = { "s": "fsq" }
assert my_solution.finalString(**test_input) == "fsq"

test_input = { "s": "hkjciaiii" }
assert my_solution.finalString(**test_input) == "ahkjc"

test_input = { "s": "l" }
assert my_solution.finalString(**test_input) == "l"

test_input = { "s": "vilcoizi" }
assert my_solution.finalString(**test_input) == "zvlco"

test_input = { "s": "tgigivipx" }
assert my_solution.finalString(**test_input) == "vgtgpx"

test_input = { "s": "ri" }
assert my_solution.finalString(**test_input) == "r"

test_input = { "s": "kficiiioiy" }
assert my_solution.finalString(**test_input) == "ofkcy"

test_input = { "s": "o" }
assert my_solution.finalString(**test_input) == "o"

test_input = { "s": "piifwiiit" }
assert my_solution.finalString(**test_input) == "wfpt"

test_input = { "s": "sifsiui" }
assert my_solution.finalString(**test_input) == "usfs"

test_input = { "s": "sxiuiiiii" }
assert my_solution.finalString(**test_input) == "usx"

test_input = { "s": "tiiiihiw" }
assert my_solution.finalString(**test_input) == "htw"

test_input = { "s": "ko" }
assert my_solution.finalString(**test_input) == "ko"

test_input = { "s": "gagi" }
assert my_solution.finalString(**test_input) == "gag"

test_input = { "s": "yyigiir" }
assert my_solution.finalString(**test_input) == "yygr"

test_input = { "s": "jimiiaci" }
assert my_solution.finalString(**test_input) == "camj"

test_input = { "s": "xiiiei" }
assert my_solution.finalString(**test_input) == "ex"

test_input = { "s": "hwi" }
assert my_solution.finalString(**test_input) == "wh"

test_input = { "s": "ji" }
assert my_solution.finalString(**test_input) == "j"

test_input = { "s": "heii" }
assert my_solution.finalString(**test_input) == "he"

test_input = { "s": "zitjcq" }
assert my_solution.finalString(**test_input) == "ztjcq"

test_input = { "s": "upmipaw" }
assert my_solution.finalString(**test_input) == "mpupaw"

test_input = { "s": "fiixkgp" }
assert my_solution.finalString(**test_input) == "fxkgp"

test_input = { "s": "ldr" }
assert my_solution.finalString(**test_input) == "ldr"

test_input = { "s": "kiboiithi" }
assert my_solution.finalString(**test_input) == "htobk"

test_input = { "s": "svcii" }
assert my_solution.finalString(**test_input) == "svc"

test_input = { "s": "d" }
assert my_solution.finalString(**test_input) == "d"

test_input = { "s": "edgijwiua" }
assert my_solution.finalString(**test_input) == "wjedgua"

test_input = { "s": "wiidqoiwov" }
assert my_solution.finalString(**test_input) == "oqdwwov"

test_input = { "s": "zimxiiqqi" }
assert my_solution.finalString(**test_input) == "qqxmz"

test_input = { "s": "githpgiini" }
assert my_solution.finalString(**test_input) == "ngphtg"

test_input = { "s": "fy" }
assert my_solution.finalString(**test_input) == "fy"

test_input = { "s": "hesi" }
assert my_solution.finalString(**test_input) == "seh"

test_input = { "s": "eiiii" }
assert my_solution.finalString(**test_input) == "e"

test_input = { "s": "be" }
assert my_solution.finalString(**test_input) == "be"

test_input = { "s": "rpi" }
assert my_solution.finalString(**test_input) == "pr"

test_input = { "s": "mi" }
assert my_solution.finalString(**test_input) == "m"

test_input = { "s": "wiiiiii" }
assert my_solution.finalString(**test_input) == "w"

test_input = { "s": "rbiiiii" }
assert my_solution.finalString(**test_input) == "br"

test_input = { "s": "diiii" }
assert my_solution.finalString(**test_input) == "d"

test_input = { "s": "poiiifl" }
assert my_solution.finalString(**test_input) == "opfl"

test_input = { "s": "loifiicii" }
assert my_solution.finalString(**test_input) == "olfc"

test_input = { "s": "bii" }
assert my_solution.finalString(**test_input) == "b"

test_input = { "s": "nirii" }
assert my_solution.finalString(**test_input) == "nr"

test_input = { "s": "wiigipio" }
assert my_solution.finalString(**test_input) == "pwgo"

test_input = { "s": "gimliibin" }
assert my_solution.finalString(**test_input) == "blmgn"

test_input = { "s": "zi" }
assert my_solution.finalString(**test_input) == "z"

test_input = { "s": "tjn" }
assert my_solution.finalString(**test_input) == "tjn"

test_input = { "s": "ly" }
assert my_solution.finalString(**test_input) == "ly"

test_input = { "s": "sqzviyiimi" }
assert my_solution.finalString(**test_input) == "mysqzv"

test_input = { "s": "jhmaxm" }
assert my_solution.finalString(**test_input) == "jhmaxm"

test_input = { "s": "py" }
assert my_solution.finalString(**test_input) == "py"

test_input = { "s": "yyilwiib" }
assert my_solution.finalString(**test_input) == "yylwb"

test_input = { "s": "ryjiilj" }
assert my_solution.finalString(**test_input) == "ryjlj"

test_input = { "s": "tnokpgfii" }
assert my_solution.finalString(**test_input) == "tnokpgf"

test_input = { "s": "niihiliiv" }
assert my_solution.finalString(**test_input) == "hnlv"

test_input = { "s": "gvhms" }
assert my_solution.finalString(**test_input) == "gvhms"

test_input = { "s": "yg" }
assert my_solution.finalString(**test_input) == "yg"

test_input = { "s": "eiiiuizgi" }
assert my_solution.finalString(**test_input) == "gzeu"


check-if-it-is-possible-to-split-array

Check if it is Possible to Split Array

Prompt:
"""
给你一个长度为 n 的数组 nums 和一个整数 m 。请你判断能否执行一系列操作，将数组拆分成 n 个 非空 数组。

在每一步操作中，你可以选择一个 长度至少为 2 的现有数组（之前步骤的结果） 并将其拆分成 2 个子数组，而得到的 每个 子数组，至少 需要满足以下条件之一：

 * 子数组的长度为 1 ，或者
 * 子数组元素之和 大于或等于  m 。

如果你可以将给定数组拆分成 n 个满足要求的数组，返回 true ；否则，返回 false 。

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

示例 1：

输入：nums = [2, 2, 1], m = 4
输出：true
解释：
第 1 步，将数组 nums 拆分成 [2, 2] 和 [1] 。
第 2 步，将数组 [2, 2] 拆分成 [2] 和 [2] 。
因此，答案为 true 。

示例 2：

输入：nums = [2, 1, 3], m = 5
输出：false
解释：
存在两种不同的拆分方法：
第 1 种，将数组 nums 拆分成 [2, 1] 和 [3] 。
第 2 种，将数组 nums 拆分成 [2] 和 [1, 3] 。
然而，这两种方法都不满足题意。因此，答案为 false 。

示例 3：

输入：nums = [2, 3, 3, 2, 3], m = 6
输出：true
解释：
第 1 步，将数组 nums 拆分成 [2, 3, 3, 2] 和 [3] 。
第 2 步，将数组 [2, 3, 3, 2] 拆分成 [2, 3, 3] 和 [2] 。
第 3 步，将数组 [2, 3, 3] 拆分成 [2] 和 [3, 3] 。
第 4 步，将数组 [3, 3] 拆分成 [3] 和 [3] 。
因此，答案为 true 。

提示：

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

给你一个长度为 n 的数组 nums 和一个整数 m 。请你判断能否执行一系列操作，将数组拆分成 n 个 非空 数组。

在每一步操作中，你可以选择一个 长度至少为 2 的现有数组（之前步骤的结果） 并将其拆分成 2 个子数组，而得到的 每个 子数组，至少 需要满足以下条件之一：

 * 子数组的长度为 1 ，或者
 * 子数组元素之和 大于或等于  m 。

如果你可以将给定数组拆分成 n 个满足要求的数组，返回 true ；否则，返回 false 。

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

示例 1：

输入：nums = [2, 2, 1], m = 4
输出：true
解释：
第 1 步，将数组 nums 拆分成 [2, 2] 和 [1] 。
第 2 步，将数组 [2, 2] 拆分成 [2] 和 [2] 。
因此，答案为 true 。

示例 2：

输入：nums = [2, 1, 3], m = 5
输出：false
解释：
存在两种不同的拆分方法：
第 1 种，将数组 nums 拆分成 [2, 1] 和 [3] 。
第 2 种，将数组 nums 拆分成 [2] 和 [1, 3] 。
然而，这两种方法都不满足题意。因此，答案为 false 。

示例 3：

输入：nums = [2, 3, 3, 2, 3], m = 6
输出：true
解释：
第 1 步，将数组 nums 拆分成 [2, 3, 3, 2] 和 [3] 。
第 2 步，将数组 [2, 3, 3, 2] 拆分成 [2, 3, 3] 和 [2] 。
第 3 步，将数组 [2, 3, 3] 拆分成 [2] 和 [3, 3] 。
第 4 步，将数组 [3, 3] 拆分成 [3] 和 [3] 。
因此，答案为 true 。

提示：

 * 1 <= n == nums.length <= 100
 * 1 <= nums[i] <= 100
 * 1 <= m <= 200

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

```

my_solution = Solution()

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

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

test_input = { "nums": [1], "m": 1 }
assert my_solution.canSplitArray(**test_input) == True

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

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

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

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

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

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

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

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

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

test_input = { "nums": [2], "m": 2 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1, 3, 1], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

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

test_input = { "nums": [2, 1, 1], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2, 2, 1], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

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

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

test_input = { "nums": [3, 1, 1], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3, 1, 3], "m": 6 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [7], "m": 5 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [4], "m": 7 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [9], "m": 7 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [2], "m": 8 }
assert my_solution.canSplitArray(**test_input) == True

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

test_input = { "nums": [4], "m": 8 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [10], "m": 11 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [6], "m": 12 }
assert my_solution.canSplitArray(**test_input) == True

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

test_input = { "nums": [3, 3, 6], "m": 10 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [2], "m": 14 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [5, 3, 6], "m": 10 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [3], "m": 18 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [4, 6, 5], "m": 12 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [9, 7], "m": 1 }
assert my_solution.canSplitArray(**test_input) == True

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

test_input = { "nums": [9, 1, 7], "m": 14 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [8, 2, 4], "m": 16 }
assert my_solution.canSplitArray(**test_input) == False

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

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

test_input = { "nums": [9, 5, 7], "m": 20 }
assert my_solution.canSplitArray(**test_input) == False

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

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

test_input = { "nums": [1, 2, 2, 5], "m": 8 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [4, 4, 4, 2], "m": 9 }
assert my_solution.canSplitArray(**test_input) == False

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

test_input = { "nums": [8, 1, 2, 5], "m": 10 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [10, 2, 9, 3], "m": 14 }
assert my_solution.canSplitArray(**test_input) == False

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

test_input = { "nums": [10, 4, 8, 6], "m": 16 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [14, 1, 1, 15], "m": 17 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [6, 11, 2, 12], "m": 18 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [14, 3, 12, 3], "m": 18 }
assert my_solution.canSplitArray(**test_input) == False

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

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

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

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

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

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

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

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

test_input = { "nums": [2, 10], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

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

test_input = { "nums": [3, 3], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [7, 9], "m": 3 }
assert my_solution.canSplitArray(**test_input) == True

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

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

test_input = { "nums": [2, 9, 2, 3, 2], "m": 12 }
assert my_solution.canSplitArray(**test_input) == False

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

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

test_input = { "nums": [4, 4, 4, 7, 5], "m": 13 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [5, 2, 6, 5, 4], "m": 13 }
assert my_solution.canSplitArray(**test_input) == False

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

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

test_input = { "nums": [13, 2, 13, 4, 11], "m": 18 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [5, 6, 10, 7, 4], "m": 19 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [16, 1, 12, 6, 7], "m": 19 }
assert my_solution.canSplitArray(**test_input) == False

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

test_input = { "nums": [9, 9, 8, 10, 8], "m": 20 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [9, 4], "m": 5 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [10, 2], "m": 5 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [16, 2, 2, 16, 2], "m": 20 }
assert my_solution.canSplitArray(**test_input) == False

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

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

test_input = { "nums": [5, 1], "m": 8 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [1, 4, 4, 2, 1, 5], "m": 9 }
assert my_solution.canSplitArray(**test_input) == False

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

test_input = { "nums": [10, 9], "m": 15 }
assert my_solution.canSplitArray(**test_input) == True

test_input = { "nums": [8, 4], "m": 18 }
assert my_solution.canSplitArray(**test_input) == True

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

test_input = { "nums": [3, 7, 2, 8, 2, 4], "m": 11 }
assert my_solution.canSplitArray(**test_input) == False

test_input = { "nums": [8, 1], "m": 19 }
assert my_solution.canSplitArray(**test_input) == True

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

test_input = { "nums": [5, 1, 1, 9, 1, 5], "m": 11 }
assert my_solution.canSplitArray(**test_input) == False

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

test_input = { "nums": [6, 4, 7, 2, 5, 4], "m": 12 }
assert my_solution.canSplitArray(**test_input) == False

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

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


find-the-safest-path-in-a-grid

Find the Safest Path in a Grid

Prompt:
"""
给你一个下标从 0 开始、大小为 n x n 的二维矩阵 grid ，其中 (r, c) 表示：

 * 如果 grid[r][c] = 1 ，则表示一个存在小偷的单元格
 * 如果 grid[r][c] = 0 ，则表示一个空单元格

你最开始位于单元格 (0, 0) 。在一步移动中，你可以移动到矩阵中的任一相邻单元格，包括存在小偷的单元格。

矩阵中路径的 安全系数 定义为：从路径中任一单元格到矩阵中任一小偷所在单元格的 最小 曼哈顿距离。

返回所有通向单元格 (n - 1, n - 1) 的路径中的 最大安全系数 。

单元格 (r, c) 的某个 相邻 单元格，是指在矩阵中存在的 (r, c + 1)、(r, c - 1)、(r + 1, c) 和 (r - 1, c) 之一。

两个单元格 (a, b) 和 (x, y) 之间的 曼哈顿距离 等于 | a - x | + | b - y | ，其中 |val| 表示 val 的绝对值。

示例 1：

[https://assets.leetcode.com/uploads/2023/07/02/example1.png]

输入：grid = [[1,0,0],[0,0,0],[0,0,1]]
输出：0
解释：从 (0, 0) 到 (n - 1, n - 1) 的每条路径都经过存在小偷的单元格 (0, 0) 和 (n - 1, n - 1) 。

示例 2：

[https://assets.leetcode.com/uploads/2023/07/02/example2.png]

输入：grid = [[0,0,1],[0,0,0],[0,0,0]]
输出：2
解释：
上图所示路径的安全系数为 2：
- 该路径上距离小偷所在单元格（0，2）最近的单元格是（0，0）。它们之间的曼哈顿距离为 | 0 - 0 | + | 0 - 2 | = 2 。
可以证明，不存在安全系数更高的其他路径。

示例 3：

[https://assets.leetcode.com/uploads/2023/07/02/example3.png]

输入：grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]
输出：2
解释：
上图所示路径的安全系数为 2：
- 该路径上距离小偷所在单元格（0，3）最近的单元格是（1，2）。它们之间的曼哈顿距离为 | 0 - 1 | + | 3 - 2 | = 2 。
- 该路径上距离小偷所在单元格（3，0）最近的单元格是（3，2）。它们之间的曼哈顿距离为 | 3 - 3 | + | 0 - 2 | = 2 。
可以证明，不存在安全系数更高的其他路径。

提示：

 * 1 <= grid.length == n <= 400
 * grid[i].length == n
 * grid[i][j] 为 0 或 1
 * grid 至少存在一个小偷
"""
class Solution:
    def maximumSafenessFactor(self, grid: List[List[int]]) -> int:

给你一个下标从 0 开始、大小为 n x n 的二维矩阵 grid ，其中 (r, c) 表示：

 * 如果 grid[r][c] = 1 ，则表示一个存在小偷的单元格
 * 如果 grid[r][c] = 0 ，则表示一个空单元格

你最开始位于单元格 (0, 0) 。在一步移动中，你可以移动到矩阵中的任一相邻单元格，包括存在小偷的单元格。

矩阵中路径的 安全系数 定义为：从路径中任一单元格到矩阵中任一小偷所在单元格的 最小 曼哈顿距离。

返回所有通向单元格 (n - 1, n - 1) 的路径中的 最大安全系数 。

单元格 (r, c) 的某个 相邻 单元格，是指在矩阵中存在的 (r, c + 1)、(r, c - 1)、(r + 1, c) 和 (r - 1, c) 之一。

两个单元格 (a, b) 和 (x, y) 之间的 曼哈顿距离 等于 | a - x | + | b - y | ，其中 |val| 表示 val 的绝对值。

示例 1：

[https://assets.leetcode.com/uploads/2023/07/02/example1.png]

输入：grid = [[1,0,0],[0,0,0],[0,0,1]]
输出：0
解释：从 (0, 0) 到 (n - 1, n - 1) 的每条路径都经过存在小偷的单元格 (0, 0) 和 (n - 1, n - 1) 。

示例 2：

[https://assets.leetcode.com/uploads/2023/07/02/example2.png]

输入：grid = [[0,0,1],[0,0,0],[0,0,0]]
输出：2
解释：
上图所示路径的安全系数为 2：
- 该路径上距离小偷所在单元格（0，2）最近的单元格是（0，0）。它们之间的曼哈顿距离为 | 0 - 0 | + | 0 - 2 | = 2 。
可以证明，不存在安全系数更高的其他路径。

示例 3：

[https://assets.leetcode.com/uploads/2023/07/02/example3.png]

输入：grid = [[0,0,0,1],[0,0,0,0],[0,0,0,0],[1,0,0,0]]
输出：2
解释：
上图所示路径的安全系数为 2：
- 该路径上距离小偷所在单元格（0，3）最近的单元格是（1，2）。它们之间的曼哈顿距离为 | 0 - 1 | + | 3 - 2 | = 2 。
- 该路径上距离小偷所在单元格（3，0）最近的单元格是（3，2）。它们之间的曼哈顿距离为 | 3 - 3 | + | 0 - 2 | = 2 。
可以证明，不存在安全系数更高的其他路径。

提示：

 * 1 <= grid.length == n <= 400
 * grid[i].length == n
 * grid[i][j] 为 0 或 1
 * grid 至少存在一个小偷

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

```

my_solution = Solution()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


maximum-elegance-of-a-k-length-subsequence

Maximum Elegance of a K-Length Subsequence

Prompt:
"""
给你一个长度为 n 的二维整数数组 items 和一个整数 k 。

items[i] = [profiti, categoryi]，其中 profiti 和 categoryi 分别表示第 i 个项目的利润和类别。

现定义 items 的 子序列 的 优雅度 可以用 total_profit + distinct_categories2 计算，其中 total_profit 是子序列中所有项目的利润总和，distinct_categories 是所选子序列所含的所有类别中不同类别的数量。

你的任务是从 items 所有长度为 k 的子序列中，找出 最大优雅度 。

用整数形式表示并返回 items 中所有长度恰好为 k 的子序列的最大优雅度。

注意：数组的子序列是经由原数组删除一些元素（可能不删除）而产生的新数组，且删除不改变其余元素相对顺序。

示例 1：

输入：items = [[3,2],[5,1],[10,1]], k = 2
输出：17
解释：
在这个例子中，我们需要选出长度为 2 的子序列。
其中一种方案是 items[0] = [3,2] 和 items[2] = [10,1] 。
子序列的总利润为 3 + 10 = 13 ，子序列包含 2 种不同类别 [2,1] 。
因此，优雅度为 13 + 22 = 17 ，可以证明 17 是可以获得的最大优雅度。

示例 2：

输入：items = [[3,1],[3,1],[2,2],[5,3]], k = 3
输出：19
解释：
在这个例子中，我们需要选出长度为 3 的子序列。
其中一种方案是 items[0] = [3,1] ，items[2] = [2,2] 和 items[3] = [5,3] 。
子序列的总利润为 3 + 2 + 5 = 10 ，子序列包含 3 种不同类别 [1, 2, 3] 。
因此，优雅度为 10 + 32 = 19 ，可以证明 19 是可以获得的最大优雅度。

示例 3：

输入：items = [[1,1],[2,1],[3,1]], k = 3
输出：7
解释：
在这个例子中，我们需要选出长度为 3 的子序列。
我们需要选中所有项目。
子序列的总利润为 1 + 2 + 3 = 6，子序列包含 1 种不同类别 [1] 。
因此，最大优雅度为 6 + 12 = 7 。

提示：

 * 1 <= items.length == n <= 105
 * items[i].length == 2
 * items[i][0] == profiti
 * items[i][1] == categoryi
 * 1 <= profiti <= 109
 * 1 <= categoryi <= n
 * 1 <= k <= n
"""
class Solution:
    def findMaximumElegance(self, items: List[List[int]], k: int) -> int:

给你一个长度为 n 的二维整数数组 items 和一个整数 k 。

items[i] = [profiti, categoryi]，其中 profiti 和 categoryi 分别表示第 i 个项目的利润和类别。

现定义 items 的 子序列 的 优雅度 可以用 total_profit + distinct_categories2 计算，其中 total_profit 是子序列中所有项目的利润总和，distinct_categories 是所选子序列所含的所有类别中不同类别的数量。

你的任务是从 items 所有长度为 k 的子序列中，找出 最大优雅度 。

用整数形式表示并返回 items 中所有长度恰好为 k 的子序列的最大优雅度。

注意：数组的子序列是经由原数组删除一些元素（可能不删除）而产生的新数组，且删除不改变其余元素相对顺序。

示例 1：

输入：items = [[3,2],[5,1],[10,1]], k = 2
输出：17
解释：
在这个例子中，我们需要选出长度为 2 的子序列。
其中一种方案是 items[0] = [3,2] 和 items[2] = [10,1] 。
子序列的总利润为 3 + 10 = 13 ，子序列包含 2 种不同类别 [2,1] 。
因此，优雅度为 13 + 22 = 17 ，可以证明 17 是可以获得的最大优雅度。

示例 2：

输入：items = [[3,1],[3,1],[2,2],[5,3]], k = 3
输出：19
解释：
在这个例子中，我们需要选出长度为 3 的子序列。
其中一种方案是 items[0] = [3,1] ，items[2] = [2,2] 和 items[3] = [5,3] 。
子序列的总利润为 3 + 2 + 5 = 10 ，子序列包含 3 种不同类别 [1, 2, 3] 。
因此，优雅度为 10 + 32 = 19 ，可以证明 19 是可以获得的最大优雅度。

示例 3：

输入：items = [[1,1],[2,1],[3,1]], k = 3
输出：7
解释：
在这个例子中，我们需要选出长度为 3 的子序列。
我们需要选中所有项目。
子序列的总利润为 1 + 2 + 3 = 6，子序列包含 1 种不同类别 [1] 。
因此，最大优雅度为 6 + 12 = 7 。

提示：

 * 1 <= items.length == n <= 105
 * items[i].length == 2
 * items[i][0] == profiti
 * items[i][1] == categoryi
 * 1 <= profiti <= 109
 * 1 <= categoryi <= n
 * 1 <= k <= n

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

```

my_solution = Solution()

test_input = { "items": [[3,2],[5,1],[10,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

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

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

test_input = { "items": [[1,1],[1,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 6

test_input = { "items": [[1,1],[4,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 5

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

test_input = { "items": [[1,1],[6,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 7

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

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

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

test_input = { "items": [[1,2],[10,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

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

test_input = { "items": [[2,1],[7,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[2,1],[9,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

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

test_input = { "items": [[2,2],[2,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 5

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

test_input = { "items": [[2,2],[6,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 12

test_input = { "items": [[3,1],[1,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 8

test_input = { "items": [[3,1],[9,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 13

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

test_input = { "items": [[3,1],[10,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

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

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

test_input = { "items": [[3,2],[10,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[3,2],[10,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 14

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

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

test_input = { "items": [[4,2],[2,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 10

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

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

test_input = { "items": [[4,2],[7,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 8

test_input = { "items": [[4,2],[8,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 16

test_input = { "items": [[4,2],[10,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 18

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

test_input = { "items": [[5,1],[8,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 14

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

test_input = { "items": [[5,1],[9,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[5,2],[2,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 6

test_input = { "items": [[5,2],[4,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[5,2],[5,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 14

test_input = { "items": [[6,1],[1,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 7

test_input = { "items": [[6,1],[4,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 7

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

test_input = { "items": [[6,1],[7,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[6,1],[8,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 15

test_input = { "items": [[6,1],[8,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 18

test_input = { "items": [[6,1],[9,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

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

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

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

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

test_input = { "items": [[6,2],[6,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 13

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

test_input = { "items": [[6,2],[7,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[6,2],[8,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 15

test_input = { "items": [[6,2],[10,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[7,1],[1,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 8

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

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

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

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

test_input = { "items": [[7,2],[7,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 15

test_input = { "items": [[7,2],[10,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 18

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

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

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

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

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

test_input = { "items": [[8,1],[8,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 17

test_input = { "items": [[8,1],[9,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[8,1],[9,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 21

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

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

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

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

test_input = { "items": [[8,2],[9,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 21

test_input = { "items": [[8,2],[9,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 18

test_input = { "items": [[8,2],[10,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 22

test_input = { "items": [[9,1],[1,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[9,1],[3,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 16

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

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

test_input = { "items": [[9,1],[9,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[9,1],[10,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[9,2],[1,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 10

test_input = { "items": [[9,2],[2,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 15

test_input = { "items": [[9,2],[6,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 19

test_input = { "items": [[9,2],[6,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 16

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

test_input = { "items": [[10,1],[2,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,1],[4,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,1],[5,1]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 16

test_input = { "items": [[10,1],[5,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 19

test_input = { "items": [[10,1],[7,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,2],[1,2]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,2],[4,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,2],[5,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,2],[7,1]], "k": 1 }
assert my_solution.findMaximumElegance(**test_input) == 11

test_input = { "items": [[10,2],[8,2]], "k": 2 }
assert my_solution.findMaximumElegance(**test_input) == 19