You are an expert Python programmer. Write correct, efficient Python 3 code that solves the problem and passes all tests. Output the code in the following format: ```python
<code>
```

PROBLEM:
You are given an integer array nums of length n.
Your goal is to start at index 0 and reach index n - 1. You can only jump to indices greater than your current index.
The score for a jump from index i to index j is calculated as (j - i) * nums[i].
Return the maximum possible total score by the time you reach the last index.

Example 1:

Input: nums = [1,3,1,5]
Output: 7
Explanation:
First, jump to index 1 and then jump to the last index. The final score is 1 * 1 + 2 * 3 = 7.

Example 2:

Input: nums = [4,3,1,3,2]
Output: 16
Explanation:
Jump directly to the last index. The final score is 4 * 4 = 16.

Constraints:

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

Your solution to the problem should be a method of the class Solution called findMaximumScore and should pass all tests. Use the following starter code:
```python
class Solution:
    def findMaximumScore(self, nums: List[int]) -> int:
        # Add your code here
```

SOLUTION:

Question:
PROBLEM:
You are given an integer array nums of length n.
Your goal is to start at index 0 and reach index n - 1. You can only jump to indices greater than your current index.
The score for a jump from index i to index j is calculated as (j - i) * nums[i].
Return the maximum possible total score by the time you reach the last index.

Example 1:

Input: nums = [1,3,1,5]
Output: 7
Explanation:
First, jump to index 1 and then jump to the last index. The final score is 1 * 1 + 2 * 3 = 7.

Example 2:

Input: nums = [4,3,1,3,2]
Output: 16
Explanation:
Jump directly to the last index. The final score is 4 * 4 = 16.

Constraints:

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

Your solution to the problem should be a method of the class Solution called findMaximumScore and should pass all tests. Use the following starter code:
```python
class Solution:
    def findMaximumScore(self, nums: List[int]) -> int:
        # Add your code here
```

SOLUTION:

assert Solution().findMaximumScore(nums = [2,3,5,6,7,8]) == 23

assert Solution().findMaximumScore(nums = [10,9,8,7,6,5,4,3,2,1]) == 90

assert Solution().findMaximumScore(nums = [2,4,6,8,10]) == 20

assert Solution().findMaximumScore(nums = [4,3,1,3,2]) == 16

assert Solution().findMaximumScore(nums = [1,2,3,4,5,6,7,8,9,10]) == 45

assert Solution().findMaximumScore(nums = [2,1,4,5,3]) == 13

assert Solution().findMaximumScore(nums = [1,3,1,5]) == 7

assert Solution().findMaximumScore(nums = [10,20,30,40,50]) == 100

assert Solution().findMaximumScore(nums = [5,5,5,5,5]) == 20

assert Solution().findMaximumScore(nums = [5,6,7,8,9]) == 26

assert Solution().findMaximumScore(nums = [1,1,1,1,1,1,1]) == 6

assert Solution().findMaximumScore(nums = [10,9,8,7,6]) == 40

assert Solution().findMaximumScore(nums = [1,2,3,4,5]) == 10

assert Solution().findMaximumScore(nums = [1,1,1,1,1,1,1,1,1,1]) == 9

assert Solution().findMaximumScore(nums = [1,1,1,1,1]) == 4

assert Solution().findMaximumScore(nums = [2,3,6,1,5]) == 17

assert Solution().findMaximumScore(nums = [5,4,3,2,1]) == 20

assert Solution().findMaximumScore(nums = [10,10,10,10,10]) == 40

