minimum-edge-weight-equilibrium-queries-in-a-tree

Minimum Edge Weight Equilibrium Queries in a Tree

Prompt:
"""
现有一棵由 n 个节点组成的无向树，节点按从 0 到 n - 1 编号。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ，其中 edges[i] = [ui, vi, wi] 表示树中存在一条位于节点 ui 和节点 vi 之间、权重为 wi 的边。

另给你一个长度为 m 的二维整数数组 queries ，其中 queries[i] = [ai, bi] 。对于每条查询，请你找出使从 ai 到 bi 路径上每条边的权重相等所需的 最小操作次数 。在一次操作中，你可以选择树上的任意一条边，并将其权重更改为任意值。

注意：

 * 查询之间 相互独立 的，这意味着每条新的查询时，树都会回到 初始状态 。
 * 从 ai 到 bi的路径是一个由 不同 节点组成的序列，从节点 ai 开始，到节点 bi 结束，且序列中相邻的两个节点在树中共享一条边。

返回一个长度为 m 的数组 answer ，其中 answer[i] 是第 i 条查询的答案。

示例 1：

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

输入：n = 7, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], queries = [[0,3],[3,6],[2,6],[0,6]]
输出：[0,0,1,3]
解释：第 1 条查询，从节点 0 到节点 3 的路径中的所有边的权重都是 1 。因此，答案为 0 。
第 2 条查询，从节点 3 到节点 6 的路径中的所有边的权重都是 2 。因此，答案为 0 。
第 3 条查询，将边 [2,3] 的权重变更为 2 。在这次操作之后，从节点 2 到节点 6 的路径中的所有边的权重都是 2 。因此，答案为 1 。
第 4 条查询，将边 [0,1]、[1,2]、[2,3] 的权重变更为 2 。在这次操作之后，从节点 0 到节点 6 的路径中的所有边的权重都是 2 。因此，答案为 3 。
对于每条查询 queries[i] ，可以证明 answer[i] 是使从 ai 到 bi 的路径中的所有边的权重相等的最小操作次数。

示例 2：

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

输入：n = 8, edges = [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], queries = [[4,6],[0,4],[6,5],[7,4]]
输出：[1,2,2,3]
解释：第 1 条查询，将边 [1,3] 的权重变更为 6 。在这次操作之后，从节点 4 到节点 6 的路径中的所有边的权重都是 6 。因此，答案为 1 。
第 2 条查询，将边 [0,3]、[3,1] 的权重变更为 6 。在这次操作之后，从节点 0 到节点 4 的路径中的所有边的权重都是 6 。因此，答案为 2 。
第 3 条查询，将边 [1,3]、[5,2] 的权重变更为 6 。在这次操作之后，从节点 6 到节点 5 的路径中的所有边的权重都是 6 。因此，答案为 2 。
第 4 条查询，将边 [0,7]、[0,3]、[1,3] 的权重变更为 6 。在这次操作之后，从节点 7 到节点 4 的路径中的所有边的权重都是 6 。因此，答案为 3 。
对于每条查询 queries[i] ，可以证明 answer[i] 是使从 ai 到 bi 的路径中的所有边的权重相等的最小操作次数。

提示：

 * 1 <= n <= 104
 * edges.length == n - 1
 * edges[i].length == 3
 * 0 <= ui, vi < n
 * 1 <= wi <= 26
 * 生成的输入满足 edges 表示一棵有效的树
 * 1 <= queries.length == m <= 2 * 104
 * queries[i].length == 2
 * 0 <= ai, bi < n
"""
class Solution:
    def minOperationsQueries(self, n: int, edges: List[List[int]], queries: List[List[int]]) -> List[int]:

现有一棵由 n 个节点组成的无向树，节点按从 0 到 n - 1 编号。给你一个整数 n 和一个长度为 n - 1 的二维整数数组 edges ，其中 edges[i] = [ui, vi, wi] 表示树中存在一条位于节点 ui 和节点 vi 之间、权重为 wi 的边。

另给你一个长度为 m 的二维整数数组 queries ，其中 queries[i] = [ai, bi] 。对于每条查询，请你找出使从 ai 到 bi 路径上每条边的权重相等所需的 最小操作次数 。在一次操作中，你可以选择树上的任意一条边，并将其权重更改为任意值。

注意：

 * 查询之间 相互独立 的，这意味着每条新的查询时，树都会回到 初始状态 。
 * 从 ai 到 bi的路径是一个由 不同 节点组成的序列，从节点 ai 开始，到节点 bi 结束，且序列中相邻的两个节点在树中共享一条边。

返回一个长度为 m 的数组 answer ，其中 answer[i] 是第 i 条查询的答案。

示例 1：

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

输入：n = 7, edges = [[0,1,1],[1,2,1],[2,3,1],[3,4,2],[4,5,2],[5,6,2]], queries = [[0,3],[3,6],[2,6],[0,6]]
输出：[0,0,1,3]
解释：第 1 条查询，从节点 0 到节点 3 的路径中的所有边的权重都是 1 。因此，答案为 0 。
第 2 条查询，从节点 3 到节点 6 的路径中的所有边的权重都是 2 。因此，答案为 0 。
第 3 条查询，将边 [2,3] 的权重变更为 2 。在这次操作之后，从节点 2 到节点 6 的路径中的所有边的权重都是 2 。因此，答案为 1 。
第 4 条查询，将边 [0,1]、[1,2]、[2,3] 的权重变更为 2 。在这次操作之后，从节点 0 到节点 6 的路径中的所有边的权重都是 2 。因此，答案为 3 。
对于每条查询 queries[i] ，可以证明 answer[i] 是使从 ai 到 bi 的路径中的所有边的权重相等的最小操作次数。

示例 2：

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

输入：n = 8, edges = [[1,2,6],[1,3,4],[2,4,6],[2,5,3],[3,6,6],[3,0,8],[7,0,2]], queries = [[4,6],[0,4],[6,5],[7,4]]
输出：[1,2,2,3]
解释：第 1 条查询，将边 [1,3] 的权重变更为 6 。在这次操作之后，从节点 4 到节点 6 的路径中的所有边的权重都是 6 。因此，答案为 1 。
第 2 条查询，将边 [0,3]、[3,1] 的权重变更为 6 。在这次操作之后，从节点 0 到节点 4 的路径中的所有边的权重都是 6 。因此，答案为 2 。
第 3 条查询，将边 [1,3]、[5,2] 的权重变更为 6 。在这次操作之后，从节点 6 到节点 5 的路径中的所有边的权重都是 6 。因此，答案为 2 。
第 4 条查询，将边 [0,7]、[0,3]、[1,3] 的权重变更为 6 。在这次操作之后，从节点 7 到节点 4 的路径中的所有边的权重都是 6 。因此，答案为 3 。
对于每条查询 queries[i] ，可以证明 answer[i] 是使从 ai 到 bi 的路径中的所有边的权重相等的最小操作次数。

提示：

 * 1 <= n <= 104
 * edges.length == n - 1
 * edges[i].length == 3
 * 0 <= ui, vi < n
 * 1 <= wi <= 26
 * 生成的输入满足 edges 表示一棵有效的树
 * 1 <= queries.length == m <= 2 * 104
 * queries[i].length == 2
 * 0 <= ai, bi < n

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