assert Solution().findMaximumScore(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 72

assert Solution().findMaximumScore(nums = [1, 100, 1, 100, 1, 100, 1]) == 501

assert Solution().findMaximumScore(nums = [9,8,7,6,5,4,3,2,1,10]) == 81

assert Solution().findMaximumScore(nums = [10, 1, 1, 1, 1, 1, 10]) == 60

assert Solution().findMaximumScore(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 81

assert Solution().findMaximumScore(nums = [2, 3, 5, 1, 4, 6, 2, 3, 1]) == 38

assert Solution().findMaximumScore(nums = [1,2,3,10,5,1,2,3,4,1]) == 66

assert Solution().findMaximumScore(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1000]) == 9

assert Solution().findMaximumScore(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 45

assert Solution().findMaximumScore(nums = [5, 3, 9, 2, 8, 6, 1, 7, 4, 10]) == 73

assert Solution().findMaximumScore(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9

assert Solution().findMaximumScore(nums = [1, 5, 3, 4, 2, 6, 8, 7, 9, 10]) == 52

assert Solution().findMaximumScore(nums = [10,1,1,1,1,1,1,1,1,10]) == 90

assert Solution().findMaximumScore(nums = [3, 5, 7, 9, 2, 4, 6, 8, 10, 1]) == 70

Answer: assert Solution().findMaximumScore(nums = [2,3,5,6,7,8]) == 23

Answer: assert Solution().findMaximumScore(nums = [10,9,8,7,6,5,4,3,2,1]) == 90

Answer: assert Solution().findMaximumScore(nums = [2,4,6,8,10]) == 20

Answer: assert Solution().findMaximumScore(nums = [4,3,1,3,2]) == 16

Answer: assert Solution().findMaximumScore(nums = [1,2,3,4,5,6,7,8,9,10]) == 45

Answer: assert Solution().findMaximumScore(nums = [2,1,4,5,3]) == 13

Answer: assert Solution().findMaximumScore(nums = [1,3,1,5]) == 7

Answer: assert Solution().findMaximumScore(nums = [10,20,30,40,50]) == 100

Answer: assert Solution().findMaximumScore(nums = [5,5,5,5,5]) == 20

Answer: assert Solution().findMaximumScore(nums = [5,6,7,8,9]) == 26

Answer: assert Solution().findMaximumScore(nums = [100000, 1, 100000, 1, 100000]) == 400000

Answer: assert Solution().findMaximumScore(nums = [1,1,1,1,1,1,1]) == 6

Answer: assert Solution().findMaximumScore(nums = [10,9,8,7,6]) == 40

Answer: assert Solution().findMaximumScore(nums = [1,2,3,4,5]) == 10

Answer: assert Solution().findMaximumScore(nums = [1,1,1,1,1,1,1,1,1,1]) == 9

Answer: assert Solution().findMaximumScore(nums = [1,1,1,1,1]) == 4

Answer: assert Solution().findMaximumScore(nums = [2,3,6,1,5]) == 17

Answer: assert Solution().findMaximumScore(nums = [5,4,3,2,1]) == 20

Answer: assert Solution().findMaximumScore(nums = [10,10,10,10,10]) == 40

Answer: assert Solution().findMaximumScore(nums = [1, 2, 4, 8, 16, 32, 64, 128, 256, 512]) == 511

Answer: assert Solution().findMaximumScore(nums = [1, 10, 100, 1000, 10000, 100000, 1, 1, 1, 1]) == 411111

Answer: assert Solution().findMaximumScore(nums = [1,5,3,7,9,2,4,8,6,10,1,3,5,7,9,2,4,6,8,10]) == 163

Answer: assert Solution().findMaximumScore(nums = [20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1]) == 380

Answer: assert Solution().findMaximumScore(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 380

Answer: assert Solution().findMaximumScore(nums = [10,1,2,3,4,5,6,7,8,9,10]) == 100

Answer: assert Solution().findMaximumScore(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1]) == 72

Answer: assert Solution().findMaximumScore(nums = [1,2,3,4,5,6,7,8,9,10,20,30,40,50,60,70,80,90,100,1]) == 595

Answer: assert Solution().findMaximumScore(nums = [15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 210

Answer: assert Solution().findMaximumScore(nums = [50, 40, 30, 20, 10, 5, 15, 25, 35, 45, 55, 65, 75, 85, 95, 105]) == 875

Answer: assert Solution().findMaximumScore(nums = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]) == 19

Answer: assert Solution().findMaximumScore(nums = [1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1]) == 135

Answer: assert Solution().findMaximumScore(nums = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30]) == 435

Answer: assert Solution().findMaximumScore(nums = [100000,100000,100000,100000,100000]) == 400000

Answer: assert Solution().findMaximumScore(nums = [30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 870

Answer: assert Solution().findMaximumScore(nums = [100,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]) == 1900

Answer: assert Solution().findMaximumScore(nums = [10,9,8,7,6,5,4,3,2,1,2,3,4,5,6,7,8,9,10]) == 180

Answer: assert Solution().findMaximumScore(nums = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]) == 88

Answer: assert Solution().findMaximumScore(nums = [1,10,2,9,3,8,4,7,5,6,1,1,1,1,1,1,1,1,1]) == 171

Answer: assert Solution().findMaximumScore(nums = [9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1]) == 171

Answer: assert Solution().findMaximumScore(nums = [1, 100, 1, 100, 1, 100, 1]) == 501

Answer: assert Solution().findMaximumScore(nums = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10]) == 100

Answer: assert Solution().findMaximumScore(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 900000

Answer: assert Solution().findMaximumScore(nums = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29]) == 196

Answer: assert Solution().findMaximumScore(nums = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10]) == 19

Answer: assert Solution().findMaximumScore(nums = [5,10,15,20,25,30,35,40,45,50,1,2,3,4,5,6,7,8,9,10]) == 725

Answer: assert Solution().findMaximumScore(nums = [9,8,7,6,5,4,3,2,1,10]) == 81

Answer: assert Solution().findMaximumScore(nums = [10, 1, 1, 1, 1, 1, 10]) == 60

Answer: assert Solution().findMaximumScore(nums = [9, 8, 7, 6, 5, 4, 3, 2, 1, 10]) == 81

Answer: assert Solution().findMaximumScore(nums = [1,2,3,4,5,6,7,8,9,10,20,19,18,17,16,15,14,13,12,11]) == 235

Answer: assert Solution().findMaximumScore(nums = [9,8,7,6,5,4,3,2,1,10,9,8,7,6,5,4,3,2,1]) == 171

Answer: assert Solution().findMaximumScore(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 190

Answer: assert Solution().findMaximumScore(nums = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) == 190

Answer: assert Solution().findMaximumScore(nums = [2, 3, 5, 1, 4, 6, 2, 3, 1]) == 38

Answer: assert Solution().findMaximumScore(nums = [50, 25, 12, 6, 3, 1, 1, 1, 1, 1]) == 450

Answer: assert Solution().findMaximumScore(nums = [99, 98, 97, 96, 95, 94, 93, 92, 91, 90]) == 891

Answer: assert Solution().findMaximumScore(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 435

Answer: assert Solution().findMaximumScore(nums = [1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5, 1, 2, 5]) == 63

Answer: assert Solution().findMaximumScore(nums = [1,2,3,10,5,1,2,3,4,1]) == 66

Answer: assert Solution().findMaximumScore(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1000]) == 9

Answer: assert Solution().findMaximumScore(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 95

Answer: assert Solution().findMaximumScore(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1000]) == 95

Answer: assert Solution().findMaximumScore(nums = [10,10,10,10,10,10,10,10,10,10]) == 90

Answer: assert Solution().findMaximumScore(nums = [100, 50, 25, 12, 6, 3, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]) == 1900

Answer: assert Solution().findMaximumScore(nums = [10,20,30,40,50,60,70,80,90,100]) == 450

Answer: assert Solution().findMaximumScore(nums = [1,100,1,1,1,100,1,1,1,1]) == 801

Answer: assert Solution().findMaximumScore(nums = [5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 45, 40, 35, 30, 25]) == 475

Answer: assert Solution().findMaximumScore(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 105

Answer: assert Solution().findMaximumScore(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 45

Answer: assert Solution().findMaximumScore(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250]) == 3000

Answer: assert Solution().findMaximumScore(nums = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,100]) == 210

Answer: assert Solution().findMaximumScore(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100]) == 14

Answer: assert Solution().findMaximumScore(nums = [1,3,5,7,9,11,13,15,17,19,21,23,25]) == 144

Answer: assert Solution().findMaximumScore(nums = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,10]) == 29

Answer: assert Solution().findMaximumScore(nums = [5, 3, 9, 2, 8, 6, 1, 7, 4, 10]) == 73

Answer: assert Solution().findMaximumScore(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 190

Answer: assert Solution().findMaximumScore(nums = [1,2,3,4,5,1,2,3,4,5,1,2,3,4,5]) == 60

Answer: assert Solution().findMaximumScore(nums = [25,23,21,19,17,15,13,11,9,7,5,3,1]) == 300

Answer: assert Solution().findMaximumScore(nums = [100, 10, 20, 30, 40, 50, 60, 70, 80, 90]) == 900

Answer: assert Solution().findMaximumScore(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 9

Answer: assert Solution().findMaximumScore(nums = [100,90,80,70,60,50,40,30,20,10]) == 900

Answer: assert Solution().findMaximumScore(nums = [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10]) == 145

Answer: assert Solution().findMaximumScore(nums = [1,100,2,99,3,98,4,97,5,96]) == 801

Answer: assert Solution().findMaximumScore(nums = [10, 20, 30, 40, 50, 40, 30, 20, 10, 5]) == 350

Answer: assert Solution().findMaximumScore(nums = [29,27,25,23,21,19,17,15,13,11,9,7,5,3,1]) == 406

Answer: assert Solution().findMaximumScore(nums = [5,10,15,20,25,30,35,40,45,50,55,60,65,70,75,80,85,90,95,100]) == 950

Answer: assert Solution().findMaximumScore(nums = [1, 5, 3, 4, 2, 6, 8, 7, 9, 10]) == 52

Answer: assert Solution().findMaximumScore(nums = [100, 1, 100, 1, 100, 1, 100, 1, 100, 1]) == 900

Answer: assert Solution().findMaximumScore(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 361

Answer: assert Solution().findMaximumScore(nums = [1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10, 1, 10]) == 181

Answer: assert Solution().findMaximumScore(nums = [1, 100, 1, 100, 1, 100, 1, 100, 1, 100]) == 801

Answer: assert Solution().findMaximumScore(nums = [1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5,1,5]) == 91

Answer: assert Solution().findMaximumScore(nums = [10,1,1,1,1,1,1,1,1,10]) == 90

Answer: assert Solution().findMaximumScore(nums = [1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2]) == 37

Answer: assert Solution().findMaximumScore(nums = [100,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) == 2000

Answer: assert Solution().findMaximumScore(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 450

Answer: assert Solution().findMaximumScore(nums = [3, 5, 7, 9, 2, 4, 6, 8, 10, 1]) == 70

Answer: assert Solution().findMaximumScore(nums = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 70

Answer: assert Solution().findMaximumScore(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 100]) == 19

Answer: assert Solution().findMaximumScore(nums = [5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]) == 70

import random
import functools
import collections
import string
import math
import datetime

from typing import *
from functools import *
from collections import *
from itertools import *
from heapq import *
from bisect import *
from string import *
from operator import *
from math import *

inf = float('inf')

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def list_node(values: list):
    if not values:
        return None
    head = ListNode(values[0])
    p = head
    for val in values[1:]:
        node = ListNode(val)
        p.next = node
        p = node
    return head

def is_same_list(p1, p2):
    if p1 is None and p2 is None:
        return True
    if not p1 or not p2:
        return False
    return p1.val == p2.val and is_same_list(p1.next, p2.next)

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def tree_node(values: list):
    if not values:
        return None
    root = TreeNode(values[0])
    i = 1
    queue = deque()
    queue.append(root)
    while queue:
        node = queue.popleft()
        if i < len(values) and values[i] is not None:
            node.left = TreeNode(values[i])
            queue.append(node.left)
        i += 1
        if i < len(values) and values[i] is not None:
            node.right = TreeNode(values[i])
            queue.append(node.right)
        i += 1
    return root

def is_same_tree(p, q):
    if not p and not q:
        return True
    elif not p or not q:
        return False
    elif p.val != q.val:
        return False
    else:
        return is_same_tree(p.left, q.left) and is_same_tree(p.right, q.right)

class Solution:
    def findMaximumScore(self, nums: List[int]) -> int:
        ans = mx = 0
        for x in nums[:-1]:
            mx = max(mx, x)
            ans += mx
        return ans


You are an expert Python programmer. Write correct, efficient Python 3 code that solves the problem and passes all tests. Output the code in the following format: ```python
<code>
```

PROBLEM:
We call an array arr of length n consecutive if one of the following holds:

arr[i] - arr[i - 1] == 1 for all 1 <= i < n.
arr[i] - arr[i - 1] == -1 for all 1 <= i < n.

The value of an array is the sum of its elements.
For example, [3, 4, 5] is a consecutive array of value 12 and [9, 8] is another of value 17. While [3, 4, 3] and [8, 6] are not consecutive.
Given an array of integers nums, return the sum of the values of all consecutive subarrays.
Since the answer may be very large, return it modulo 109 + 7.
Note that an array of length 1 is also considered consecutive.

Example 1:

Input: nums = [1,2,3]
Output: 20
Explanation:
The consecutive subarrays are: [1], [2], [3], [1, 2], [2, 3], [1, 2, 3].
Sum of their values would be: 1 + 2 + 3 + 3 + 5 + 6 = 20.

Example 2:

Input: nums = [1,3,5,7]
Output: 16
Explanation:
The consecutive subarrays are: [1], [3], [5], [7].
Sum of their values would be: 1 + 3 + 5 + 7 = 16.

Example 3:

Input: nums = [7,6,1,2]
Output: 32
Explanation:
The consecutive subarrays are: [7], [6], [1], [2], [7, 6], [1, 2].
Sum of their values would be: 7 + 6 + 1 + 2 + 13 + 3 = 32.

Constraints:

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

Your solution to the problem should be a method of the class Solution called getSum and should pass all tests. Use the following starter code:
```python
class Solution:
    def getSum(self, nums: List[int]) -> int:
        # Add your code here
```

SOLUTION:

Question:
PROBLEM:
We call an array arr of length n consecutive if one of the following holds:

arr[i] - arr[i - 1] == 1 for all 1 <= i < n.
arr[i] - arr[i - 1] == -1 for all 1 <= i < n.

The value of an array is the sum of its elements.
For example, [3, 4, 5] is a consecutive array of value 12 and [9, 8] is another of value 17. While [3, 4, 3] and [8, 6] are not consecutive.
Given an array of integers nums, return the sum of the values of all consecutive subarrays.
Since the answer may be very large, return it modulo 109 + 7.
Note that an array of length 1 is also considered consecutive.

Example 1:

Input: nums = [1,2,3]
Output: 20
Explanation:
The consecutive subarrays are: [1], [2], [3], [1, 2], [2, 3], [1, 2, 3].
Sum of their values would be: 1 + 2 + 3 + 3 + 5 + 6 = 20.

Example 2:

Input: nums = [1,3,5,7]
Output: 16
Explanation:
The consecutive subarrays are: [1], [3], [5], [7].
Sum of their values would be: 1 + 3 + 5 + 7 = 16.

Example 3:

Input: nums = [7,6,1,2]
Output: 32
Explanation:
The consecutive subarrays are: [7], [6], [1], [2], [7, 6], [1, 2].
Sum of their values would be: 7 + 6 + 1 + 2 + 13 + 3 = 32.

Constraints:

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

Your solution to the problem should be a method of the class Solution called getSum and should pass all tests. Use the following starter code:
```python
class Solution:
    def getSum(self, nums: List[int]) -> int:
        # Add your code here
```

SOLUTION:

assert Solution().getSum(nums = [7,6,1,2]) == 32

assert Solution().getSum(nums = [10]) == 10

assert Solution().getSum(nums = [1]) == 1

assert Solution().getSum(nums = [5,5,5,5,5]) == 25

assert Solution().getSum(nums = [10,9,8,7,6]) == 280

assert Solution().getSum(nums = [1,1,1,1,1]) == 5

assert Solution().getSum(nums = [5,4,3,2,1]) == 105

assert Solution().getSum(nums = [1,3,5,7]) == 16

assert Solution().getSum(nums = [1,2,3]) == 20

assert Solution().getSum(nums = [5]) == 5

Answer: assert Solution().getSum(nums = [1,3,2,4,3,5,4,6,5,7]) == 72

Answer: assert Solution().getSum(nums = [7,6,1,2]) == 32

Answer: assert Solution().getSum(nums = [1,3,2,4,5,7,6,8,9,10]) == 145

Answer: assert Solution().getSum(nums = [1,2,4,5,6,8,9]) == 90

Answer: assert Solution().getSum(nums = [10,9,8,7,6,5,4,3,2,1]) == 1210

Answer: assert Solution().getSum(nums = [10,11,12,13,14]) == 420

Answer: assert Solution().getSum(nums = [1,2,3,4,5,6,7,8,9,10]) == 1210

Answer: assert Solution().getSum(nums = [10]) == 10

Answer: assert Solution().getSum(nums = [1]) == 1

Answer: assert Solution().getSum(nums = [3,2,1,2,3,4,5,4,3,2,1]) == 224

Answer: assert Solution().getSum(nums = [5,5,5,5,5]) == 25

Answer: assert Solution().getSum(nums = [1,2,4,5,7,8,10,11]) == 96

Answer: assert Solution().getSum(nums = [3,2,1,2,3,2,1]) == 56

Answer: assert Solution().getSum(nums = [10,9,8,7,6]) == 280

Answer: assert Solution().getSum(nums = [1,1,1,1,1,1,1,1,1,1]) == 10

Answer: assert Solution().getSum(nums = [1,2,2,3,4,4,5]) == 54

Answer: assert Solution().getSum(nums = [1,1,1,1,1]) == 5

Answer: assert Solution().getSum(nums = [100000,99999,99998,99997,99996,99995]) == 5599860

Answer: assert Solution().getSum(nums = [5,6,7,8,9,10,11,12]) == 1020

Answer: assert Solution().getSum(nums = [100000,99999,99998,99997]) == 1999970

Answer: assert Solution().getSum(nums = [5,4,3,2,1]) == 105

Answer: assert Solution().getSum(nums = [1,2,4,5,6,7,8]) == 216

Answer: assert Solution().getSum(nums = [1,3,5,7]) == 16

Answer: assert Solution().getSum(nums = [1,2,3]) == 20

Answer: assert Solution().getSum(nums = [5,5,5,5,5,5,5,5,5,5]) == 50

Answer: assert Solution().getSum(nums = [1,3,2,4,3,5,6,7]) == 85

Answer: assert Solution().getSum(nums = [5]) == 5

Answer: assert Solution().getSum(nums = [1,2,4,5,6,7,8,9]) == 370

Answer: assert Solution().getSum(nums = [100000,99999,99998,99997,99996]) == 3499930

Answer: assert Solution().getSum(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6]) == 1575

Answer: assert Solution().getSum(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110]) == 30030

Answer: assert Solution().getSum(nums = [20,21,22,23,19,18,17,16,15,14,13,12,11,10,9,8,7]) == 6345

Answer: assert Solution().getSum(nums = [1,2,3,5,6,8,9,11,12,14,15,16]) == 272

Answer: assert Solution().getSum(nums = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31]) == 256

Answer: assert Solution().getSum(nums = [1, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20]) == 114

Answer: assert Solution().getSum(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 241

Answer: assert Solution().getSum(nums = [100,101,102,99,98,97,96,95,94,93,92]) == 12470

Answer: assert Solution().getSum(nums = [1, 2, 3, 5, 6, 7, 9, 10, 11, 12]) == 290

Answer: assert Solution().getSum(nums = [1,3,2,4,3,5,6,7,8,7,6,5,4,5,6,7,8,9,10]) == 941

Answer: assert Solution().getSum(nums = [20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10]) == 4290

Answer: assert Solution().getSum(nums = [1, 2, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 5476

Answer: assert Solution().getSum(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 3, 5, 7, 9]) == 1235

Answer: assert Solution().getSum(nums = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]) == 20

Answer: assert Solution().getSum(nums = [100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112]) == 48230

Answer: assert Solution().getSum(nums = [1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1]) == 2410

Answer: assert Solution().getSum(nums = [5, 6, 7, 8, 9, 10, 8, 7, 6, 5]) == 550

Answer: assert Solution().getSum(nums = [3, 4, 5, 4, 5, 6, 7, 6, 7, 8, 9, 8, 9, 10, 11, 10, 11, 12, 13, 12]) == 817

Answer: assert Solution().getSum(nums = [1, 3, 2, 4, 3, 5, 6, 7, 8, 9, 10, 8, 7, 6, 5, 4, 3, 2, 1]) == 985

Answer: assert Solution().getSum(nums = [10,11,12,13,14,15,16,17,18,19,20,19,18,17,16,15,14,13,12,11]) == 7680

Answer: assert Solution().getSum(nums = [1, 2, 3, 4, 3, 4, 5, 6, 5, 6, 7, 8, 7, 8, 9]) == 383

Answer: assert Solution().getSum(nums = [5, 6, 7, 8, 10, 11, 12, 13, 14, 15]) == 830

Answer: assert Solution().getSum(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 2410

Answer: assert Solution().getSum(nums = [5,4,3,2,1,2,3,4,5,4,3,2,1]) == 309

Answer: assert Solution().getSum(nums = [1,2,3,4,5,4,5,6,7,6,7,8,9,8,9,10,11,10,11,12,13,12,13,14,15,14,15,16,17]) == 1479

Answer: assert Solution().getSum(nums = [1, 2, 3, 5, 6, 8, 9, 11, 12, 14, 15, 17, 18, 20, 21, 23, 24]) == 426

Answer: assert Solution().getSum(nums = [50000, 50001, 50002, 50003, 50002, 50001, 50000, 49999, 49998, 49997]) == 5150027

Answer: assert Solution().getSum(nums = [1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1,2,3,4,5,6,7,8,9,10]) == 3619

Answer: assert Solution().getSum(nums = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15]) == 5440

Answer: assert Solution().getSum(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5]) == 1315

Answer: assert Solution().getSum(nums = [1, 2, 3, 5, 6, 7, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20]) == 1718

Answer: assert Solution().getSum(nums = [1,2,3,4,5,4,3,4,5,6,7,8,9,10]) == 917

Answer: assert Solution().getSum(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5]) == 1570

Answer: assert Solution().getSum(nums = [10,11,12,13,14,15,16,17,18,19,20,19,18,17,16]) == 4900

Answer: assert Solution().getSum(nums = [2,1,3,2,4,3,5,4,6,5,7,6,8,7,9]) == 135

Answer: assert Solution().getSum(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 15

Answer: assert Solution().getSum(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 21999010

Answer: assert Solution().getSum(nums = [1, 2, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15]) == 320

Answer: assert Solution().getSum(nums = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29]) == 225

Answer: assert Solution().getSum(nums = [5,6,7,8,9,10,11,12,13,14,15]) == 2860

Answer: assert Solution().getSum(nums = [100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115]) == 87720

Answer: assert Solution().getSum(nums = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]) == 15

Answer: assert Solution().getSum(nums = [1, 2, 3, 6, 7, 8, 11, 12, 13, 16, 17, 18, 21, 22, 23]) == 600

Answer: assert Solution().getSum(nums = [40, 39, 38, 37, 36, 35, 34, 33, 32, 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 21, 20]) == 53130

Answer: assert Solution().getSum(nums = [25,24,23,22,21,20,19,18,17,16,15,14,13]) == 8645

Answer: assert Solution().getSum(nums = [1,2,3,6,7,8,11,12,13,14]) == 340

Answer: assert Solution().getSum(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4]) == 2040

Answer: assert Solution().getSum(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == 38025

Answer: assert Solution().getSum(nums = [1, 2, 3, 2, 1, 2, 3, 2, 1, 2, 3, 2, 1]) == 109

Answer: assert Solution().getSum(nums = [3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1]) == 224

Answer: assert Solution().getSum(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 0

Answer: assert Solution().getSum(nums = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1]) == 109

Answer: assert Solution().getSum(nums = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) == 16170

Answer: assert Solution().getSum(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 10, 9, 8, 7, 6]) == 1490

Answer: assert Solution().getSum(nums = [5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,15,14,13,12,11,10,9,8,7,6,5]) == 13060

Answer: assert Solution().getSum(nums = [1,2,3,2,1,2,3,4,5,6,5,4,3,2,1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1]) == 2831

Answer: assert Solution().getSum(nums = [1,2,3,2,1,2,3,2,1,2,3,2,1,2,3,2,1,2,3,2,1]) == 181

Answer: assert Solution().getSum(nums = [100000, 99999, 99998, 99997, 99996, 99995]) == 5599860

Answer: assert Solution().getSum(nums = [1,2,3,5,6,7,9,10,11,13,14,15,17,18,19]) == 500

Answer: assert Solution().getSum(nums = [2, 1, 3, 4, 6, 5, 7, 8, 10, 9, 11, 12, 14, 13, 15]) == 225

Answer: assert Solution().getSum(nums = [10,9,8,7,6,5,4,3,2,1,0,-1,-2,-3,-4]) == 2040

Answer: assert Solution().getSum(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 7550

Answer: assert Solution().getSum(nums = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]) == 1210

Answer: assert Solution().getSum(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == 100

Answer: assert Solution().getSum(nums = [1,10,20,30,40,50,60,70,80,90,100,90,80,70,60,50,40,30,20,10,1]) == 1002

Answer: assert Solution().getSum(nums = [1,3,2,4,6,5,7,9,8,10,12,11,13,15,14]) == 205

Answer: assert Solution().getSum(nums = [1, 2, 2, 3, 4, 5, 6, 6, 7, 8, 9, 10, 10, 11, 12, 13, 14, 15, 16]) == 1518

Answer: assert Solution().getSum(nums = [100,101,102,103,104,103,102,103,104,105,106,107,108,109,110]) == 21884

Answer: assert Solution().getSum(nums = [10, 12, 14, 16, 18, 17, 16, 15, 14, 13, 12, 11, 10]) == 2362

Answer: assert Solution().getSum(nums = [1, 3, 2, 4, 3, 5, 6, 7, 9, 10, 11, 13, 14, 15, 17, 18, 19, 21]) == 526

Answer: assert Solution().getSum(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25]) == 169

Answer: assert Solution().getSum(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 2860

Answer: assert Solution().getSum(nums = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993]) == 11999580

Answer: assert Solution().getSum(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 4, 3, 2, 1, 2, 3, 4, 5]) == 413