```


check-if-strings-can-be-made-equal-with-operations-i

Check if Strings Can be Made Equal With Operations I

Prompt:
"""
给你两个字符串 s1 和 s2 ，两个字符串的长度都为 4 ，且只包含 小写 英文字母。

你可以对两个字符串中的 任意一个 执行以下操作 任意 次：

 * 选择两个下标 i 和 j 且满足 j - i = 2 ，然后 交换 这个字符串中两个下标对应的字符。

如果你可以让字符串 s1 和 s2 相等，那么返回 true ，否则返回 false 。

示例 1：

输入：s1 = "abcd", s2 = "cdab"
输出：true
解释： 我们可以对 s1 执行以下操作：
- 选择下标 i = 0 ，j = 2 ，得到字符串 s1 = "cbad" 。
- 选择下标 i = 1 ，j = 3 ，得到字符串 s1 = "cdab" = s2 。

示例 2：

输入：s1 = "abcd", s2 = "dacb"
输出：false
解释：无法让两个字符串相等。

提示：

 * s1.length == s2.length == 4
 * s1 和 s2 只包含小写英文字母。
"""
class Solution:
    def canBeEqual(self, s1: str, s2: str) -> bool:

给你两个字符串 s1 和 s2 ，两个字符串的长度都为 4 ，且只包含 小写 英文字母。

你可以对两个字符串中的 任意一个 执行以下操作 任意 次：

 * 选择两个下标 i 和 j 且满足 j - i = 2 ，然后 交换 这个字符串中两个下标对应的字符。

如果你可以让字符串 s1 和 s2 相等，那么返回 true ，否则返回 false 。

示例 1：

输入：s1 = "abcd", s2 = "cdab"
输出：true
解释： 我们可以对 s1 执行以下操作：
- 选择下标 i = 0 ，j = 2 ，得到字符串 s1 = "cbad" 。
- 选择下标 i = 1 ，j = 3 ，得到字符串 s1 = "cdab" = s2 。

示例 2：

输入：s1 = "abcd", s2 = "dacb"
输出：false
解释：无法让两个字符串相等。

提示：

 * s1.length == s2.length == 4
 * s1 和 s2 只包含小写英文字母。

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

```

my_solution = Solution()

test_input = { "s1": "abcd", "s2": "cdab" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "abcd", "s2": "dacb" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "gudo", "s2": "ogdu" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "bnxw", "s2": "bwxn" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "zzon", "s2": "zozn" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "cmpr", "s2": "rmcp" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "qnde", "s2": "flsi" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "vofo", "s2": "oofv" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "xsvc", "s2": "vcxs" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "hvsz", "s2": "hzsv" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "ifjz", "s2": "jzfi" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "zrmq", "s2": "mrzq" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "hazw", "s2": "pfmp" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "kina", "s2": "kina" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "fymg", "s2": "famj" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "riti", "s2": "riti" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "goze", "s2": "gezo" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "seeo", "s2": "vfvm" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "ybyd", "s2": "himj" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "gcdm", "s2": "dmgc" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "kvne", "s2": "nekv" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "cbyo", "s2": "cbyo" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "fezu", "s2": "zufe" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "homs", "s2": "fhdu" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "zlek", "s2": "zlek" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "bxqt", "s2": "xbtq" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "waso", "s2": "wyjd" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "nibi", "s2": "seua" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "oynw", "s2": "sgxl" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "ehui", "s2": "uhei" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "vchn", "s2": "jfwr" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "zgmt", "s2": "zgmt" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "eobz", "s2": "boez" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "zpzg", "s2": "zzpg" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "bbfp", "s2": "fbbp" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "vxqp", "s2": "xpvq" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "ihtv", "s2": "ixji" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "ahsk", "s2": "aksh" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "zexw", "s2": "miva" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "iicq", "s2": "ihda" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "kunv", "s2": "ziac" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "gqzd", "s2": "gqzd" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "ppeb", "s2": "ebpp" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "uouc", "s2": "ucuo" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "laxa", "s2": "xala" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "rbwe", "s2": "wbre" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "mswt", "s2": "wsmt" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "yfyz", "s2": "deyv" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "jlai", "s2": "alji" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "uliu", "s2": "bsmu" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "bhag", "s2": "kuws" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "bvwr", "s2": "wrbv" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "safs", "s2": "safs" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "hzfp", "s2": "hpfz" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "xide", "s2": "dixe" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "qpye", "s2": "qpye" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "zaus", "s2": "zsua" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "lpsc", "s2": "cslp" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "taxc", "s2": "taxc" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "kkjc", "s2": "kcjk" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "pshr", "s2": "prhs" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "kpdr", "s2": "djoe" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "vzla", "s2": "lzva" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "tcar", "s2": "tacr" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "zkyt", "s2": "yfzr" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "puwg", "s2": "pgwu" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "ownv", "s2": "ovnw" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "rayz", "s2": "bpnf" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "zbwg", "s2": "wbzg" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "rypk", "s2": "pyrk" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "qchw", "s2": "bcqn" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "qtpf", "s2": "qfpt" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "apnl", "s2": "nlap" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "pkmh", "s2": "mkph" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "ouxw", "s2": "xuow" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "dlgd", "s2": "gdld" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "xbcx", "s2": "cxxb" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "eaba", "s2": "uaul" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "fyro", "s2": "rofy" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "bzqb", "s2": "bzqb" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "zyjv", "s2": "xjzr" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "jdvv", "s2": "djvv" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "nyxb", "s2": "ocry" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "gxlx", "s2": "lxgx" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "kgkr", "s2": "krkg" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "edfw", "s2": "fdew" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "vxkq", "s2": "kqxv" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "qnjc", "s2": "jivc" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "zzaf", "s2": "azzf" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "esgr", "s2": "gres" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "meuu", "s2": "yqlh" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "gjda", "s2": "djga" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "qaqz", "s2": "qaqz" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "legy", "s2": "lyge" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "eeum", "s2": "emue" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "vsvs", "s2": "vsvs" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "mxlk", "s2": "mxlk" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "nbre", "s2": "renb" }
assert my_solution.canBeEqual(**test_input) == True

test_input = { "s1": "erfk", "s2": "gmfy" }
assert my_solution.canBeEqual(**test_input) == False

test_input = { "s1": "gsic", "s2": "snvs" }
assert my_solution.canBeEqual(**test_input) == False


check-if-strings-can-be-made-equal-with-operations-ii

Check if Strings Can be Made Equal With Operations II

Prompt:
"""
给你两个字符串 s1 和 s2 ，两个字符串长度都为 n ，且只包含 小写 英文字母。

你可以对两个字符串中的 任意一个 执行以下操作 任意 次：

 * 选择两个下标 i 和 j ，满足 i < j 且 j - i 是 偶数，然后 交换 这个字符串中两个下标对应的字符。

如果你可以让字符串 s1 和 s2 相等，那么返回 true ，否则返回 false 。

示例 1：

输入：s1 = "abcdba", s2 = "cabdab"
输出：true
解释：我们可以对 s1 执行以下操作：
- 选择下标 i = 0 ，j = 2 ，得到字符串 s1 = "cbadba" 。
- 选择下标 i = 2 ，j = 4 ，得到字符串 s1 = "cbbdaa" 。
- 选择下标 i = 1 ，j = 5 ，得到字符串 s1 = "cabdab" = s2 。

示例 2：

输入：s1 = "abe", s2 = "bea"
输出：false
解释：无法让两个字符串相等。

提示：

 * n == s1.length == s2.length
 * 1 <= n <= 105
 * s1 和 s2 只包含小写英文字母。
"""
class Solution:
    def checkStrings(self, s1: str, s2: str) -> bool:

给你两个字符串 s1 和 s2 ，两个字符串长度都为 n ，且只包含 小写 英文字母。

你可以对两个字符串中的 任意一个 执行以下操作 任意 次：

 * 选择两个下标 i 和 j ，满足 i < j 且 j - i 是 偶数，然后 交换 这个字符串中两个下标对应的字符。

如果你可以让字符串 s1 和 s2 相等，那么返回 true ，否则返回 false 。

示例 1：

输入：s1 = "abcdba", s2 = "cabdab"
输出：true
解释：我们可以对 s1 执行以下操作：
- 选择下标 i = 0 ，j = 2 ，得到字符串 s1 = "cbadba" 。
- 选择下标 i = 2 ，j = 4 ，得到字符串 s1 = "cbbdaa" 。
- 选择下标 i = 1 ，j = 5 ，得到字符串 s1 = "cabdab" = s2 。

示例 2：

输入：s1 = "abe", s2 = "bea"
输出：false
解释：无法让两个字符串相等。

提示：

 * n == s1.length == s2.length
 * 1 <= n <= 105
 * s1 和 s2 只包含小写英文字母。

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

```

my_solution = Solution()

test_input = { "s1": "abe", "s2": "bea" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "abcdba", "s2": "cabdab" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "ublnlasppynwgx", "s2": "ganplbuylnswpx" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "jghn", "s2": "jghn" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "pqtsprqmvi", "s2": "qrvqpitmps" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "aavizsxpqhxztrwi", "s2": "zvisqatzpaxhixwr" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "slmqqdbrwyvm", "s2": "qyldmmwsrqvb" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "shvqocguj", "s2": "vqsghujco" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "ktjpralqanofuuqsyal", "s2": "qjlornpasktfuyluaqa" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "mgflranpdjdkrh", "s2": "fpcgobmkdxbzyl" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "usvpwcehhvlg", "s2": "ehuvvshcwplg" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "jh", "s2": "fy" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "kfqofkvsoiiirznw", "s2": "hosthwbinxrsikkf" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "ppmfd", "s2": "pfdpm" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "ntuuwwh", "s2": "jyjwmdf" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "lcgcm", "s2": "brdxe" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "hjswnccgwjcapko", "s2": "acwjnjoscchgwpk" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "epjtzubboiallzd", "s2": "dboilpzzjteualb" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "c", "s2": "c" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "oziiqbotydegrm", "s2": "ytizriobogqmed" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "ztmuzn", "s2": "muztzn" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "jkzcqlh", "s2": "hkqczlj" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "qnh", "s2": "cmq" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "azagmtvhske", "s2": "mkazstvhage" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "jitb", "s2": "zqbg" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "tgznpamgczyvqjzvp", "s2": "mpyzvzzjvaqntgpgc" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "tcl", "s2": "lct" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "datuhdkoqe", "s2": "hetddokuqa" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "ztnpdilyrxz", "s2": "yxzitnrdlzp" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "vx", "s2": "zv" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "tpfcyceq", "s2": "fceqtpyc" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "rcugebinbszkhy", "s2": "zkebryhcbginus" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "ryykp", "s2": "rkpyy" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "lpyfmysemgoxgawwr", "s2": "wfoyspygralemxgwm" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "bfylavpyffcnj", "s2": "cljfbfyvpnayf" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "chhbmikpp", "s2": "hpcimbkhp" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "nateujd", "s2": "jeutnad" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "sxrjofoedghtplnex", "s2": "sgdeolnepthfojrxx" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "ajvfujrczdciilihi", "s2": "jcriaviuiflicdhzj" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "gajpuahzcexdunltldh", "s2": "xxatubgvqzmxjvzcxah" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "hnisnfvikgrhkfoe", "s2": "hgkivsifrekfonnh" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "fvfsxftpuemgpnkzz", "s2": "mgknxpuztffvzepsf" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "zrwzpibwp", "s2": "pwpiwzbrz" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "zoqpcssnhugxffcptsj", "s2": "chgospjssfxnfpcuqzt" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "ldpjhj", "s2": "jdlpjh" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "zodbh", "s2": "pqdpy" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "mdcvitezgqur", "s2": "mvigcqrdeztu" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "rdyau", "s2": "dyrau" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "pyymcw", "s2": "ptlqxp" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "ebicv", "s2": "vibce" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "xkzknvrbvajwbj", "s2": "rnkwzbvvxkjbja" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "zoxpiqxvnk", "s2": "xvkpxinqoz" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "obhmqltgmoszljeyh", "s2": "ogmmlbhoeysjtlhzq" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "wfsdirrheuglhfkbjk", "s2": "wfsuhhglifkrebrdjk" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "shn", "s2": "hsn" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "xdicugry", "s2": "igucxdry" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "bkfmkrbybim", "s2": "brbimkkmbyf" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "dwowyfgreakdvfi", "s2": "yfiddfvwerkaowg" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "bdywnvbgmum", "s2": "guymbwdbnmv" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "tmujoqerfvupnyy", "s2": "uvortyfmuqypnje" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "hggckwudke", "s2": "ylkgulkehd" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "zrppcm", "s2": "okurkg" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "ennl", "s2": "ennl" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "spznlxodciidngyvvkl", "s2": "lnvnzdixivoglydscpk" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "nxezcoklmdbekyjp", "s2": "cdkenlkyeomxjzbp" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "yui", "s2": "iyu" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "zphe", "s2": "hpze" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "oyjngnej", "s2": "oynjjeng" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "kvwdssgl", "s2": "wskxsdgv" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "ozzfbhzkowpcv", "s2": "vzpwzkbhzfoco" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "h", "s2": "h" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "mqkdv", "s2": "kqvdm" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "hphfqesitgprud", "s2": "tpisuhqhfgdrpe" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "yrbto", "s2": "orytb" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "lvahby", "s2": "ilbyaz" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "bbaiabphflgyfo", "s2": "bhglybaoaipbff" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "uielps", "s2": "uselpi" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "ftyhgkgwg", "s2": "gtfhgwgky" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "mzrfxrwlliuoi", "s2": "llrouzirwimfx" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "drofbzocwolcznzfi", "s2": "wzocdnirzfbclozfo" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "popefwbkepdxy", "s2": "pxbwpeekfoypd" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "swgzqluzcvhskegvdry", "s2": "seuwkvclqzyvdsgrgzh" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "hik", "s2": "ihk" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "zq", "s2": "zq" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "igdzd", "s2": "phcyi" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "cazutcxkhcklpuogt", "s2": "ockghuukctcztxapl" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "bx", "s2": "bx" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "bkujvjwgjzxdzuw", "s2": "zgjubjwkwzxdujv" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "ujpudt", "s2": "dtujpu" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "hkalpd", "s2": "hlpkad" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "kbcpjzadbv", "s2": "dsgzcapzao" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "rubbbf", "s2": "rbbubf" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "ybudbyrlmiddsxks", "s2": "nuyyabyisyptvdnb" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "wiijtcgqez", "s2": "ctqzwjgiei" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "bgalfvefwmhodexazkd", "s2": "fbgmdfholzakvxaweed" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "oxlphorosradotpshnt", "s2": "hdotpaoorosrlhtsxpn" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "mnvnzakjaymsxhojq", "s2": "oaxjoeanksmyqmglm" }
assert my_solution.checkStrings(**test_input) == False

test_input = { "s1": "hsm", "s2": "hsm" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "qgloiyhewunm", "s2": "qehuwonmiylg" }
assert my_solution.checkStrings(**test_input) == True

test_input = { "s1": "drdu", "s2": "dudr" }
assert my_solution.checkStrings(**test_input) == True


maximum-sum-of-almost-unique-subarray

Maximum Sum of Almost Unique Subarray

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

请你返回 nums 中长度为 k 的 几乎唯一 子数组的 最大和 ，如果不存在几乎唯一子数组，请你返回 0 。

如果 nums 的一个子数组有至少 m 个互不相同的元素，我们称它是 几乎唯一 子数组。

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

示例 1：

输入：nums = [2,6,7,3,1,7], m = 3, k = 4
输出：18
解释：总共有 3 个长度为 k = 4 的几乎唯一子数组。分别为 [2, 6, 7, 3] ，[6, 7, 3, 1] 和 [7, 3, 1, 7] 。这些子数组中，和最大的是 [2, 6, 7, 3] ，和为 18 。

示例 2：

输入：nums = [5,9,9,2,4,5,4], m = 1, k = 3
输出：23
解释：总共有 5 个长度为 k = 3 的几乎唯一子数组。分别为 [5, 9, 9] ，[9, 9, 2] ，[9, 2, 4] ，[2, 4, 5] 和 [4, 5, 4] 。这些子数组中，和最大的是 [5, 9, 9] ，和为 23 。

示例 3：

输入：nums = [1,2,1,2,1,2,1], m = 3, k = 3
输出：0
解释：输入数组中不存在长度为 k = 3 的子数组含有至少  m = 3 个互不相同元素的子数组。所以不存在几乎唯一子数组，最大和为 0 。

提示：

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

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

请你返回 nums 中长度为 k 的 几乎唯一 子数组的 最大和 ，如果不存在几乎唯一子数组，请你返回 0 。

如果 nums 的一个子数组有至少 m 个互不相同的元素，我们称它是 几乎唯一 子数组。

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

示例 1：

输入：nums = [2,6,7,3,1,7], m = 3, k = 4
输出：18
解释：总共有 3 个长度为 k = 4 的几乎唯一子数组。分别为 [2, 6, 7, 3] ，[6, 7, 3, 1] 和 [7, 3, 1, 7] 。这些子数组中，和最大的是 [2, 6, 7, 3] ，和为 18 。

示例 2：

输入：nums = [5,9,9,2,4,5,4], m = 1, k = 3
输出：23
解释：总共有 5 个长度为 k = 3 的几乎唯一子数组。分别为 [5, 9, 9] ，[9, 9, 2] ，[9, 2, 4] ，[2, 4, 5] 和 [4, 5, 4] 。这些子数组中，和最大的是 [5, 9, 9] ，和为 23 。

示例 3：

输入：nums = [1,2,1,2,1,2,1], m = 3, k = 3
输出：0
解释：输入数组中不存在长度为 k = 3 的子数组含有至少  m = 3 个互不相同元素的子数组。所以不存在几乎唯一子数组，最大和为 0 。

提示：

 * 1 <= nums.length <= 2 * 104
 * 1 <= m <= k <= nums.length
 * 1 <= nums[i] <= 109

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

```

my_solution = Solution()

test_input = { "nums": [2,6,7,3,1,7], "m": 3, "k": 4 }
assert my_solution.maxSum(**test_input) == 18

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


count-k-subsequences-of-a-string-with-maximum-beauty

Count K-Subsequences of a String With Maximum Beauty

Prompt:
"""
给你一个字符串 s 和一个整数 k 。

k 子序列指的是 s 的一个长度为 k 的 子序列 ，且所有字符都是 唯一 的，也就是说每个字符在子序列里只出现过一次。

定义 f(c) 为字符 c 在 s 中出现的次数。

k 子序列的 美丽值 定义为这个子序列中每一个字符 c 的 f(c) 之 和 。

比方说，s = "abbbdd" 和 k = 2 ，我们有：

 * f('a') = 1, f('b') = 3, f('d') = 2
 * s 的部分 k 子序列为：
   * "abbbdd" -> "ab" ，美丽值为 f('a') + f('b') = 4
   * "abbbdd" -> "ad" ，美丽值为 f('a') + f('d') = 3
   * "abbbdd" -> "bd" ，美丽值为 f('b') + f('d') = 5

请你返回一个整数，表示所有 k 子序列 里面 美丽值 是 最大值 的子序列数目。由于答案可能很大，将结果对 109 + 7 取余后返回。

一个字符串的子序列指的是从原字符串里面删除一些字符（也可能一个字符也不删除），不改变剩下字符顺序连接得到的新字符串。

注意：

 * f(c) 指的是字符 c 在字符串 s 的出现次数，不是在 k 子序列里的出现次数。
 * 两个 k 子序列如果有任何一个字符在原字符串中的下标不同，则它们是两个不同的子序列。所以两个不同的 k 子序列可能产生相同的字符串。

示例 1：

输入：s = "bcca", k = 2
输出：4
解释：s 中我们有 f('a') = 1 ，f('b') = 1 和 f('c') = 2 。
s 的 k 子序列为：
bcca ，美丽值为 f('b') + f('c') = 3
bcca ，美丽值为 f('b') + f('c') = 3
bcca ，美丽值为 f('b') + f('a') = 2
bcca ，美丽值为 f('c') + f('a') = 3
bcca ，美丽值为 f('c') + f('a') = 3
总共有 4 个 k 子序列美丽值为最大值 3 。
所以答案为 4 。

示例 2：

输入：s = "abbcd", k = 4
输出：2
解释：s 中我们有 f('a') = 1 ，f('b') = 2 ，f('c') = 1 和 f('d') = 1 。
s 的 k 子序列为：
abbcd ，美丽值为 f('a') + f('b') + f('c') + f('d') = 5
abbcd ，美丽值为 f('a') + f('b') + f('c') + f('d') = 5
总共有 2 个 k 子序列美丽值为最大值 5 。
所以答案为 2 。

提示：

 * 1 <= s.length <= 2 * 105
 * 1 <= k <= s.length
 * s 只包含小写英文字母。
"""
class Solution:
    def countKSubsequencesWithMaxBeauty(self, s: str, k: int) -> int:

给你一个字符串 s 和一个整数 k 。

k 子序列指的是 s 的一个长度为 k 的 子序列 ，且所有字符都是 唯一 的，也就是说每个字符在子序列里只出现过一次。

定义 f(c) 为字符 c 在 s 中出现的次数。

k 子序列的 美丽值 定义为这个子序列中每一个字符 c 的 f(c) 之 和 。