Answer: assert Solution().getSum(nums = [1, 2, 3, 4, 3, 2, 1, 2, 3, 4, 3, 2, 1]) == 191

Answer: assert Solution().getSum(nums = [5,6,7,8,7,6,5,4,3,2,1,2,3,4,5,6]) == 857

Answer: assert Solution().getSum(nums = [1,3,5,7,9,11,13,15,17,19,21,23,25]) == 169

Answer: assert Solution().getSum(nums = [1, 2, 3, 4, 5, 3, 2, 1, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1]) == 510

Answer: assert Solution().getSum(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 16170

Answer: assert Solution().getSum(nums = [25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14, 13, 12, 11, 10]) == 14280

Answer: assert Solution().getSum(nums = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 25

Answer: assert Solution().getSum(nums = [5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 10200

Answer: assert Solution().getSum(nums = [2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 0, 1, 2, 3, 4, 3, 2, 1, 0, 1, 2, 3]) == 552

Answer: assert Solution().getSum(nums = [5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5]) == 0

Answer: assert Solution().getSum(nums = [50000, 50001, 50002, 50001, 50000, 49999, 49998, 49999, 50000, 50001]) == 3150000

Answer: assert Solution().getSum(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39]) == 400

Answer: assert Solution().getSum(nums = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 2420

Answer: assert Solution().getSum(nums = [10,20,30,40,50,60,70,80,90,100,95,90,85,80,75,70,65,60,55,50,45,40,35,30,25,20,15,10,5]) == 1500

Answer: assert Solution().getSum(nums = [99999, 100000, 99999, 100000, 99999, 100000, 99999, 100000]) == 2199989

Answer: assert Solution().getSum(nums = [1,2,3,5,6,8,9,11,12,14,15,17,18,20,21,23,24,26,27,29]) == 561

Answer: assert Solution().getSum(nums = [1, 2, 3, 4, 5, 3, 4, 5, 6, 7]) == 280

Answer: assert Solution().getSum(nums = [1, 2, 3, 5, 6, 7, 9, 10, 11, 12, 14]) == 304

Answer: assert Solution().getSum(nums = [3,2,1,0,-1,-2,-3,-2,-1,0,1,2,3,4,5,6,7,8,9]) == 1368

Answer: assert Solution().getSum(nums = [1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2]) == 87

Answer: assert Solution().getSum(nums = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 550

Answer: assert Solution().getSum(nums = [10,12,14,16,18,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1]) == 16240

Answer: assert Solution().getSum(nums = [5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5]) == 20380

Answer: assert Solution().getSum(nums = [5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 1314

Answer: assert Solution().getSum(nums = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23]) == 144

Answer: assert Solution().getSum(nums = [1, 2, 2, 2, 3, 4, 5, 6, 5, 4, 3, 2, 1, 2, 3, 4, 5, 6, 7, 8, 9]) == 1162

import random
import functools
import collections
import string
import math
import datetime

from typing import *
from functools import *
from collections import *
from itertools import *
from heapq import *
from bisect import *
from string import *
from operator import *
from math import *

inf = float('inf')

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def list_node(values: list):
    if not values:
        return None
    head = ListNode(values[0])
    p = head
    for val in values[1:]:
        node = ListNode(val)
        p.next = node
        p = node
    return head

def is_same_list(p1, p2):
    if p1 is None and p2 is None:
        return True
    if not p1 or not p2:
        return False
    return p1.val == p2.val and is_same_list(p1.next, p2.next)

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def tree_node(values: list):
    if not values:
        return None
    root = TreeNode(values[0])
    i = 1
    queue = deque()
    queue.append(root)
    while queue:
        node = queue.popleft()
        if i < len(values) and values[i] is not None:
            node.left = TreeNode(values[i])
            queue.append(node.left)
        i += 1
        if i < len(values) and values[i] is not None:
            node.right = TreeNode(values[i])
            queue.append(node.right)
        i += 1
    return root

def is_same_tree(p, q):
    if not p and not q:
        return True
    elif not p or not q:
        return False
    elif p.val != q.val:
        return False
    else:
        return is_same_tree(p.left, q.left) and is_same_tree(p.right, q.right)

class Solution:
    def getSum(self, nums: List[int]) -> int:
        mod = 10**9 + 7
        f = g = 1
        s = t = nums[0]
        ans = nums[0]
        for x, y in pairwise(nums):
            if y - x == 1:
                f += 1
                s += f * y
                ans = (ans + s) % mod
            else:
                f = 1
                s = y
            if y - x == -1:
                g += 1
                t += g * y
                ans = (ans + t) % mod
            else:
                g = 1
                t = y
            if abs(y - x) != 1:
                ans = (ans + y) % mod
        return ans


You are an expert Python programmer. Write correct, efficient Python 3 code that solves the problem and passes all tests. Output the code in the following format: ```python
<code>
```

PROBLEM:
You are given an m x n binary matrix grid and an integer health.
You start on the upper-left corner (0, 0) and would like to get to the lower-right corner (m - 1, n - 1).
You can move up, down, left, or right from one cell to another adjacent cell as long as your health remains positive.
Cells (i, j) with grid[i][j] = 1 are considered unsafe and reduce your health by 1.
Return true if you can reach the final cell with a health value of 1 or more, and false otherwise.

Example 1:

Input: grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]], health = 1
Output: true
Explanation:
The final cell can be reached safely by walking along the gray cells below.

Example 2:

Input: grid = [[0,1,1,0,0,0],[1,0,1,0,0,0],[0,1,1,1,0,1],[0,0,1,0,1,0]], health = 3
Output: false
Explanation:
A minimum of 4 health points is needed to reach the final cell safely.

Example 3:

Input: grid = [[1,1,1],[1,0,1],[1,1,1]], health = 5
Output: true
Explanation:
The final cell can be reached safely by walking along the gray cells below.

Any path that does not go through the cell (1, 1) is unsafe since your health will drop to 0 when reaching the final cell.

Constraints:

m == grid.length
n == grid[i].length
1 <= m, n <= 50
2 <= m * n
1 <= health <= m + n
grid[i][j] is either 0 or 1.

Your solution to the problem should be a method of the class Solution called findSafeWalk and should pass all tests. Use the following starter code:
```python
class Solution:
    def findSafeWalk(self, grid: List[List[int]], health: int) -> bool:
        # Add your code here
```

SOLUTION:

Question:
PROBLEM:
You are given an m x n binary matrix grid and an integer health.
You start on the upper-left corner (0, 0) and would like to get to the lower-right corner (m - 1, n - 1).
You can move up, down, left, or right from one cell to another adjacent cell as long as your health remains positive.
Cells (i, j) with grid[i][j] = 1 are considered unsafe and reduce your health by 1.
Return true if you can reach the final cell with a health value of 1 or more, and false otherwise.

Example 1:

Input: grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]], health = 1
Output: true
Explanation:
The final cell can be reached safely by walking along the gray cells below.

Example 2:

Input: grid = [[0,1,1,0,0,0],[1,0,1,0,0,0],[0,1,1,1,0,1],[0,0,1,0,1,0]], health = 3
Output: false
Explanation:
A minimum of 4 health points is needed to reach the final cell safely.

Example 3:

Input: grid = [[1,1,1],[1,0,1],[1,1,1]], health = 5
Output: true
Explanation:
The final cell can be reached safely by walking along the gray cells below.

Any path that does not go through the cell (1, 1) is unsafe since your health will drop to 0 when reaching the final cell.

Constraints:

m == grid.length
n == grid[i].length
1 <= m, n <= 50
2 <= m * n
1 <= health <= m + n
grid[i][j] is either 0 or 1.

Your solution to the problem should be a method of the class Solution called findSafeWalk and should pass all tests. Use the following starter code:
```python
class Solution:
    def findSafeWalk(self, grid: List[List[int]], health: int) -> bool:
        # Add your code here
```

SOLUTION:

assert Solution().findSafeWalk(grid = [[0,0,0],[0,0,0],[0,0,0]], health = 1) == True

assert Solution().findSafeWalk(grid = [[1,1,1],[1,0,1],[1,1,1]], health = 5) == True

assert Solution().findSafeWalk(grid = [[1,1,1],[1,1,1],[1,1,1]], health = 8) == True

assert Solution().findSafeWalk(grid = [[1,1],[1,1]], health = 10) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,0,0],[0,1,0,1,0],[0,0,0,1,0]], health = 1) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0],[0,0,0],[0,0,0]], health = 1) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1],[1,0,1],[1,1,1]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1],[1,1,1],[1,1,1]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,0,0,0],[1,0,1,0,0,0],[0,1,1,1,0,1],[0,0,1,0,1,0]], health = 3) == False

Answer: assert Solution().findSafeWalk(grid = [[1,1],[1,1]], health = 10) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,0,0,0,1,0],[1,0,1,0,1,0,1,0],[0,1,1,0,1,0,1,0],[0,1,0,0,1,0,1,0],[0,1,0,1,1,0,1,0],[0,0,0,0,1,0,1,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0],[0,1,1,1,0],[0,1,0,1,0],[0,1,1,1,0],[0,0,0,0,0]], health = 3) == True

Answer: assert Solution().findSafeWalk(grid = [[1,0,1,0,1,0,1],[0,1,0,1,0,1,0],[1,0,1,0,1,0,1],[0,1,0,1,0,1,0],[1,0,1,0,1,0,1]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0,1],[0,1,1,1,1,0],[0,1,0,0,1,0],[0,1,0,1,0,0],[0,1,0,0,0,0],[0,0,0,1,1,0]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,0,0,0,0,0],[0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1],[0,0,0,0,0,0,0,0]], health = 7) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,0,1,1],[0,1,0,1,0],[1,0,0,0,1],[0,1,1,0,0],[1,0,0,0,1]], health = 7) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0,0,0],[1,1,1,1,1,1,0],[0,0,0,0,0,0,0],[0,1,1,1,1,0,0],[0,0,0,0,0,0,0],[0,0,1,1,0,0,0]], health = 4) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0,0,0]], health = 20) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,1,0,1,0,1,0],[1,0,0,0,0,0,0,0,0],[0,0,1,0,1,0,1,0,1],[0,1,0,0,0,0,0,0,0],[1,0,1,0,1,0,1,0,1]], health = 9) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,1,1,1,0,1,0,0,1],[1,0,0,0,0,0,0,1,1,0],[0,1,1,1,0,1,0,0,0,0],[1,0,0,0,1,0,1,1,0,1],[0,1,0,1,0,0,0,0,1,0]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0,0],[0,1,1,1,1,0],[0,1,0,0,1,0],[0,1,0,1,0,0],[0,1,1,1,1,0],[0,0,0,0,0,0]], health = 6) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,0,0,0,0],[0,0,0,1,1,0,0],[0,1,1,1,0,0,0],[0,0,0,0,0,1,1],[1,1,0,0,0,0,0],[0,0,0,1,1,0,0]], health = 6) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,1,0,1,0],[1,0,0,0,1,0,0],[0,0,1,0,0,1,0],[1,0,1,0,0,0,1],[0,1,0,1,0,1,0]], health = 7) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,0,0,0],[0,0,1,1,0],[0,1,0,0,1],[0,0,1,0,0],[0,1,0,0,0]], health = 6) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0,0,0],[0,1,1,1,1,1,0],[0,1,0,0,0,1,0],[0,1,0,1,0,1,0],[0,1,0,1,0,0,0],[0,0,0,1,1,1,0]], health = 3) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1,1,0],[1,0,0,0,0],[0,0,0,0,0],[0,0,0,1,1],[0,0,0,1,0]], health = 7) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,1,1,1,0,0],[1,0,1,0,1,0,1],[0,1,0,1,0,1,0],[1,0,1,0,1,0,1],[0,0,0,0,0,0,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,0,1,1,1,1,0],[0,1,0,0,0,0,0,1,0],[1,0,1,1,0,1,0,0,0],[0,0,0,1,0,0,1,1,0],[1,1,0,0,0,1,0,0,0]], health = 6) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,0,0,0,1,0,0,1,0],[0,0,1,1,1,0,1,0,0,1],[1,0,0,0,0,1,0,1,1,0],[0,1,1,0,1,0,0,0,0,0],[0,0,0,1,0,1,1,0,1,1]], health = 9) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,1,0,0,0],[0,0,1,0,0,1,0],[1,0,0,0,1,0,0],[0,1,0,1,0,1,0],[0,0,0,0,0,0,0]], health = 6) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,1,1,1,0,0],[0,1,0,0,0,0,0,1],[0,1,1,1,1,1,0,0],[0,0,0,0,0,0,0,0],[1,0,1,0,1,0,1,0]], health = 7) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,0,1,0,0,0,0],[0,1,1,0,1,0,1,0,0],[0,0,0,0,1,0,0,0,0],[0,1,0,0,0,1,0,1,0],[0,0,1,1,1,0,0,0,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,1,1,1,0,0],[1,0,1,0,1,0,1],[0,1,0,1,0,1,0],[1,0,1,0,1,0,1],[0,0,0,0,0,0,0]], health = 4) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,0,1,1,1,1],[0,0,0,0,0,0,0],[1,1,1,1,1,1,1],[0,0,0,0,0,0,0],[1,1,0,1,1,1,1]], health = 20) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0],[1,1,1,1,0],[0,0,0,0,0],[0,1,1,1,0],[0,0,0,0,0]], health = 4) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,1],[1,1,0,1],[1,0,1,1],[1,0,0,1],[1,1,1,0]], health = 6) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]], health = 10) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0,0],[0,1,0,1,0,0],[0,1,0,1,0,1],[0,0,0,1,0,0],[1,0,1,1,1,0],[0,0,0,0,0,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0,0],[0,1,1,1,1,0],[0,0,0,0,0,0],[0,1,1,1,1,0],[0,0,0,0,0,0]], health = 3) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,1,0,1,0],[1,0,1,0,1,0,1],[0,1,0,1,0,1,0],[1,0,1,0,1,0,1],[0,1,0,1,0,1,0]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,1,0,0,1,0],[1,0,0,0,1,0,1,1],[0,0,1,0,0,0,0,0],[1,0,1,0,1,1,0,0],[0,0,0,0,0,1,0,1]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,1,1,1,1,1,0],[1,1,0,0,0,0,0,1,1],[0,1,1,0,1,1,0,0,0],[1,0,0,0,0,1,0,1,0],[0,0,1,1,0,0,0,0,0]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,1,0,0,0,0,1],[0,0,0,0,1,1,1,0,0],[0,1,1,0,0,0,1,1,0],[1,0,0,0,1,0,0,1,0],[0,1,0,1,0,1,0,0,0]], health = 7) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,0,1,0,0,0],[0,1,0,1,0,1,0,1],[0,0,1,0,0,0,1,0],[1,0,1,0,0,0,0,1],[0,1,0,0,1,0,0,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0,0,0],[0,1,1,1,1,1,0],[0,1,0,0,0,1,0],[0,1,1,1,1,1,0],[0,0,0,0,0,0,0]], health = 6) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0,0],[0,1,1,1,1,0],[0,1,0,0,1,0],[0,1,1,1,1,0],[0,0,0,0,0,0]], health = 7) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,1,0,0,0,0,0,0],[0,1,0,1,0,1,0,1,0,1],[0,0,0,1,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,1],[0,0,0,1,0,0,0,0,0,0]], health = 6) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0],[0,1,1,1,0],[0,1,1,1,0],[0,0,0,0,0]], health = 2) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0],[0,1,1,1,0],[0,1,0,1,0],[0,1,1,1,0],[0,0,0,0,0]], health = 4) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,0,0,1,0],[0,0,1,0,0,0],[0,1,0,1,0,1],[0,0,0,0,1,0],[1,0,1,0,0,0]], health = 6) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1],[0,0,0,0,0,0,0,0]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1]], health = 10) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,1,1],[1,1,0,0,1],[1,0,1,0,1],[1,0,0,1,1],[1,1,1,0,0]], health = 7) == True