比方说，s = "abbbdd" 和 k = 2 ，我们有：

 * f('a') = 1, f('b') = 3, f('d') = 2
 * s 的部分 k 子序列为：
   * "abbbdd" -> "ab" ，美丽值为 f('a') + f('b') = 4
   * "abbbdd" -> "ad" ，美丽值为 f('a') + f('d') = 3
   * "abbbdd" -> "bd" ，美丽值为 f('b') + f('d') = 5

请你返回一个整数，表示所有 k 子序列 里面 美丽值 是 最大值 的子序列数目。由于答案可能很大，将结果对 109 + 7 取余后返回。

一个字符串的子序列指的是从原字符串里面删除一些字符（也可能一个字符也不删除），不改变剩下字符顺序连接得到的新字符串。

注意：

 * f(c) 指的是字符 c 在字符串 s 的出现次数，不是在 k 子序列里的出现次数。
 * 两个 k 子序列如果有任何一个字符在原字符串中的下标不同，则它们是两个不同的子序列。所以两个不同的 k 子序列可能产生相同的字符串。

示例 1：

输入：s = "bcca", k = 2
输出：4
解释：s 中我们有 f('a') = 1 ，f('b') = 1 和 f('c') = 2 。
s 的 k 子序列为：
bcca ，美丽值为 f('b') + f('c') = 3
bcca ，美丽值为 f('b') + f('c') = 3
bcca ，美丽值为 f('b') + f('a') = 2
bcca ，美丽值为 f('c') + f('a') = 3
bcca ，美丽值为 f('c') + f('a') = 3
总共有 4 个 k 子序列美丽值为最大值 3 。
所以答案为 4 。

示例 2：

输入：s = "abbcd", k = 4
输出：2
解释：s 中我们有 f('a') = 1 ，f('b') = 2 ，f('c') = 1 和 f('d') = 1 。
s 的 k 子序列为：
abbcd ，美丽值为 f('a') + f('b') + f('c') + f('d') = 5
abbcd ，美丽值为 f('a') + f('b') + f('c') + f('d') = 5
总共有 2 个 k 子序列美丽值为最大值 5 。
所以答案为 2 。

提示：

 * 1 <= s.length <= 2 * 105
 * 1 <= k <= s.length
 * s 只包含小写英文字母。

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

```

my_solution = Solution()

test_input = { "s": "bcca", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4

test_input = { "s": "abbcd", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "am", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "az", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "ci", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "dd", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0

test_input = { "s": "di", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "dw", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "ef", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "gq", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "hj", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "hx", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "ii", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0

test_input = { "s": "il", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "jb", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "kx", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "qh", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "qk", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "qr", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "rg", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "rn", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "st", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "tb", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "tl", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "xc", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "auy", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "axm", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "dqc", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "fkp", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "fmk", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "fvl", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "hcx", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "iua", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "kzb", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "mhb", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "nzo", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "oof", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0

test_input = { "s": "rfh", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "sty", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "sue", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "tba", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "tmc", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "wes", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "wvl", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "xho", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "xke", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "ysu", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "yxn", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "zco", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "zpq", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "axgn", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "dfyq", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6

test_input = { "s": "dogq", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6

test_input = { "s": "drbs", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6

test_input = { "s": "elex", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0

test_input = { "s": "fsaj", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4

test_input = { "s": "fxau", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6

test_input = { "s": "glbq", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "hzcj", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "minc", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4

test_input = { "s": "nkim", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4

test_input = { "s": "otpl", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6

test_input = { "s": "pvrz", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "qwmy", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "rliu", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "tpig", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6

test_input = { "s": "ucvh", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "vevt", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4

test_input = { "s": "xstt", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "ypmv", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4

test_input = { "s": "znoq", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 4

test_input = { "s": "bicnt", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5

test_input = { "s": "bnhom", "k": 5 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "culhr", "k": 5 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 1

test_input = { "s": "dpfki", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5

test_input = { "s": "dscbu", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10

test_input = { "s": "edwlo", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10

test_input = { "s": "ggsgo", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "guzzf", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "gzzzl", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 3

test_input = { "s": "kjojr", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6

test_input = { "s": "kvsds", "k": 5 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0

test_input = { "s": "ljdvp", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5

test_input = { "s": "mdccc", "k": 5 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0

test_input = { "s": "mmqny", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "mrbrj", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6

test_input = { "s": "pwtbx", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5

test_input = { "s": "qcxkr", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10

test_input = { "s": "qvauy", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5

test_input = { "s": "tzwoq", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10

test_input = { "s": "ufxge", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5

test_input = { "s": "unzxd", "k": 4 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5

test_input = { "s": "vhqqj", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 6

test_input = { "s": "vnkbt", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5

test_input = { "s": "wpbkz", "k": 2 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10

test_input = { "s": "xdgvy", "k": 1 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 5

test_input = { "s": "yelem", "k": 5 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 0

test_input = { "s": "zwkhq", "k": 3 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 10

test_input = { "s": "anxnfi", "k": 5 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2

test_input = { "s": "cfbyuf", "k": 5 }
assert my_solution.countKSubsequencesWithMaxBeauty(**test_input) == 2


furthest-point-from-origin

Furthest Point From Origin

Prompt:
"""
给你一个长度为 n 的字符串 moves ，该字符串仅由字符 'L'、'R' 和 '_' 组成。字符串表示你在一条原点为 0 的数轴上的若干次移动。

你的初始位置就在原点（0），第 i 次移动过程中，你可以根据对应字符选择移动方向：

 * 如果 moves[i] = 'L' 或 moves[i] = '_' ，可以选择向左移动一个单位距离
 * 如果 moves[i] = 'R' 或 moves[i] = '_' ，可以选择向右移动一个单位距离

移动 n 次之后，请你找出可以到达的距离原点 最远 的点，并返回 从原点到这一点的距离 。

示例 1：

输入：moves = "L_RL__R"
输出：3
解释：可以到达的距离原点 0 最远的点是 -3 ，移动的序列为 "LLRLLLR" 。

示例 2：

输入：moves = "_R__LL_"
输出：5
解释：可以到达的距离原点 0 最远的点是 -5 ，移动的序列为 "LRLLLLL" 。

示例 3：

输入：moves = "_______"
输出：7
解释：可以到达的距离原点 0 最远的点是 7 ，移动的序列为 "RRRRRRR" 。

提示：

 * 1 <= moves.length == n <= 50
 * moves 仅由字符 'L'、'R' 和 '_' 组成
"""
class Solution:
    def furthestDistanceFromOrigin(self, moves: str) -> int:

给你一个长度为 n 的字符串 moves ，该字符串仅由字符 'L'、'R' 和 '_' 组成。字符串表示你在一条原点为 0 的数轴上的若干次移动。

你的初始位置就在原点（0），第 i 次移动过程中，你可以根据对应字符选择移动方向：

 * 如果 moves[i] = 'L' 或 moves[i] = '_' ，可以选择向左移动一个单位距离
 * 如果 moves[i] = 'R' 或 moves[i] = '_' ，可以选择向右移动一个单位距离

移动 n 次之后，请你找出可以到达的距离原点 最远 的点，并返回 从原点到这一点的距离 。

示例 1：

输入：moves = "L_RL__R"
输出：3
解释：可以到达的距离原点 0 最远的点是 -3 ，移动的序列为 "LLRLLLR" 。

示例 2：

输入：moves = "_R__LL_"
输出：5
解释：可以到达的距离原点 0 最远的点是 -5 ，移动的序列为 "LRLLLLL" 。

示例 3：

输入：moves = "_______"
输出：7
解释：可以到达的距离原点 0 最远的点是 7 ，移动的序列为 "RRRRRRR" 。

提示：

 * 1 <= moves.length == n <= 50
 * moves 仅由字符 'L'、'R' 和 '_' 组成

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

```