Answer: assert Solution().findSafeWalk(grid = [[1,0,1,1,1,0,1,1],[1,1,0,0,0,1,0,0],[0,1,0,1,1,1,0,1],[1,0,1,0,1,0,1,0],[0,1,0,0,0,1,0,1]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,1,1,0,0],[1,0,0,0,0,1,0],[0,1,1,0,1,0,0],[0,0,0,0,1,0,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,1,1,1],[1,0,0,0,0,1],[1,0,1,1,0,1],[1,0,0,1,0,1],[1,1,1,0,0,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,0,1,1,0,1,1],[1,0,0,0,0,0,0,0],[0,0,1,0,1,0,1,1],[0,1,0,0,0,0,0,1],[1,0,1,1,0,1,1,0]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,1,0,1],[0,1,1,0,0,0],[0,0,0,0,1,0],[1,0,1,0,1,1],[0,0,0,0,0,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1,1,1,1,1,1,1],[1,0,0,0,0,0,0,0,1],[1,0,1,1,1,1,1,0,1],[1,0,1,0,0,0,1,0,1],[1,0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0,1],[1,0,0,0,0,0,0,0,1],[1,1,1,1,1,1,1,1,1]], health = 10) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,0,0,0,0,0,0,0],[0,1,0,1,1,1,1,1,1,0],[0,1,0,1,0,0,0,0,1,0],[0,1,0,1,0,1,1,0,1,0],[0,1,0,1,0,1,0,1,1,0],[0,1,0,1,0,1,0,1,0,0],[0,1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0,1],[0,0,0,0,0,0,0,0,0,0]], health = 15) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,1,1,0,0],[0,1,0,0,1,0],[1,0,1,0,0,0],[0,0,0,1,0,0]], health = 4) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,1,0,0,0,0,0],[0,1,0,1,1,1,1,0],[0,0,0,0,0,1,0,0],[0,1,1,1,1,0,1,0],[0,0,0,1,0,0,0,0]], health = 6) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,1,1,0],[0,1,0,0,0,0,0,1,0],[0,1,0,1,1,1,0,1,0],[0,0,0,0,0,0,0,0,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[1,0,1,0,1,0],[0,1,0,1,0,1],[1,0,1,0,1,0],[0,1,0,1,0,1],[1,0,1,0,1,0]], health = 10) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,0,0,0,1,0,1,0],[1,0,1,0,1,0,1,0,1,0],[0,1,1,0,1,0,1,0,1,0],[0,1,0,0,1,0,1,0,1,0],[0,1,0,1,1,0,1,0,1,0],[0,0,0,0,1,0,1,0,1,0],[0,1,1,0,1,0,1,0,1,0],[0,1,0,0,1,0,1,0,1,0],[0,1,0,1,1,0,1,0,1,0],[0,0,0,0,1,0,0,0,0,0]], health = 20) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[1,0,1,0,1,0,1],[0,1,0,1,0,1,0],[1,0,1,0,1,0,1],[0,1,0,1,0,1,0],[1,0,1,0,1,0,1]], health = 10) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,0,1,1,0,0,1,0],[1,0,0,0,0,0,1,0,0,1],[0,1,0,1,0,1,0,1,0,0],[0,0,1,0,0,0,0,0,1,1],[1,1,0,1,1,0,1,0,0,0]], health = 9) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,1,1,0,0],[0,1,0,0,0,1,0],[0,0,1,1,1,0,0],[1,0,0,0,0,0,1],[0,1,1,1,1,0,0],[0,0,0,1,1,0,0]], health = 7) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,0,0,1,0],[1,0,1,0,1,0,1],[0,0,0,0,0,1,0],[1,1,1,0,1,0,0],[0,0,0,0,0,0,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]], health = 15) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0],[0,1,1,0],[0,1,1,0],[0,0,0,0]], health = 3) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0,0,0],[0,1,1,1,1,1,0],[0,1,0,0,0,1,0],[0,1,0,1,0,1,0],[0,1,0,0,0,1,0],[0,1,1,1,1,1,0],[0,0,0,0,0,0,0]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,0,0,0,0,0,0,0],[1,1,1,1,1,1,1,1,1,0],[0,0,0,0,0,0,0,0,0,0],[0,1,1,1,1,1,1,1,0,0],[0,0,0,0,0,0,0,0,0,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0,1,0],[0,1,0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0,1,0]], health = 15) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1,1,1,1,1],[1,0,0,0,0,0,1],[1,0,1,1,1,0,1],[1,0,1,0,1,0,1],[1,0,1,1,1,0,1],[1,0,0,0,0,0,1],[1,1,1,1,1,1,1]], health = 15) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,0,1,0,0,0,0],[0,1,1,1,0,1,1,0],[0,1,0,0,0,0,1,0],[0,1,0,1,1,0,1,0],[0,0,0,0,1,0,0,0]], health = 7) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,0,0,1,0,1,0,1],[1,0,0,1,0,1,0,1,0],[0,1,0,0,1,0,1,0,1],[1,0,1,0,0,1,0,1,0],[0,1,0,1,0,0,1,0,1],[1,0,1,0,1,0,0,1,0]], health = 12) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1,0,0,0,0,1,1],[0,0,0,1,1,1,0,0,0],[1,1,0,0,0,1,1,0,1],[0,1,0,1,0,0,0,0,0],[0,0,1,0,1,1,0,1,0]], health = 10) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,1,1,0,0,0,1,0],[0,0,0,0,0,1,1,0,0,1],[1,1,0,1,0,0,0,1,0,0],[0,0,1,0,0,1,0,0,1,1],[1,0,0,0,1,0,1,0,0,0]], health = 7) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1,1,1,1,1],[1,0,0,0,0,0,1],[1,0,1,1,1,0,1],[1,0,0,0,0,0,1],[1,1,1,1,1,1,1]], health = 10) == True