my_solution = Solution()

test_input = { "moves": "L_RL__R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "_R__LL_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 5

test_input = { "moves": "_______" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 7

test_input = { "moves": "L" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "LL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 0

test_input = { "moves": "L_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 0

test_input = { "moves": "RR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "R_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "_L" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "_R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "__" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LLL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "LLR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "LL_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "LRL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "LRR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "LR_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "L_L" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "L_R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "L__" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "RLL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "RLR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "RL_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "RRL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "RRR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "RR_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "R_L" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "R_R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "R__" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "_LL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "_LR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "_L_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "_RL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 1

test_input = { "moves": "_RR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "_R_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "__L" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "__R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "___" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 3

test_input = { "moves": "LLLL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "LLLR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LLL_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "LLRL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LLRR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 0

test_input = { "moves": "LLR_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LL_L" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "LL_R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LL__" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "LRLL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LRLR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 0

test_input = { "moves": "LRL_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LRRL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 0

test_input = { "moves": "LRRR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LRR_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LR_L" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LR_R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "LR__" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "L_LL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "L_LR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "L_L_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "L_RL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "L_RR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "L_R_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "L__L" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "L__R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "L___" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "RLLL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RLLR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 0

test_input = { "moves": "RLL_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RLRL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 0

test_input = { "moves": "RLRR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RLR_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RL_L" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RL_R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RL__" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RRLL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 0

test_input = { "moves": "RRLR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RRL_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RRRL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RRRR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "RRR_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "RR_L" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "RR_R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "RR__" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "R_LL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "R_LR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "R_L_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "R_RL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "R_RR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "R_R_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "R__L" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "R__R" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "R___" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "_LLL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "_LLR" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2

test_input = { "moves": "_LL_" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 4

test_input = { "moves": "_LRL" }
assert my_solution.furthestDistanceFromOrigin(**test_input) == 2


find-the-minimum-possible-sum-of-a-beautiful-array

Find the Minimum Possible Sum of a Beautiful Array

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

如果数组 nums 满足下述条件，则称其为 美丽数组 。

 * nums.length == n.
 * nums 由两两互不相同的正整数组成。
 * 在范围 [0, n-1] 内，不存在 两个 不同 下标 i 和 j ，使得 nums[i] + nums[j] == target 。

返回符合条件的美丽数组所可能具备的 最小 和，并对结果进行取模 109 + 7。

示例 1：

输入：n = 2, target = 3
输出：4
解释：nums = [1,3] 是美丽数组。
- nums 的长度为 n = 2 。
- nums 由两两互不相同的正整数组成。
- 不存在两个不同下标 i 和 j ，使得 nums[i] + nums[j] == 3 。
可以证明 4 是符合条件的美丽数组所可能具备的最小和。

示例 2：

输入：n = 3, target = 3
输出：8
解释：
nums = [1,3,4] 是美丽数组。
- nums 的长度为 n = 3 。
- nums 由两两互不相同的正整数组成。
- 不存在两个不同下标 i 和 j ，使得 nums[i] + nums[j] == 3 。
可以证明 8 是符合条件的美丽数组所可能具备的最小和。

示例 3：

输入：n = 1, target = 1
输出：1
解释：nums = [1] 是美丽数组。

提示：

 * 1 <= n <= 109
 * 1 <= target <= 109
"""
class Solution:
    def minimumPossibleSum(self, n: int, target: int) -> int:

给你两个正整数：n 和 target 。

如果数组 nums 满足下述条件，则称其为 美丽数组 。

 * nums.length == n.
 * nums 由两两互不相同的正整数组成。
 * 在范围 [0, n-1] 内，不存在 两个 不同 下标 i 和 j ，使得 nums[i] + nums[j] == target 。

返回符合条件的美丽数组所可能具备的 最小 和，并对结果进行取模 109 + 7。

示例 1：

输入：n = 2, target = 3
输出：4
解释：nums = [1,3] 是美丽数组。
- nums 的长度为 n = 2 。
- nums 由两两互不相同的正整数组成。
- 不存在两个不同下标 i 和 j ，使得 nums[i] + nums[j] == 3 。
可以证明 4 是符合条件的美丽数组所可能具备的最小和。

示例 2：

输入：n = 3, target = 3
输出：8
解释：
nums = [1,3,4] 是美丽数组。
- nums 的长度为 n = 3 。
- nums 由两两互不相同的正整数组成。
- 不存在两个不同下标 i 和 j ，使得 nums[i] + nums[j] == 3 。
可以证明 8 是符合条件的美丽数组所可能具备的最小和。

示例 3：

输入：n = 1, target = 1
输出：1
解释：nums = [1] 是美丽数组。

提示：

 * 1 <= n <= 109
 * 1 <= target <= 109

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

```

my_solution = Solution()

test_input = { "n": 2, "target": 3 }
assert my_solution.minimumPossibleSum(**test_input) == 4

test_input = { "n": 3, "target": 3 }
assert my_solution.minimumPossibleSum(**test_input) == 8

test_input = { "n": 1, "target": 1 }
assert my_solution.minimumPossibleSum(**test_input) == 1

test_input = { "n": 16, "target": 6 }
assert my_solution.minimumPossibleSum(**test_input) == 162

test_input = { "n": 16, "target": 32 }
assert my_solution.minimumPossibleSum(**test_input) == 136

test_input = { "n": 13, "target": 50 }
assert my_solution.minimumPossibleSum(**test_input) == 91

test_input = { "n": 36, "target": 21 }
assert my_solution.minimumPossibleSum(**test_input) == 926

test_input = { "n": 40, "target": 17 }
assert my_solution.minimumPossibleSum(**test_input) == 1076

test_input = { "n": 37, "target": 46 }
assert my_solution.minimumPossibleSum(**test_input) == 1011

test_input = { "n": 33, "target": 7 }
assert my_solution.minimumPossibleSum(**test_input) == 651

test_input = { "n": 42, "target": 46 }
assert my_solution.minimumPossibleSum(**test_input) == 1321

test_input = { "n": 46, "target": 29 }
assert my_solution.minimumPossibleSum(**test_input) == 1529

test_input = { "n": 9, "target": 43 }
assert my_solution.minimumPossibleSum(**test_input) == 45

test_input = { "n": 30, "target": 31 }
assert my_solution.minimumPossibleSum(**test_input) == 690

test_input = { "n": 14, "target": 47 }
assert my_solution.minimumPossibleSum(**test_input) == 105

test_input = { "n": 5, "target": 3 }
assert my_solution.minimumPossibleSum(**test_input) == 19

test_input = { "n": 41, "target": 23 }
assert my_solution.minimumPossibleSum(**test_input) == 1191

test_input = { "n": 17, "target": 13 }
assert my_solution.minimumPossibleSum(**test_input) == 219

test_input = { "n": 9, "target": 13 }
assert my_solution.minimumPossibleSum(**test_input) == 63

test_input = { "n": 29, "target": 18 }
assert my_solution.minimumPossibleSum(**test_input) == 595

test_input = { "n": 21, "target": 14 }
assert my_solution.minimumPossibleSum(**test_input) == 315

test_input = { "n": 4, "target": 6 }
assert my_solution.minimumPossibleSum(**test_input) == 12

test_input = { "n": 38, "target": 15 }
assert my_solution.minimumPossibleSum(**test_input) == 958

test_input = { "n": 14, "target": 7 }
assert my_solution.minimumPossibleSum(**test_input) == 138

test_input = { "n": 18, "target": 26 }
assert my_solution.minimumPossibleSum(**test_input) == 231

test_input = { "n": 11, "target": 15 }
assert my_solution.minimumPossibleSum(**test_input) == 94

test_input = { "n": 7, "target": 8 }
assert my_solution.minimumPossibleSum(**test_input) == 37

test_input = { "n": 11, "target": 22 }
assert my_solution.minimumPossibleSum(**test_input) == 66

test_input = { "n": 36, "target": 11 }
assert my_solution.minimumPossibleSum(**test_input) == 821

test_input = { "n": 18, "target": 29 }
assert my_solution.minimumPossibleSum(**test_input) == 227

test_input = { "n": 26, "target": 17 }
assert my_solution.minimumPossibleSum(**test_input) == 495

test_input = { "n": 37, "target": 13 }
assert my_solution.minimumPossibleSum(**test_input) == 889

test_input = { "n": 46, "target": 38 }
assert my_solution.minimumPossibleSum(**test_input) == 1567

test_input = { "n": 13, "target": 7 }
assert my_solution.minimumPossibleSum(**test_input) == 121

test_input = { "n": 33, "target": 34 }
assert my_solution.minimumPossibleSum(**test_input) == 817

test_input = { "n": 39, "target": 12 }
assert my_solution.minimumPossibleSum(**test_input) == 945

test_input = { "n": 1, "target": 45 }
assert my_solution.minimumPossibleSum(**test_input) == 1

test_input = { "n": 37, "target": 36 }
assert my_solution.minimumPossibleSum(**test_input) == 1026

test_input = { "n": 16, "target": 19 }
assert my_solution.minimumPossibleSum(**test_input) == 199

test_input = { "n": 22, "target": 15 }
assert my_solution.minimumPossibleSum(**test_input) == 358

test_input = { "n": 34, "target": 42 }
assert my_solution.minimumPossibleSum(**test_input) == 855

test_input = { "n": 50, "target": 22 }
assert my_solution.minimumPossibleSum(**test_input) == 1665

test_input = { "n": 42, "target": 44 }
assert my_solution.minimumPossibleSum(**test_input) == 1323

test_input = { "n": 40, "target": 8 }
assert my_solution.minimumPossibleSum(**test_input) == 928

test_input = { "n": 7, "target": 19 }
assert my_solution.minimumPossibleSum(**test_input) == 28

test_input = { "n": 44, "target": 10 }
assert my_solution.minimumPossibleSum(**test_input) == 1146

test_input = { "n": 21, "target": 6 }
assert my_solution.minimumPossibleSum(**test_input) == 267

test_input = { "n": 27, "target": 26 }
assert my_solution.minimumPossibleSum(**test_input) == 546

test_input = { "n": 49, "target": 4 }
assert my_solution.minimumPossibleSum(**test_input) == 1272

test_input = { "n": 35, "target": 2 }
assert my_solution.minimumPossibleSum(**test_input) == 630

test_input = { "n": 32, "target": 29 }
assert my_solution.minimumPossibleSum(**test_input) == 780

test_input = { "n": 20, "target": 41 }
assert my_solution.minimumPossibleSum(**test_input) == 210

test_input = { "n": 30, "target": 48 }
assert my_solution.minimumPossibleSum(**test_input) == 603

test_input = { "n": 12, "target": 34 }
assert my_solution.minimumPossibleSum(**test_input) == 78

test_input = { "n": 50, "target": 44 }
assert my_solution.minimumPossibleSum(**test_input) == 1863

test_input = { "n": 42, "target": 26 }
assert my_solution.minimumPossibleSum(**test_input) == 1251

test_input = { "n": 3, "target": 18 }
assert my_solution.minimumPossibleSum(**test_input) == 6

test_input = { "n": 11, "target": 3 }
assert my_solution.minimumPossibleSum(**test_input) == 76

test_input = { "n": 38, "target": 29 }
assert my_solution.minimumPossibleSum(**test_input) == 1077

test_input = { "n": 17, "target": 24 }
assert my_solution.minimumPossibleSum(**test_input) == 208

test_input = { "n": 50, "target": 31 }
assert my_solution.minimumPossibleSum(**test_input) == 1800

test_input = { "n": 32, "target": 41 }
assert my_solution.minimumPossibleSum(**test_input) == 768

test_input = { "n": 12, "target": 24 }
assert my_solution.minimumPossibleSum(**test_input) == 78

test_input = { "n": 35, "target": 43 }
assert my_solution.minimumPossibleSum(**test_input) == 924

test_input = { "n": 9, "target": 47 }
assert my_solution.minimumPossibleSum(**test_input) == 45

test_input = { "n": 32, "target": 26 }
assert my_solution.minimumPossibleSum(**test_input) == 756

test_input = { "n": 6, "target": 42 }
assert my_solution.minimumPossibleSum(**test_input) == 21

test_input = { "n": 11, "target": 1 }
assert my_solution.minimumPossibleSum(**test_input) == 66

test_input = { "n": 11, "target": 24 }
assert my_solution.minimumPossibleSum(**test_input) == 66

test_input = { "n": 39, "target": 38 }
assert my_solution.minimumPossibleSum(**test_input) == 1140

test_input = { "n": 18, "target": 8 }
assert my_solution.minimumPossibleSum(**test_input) == 213

test_input = { "n": 29, "target": 5 }
assert my_solution.minimumPossibleSum(**test_input) == 489

test_input = { "n": 44, "target": 6 }
assert my_solution.minimumPossibleSum(**test_input) == 1072

test_input = { "n": 29, "target": 30 }
assert my_solution.minimumPossibleSum(**test_input) == 631

test_input = { "n": 13, "target": 47 }
assert my_solution.minimumPossibleSum(**test_input) == 91

test_input = { "n": 46, "target": 21 }
assert my_solution.minimumPossibleSum(**test_input) == 1441

test_input = { "n": 46, "target": 6 }
assert my_solution.minimumPossibleSum(**test_input) == 1167

test_input = { "n": 27, "target": 30 }
assert my_solution.minimumPossibleSum(**test_input) == 546

test_input = { "n": 5, "target": 35 }
assert my_solution.minimumPossibleSum(**test_input) == 15

test_input = { "n": 12, "target": 32 }
assert my_solution.minimumPossibleSum(**test_input) == 78

test_input = { "n": 13, "target": 39 }
assert my_solution.minimumPossibleSum(**test_input) == 91

test_input = { "n": 10, "target": 11 }
assert my_solution.minimumPossibleSum(**test_input) == 80

test_input = { "n": 46, "target": 14 }
assert my_solution.minimumPossibleSum(**test_input) == 1315

test_input = { "n": 37, "target": 18 }
assert my_solution.minimumPossibleSum(**test_input) == 927

test_input = { "n": 32, "target": 8 }
assert my_solution.minimumPossibleSum(**test_input) == 612

test_input = { "n": 26, "target": 14 }
assert my_solution.minimumPossibleSum(**test_input) == 465

test_input = { "n": 33, "target": 41 }
assert my_solution.minimumPossibleSum(**test_input) == 821

test_input = { "n": 44, "target": 39 }
assert my_solution.minimumPossibleSum(**test_input) == 1465

test_input = { "n": 3, "target": 21 }
assert my_solution.minimumPossibleSum(**test_input) == 6

test_input = { "n": 9, "target": 11 }
assert my_solution.minimumPossibleSum(**test_input) == 65

test_input = { "n": 16, "target": 43 }
assert my_solution.minimumPossibleSum(**test_input) == 136

test_input = { "n": 7, "target": 22 }
assert my_solution.minimumPossibleSum(**test_input) == 28

test_input = { "n": 21, "target": 49 }
assert my_solution.minimumPossibleSum(**test_input) == 231

test_input = { "n": 23, "target": 16 }
assert my_solution.minimumPossibleSum(**test_input) == 381

test_input = { "n": 33, "target": 32 }
assert my_solution.minimumPossibleSum(**test_input) == 816

test_input = { "n": 22, "target": 1 }
assert my_solution.minimumPossibleSum(**test_input) == 253

test_input = { "n": 5, "target": 47 }
assert my_solution.minimumPossibleSum(**test_input) == 15

test_input = { "n": 38, "target": 7 }
assert my_solution.minimumPossibleSum(**test_input) == 846

test_input = { "n": 38, "target": 24 }
assert my_solution.minimumPossibleSum(**test_input) == 1027

test_input = { "n": 13, "target": 36 }
assert my_solution.minimumPossibleSum(**test_input) == 91


minimum-operations-to-form-subsequence-with-target-sum

Minimum Operations to Form Subsequence With Target Sum

Prompt:
"""
给你一个下标从 0 开始的数组 nums ，它包含 非负 整数，且全部为 2 的幂，同时给你一个整数 target 。

一次操作中，你必须对数组做以下修改：

 * 选择数组中一个元素 nums[i] ，满足 nums[i] > 1 。
 * 将 nums[i] 从数组中删除。
 * 在 nums 的 末尾 添加 两个 数，值都为 nums[i] / 2 。

你的目标是让 nums 的一个 子序列 的元素和等于 target ，请你返回达成这一目标的 最少操作次数 。如果无法得到这样的子序列，请你返回 -1 。

数组中一个 子序列 是通过删除原数组中一些元素，并且不改变剩余元素顺序得到的剩余数组。

示例 1：

输入：nums = [1,2,8], target = 7
输出：1
解释：第一次操作中，我们选择元素 nums[2] 。数组变为 nums = [1,2,4,4] 。
这时候，nums 包含子序列 [1,2,4] ，和为 7 。
无法通过更少的操作得到和为 7 的子序列。

示例 2：

输入：nums = [1,32,1,2], target = 12
输出：2
解释：第一次操作中，我们选择元素 nums[1] 。数组变为 nums = [1,1,2,16,16] 。
第二次操作中，我们选择元素 nums[3] 。数组变为 nums = [1,1,2,16,8,8] 。
这时候，nums 包含子序列 [1,1,2,8] ，和为 12 。
无法通过更少的操作得到和为 12 的子序列。

示例 3：

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

提示：

 * 1 <= nums.length <= 1000
 * 1 <= nums[i] <= 230
 * nums 只包含非负整数，且均为 2 的幂。
 * 1 <= target < 231
"""
class Solution:
    def minOperations(self, nums: List[int], target: int) -> int:

给你一个下标从 0 开始的数组 nums ，它包含 非负 整数，且全部为 2 的幂，同时给你一个整数 target 。

一次操作中，你必须对数组做以下修改：

 * 选择数组中一个元素 nums[i] ，满足 nums[i] > 1 。
 * 将 nums[i] 从数组中删除。
 * 在 nums 的 末尾 添加 两个 数，值都为 nums[i] / 2 。

你的目标是让 nums 的一个 子序列 的元素和等于 target ，请你返回达成这一目标的 最少操作次数 。如果无法得到这样的子序列，请你返回 -1 。

数组中一个 子序列 是通过删除原数组中一些元素，并且不改变剩余元素顺序得到的剩余数组。

示例 1：

输入：nums = [1,2,8], target = 7
输出：1
解释：第一次操作中，我们选择元素 nums[2] 。数组变为 nums = [1,2,4,4] 。
这时候，nums 包含子序列 [1,2,4] ，和为 7 。
无法通过更少的操作得到和为 7 的子序列。

示例 2：

输入：nums = [1,32,1,2], target = 12
输出：2
解释：第一次操作中，我们选择元素 nums[1] 。数组变为 nums = [1,1,2,16,16] 。
第二次操作中，我们选择元素 nums[3] 。数组变为 nums = [1,1,2,16,8,8] 。
这时候，nums 包含子序列 [1,1,2,8] ，和为 12 。
无法通过更少的操作得到和为 12 的子序列。

示例 3：

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

提示：

 * 1 <= nums.length <= 1000
 * 1 <= nums[i] <= 230
 * nums 只包含非负整数，且均为 2 的幂。
 * 1 <= target < 231

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

```

my_solution = Solution()

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

test_input = { "nums": [128,256,32,1,1,1], "target": 5 }
assert my_solution.minOperations(**test_input) == 3

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

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

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

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

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

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

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

test_input = { "nums": [128,1,256,1,1,1,32], "target": 6 }
assert my_solution.minOperations(**test_input) == 3

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

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

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

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

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

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

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

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

test_input = { "nums": [16,64,4,128], "target": 6 }
assert my_solution.minOperations(**test_input) == 3

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

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

test_input = { "nums": [64,128,1,32,1,2], "target": 6 }
assert my_solution.minOperations(**test_input) == 3

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

test_input = { "nums": [1,128,1,256,32,1], "target": 6 }
assert my_solution.minOperations(**test_input) == 3

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

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

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

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

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

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

test_input = { "nums": [128,1,1,1,64,32], "target": 6 }
assert my_solution.minOperations(**test_input) == 3

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

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

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

test_input = { "nums": [1,1,256,1,64,1,128], "target": 6 }
assert my_solution.minOperations(**test_input) == 4

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

test_input = { "nums": [2,32,128,1,64], "target": 6 }
assert my_solution.minOperations(**test_input) == 3

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

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

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

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

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

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

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

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

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

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

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

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

test_input = { "nums": [32,1,2,1,256,128], "target": 7 }
assert my_solution.minOperations(**test_input) == 3

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

test_input = { "nums": [1,8,256,32,1], "target": 7 }
assert my_solution.minOperations(**test_input) == 2

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

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

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

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

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

test_input = { "nums": [64,1,32,256,1,1,1], "target": 7 }
assert my_solution.minOperations(**test_input) == 3

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

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

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

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

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

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

test_input = { "nums": [64,256,1,1,1,32,2], "target": 7 }
assert my_solution.minOperations(**test_input) == 3

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

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

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

test_input = { "nums": [2,1,8,256,1,128,1], "target": 7 }
assert my_solution.minOperations(**test_input) == 1

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

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

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

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