Answer: assert Solution().findSafeWalk(grid = [[0,1,1,1,1,1,1,1,1,1,1],[1,0,0,0,0,0,0,0,0,0,1],[1,0,1,1,1,1,1,1,1,0,1],[1,0,1,0,0,0,0,0,1,0,1],[1,0,1,0,1,1,1,0,1,0,1],[1,0,1,0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0,1,0,1],[1,0,1,0,1,0,1,0,1,0,1],[1,0,0,0,0,0,0,0,0,0,1],[1,1,1,1,1,1,1,1,1,1,1]], health = 20) == True

Answer: assert Solution().findSafeWalk(grid = [[0,0,1,1,1,0],[0,1,0,0,1,0],[0,0,1,0,0,0],[1,0,0,0,1,0],[0,0,1,1,0,0]], health = 5) == True

Answer: assert Solution().findSafeWalk(grid = [[1,0,1,1,0,1],[0,1,0,0,1,0],[1,0,1,0,1,0],[0,1,0,0,0,1],[1,0,1,1,0,0]], health = 8) == True

Answer: assert Solution().findSafeWalk(grid = [[1,1,1,1,1,1,1,1,1,1],[1,0,0,0,0,0,0,0,0,1],[1,0,1,1,1,1,1,1,0,1],[1,0,1,0,0,0,0,1,0,1],[1,0,1,0,1,1,0,1,0,1],[1,0,1,0,1,0,0,1,0,1],[1,0,1,0,1,0,1,1,0,1],[1,0,1,0,1,0,1,0,0,1],[1,0,1,0,1,0,1,0,1,0],[1,1,1,1,1,1,1,1,1,1]], health = 15) == True

import random
import functools
import collections
import string
import math
import datetime

from typing import *
from functools import *
from collections import *
from itertools import *
from heapq import *
from bisect import *
from string import *
from operator import *
from math import *

inf = float('inf')

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def list_node(values: list):
    if not values:
        return None
    head = ListNode(values[0])
    p = head
    for val in values[1:]:
        node = ListNode(val)
        p.next = node
        p = node
    return head

def is_same_list(p1, p2):
    if p1 is None and p2 is None:
        return True
    if not p1 or not p2:
        return False
    return p1.val == p2.val and is_same_list(p1.next, p2.next)

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def tree_node(values: list):
    if not values:
        return None
    root = TreeNode(values[0])
    i = 1
    queue = deque()
    queue.append(root)
    while queue:
        node = queue.popleft()
        if i < len(values) and values[i] is not None:
            node.left = TreeNode(values[i])
            queue.append(node.left)
        i += 1
        if i < len(values) and values[i] is not None:
            node.right = TreeNode(values[i])
            queue.append(node.right)
        i += 1
    return root

def is_same_tree(p, q):
    if not p and not q:
        return True
    elif not p or not q:
        return False
    elif p.val != q.val:
        return False
    else:
        return is_same_tree(p.left, q.left) and is_same_tree(p.right, q.right)

class Solution:
    def findSafeWalk(self, grid: List[List[int]], health: int) -> bool:
        m, n = len(grid), len(grid[0])
        dist = [[inf] * n for _ in range(m)]
        dist[0][0] = grid[0][0]
        q = deque([(0, 0)])
        dirs = (-1, 0, 1, 0, -1)
        while q:
            x, y = q.popleft()
            for a, b in pairwise(dirs):
                nx, ny = x + a, y + b
                if (
                    0 <= nx < m
                    and 0 <= ny < n
                    and dist[nx][ny] > dist[x][y] + grid[nx][ny]
                ):
                    dist[nx][ny] = dist[x][y] + grid[nx][ny]
                    q.append((nx, ny))
        return dist[-1][-1] < health


You are an expert Python programmer. Write correct, efficient Python 3 code that solves the problem and passes all tests. Output the code in the following format: ```python
<code>
```

PROBLEM:
You are given an integer array a of size 4 and another integer array b of size at least 4.
You need to choose 4 indices i0, i1, i2, and i3 from the array b such that i0 < i1 < i2 < i3. Your score will be equal to the value a[0] * b[i0] + a[1] * b[i1] + a[2] * b[i2] + a[3] * b[i3].
Return the maximum score you can achieve.

Example 1:

Input: a = [3,2,5,6], b = [2,-6,4,-5,-3,2,-7]
Output: 26
Explanation:
We can choose the indices 0, 1, 2, and 5. The score will be 3 * 2 + 2 * (-6) + 5 * 4 + 6 * 2 = 26.

Example 2:

Input: a = [-1,4,5,-2], b = [-5,-1,-3,-2,-4]
Output: -1
Explanation:
We can choose the indices 0, 1, 3, and 4. The score will be (-1) * (-5) + 4 * (-1) + 5 * (-2) + (-2) * (-4) = -1.

Constraints:

a.length == 4
4 <= b.length <= 105
-105 <= a[i], b[i] <= 105

Your solution to the problem should be a method of the class Solution called maxScore and should pass all tests. Use the following starter code:
```python
class Solution:
    def maxScore(self, a: List[int], b: List[int]) -> int:
        # Add your code here
```

SOLUTION:

Question:
PROBLEM:
You are given an integer array a of size 4 and another integer array b of size at least 4.
You need to choose 4 indices i0, i1, i2, and i3 from the array b such that i0 < i1 < i2 < i3. Your score will be equal to the value a[0] * b[i0] + a[1] * b[i1] + a[2] * b[i2] + a[3] * b[i3].
Return the maximum score you can achieve.

Example 1:

Input: a = [3,2,5,6], b = [2,-6,4,-5,-3,2,-7]
Output: 26
Explanation:
We can choose the indices 0, 1, 2, and 5. The score will be 3 * 2 + 2 * (-6) + 5 * 4 + 6 * 2 = 26.

Example 2:

Input: a = [-1,4,5,-2], b = [-5,-1,-3,-2,-4]
Output: -1
Explanation:
We can choose the indices 0, 1, 3, and 4. The score will be (-1) * (-5) + 4 * (-1) + 5 * (-2) + (-2) * (-4) = -1.

Constraints:

a.length == 4
4 <= b.length <= 105
-105 <= a[i], b[i] <= 105

Your solution to the problem should be a method of the class Solution called maxScore and should pass all tests. Use the following starter code:
```python
class Solution:
    def maxScore(self, a: List[int], b: List[int]) -> int:
        # Add your code here
```

SOLUTION:

Answer: assert Solution().maxScore(a = [0,0,0,0], b = [1,2,3,4,5,6,7,8,9,10]) == 0

Answer: assert Solution().maxScore(a = [1,2,3,4], b = [10,20,30,40,50,60,70,80]) == 700

Answer: assert Solution().maxScore(a = [10,20,30,40], b = [1,2,3,4]) == 300

Answer: assert Solution().maxScore(a = [-1,-2,-3,-4], b = [-10,-9,-8,-7,-6,-5,-4,-3,-2,-1]) == 80

Answer: assert Solution().maxScore(a = [100000,-100000,100000,-100000], b = [100000,-100000,100000,-100000,100000,-100000,100000,-100000]) == 40000000000

Answer: assert Solution().maxScore(a = [-1,-2,-3,-4], b = [-10,-20,-30,-40,-50,-60,-70,-80]) == 700

Answer: assert Solution().maxScore(a = [10,-10,10,-10], b = [1,2,3,4,5,6,7,8,9,10]) == -20

Answer: assert Solution().maxScore(a = [-1,4,5,-2], b = [-5,-1,-3,-2,-4]) == -1

Answer: assert Solution().maxScore(a = [1,1,1,1], b = [1,2,3,4,5,6,7,8]) == 26

Answer: assert Solution().maxScore(a = [1,2,3,4], b = [1,2,3,4,5,6,7,8,9,10]) == 90

Answer: assert Solution().maxScore(a = [-10,-20,-30,-40], b = [-1,-2,-3,-4,-5,-6,-7,-8]) == 700

Answer: assert Solution().maxScore(a = [0,0,0,0], b = [1,2,3,4,5,6,7,8,9,10,11,12]) == 0

Answer: assert Solution().maxScore(a = [3,2,5,6], b = [2,-6,4,-5,-3,2,-7]) == 26

Answer: assert Solution().maxScore(a = [1,-1,1,-1], b = [100,-100,200,-200,300,-300,400,-400]) == 1400

Answer: assert Solution().maxScore(a = [5, 15, 25, 35], b = [-100, -50, 0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000]) == 76500

Answer: assert Solution().maxScore(a = [100, 200, 300, 400], b = [-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 19000

Answer: assert Solution().maxScore(a = [1, 3, -2, 4], b = [5, -10, 3, 7, -8, 6, 2, -15, 9, 11]) == 100

Answer: assert Solution().maxScore(a = [-1,-1,-1,-1], b = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20]) == -10

Answer: assert Solution().maxScore(a = [100, -100, 200, -200], b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == -300

Answer: assert Solution().maxScore(a = [5, -3, 2, -1], b = [10, 8, -5, 3, 15, 12, -20, 7, 6, 4, 9, -1]) == 154

Answer: assert Solution().maxScore(a = [100,-50,25,-12], b = [-100,100,-100,100,-100,100,-100,100,-100,100,-100,100,-100,100,-100,100,-100,100,-100,100]) == 18700

Answer: assert Solution().maxScore(a = [10, 20, 30, 40], b = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 100000, 200000, 300000, 400000, 500000, 600000]) == 50000000

Answer: assert Solution().maxScore(a = [-5, -10, -15, -20], b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -150

Answer: assert Solution().maxScore(a = [0, 0, 0, 1], b = [100000, -100000, 50000, -50000, 25000, -25000, 12500, -12500, 6250, -6250]) == 25000

Answer: assert Solution().maxScore(a = [1, -2, 3, -4], b = [100, -50, 200, -250, 300, -350, 400, -450, 500]) == 4000

Answer: assert Solution().maxScore(a = [0, 0, 0, 0], b = [100000, -100000, 200000, -200000, 300000, -300000, 400000, -400000, 500000, -500000]) == 0

Answer: assert Solution().maxScore(a = [5,3,1,-2], b = [-100,50,-20,10,0,-5,3,8,-15,7]) == 318

Answer: assert Solution().maxScore(a = [100, 200, 300, 400], b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 19000

Answer: assert Solution().maxScore(a = [0, 0, 0, 0], b = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]) == 0

Answer: assert Solution().maxScore(a = [1, 1, 1, 1], b = [-100000, -99999, -99998, -99997, -99996, -99995, -99994, -99993, -99992, -99991, 1, 2, 3, 4]) == 10

Answer: assert Solution().maxScore(a = [-100000, -200000, -300000, -400000], b = [100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 900000]) == -300000000000

Answer: assert Solution().maxScore(a = [1, -1, 1, -1], b = [-100000, -99999, -99998, -99997, -99996, -99995, -99994, -99993, -99992, -99991]) == -2

Answer: assert Solution().maxScore(a = [1, 1, 1, 1], b = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == 399994

Answer: assert Solution().maxScore(a = [5, 15, 25, 35], b = [-10, 5, -20, 15, -30, 25, -40, 35, -50, 45]) == 2900

Answer: assert Solution().maxScore(a = [-1, 2, -3, 4], b = [10000, -10000, 5000, -5000, 2500, -2500, 1250, -1250, 625, -625, 312, -312, 156, -156, 78, -78, 39, -39, 19, -19, 9, -9, 4, -4, 2, -2, 1, -1]) == 45000

Answer: assert Solution().maxScore(a = [100000, -100000, 50000, -50000], b = [-100000, 100000, -100000, 100000, -100000, 100000, -100000, 100000]) == 30000000000

Answer: assert Solution().maxScore(a = [10, 15, -20, 25], b = [3, 7, -5, 8, 2, -1, 10, -4, 6, 12, -3, 9, 11, -6, 15, -8, 14, -7, 13, -2]) == 855

Answer: assert Solution().maxScore(a = [1,-1,1,-1], b = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]) == 0

Answer: assert Solution().maxScore(a = [5, -3, 2, 7], b = [1, -2, 3, -4, 5, -6, 7, -8, 9, -10, 11, -12, 13, -14, 15, -16, 17, -18, 19, -20, 21, -22, 23, -24, 25]) == 392

Answer: assert Solution().maxScore(a = [100, -50, 75, 25], b = [-99999, 50000, 25000, -10000, 30000, -5000, 2000, -3000, 1000, -2000]) == 7800000

Answer: assert Solution().maxScore(a = [1, 2, 3, 4], b = [-100000, -99999, -99998, -99997, -99996, -99995, -99994, -99993, -99992, -99991]) == -999920

Answer: assert Solution().maxScore(a = [-1, -2, -3, -4], b = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991]) == -999920

Answer: assert Solution().maxScore(a = [100, 200, 300, 400], b = [99999, -99999, 88888, -88888, 77777, -77777, 66666, -66666, 55555, -55555, 44444, -44444, 33333, -33333, 22222, -22222, 11111, -11111, 1, -1]) == 77777000

Answer: assert Solution().maxScore(a = [500, -500, 1000, -1000], b = [100, -200, 300, -400, 500, -600, 700, -800, 900, -1000, 1100, -1200, 1300, -1400, 1500]) == 3850000

Answer: assert Solution().maxScore(a = [-1, -2, -3, -4], b = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000, 0, -10000, -20000, -30000, -40000, -50000, -60000, -70000, -80000, -90000, -100000]) == 900000

Answer: assert Solution().maxScore(a = [100, 200, 300, 400], b = [-100, -200, -300, -400, -500, -600, -700, -800]) == -300000

Answer: assert Solution().maxScore(a = [10, -10, 10, -10], b = [-10, -20, -30, -40, -50, -60, -70, -80, -90, -100]) == 800

Answer: assert Solution().maxScore(a = [-5, 3, 2, -1], b = [10000, 9000, 8000, 7000, 6000, 5000, 4000, 3000, 2000, 1000]) == -8000

Answer: assert Solution().maxScore(a = [-1, -2, -3, -4], b = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 90

Answer: assert Solution().maxScore(a = [1, 1, 1, 1], b = [-100, -90, -80, -70, -60, -50, -40, -30, -20, -10]) == -100

Answer: assert Solution().maxScore(a = [-1, -1, -1, -1], b = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == -4

Answer: assert Solution().maxScore(a = [1, 2, 3, 4], b = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1]) == -20

Answer: assert Solution().maxScore(a = [1,1,1,1], b = [-10,-9,-8,-7,-6,-5,-4,-3,-2,-1,0,1,2,3,4,5,6,7,8,9,10]) == 34

Answer: assert Solution().maxScore(a = [0, 0, 0, 0], b = [10000, -10000, 20000, -20000, 30000, -30000, 40000, -40000]) == 0

Answer: assert Solution().maxScore(a = [1000, 2000, -1500, 500], b = [-100, 200, -300, 400, -500, 600, -700, 800, -900, 1000, -1100, 1200]) == 5050000

Answer: assert Solution().maxScore(a = [-1000, -2000, -3000, -4000], b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]) == -30000

Answer: assert Solution().maxScore(a = [-10, -20, -30, -40], b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == -300

Answer: assert Solution().maxScore(a = [1, 1, 1, 1], b = [100000, -100000, 200000, -200000, 300000, -300000, 400000, -400000, 500000, -500000, 600000, -600000, 700000, -700000, 800000, -800000, 900000, -900000, 1000000, -1000000]) == 3400000

Answer: assert Solution().maxScore(a = [10, 20, 30, 40], b = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]) == 100

Answer: assert Solution().maxScore(a = [100, -50, 25, -10], b = [500, -400, 300, -200, 100, -50, 20, -10, 0, 10, 20, 50, 100, 200, 300, 400, 500]) == 79500

Answer: assert Solution().maxScore(a = [100000, 200000, 300000, 400000], b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]) == 14000000

Answer: assert Solution().maxScore(a = [1000, 2000, 3000, 4000], b = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000, 11000, 12000, 13000, 14000, 15000, 16000, 17000, 18000, 19000, 20000]) == 190000000

Answer: assert Solution().maxScore(a = [5, -5, 5, -5], b = [10000, -10000, 5000, -5000, 2500, -2500, 1250, -1250, 625, -625, 312, -312, 156, -156, 78, -78, 39, -39, 19, -19, 9, -9, 4, -4, 2, -2, 1, -1]) == 150000

Answer: assert Solution().maxScore(a = [1, -2, 3, -4], b = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100, 110, -120, 130, -140, 150, -160, 170]) == 1500

Answer: assert Solution().maxScore(a = [10, 20, 30, 40], b = [-10000, 20000, -30000, 40000, -50000, 60000, -70000, 80000, -90000, 100000, -110000, 120000, -130000, 140000]) == 12000000

Answer: assert Solution().maxScore(a = [1, -1, 1, -1], b = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8]) == 30

Answer: assert Solution().maxScore(a = [-100, -200, -300, -400], b = [-99999, 99999, -88888, 88888, -77777, 77777, -66666, 66666, -55555, 55555, -44444, 44444, -33333, 33333, -22222, 22222, -11111, 11111, -1, 1]) == 77777000

Answer: assert Solution().maxScore(a = [1000,-1000,500,-500], b = [10000,-10000,5000,-5000,2500,-2500,1250,-1250,625,-625]) == 25000000

Answer: assert Solution().maxScore(a = [0, 0, 0, 1], b = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 2000

Answer: assert Solution().maxScore(a = [1, -1, 1, -1], b = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10, -10]) == 38

Answer: assert Solution().maxScore(a = [-100, 200, -300, 400], b = [-99999, 99998, -99997, 99996, -99995, 99994, -99993, 99992, -99991, 99990]) == 99997000

Answer: assert Solution().maxScore(a = [0, 0, 0, 0], b = [100000, -100000, 50000, -50000, 25000, -25000, 12500, -12500, 6250, -6250]) == 0

Answer: assert Solution().maxScore(a = [1, 1, -1, -1], b = [1, -1, 2, -2, 3, -3, 4, -4, 5, -5, 6, -6, 7, -7, 8, -8, 9, -9, 10]) == 32

Answer: assert Solution().maxScore(a = [5, -1, 3, 2], b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]) == 164

Answer: assert Solution().maxScore(a = [-1, -1, -1, -1], b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == -10

Answer: assert Solution().maxScore(a = [1,2,3,4], b = [10,20,30,40,50,60,70,80,90,100]) == 900

Answer: assert Solution().maxScore(a = [1, 1, 1, 1], b = [-1000, -999, -998, -997, -996, -995, -994, -993, -992, -991, -990, -989, -988]) == -3958

Answer: assert Solution().maxScore(a = [1,1,1,1], b = [100000,90000,80000,70000,60000,50000,40000,30000,20000,10000,0,-10000,-20000,-30000,-40000,-50000,-60000,-70000,-80000,-90000,-100000]) == 340000

Answer: assert Solution().maxScore(a = [100000, -100000, 50000, -50000], b = [-99999, 99999, -99998, 99998, -99997, 99997, -99996, 99996, -99995, 99995]) == 29999450000

Answer: assert Solution().maxScore(a = [1,-2,3,-4], b = [-50000,50000,-25000,25000,-12500,12500,-6250,6250,-3125,3125,-1562,1562,-781,781,-390,390,-195,195,-97,97,-48,48,-24,24,-12,12,-6,6,-3,3,-1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]) == 225000

Answer: assert Solution().maxScore(a = [10, 0, 5, 0], b = [1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 9, 0, 10, 0]) == 140

Answer: assert Solution().maxScore(a = [1, 2, 3, 4], b = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 90

Answer: assert Solution().maxScore(a = [5, 3, 1, 2], b = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100]) == 560

Answer: assert Solution().maxScore(a = [1, 2, 3, 4], b = [10, -20, 30, -40, 50, -60, 70, -80, 90, -100, 110, -120]) == 900

Answer: assert Solution().maxScore(a = [1000, 2000, 3000, 4000], b = [1000, 999, 998, 997, 996, 995, 994, 993, 992, 991, 990]) == 9980000

Answer: assert Solution().maxScore(a = [100, 200, 300, 400], b = [-5000, 6000, -7000, 8000, -9000, 10000, -11000, 12000, -13000, 14000, -15000, 16000, -17000, 18000, -19000, 20000, -21000, 22000, -23000, 24000, -25000, 26000, -27000, 28000, -29000, 30000]) == 28000000

Answer: assert Solution().maxScore(a = [1, -1, 1, -1], b = [100, -100, 200, -200, 300, -300, 400, -400, 500, -500, 600, -600, 700, -700, 800, -800, 900, -900, 1000, -1000, 1100, -1100, 1200, -1200, 1300, -1300, 1400, -1400, 1500, -1500]) == 5800

Answer: assert Solution().maxScore(a = [-5, 3, 7, -2], b = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200]) == 7800

Answer: assert Solution().maxScore(a = [0, 0, 0, 1], b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 10

Answer: assert Solution().maxScore(a = [-10, -20, -30, -40], b = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 0, -100, -200, -300, -400, -500, -600, -700, -800, -900, -1000]) == 90000

Answer: assert Solution().maxScore(a = [1, 2, 3, 4], b = [-1, -2, -3, -4, -5, -6, -7, -8, -9, -10, -11, -12, -13, -14, -15]) == -30

Answer: assert Solution().maxScore(a = [1000, 2000, 3000, 4000], b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30]) == 290000

Answer: assert Solution().maxScore(a = [1, 1, 1, 1], b = [100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200, 1300, 1400, 1500, 1600, 1700, 1800, 1900, 2000]) == 7400

Answer: assert Solution().maxScore(a = [1, 0, 0, 0], b = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == 7

Answer: assert Solution().maxScore(a = [100000, -100000, 200000, -200000], b = [-50000, 60000, -70000, 80000, -90000, 100000, -110000, 120000, -130000, 140000, -150000, 160000, -170000, 180000, -190000, 200000, -210000, 220000, -230000, 240000]) == 131000000000

Answer: assert Solution().maxScore(a = [0,0,0,1], b = [100000,-100000,50000,-50000,25000,-25000,12500,-12500,6250,-6250,3125,-3125,1562,-1562,781,-781,390,-390,195,-195,97,-97,48,-48,24,-24,12,-12,6,-6,3,-3,1,-1,0,0,0,0]) == 25000

Answer: assert Solution().maxScore(a = [1, -1, 1, -1], b = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == -20

Answer: assert Solution().maxScore(a = [3, 1, -4, 2], b = [5, -7, 12, 3, 1, -9, 8, -1, 10, 4]) == 95

Answer: assert Solution().maxScore(a = [-5, 2, -3, 1], b = [-1, 2, -3, 4, -5, 6, -7, 8, -9, 10, -11, 12, -13, 14]) == 132

Answer: assert Solution().maxScore(a = [1, 2, 3, 4], b = [-5, 4, -3, 2, -1, 0, 1, -2, 3, -4, 5, -6, 7, -8, 9, -10]) == 71

Answer: assert Solution().maxScore(a = [100, 200, 300, 400], b = [-100, -200, -300, -400, 500, 600, 700, 800, 900, 1000]) == 900000

Answer: assert Solution().maxScore(a = [1, 1, 1, 1], b = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]) == 34

Answer: assert Solution().maxScore(a = [100, -200, 300, -400], b = [1000, 2000, 3000, 4000, 5000, 6000, 7000, 8000, 9000, 10000]) == -1000000

Answer: assert Solution().maxScore(a = [5, -5, 3, -3], b = [20, -20, 15, -15, 10, -10, 5, -5, 0, 5, -5, 10, -10, 15, -15, 20, -20, 25, -25, 30, -30]) == 430

import random
import functools
import collections
import string
import math
import datetime

from typing import *
from functools import *
from collections import *
from itertools import *
from heapq import *
from bisect import *
from string import *
from operator import *
from math import *

inf = float('inf')

class ListNode:
    def __init__(self, val=0, next=None):
        self.val = val
        self.next = next

def list_node(values: list):
    if not values:
        return None
    head = ListNode(values[0])
    p = head
    for val in values[1:]:
        node = ListNode(val)
        p.next = node
        p = node
    return head

def is_same_list(p1, p2):
    if p1 is None and p2 is None:
        return True
    if not p1 or not p2:
        return False
    return p1.val == p2.val and is_same_list(p1.next, p2.next)

class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right

def tree_node(values: list):
    if not values:
        return None
    root = TreeNode(values[0])
    i = 1
    queue = deque()
    queue.append(root)
    while queue:
        node = queue.popleft()
        if i < len(values) and values[i] is not None:
            node.left = TreeNode(values[i])
            queue.append(node.left)
        i += 1
        if i < len(values) and values[i] is not None:
            node.right = TreeNode(values[i])
            queue.append(node.right)
        i += 1
    return root

def is_same_tree(p, q):
    if not p and not q:
        return True
    elif not p or not q:
        return False
    elif p.val != q.val:
        return False
    else:
        return is_same_tree(p.left, q.left) and is_same_tree(p.right, q.right)

class Solution:
    def maxScore(self, a: List[int], b: List[int]) -> int:
        @cache
        def dfs(i: int, j: int) -> int:
            if j >= len(b):
                return 0 if i >= len(a) else -inf
            if i >= len(a):
                return 0
            return max(dfs(i, j + 1), a[i] * b[j] + dfs(i + 1, j + 1))

        return dfs(0, 0)