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:
There are n points on an infinite plane. You are given two integer arrays xCoord and yCoord where (xCoord[i], yCoord[i]) represents the coordinates of the ith point.
Your task is to find the maximum area of a rectangle that:

Can be formed using four of these points as its corners.
Does not contain any other point inside or on its border.
Has its edges parallel to the axes.

Return the maximum area that you can obtain or -1 if no such rectangle is possible.

Example 1:

Input: xCoord = [1,1,3,3], yCoord = [1,3,1,3]
Output: 4
Explanation:

We can make a rectangle with these 4 points as corners and there is no other point that lies inside or on the border. Hence, the maximum possible area would be 4.

Example 2:

Input: xCoord = [1,1,3,3,2], yCoord = [1,3,1,3,2]
Output: -1
Explanation:

There is only one rectangle possible is with points [1,1], [1,3], [3,1] and [3,3] but [2,2] will always lie inside it. Hence, returning -1.

Example 3:

Input: xCoord = [1,1,3,3,1,3], yCoord = [1,3,1,3,2,2]
Output: 2
Explanation:

The maximum area rectangle is formed by the points [1,3], [1,2], [3,2], [3,3], which has an area of 2. Additionally, the points [1,1], [1,2], [3,1], [3,2] also form a valid rectangle with the same area.

Constraints:

1 <= xCoord.length == yCoord.length <= 2 * 105
0 <= xCoord[i], yCoord[i] <= 8 * 107
All the given points are unique.

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

SOLUTION:

Question:
PROBLEM:
There are n points on an infinite plane. You are given two integer arrays xCoord and yCoord where (xCoord[i], yCoord[i]) represents the coordinates of the ith point.
Your task is to find the maximum area of a rectangle that:

Can be formed using four of these points as its corners.
Does not contain any other point inside or on its border.
Has its edges parallel to the axes.

Return the maximum area that you can obtain or -1 if no such rectangle is possible.

Example 1:

Input: xCoord = [1,1,3,3], yCoord = [1,3,1,3]
Output: 4
Explanation:

We can make a rectangle with these 4 points as corners and there is no other point that lies inside or on the border. Hence, the maximum possible area would be 4.

Example 2:

Input: xCoord = [1,1,3,3,2], yCoord = [1,3,1,3,2]
Output: -1
Explanation:

There is only one rectangle possible is with points [1,1], [1,3], [3,1] and [3,3] but [2,2] will always lie inside it. Hence, returning -1.

Example 3:

Input: xCoord = [1,1,3,3,1,3], yCoord = [1,3,1,3,2,2]
Output: 2
Explanation:

The maximum area rectangle is formed by the points [1,3], [1,2], [3,2], [3,3], which has an area of 2. Additionally, the points [1,1], [1,2], [3,1], [3,2] also form a valid rectangle with the same area.

Constraints:

1 <= xCoord.length == yCoord.length <= 2 * 105
0 <= xCoord[i], yCoord[i] <= 8 * 107
All the given points are unique.

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

SOLUTION:

assert Solution().maxRectangleArea(xCoord = [5,5,7,7], yCoord = [5,7,5,7]) == 4

assert Solution().maxRectangleArea(xCoord = [1,1,10,10], yCoord = [1,10,1,10]) == 81

assert Solution().maxRectangleArea(xCoord = [1,1,3,3,1,3], yCoord = [1,3,1,3,2,2]) == 2

assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5], yCoord = [1,3,1,3,1,3]) == 4

assert Solution().maxRectangleArea(xCoord = [1,2,3,4,5], yCoord = [1,2,3,4,5]) == -1

assert Solution().maxRectangleArea(xCoord = [1,1,1,1], yCoord = [1,1,1,1]) == -1

assert Solution().maxRectangleArea(xCoord = [5,5,10,10], yCoord = [5,10,5,10]) == 25

assert Solution().maxRectangleArea(xCoord = [0,0,2,2], yCoord = [0,2,0,2]) == 4

assert Solution().maxRectangleArea(xCoord = [1,1,3,3,4,4], yCoord = [1,3,1,3,2,3]) == 4

assert Solution().maxRectangleArea(xCoord = [1,1,3,3,2], yCoord = [1,3,1,3,2]) == -1

assert Solution().maxRectangleArea(xCoord = [0,0,2,2,4,4], yCoord = [0,2,0,2,0,2]) == 4

assert Solution().maxRectangleArea(xCoord = [10,10,20,20], yCoord = [10,20,10,20]) == 100

assert Solution().maxRectangleArea(xCoord = [0,0,8,8,4,4], yCoord = [0,8,0,8,4,4]) == -1

assert Solution().maxRectangleArea(xCoord = [5,5,7,7,6], yCoord = [5,7,5,7,6]) == -1

assert Solution().maxRectangleArea(xCoord = [5,5,15,15], yCoord = [5,15,5,15]) == 100

assert Solution().maxRectangleArea(xCoord = [1,1,3,3], yCoord = [1,3,1,3]) == 4

assert Solution().maxRectangleArea(xCoord = [1,2,3,4], yCoord = [1,1,1,1]) == -1

assert Solution().maxRectangleArea(xCoord = [1,1,1,1], yCoord = [1,2,3,4]) == -1

assert Solution().maxRectangleArea(xCoord = [10,20,30,40], yCoord = [10,20,30,40]) == -1

assert Solution().maxRectangleArea(xCoord = [1,1,10,10,5,5], yCoord = [1,10,1,10,5,5]) == -1

assert Solution().maxRectangleArea(xCoord = [1,5,5,9,9,13], yCoord = [1,5,1,5,1,5]) == 16

assert Solution().maxRectangleArea(xCoord = [1,2,2,3,3,4], yCoord = [1,2,3,1,3,2]) == -1

assert Solution().maxRectangleArea(xCoord = [1, 1, 4, 4, 2, 2], yCoord = [1, 4, 1, 4, 2, 2]) == -1

assert Solution().maxRectangleArea(xCoord = [1,1,5,5,9,9], yCoord = [1,9,1,9,1,9]) == 32

Answer: assert Solution().maxRectangleArea(xCoord = [5,5,7,7], yCoord = [5,7,5,7]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,10,10], yCoord = [1,10,1,10]) == 81

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,1,3], yCoord = [1,3,1,3,2,2]) == 2

Answer: assert Solution().maxRectangleArea(xCoord = [0,0,80000000,80000000], yCoord = [0,80000000,0,80000000]) == 6400000000000000

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5], yCoord = [1,3,1,3,1,3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1,2,3,4,5], yCoord = [1,2,3,4,5]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,1,1], yCoord = [1,1,1,1]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [5,5,10,10], yCoord = [5,10,5,10]) == 25

Answer: assert Solution().maxRectangleArea(xCoord = [0,0,2,2], yCoord = [0,2,0,2]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,4,4], yCoord = [1,3,1,3,2,3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,2], yCoord = [1,3,1,3,2]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [0,0,2,2,4,4], yCoord = [0,2,0,2,0,2]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [10,10,20,20], yCoord = [10,20,10,20]) == 100

Answer: assert Solution().maxRectangleArea(xCoord = [0,0,8,8,4,4], yCoord = [0,8,0,8,4,4]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [5,5,7,7,6], yCoord = [5,7,5,7,6]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [5,5,15,15], yCoord = [5,15,5,15]) == 100

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3], yCoord = [1,3,1,3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1,2,3,4], yCoord = [1,1,1,1]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,2,3,4,5,6,7,8], yCoord = [1,2,3,4,5,6,7,8]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,1,1], yCoord = [1,2,3,4]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [10,20,30,40], yCoord = [10,20,30,40]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9], yCoord = [1,3,1,3,5,7,5,7,9,9]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [0, 0, 100000000, 100000000], yCoord = [0, 100000000, 0, 100000000]) == 10000000000000000

Answer: assert Solution().maxRectangleArea(xCoord = [10,20,30,40,50,60,70,80,90,100], yCoord = [10,20,30,40,50,60,70,80,90,100]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 5, 5, 10, 10, 15, 15], yCoord = [1, 10, 1, 10, 1, 10, 1, 10]) == 45

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9,11,11,13,13], yCoord = [1,9,1,9,5,5,7,7,3,3,11,11,13,13]) == 16

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

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 2, 2, 4, 4, 6, 6], yCoord = [1, 3, 1, 3, 1, 3, 1, 3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [10,10,20,20,30,30,40,40], yCoord = [10,20,10,20,10,20,10,20]) == 100

Answer: assert Solution().maxRectangleArea(xCoord = [0,0,100000000,100000000], yCoord = [0,100000000,0,100000000]) == 10000000000000000

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

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,2,2,4,4,5,5,6,6,8,8,9,9], yCoord = [1,9,1,9,5,5,7,7,3,3,11,11,13,13]) == 8

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9,11,11,13,13,15,15,17,17,19,19], yCoord = [1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3,1,3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,10,10,5,5], yCoord = [1,10,1,10,5,5]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [5,5,15,15,25,25,35,35,45,45], yCoord = [5,45,5,45,5,45,5,45,5,45]) == 400

Answer: assert Solution().maxRectangleArea(xCoord = [10000000, 10000000, 20000000, 20000000, 30000000, 30000000, 40000000, 40000000], yCoord = [10000000, 20000000, 10000000, 20000000, 10000000, 20000000, 10000000, 20000000]) == 100000000000000

Answer: assert Solution().maxRectangleArea(xCoord = [1, 4, 4, 1, 7, 7, 10, 10], yCoord = [1, 1, 5, 5, 3, 8, 3, 8]) == 15

Answer: assert Solution().maxRectangleArea(xCoord = [5,5,6,6,7,7,8,8], yCoord = [5,6,5,6,7,8,7,8]) == 1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10], yCoord = [1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2]) == 1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3,3,3], yCoord = [1,2,3,4,5,6,7,8,9,10,1,2,3,4,5,6,7,8,9,10]) == 2

Answer: assert Solution().maxRectangleArea(xCoord = [2,2,4,4,6,6,8,8,10,10], yCoord = [2,4,2,4,6,8,6,8,10,10]) == 4

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

Answer: assert Solution().maxRectangleArea(xCoord = [0,0,8,8,4,4,6,6,2,2,7,7,3,3,5,5], yCoord = [0,8,0,8,4,6,4,6,2,7,2,7,3,5,3,5]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [2, 2, 5, 5, 3, 3, 4, 4], yCoord = [2, 5, 2, 5, 3, 3, 4, 4]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [10, 10, 30, 30, 20, 20, 25, 25], yCoord = [10, 30, 10, 30, 15, 15, 25, 25]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1, 4, 4, 1, 6, 6, 9, 9, 3, 3, 12, 12], yCoord = [1, 1, 5, 5, 3, 7, 3, 7, 2, 4, 2, 4]) == 12

Answer: assert Solution().maxRectangleArea(xCoord = [5,5,15,15,25,25,35,35,45,45], yCoord = [5,15,5,15,25,25,35,35,45,45]) == 100

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10], yCoord = [1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19], yCoord = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [5,5,10,10,15,15,20,20,25,25], yCoord = [5,10,5,10,5,10,5,10,5,10]) == 25

Answer: assert Solution().maxRectangleArea(xCoord = [1,2,3,4,5,6,7,8,9,10], yCoord = [1,2,3,4,5,6,7,8,9,10]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,1,1,3,3,3,3,5,5,5,5], yCoord = [1,3,5,7,1,3,5,7,1,3,5,7]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [2, 2, 4, 4, 6, 6, 8, 8], yCoord = [2, 6, 2, 6, 2, 6, 2, 6]) == 8

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9,11,11,13,13], yCoord = [1,3,1,3,5,7,5,7,9,11,9,11,13,13]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [0,0,0,0,10,10,10,10,20,20,20,20], yCoord = [0,10,20,30,0,10,20,30,0,10,20,30]) == 100

Answer: assert Solution().maxRectangleArea(xCoord = [2,2,4,4,6,6,8,8], yCoord = [2,8,2,8,2,8,2,8]) == 12

Answer: assert Solution().maxRectangleArea(xCoord = [10,10,30,30,20,20,40,40], yCoord = [10,30,10,30,20,40,20,40]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5], yCoord = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,1,1,3,3,2,2,4,4], yCoord = [1,3,1,3,2,4,2,4,1,3,1,3]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], yCoord = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [100, 100, 150, 150, 120, 120, 130, 130], yCoord = [100, 150, 100, 150, 120, 130, 120, 130]) == 100

Answer: assert Solution().maxRectangleArea(xCoord = [10, 10, 20, 20, 30, 30, 40, 40], yCoord = [10, 20, 10, 20, 10, 20, 10, 20]) == 100

Answer: assert Solution().maxRectangleArea(xCoord = [10,10,20,20,30,30,40,40,50,50], yCoord = [10,50,10,50,30,30,40,40,20,20]) == 400

Answer: assert Solution().maxRectangleArea(xCoord = [0, 0, 80000000, 80000000], yCoord = [0, 80000000, 0, 80000000]) == 6400000000000000

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9,11,11,13,13], yCoord = [1,13,1,13,1,13,1,13,1,13,1,13,1,13]) == 24

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 3, 3, 5, 5, 7, 7], yCoord = [1, 3, 1, 3, 1, 3, 1, 3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 5, 5, 10, 10, 15, 15, 20, 20, 25, 25], yCoord = [1, 5, 1, 5, 1, 5, 1, 5, 1, 5, 1, 5]) == 20

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 10, 10, 5, 5, 7, 7, 3, 3], yCoord = [1, 10, 1, 10, 5, 5, 7, 7, 3, 3]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,2,3,4,5,6,7,8,9,10], yCoord = [1,1,1,1,1,1,1,1,1,1]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,5,5,9,9,13], yCoord = [1,5,1,5,1,5]) == 16

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 9, 9, 5, 5, 3, 3, 7, 7, 6, 6, 4, 4, 8, 8], yCoord = [1, 9, 1, 9, 5, 5, 3, 3, 7, 7, 6, 6, 4, 4, 8, 8]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [0, 0, 2, 2, 4, 4, 6, 6], yCoord = [0, 2, 0, 2, 0, 2, 0, 2]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [0,0,1,1,2,2,3,3], yCoord = [0,1,0,1,0,1,0,1]) == 1

Answer: assert Solution().maxRectangleArea(xCoord = [1,3,5,7,9,11,13,15], yCoord = [1,3,5,7,9,11,13,15]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,2,2,3,3,4,4,5,5], yCoord = [1,5,1,5,1,5,1,5,1,5]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [2,2,8,8,4,4,6,6], yCoord = [2,8,2,8,4,6,4,6]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [8,8,16,16,12,12], yCoord = [8,16,8,16,10,14]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [0,0,4,4,8,8,12,12], yCoord = [0,4,0,4,0,4,0,4]) == 16

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9], yCoord = [1,9,1,9,1,9,1,9,1,9]) == 16

Answer: assert Solution().maxRectangleArea(xCoord = [2, 2, 4, 4, 6, 6, 8, 8, 10, 10], yCoord = [2, 6, 2, 6, 2, 6, 2, 6, 2, 6]) == 8

Answer: assert Solution().maxRectangleArea(xCoord = [0,0,10,10,5,5,6,6], yCoord = [0,10,0,10,5,6,5,6]) == 1

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 2, 2, 4, 4, 8, 8], yCoord = [1, 2, 1, 2, 1, 2, 1, 2]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [2,2,6,6,10,10,14,14,18,18,22,22], yCoord = [2,22,2,22,10,10,14,14,6,6,18,18]) == 80

Answer: assert Solution().maxRectangleArea(xCoord = [1,2,2,3,3,4], yCoord = [1,2,3,1,3,2]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [10,10,20,20,15,15], yCoord = [10,20,10,20,12,18]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [2,2,8,8,12,12,18,18], yCoord = [3,9,3,9,3,9,3,9]) == 36

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11, 13, 13], yCoord = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,5,5,3,3,7,7], yCoord = [1,5,1,5,3,7,3,7]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 4, 4, 2, 2], yCoord = [1, 4, 1, 4, 2, 2]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [100, 100, 200, 200, 300, 300, 400, 400], yCoord = [100, 200, 100, 200, 100, 200, 100, 200]) == 10000

Answer: assert Solution().maxRectangleArea(xCoord = [2,2,5,5,7,7,9,9], yCoord = [2,5,2,5,7,7,9,9]) == 9

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 3, 3, 5, 5, 7, 7, 9, 9, 11, 11], yCoord = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8], yCoord = [1, 2, 1, 2, 3, 4, 3, 4, 5, 6, 5, 6, 7, 8, 7, 8]) == 1

Answer: assert Solution().maxRectangleArea(xCoord = [3, 3, 15, 15, 8, 8, 10, 10], yCoord = [3, 15, 3, 15, 8, 10, 8, 10]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 3, 3, 5, 5, 7, 7, 9, 9], yCoord = [1, 3, 1, 3, 1, 3, 1, 3, 1, 3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 10000000, 10000000, 5000000, 5000000, 6000000, 6000000], yCoord = [1, 10000000, 1, 10000000, 5000000, 6000000, 5000000, 6000000]) == 1000000000000

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3], yCoord = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == 1

Answer: assert Solution().maxRectangleArea(xCoord = [1,2,3,4,5,6,7,8,9,10], yCoord = [1,1,1,1,2,2,2,2,3,3]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [0, 0, 100000000, 100000000, 50000000, 50000000], yCoord = [0, 100000000, 0, 100000000, 50000000, 50000000]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7], yCoord = [1,3,1,3,5,7,5,7]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 5, 5, 3, 3, 2, 2, 4, 4, 6, 6], yCoord = [1, 5, 1, 5, 3, 3, 2, 2, 4, 4, 6, 6]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9,11,11], yCoord = [1,3,1,3,1,3,1,3,1,3,1,3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9,11,11,13,13], yCoord = [1,3,1,3,1,3,1,3,1,3,1,3,1,3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 3, 3, 5, 5, 7, 7], yCoord = [1, 3, 1, 3, 5, 5, 7, 7]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [0,0,20000000,20000000,10000000,10000000], yCoord = [0,20000000,0,20000000,10000000,10000000]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,2,2,1,4,5,5,4,6,7,7,6,8,9,9,8], yCoord = [1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2]) == 2

Answer: assert Solution().maxRectangleArea(xCoord = [2, 2, 8, 8, 5, 5, 7, 7], yCoord = [2, 6, 2, 6, 4, 4, 8, 8]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [3,3,5,5,7,7,9,9], yCoord = [3,7,3,7,3,7,3,7]) == 8

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,1,1,1,1,1,1,3,3,3,3,3,3,3,3], yCoord = [1,2,3,4,5,6,7,8,1,2,3,4,5,6,7,8]) == 2

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 5, 5, 10, 10, 15, 15, 20, 20], yCoord = [1, 5, 1, 5, 1, 5, 1, 5, 1, 5]) == 20

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9], yCoord = [1,9,1,9,5,5,3,3,7,7]) == 16

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9,11,11], yCoord = [1,11,1,11,1,11,1,11,1,11,1,11]) == 20

Answer: assert Solution().maxRectangleArea(xCoord = [0, 0, 5, 5, 3, 3, 2, 2], yCoord = [0, 5, 0, 5, 1, 3, 1, 3]) == 2

Answer: assert Solution().maxRectangleArea(xCoord = [1,2,2,3,3,4,4,5,5,6], yCoord = [1,1,2,1,2,2,3,2,3,3]) == 1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,5,5,9,9], yCoord = [1,9,1,9,1,9]) == 32

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5], yCoord = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == 1

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 10000000, 10000000, 5000000, 5000000], yCoord = [1, 10000000, 1, 10000000, 5000000, 5000000]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,4,4,2,2,5,5], yCoord = [1,4,1,4,2,5,2,5]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1, 4, 4, 1, 6, 6, 9, 9], yCoord = [1, 1, 5, 5, 3, 7, 3, 7]) == 12

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7], yCoord = [1,3,1,3,1,3,1,3]) == 4

Answer: assert Solution().maxRectangleArea(xCoord = [10, 10, 20, 20, 15, 15, 18, 18], yCoord = [10, 20, 10, 20, 12, 18, 12, 18]) == 18

Answer: assert Solution().maxRectangleArea(xCoord = [100,100,150,150,200,200,250,250], yCoord = [100,150,100,150,100,150,100,150]) == 2500

Answer: assert Solution().maxRectangleArea(xCoord = [2,2,6,6,4,4,8,8], yCoord = [2,6,2,6,2,6,2,6]) == 8

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,1,1,1,1,1,1,1,1], yCoord = [1,2,3,4,5,6,7,8,9,10]) == -1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9,11,11,13,13,15,15,17,17], yCoord = [1,9,1,9,5,5,7,7,3,3,11,11,13,13,15,15,17,17]) == 16

Answer: assert Solution().maxRectangleArea(xCoord = [50000000,50000000,60000000,60000000,70000000,70000000,80000000,80000000], yCoord = [50000000,60000000,50000000,60000000,50000000,60000000,50000000,60000000]) == 100000000000000

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 3, 3, 5, 5, 7, 7], yCoord = [1, 3, 1, 3, 5, 7, 5, 7]) == 4

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

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,4,4,6,6,10,10], yCoord = [1,5,1,5,1,5,1,5]) == 16

Answer: assert Solution().maxRectangleArea(xCoord = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6], yCoord = [1, 2, 1, 2, 1, 2, 1, 2, 1, 2, 1, 2]) == 1

Answer: assert Solution().maxRectangleArea(xCoord = [1,1,3,3,5,5,7,7,9,9,11,11,13,13,15,15], yCoord = [1,15,1,15,5,5,7,7,3,3,11,11,13,13,9,9]) == 28

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 Fenwick:
    def __init__(self, n: int):
        self.tree = [0] * (n + 1)

    def add(self, i: int) -> None:
        while i < len(self.tree):
            self.tree[i] += 1
            i += i & -i

    # [1,i] 中的元素和
    def pre(self, i: int) -> int:
        res = 0
        while i > 0:
            res += self.tree[i]
            i &= i - 1
        return res

    # [l,r] 中的元素和
    def query(self, l: int, r: int) -> int:
        return self.pre(r) - self.pre(l - 1)

class Solution:
    def maxRectangleArea(self, xCoord: List[int], yCoord: List[int]) -> int:
        points = sorted(zip(xCoord, yCoord))
        ys = sorted(set(yCoord))  # 离散化用

        ans = -1
        tree = Fenwick(len(ys))
        tree.add(bisect_left(ys, points[0][1]) + 1)  # 离散化
        pre = {}
        for (x1, y1), (x2, y2) in pairwise(points):
            y = bisect_left(ys, y2) + 1  # 离散化
            tree.add(y)
            if x1 != x2:  # 两点不在同一列
                continue
            cur = tree.query(bisect_left(ys, y1) + 1, y)
            if y2 in pre and pre[y2][1] == y1 and pre[y2][2] + 2 == cur:
                ans = max(ans, (x2 - pre[y2][0]) * (y2 - y1))
            pre[y2] = (x1, y1, cur)
        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:
Alice has just graduated from wizard school, and wishes to cast a magic spell to celebrate. The magic spell contains certain focus points where magic needs to be concentrated, and some of these focus points contain magic crystals which serve as the spell's energy source. Focus points can be linked through directed runes, which channel magic flow from one focus point to another.
You are given a integer n denoting the number of focus points and an array of integers crystals where crystals[i] indicates a focus point which holds a magic crystal. You are also given two integer arrays flowFrom and flowTo, which represent the existing directed runes. The ith rune allows magic to freely flow from focus point flowFrom[i] to focus point flowTo[i].
You need to find the number of directed runes Alice must add to her spell, such that each focus point either:

Contains a magic crystal.
Receives magic flow from another focus point.

Return the minimum number of directed runes that she should add.

Example 1:

Input: n = 6, crystals = [0], flowFrom = [0,1,2,3], flowTo = [1,2,3,0]
Output: 2
Explanation:

Add two directed runes:

From focus point 0 to focus point 4.
From focus point 0 to focus point 5.

Example 2:

Input: n = 7, crystals = [3,5], flowFrom = [0,1,2,3,5], flowTo = [1,2,0,4,6]
Output: 1
Explanation:

Add a directed rune from focus point 4 to focus point 2.

Constraints:

2 <= n <= 105
1 <= crystals.length <= n
0 <= crystals[i] <= n - 1
1 <= flowFrom.length == flowTo.length <= min(2 * 105, (n * (n - 1)) / 2)
0 <= flowFrom[i], flowTo[i] <= n - 1
flowFrom[i] != flowTo[i]
All pre-existing directed runes are distinct.

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

SOLUTION:

Question:
PROBLEM:
Alice has just graduated from wizard school, and wishes to cast a magic spell to celebrate. The magic spell contains certain focus points where magic needs to be concentrated, and some of these focus points contain magic crystals which serve as the spell's energy source. Focus points can be linked through directed runes, which channel magic flow from one focus point to another.
You are given a integer n denoting the number of focus points and an array of integers crystals where crystals[i] indicates a focus point which holds a magic crystal. You are also given two integer arrays flowFrom and flowTo, which represent the existing directed runes. The ith rune allows magic to freely flow from focus point flowFrom[i] to focus point flowTo[i].
You need to find the number of directed runes Alice must add to her spell, such that each focus point either:

Contains a magic crystal.
Receives magic flow from another focus point.

Return the minimum number of directed runes that she should add.

Example 1:

Input: n = 6, crystals = [0], flowFrom = [0,1,2,3], flowTo = [1,2,3,0]
Output: 2
Explanation:

Add two directed runes:

From focus point 0 to focus point 4.
From focus point 0 to focus point 5.

Example 2:

Input: n = 7, crystals = [3,5], flowFrom = [0,1,2,3,5], flowTo = [1,2,0,4,6]
Output: 1
Explanation:

Add a directed rune from focus point 4 to focus point 2.

Constraints:

2 <= n <= 105
1 <= crystals.length <= n
0 <= crystals[i] <= n - 1
1 <= flowFrom.length == flowTo.length <= min(2 * 105, (n * (n - 1)) / 2)
0 <= flowFrom[i], flowTo[i] <= n - 1
flowFrom[i] != flowTo[i]
All pre-existing directed runes are distinct.

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

SOLUTION:

assert Solution().minRunesToAdd(n = 4, crystals = [2], flowFrom = [1,3], flowTo = [2,0]) == 2

assert Solution().minRunesToAdd(n = 5, crystals = [1,4], flowFrom = [0,2], flowTo = [1,3]) == 2

assert Solution().minRunesToAdd(n = 3, crystals = [0,2], flowFrom = [], flowTo = []) == 1

assert Solution().minRunesToAdd(n = 7, crystals = [3,5], flowFrom = [0,1,2,3,5], flowTo = [1,2,0,4,6]) == 1

assert Solution().minRunesToAdd(n = 6, crystals = [0], flowFrom = [0,1,2,3], flowTo = [1,2,3,0]) == 2

assert Solution().minRunesToAdd(n = 8, crystals = [3, 6], flowFrom = [0,1,2,4,5,7], flowTo = [1,2,3,5,6,0]) == 2

Answer: assert Solution().minRunesToAdd(n = 4, crystals = [2], flowFrom = [1,3], flowTo = [2,0]) == 2

Answer: assert Solution().minRunesToAdd(n = 5, crystals = [1,4], flowFrom = [0,2], flowTo = [1,3]) == 2

Answer: assert Solution().minRunesToAdd(n = 3, crystals = [0,2], flowFrom = [], flowTo = []) == 1

Answer: assert Solution().minRunesToAdd(n = 7, crystals = [3,5], flowFrom = [0,1,2,3,5], flowTo = [1,2,0,4,6]) == 1

Answer: assert Solution().minRunesToAdd(n = 6, crystals = [0], flowFrom = [0,1,2,3], flowTo = [1,2,3,0]) == 2

Answer: assert Solution().minRunesToAdd(n = 15, crystals = [7, 12], flowFrom = [0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 13, 14], flowTo = [1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 14, 0]) == 2

Answer: assert Solution().minRunesToAdd(n = 50, crystals = [5, 15, 25, 35, 45], flowFrom = [0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40, 41, 42, 43, 44, 46, 47, 48, 49], flowTo = [1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 43, 44, 45, 47, 48, 49, 0]) == 5

Answer: assert Solution().minRunesToAdd(n = 20, crystals = [5, 15], flowFrom = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19], flowTo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0]) == 0

Answer: assert Solution().minRunesToAdd(n = 11, crystals = [2, 8], flowFrom = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], flowTo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 0]) == 0

Answer: assert Solution().minRunesToAdd(n = 12, crystals = [5, 9], flowFrom = [0, 1, 2, 3, 4, 6, 7, 8, 10, 11], flowTo = [1, 2, 3, 4, 5, 7, 8, 9, 11, 5]) == 3

Answer: assert Solution().minRunesToAdd(n = 50, crystals = [10, 20, 30, 40], flowFrom = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49], flowTo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 48, 49, 0]) == 4

Answer: assert Solution().minRunesToAdd(n = 10, crystals = [0, 8], flowFrom = [1, 2, 3, 4, 5, 6, 7, 9], flowTo = [2, 3, 4, 5, 6, 7, 8, 0]) == 2

Answer: assert Solution().minRunesToAdd(n = 100, crystals = [1, 33, 66, 99], flowFrom = [1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19], flowTo = [2,3,4,5,6,7,8,9,10,11,12,13,14,15,17,18,19,0]) == 78

Answer: assert Solution().minRunesToAdd(n = 20, crystals = [5, 15], flowFrom = [0,1,2,3,4,6,7,8,9,10,11,12,13,14,16,17,18,19], flowTo = [1,2,3,4,5,10,11,12,13,14,15,16,17,18,5,6,7,8]) == 3

Answer: assert Solution().minRunesToAdd(n = 15, crystals = [3, 7, 12], flowFrom = [0, 1, 2, 4, 5, 6, 8, 9, 10, 11, 13, 14], flowTo = [1, 2, 3, 5, 6, 7, 9, 10, 11, 12, 14, 3]) == 4

Answer: assert Solution().minRunesToAdd(n = 35, crystals = [2, 12, 22, 32, 34], flowFrom = [0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33], flowTo = [1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 34]) == 5

Answer: assert Solution().minRunesToAdd(n = 100, crystals = [0, 30, 60, 90], flowFrom = [1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 56, 57, 58, 59, 61, 62, 63, 64, 65, 66, 67, 68, 69, 71, 72, 73, 74, 75, 76, 77, 78, 79, 81, 82, 83, 84, 85, 86, 87, 88, 89, 91, 92, 93, 94, 95, 96, 97, 98, 99], flowTo = [2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 48, 49, 50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 62, 63, 64, 65, 66, 67, 68, 69, 70, 72, 73, 74, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 92, 93, 94, 95, 96, 97, 98, 99, 0]) == 10

Answer: assert Solution().minRunesToAdd(n = 75, crystals = [10, 25, 40, 55, 70], flowFrom = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74], flowTo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 0]) == 32

Answer: assert Solution().minRunesToAdd(n = 20, crystals = [1, 15, 18], flowFrom = [0, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 19], flowTo = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 1]) == 3

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

Answer: assert Solution().minRunesToAdd(n = 15, crystals = [3, 11, 14], flowFrom = [0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 12, 13], flowTo = [1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14]) == 3

Answer: assert Solution().minRunesToAdd(n = 10, crystals = [0, 7], flowFrom = [1,2,3,4,5,6,8,9], flowTo = [0,0,0,0,0,0,0,0]) == 8

Answer: assert Solution().minRunesToAdd(n = 8, crystals = [3, 6], flowFrom = [0,1,2,4,5,7], flowTo = [1,2,3,5,6,0]) == 2

Answer: assert Solution().minRunesToAdd(n = 30, crystals = [0, 10, 20], flowFrom = [1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19], flowTo = [2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,0]) == 11

Answer: assert Solution().minRunesToAdd(n = 50, crystals = [25, 49], flowFrom = [0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48], flowTo = [25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,25,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49,49]) == 48

Answer: assert Solution().minRunesToAdd(n = 10, crystals = [0, 9], flowFrom = [0, 1, 2, 3, 4, 5, 6, 7, 8], flowTo = [1, 2, 3, 4, 5, 6, 7, 8, 9]) == 0

Answer: assert Solution().minRunesToAdd(n = 10, crystals = [0, 7], flowFrom = [0,1,2,3,4,5,6,7,8,9], flowTo = [1,2,3,4,5,6,7,8,9,0]) == 0

Answer: assert Solution().minRunesToAdd(n = 12, crystals = [3, 8], flowFrom = [0, 1, 2, 4, 5, 6, 7, 9, 10, 11], flowTo = [1, 2, 3, 5, 6, 7, 8, 10, 11, 0]) == 2

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

Answer: assert Solution().minRunesToAdd(n = 8, crystals = [1, 6], flowFrom = [0, 1, 2, 3, 4, 5, 6, 7], flowTo = [1, 2, 3, 4, 5, 6, 7, 0]) == 0

Answer: assert Solution().minRunesToAdd(n = 18, crystals = [4, 14], flowFrom = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17], flowTo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0]) == 0

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

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

Answer: assert Solution().minRunesToAdd(n = 20, crystals = [0, 10, 15], flowFrom = [1,2,3,4,5,6,7,8,9,11,12,13,14,16,17,18,19], flowTo = [2,3,4,5,6,7,8,9,10,12,13,14,15,17,18,19,0]) == 3

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

Answer: assert Solution().minRunesToAdd(n = 50, crystals = [10, 30, 40], flowFrom = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49], flowTo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22, 23, 24, 25, 26, 27, 28, 29, 30, 32, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 48, 49, 0]) == 4

Answer: assert Solution().minRunesToAdd(n = 20, crystals = [0, 5, 15], flowFrom = [1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19], flowTo = [2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 0]) == 3

Answer: assert Solution().minRunesToAdd(n = 15, crystals = [2, 7, 12], flowFrom = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14], flowTo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0]) == 0

Answer: assert Solution().minRunesToAdd(n = 10, crystals = [0, 7], flowFrom = [1, 2, 3, 4, 5, 6, 8, 9], flowTo = [2, 3, 4, 5, 6, 7, 8, 9]) == 3

Answer: assert Solution().minRunesToAdd(n = 10, crystals = [0, 5, 9], flowFrom = [1, 2, 3, 4, 6, 7, 8], flowTo = [0, 1, 2, 3, 4, 5, 6]) == 2

Answer: assert Solution().minRunesToAdd(n = 15, crystals = [4, 11, 13], flowFrom = [0,1,2,3,5,6,7,8,9,10,12,14], flowTo = [1,2,3,4,6,7,8,9,10,11,13,12]) == 3

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

Answer: assert Solution().minRunesToAdd(n = 50, crystals = [5, 15, 25, 35], flowFrom = [0,1,2,3,4,6,7,8,9,10,11,12,13,14,16,17,18,19], flowTo = [1,2,3,4,5,7,8,9,10,11,12,13,14,15,17,18,19,0]) == 30

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

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

Answer: assert Solution().minRunesToAdd(n = 12, crystals = [5, 9], flowFrom = [0,1,2,3,4,6,7,8,10,11], flowTo = [1,2,3,4,5,7,8,9,11,6]) == 2

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

Answer: assert Solution().minRunesToAdd(n = 100, crystals = [10, 50, 90], flowFrom = [0,1,2,3,4,5,6,7,8,9,11,12,13,14,15,16,17,18,19], flowTo = [1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,0]) == 79

Answer: assert Solution().minRunesToAdd(n = 60, crystals = [15, 45, 50], flowFrom = [1,2,3,4,5,6,7,8,9,11,12,13,14,16,17,18,19], flowTo = [2,3,4,5,6,7,8,9,10,12,13,14,15,17,18,19,0]) == 41

Answer: assert Solution().minRunesToAdd(n = 15, crystals = [10, 14], flowFrom = [0,1,2,3,4,5,6,7,8,9,11,12,13], flowTo = [1,2,3,4,5,6,7,8,9,10,12,13,14]) == 2

Answer: assert Solution().minRunesToAdd(n = 15, crystals = [3, 11, 14], flowFrom = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13], flowTo = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]) == 1

Answer: assert Solution().minRunesToAdd(n = 20, crystals = [3, 8, 15, 19], flowFrom = [0, 1, 2, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 16, 17, 18], flowTo = [1, 2, 3, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 17, 18, 19]) == 4

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 minRunesToAdd(
        self, n: int, crystals: List[int], flowFrom: List[int], flowTo: List[int]
    ) -> int:
        def bfs(q: Deque[int]):
            while q:
                a = q.popleft()
                for b in g[a]:
                    if vis[b] == 1:
                        continue
                    vis[b] = 1
                    q.append(b)

        def dfs(a: int):
            vis[a] = 2
            for b in g[a]:
                if vis[b] > 0:
                    continue
                dfs(b)
            seq.append(a)

        g = [[] for _ in range(n)]
        for a, b in zip(flowFrom, flowTo):
            g[a].append(b)

        q = deque(crystals)
        vis = [0] * n
        for x in crystals:
            vis[x] = 1
        bfs(q)

        seq = []
        for i in range(n):
            if vis[i] == 0:
                dfs(i)
        seq.reverse()
        ans = 0
        for i in seq:
            if vis[i] == 2:
                q = deque([i])
                vis[i] = 1
                bfs(q)
                ans += 1
        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 array nums.
A split of an array nums is beautiful if:

The array nums is split into three subarrays: nums1, nums2, and nums3, such that nums can be formed by concatenating nums1, nums2, and nums3 in that order.
The subarray nums1 is a prefix of nums2 OR nums2 is a prefix of nums3.

Return the number of ways you can make this split.

Example 1:

Input: nums = [1,1,2,1]
Output: 2
Explanation:
The beautiful splits are:

A split with nums1 = [1], nums2 = [1,2], nums3 = [1].
A split with nums1 = [1], nums2 = [1], nums3 = [2,1].

Example 2:

Input: nums = [1,2,3,4]
Output: 0
Explanation:
There are 0 beautiful splits.

Constraints:

1 <= nums.length <= 5000
0 <= nums[i] <= 50

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

SOLUTION:

Question:
PROBLEM:
You are given an array nums.
A split of an array nums is beautiful if:

The array nums is split into three subarrays: nums1, nums2, and nums3, such that nums can be formed by concatenating nums1, nums2, and nums3 in that order.
The subarray nums1 is a prefix of nums2 OR nums2 is a prefix of nums3.

Return the number of ways you can make this split.

Example 1:

Input: nums = [1,1,2,1]
Output: 2
Explanation:
The beautiful splits are:

A split with nums1 = [1], nums2 = [1,2], nums3 = [1].
A split with nums1 = [1], nums2 = [1], nums3 = [2,1].

Example 2:

Input: nums = [1,2,3,4]
Output: 0
Explanation:
There are 0 beautiful splits.

Constraints:

1 <= nums.length <= 5000
0 <= nums[i] <= 50

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

SOLUTION:

assert Solution().beautifulSplits(nums = [1,2,3,1,2,3]) == 0

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

assert Solution().beautifulSplits(nums = [1,1,1,1]) == 3

assert Solution().beautifulSplits(nums = [0,0,0,0,0,0,0,0]) == 19

assert Solution().beautifulSplits(nums = [50,50,50,50,50]) == 6

assert Solution().beautifulSplits(nums = [1,2,2,1]) == 1

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

assert Solution().beautifulSplits(nums = [1,3,2,3,1]) == 0

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

assert Solution().beautifulSplits(nums = [1,2,3,4]) == 0

assert Solution().beautifulSplits(nums = [10,20,30,20,10,20]) == 0

assert Solution().beautifulSplits(nums = [5,5,5,0,0,5,5]) == 7

assert Solution().beautifulSplits(nums = [10,20,30,40,50]) == 0

assert Solution().beautifulSplits(nums = [5,5,5,5,5]) == 6

assert Solution().beautifulSplits(nums = [0,0,0,0,0]) == 6

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

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

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

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

assert Solution().beautifulSplits(nums = [50,50,50,50,50,50]) == 9

assert Solution().beautifulSplits(nums = [0,0,0,0,0,0]) == 9

assert Solution().beautifulSplits(nums = [1,1,1,2,1,1,1]) == 7

assert Solution().beautifulSplits(nums = [5,5,5,5,5,5]) == 9

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

assert Solution().beautifulSplits(nums = [1,1,2,1]) == 2

assert Solution().beautifulSplits(nums = [1,2,3,2,1]) == 0

assert Solution().beautifulSplits(nums = [1,2,1,3,2,1]) == 0

assert Solution().beautifulSplits(nums = [5,5,5,5,5,5,5,5,5,5]) == 32

assert Solution().beautifulSplits(nums = [1,1,1,2,2,2,3,3,3]) == 11

assert Solution().beautifulSplits(nums = [1,2,1,2,1]) == 2

assert Solution().beautifulSplits(nums = [1,2,1,1,2,1,2,1,1,2]) == 8

assert Solution().beautifulSplits(nums = [1,2,1,2,1,2,1,2]) == 7

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

assert Solution().beautifulSplits(nums = [1,1,2,2,3,3,4,4,5,5]) == 12

assert Solution().beautifulSplits(nums = [5,4,3,2,1,2,3,4,5]) == 0

assert Solution().beautifulSplits(nums = [1,2,3,1,2,3,1,2,3]) == 5

assert Solution().beautifulSplits(nums = [1,2,1,2,1,2,1,2,1,2]) == 14

assert Solution().beautifulSplits(nums = [1,1,2,2,1,1,2,2,1,1]) == 15

assert Solution().beautifulSplits(nums = [1,2,3,4,5,4,3,2,1]) == 0

assert Solution().beautifulSplits(nums = [1,2,1,1,2,1]) == 1

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

Answer: assert Solution().beautifulSplits(nums = [1,2,3,1,2,3]) == 0

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

Answer: assert Solution().beautifulSplits(nums = [1,1,1,1]) == 3

Answer: assert Solution().beautifulSplits(nums = [0,0,0,0,0,0,0,0]) == 19

Answer: assert Solution().beautifulSplits(nums = [50,50,50,50,50]) == 6

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

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

Answer: assert Solution().beautifulSplits(nums = [1,3,2,3,1]) == 0

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

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

Answer: assert Solution().beautifulSplits(nums = [10,20,30,20,10,20]) == 0

Answer: assert Solution().beautifulSplits(nums = [5,5,5,0,0,5,5]) == 7

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

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

Answer: assert Solution().beautifulSplits(nums = [5,5,5,5,5]) == 6

Answer: assert Solution().beautifulSplits(nums = [0,0,0,0,0]) == 6

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

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

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

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

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

Answer: assert Solution().beautifulSplits(nums = [50,50,50,50,50,50]) == 9

Answer: assert Solution().beautifulSplits(nums = [0,0,0,0,0,0]) == 9

Answer: assert Solution().beautifulSplits(nums = [1,1,1,2,1,1,1]) == 7

Answer: assert Solution().beautifulSplits(nums = [5,5,5,5,5,5]) == 9

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

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

Answer: assert Solution().beautifulSplits(nums = [50,50,50,50,50,50,50,50,50,50]) == 32

Answer: assert Solution().beautifulSplits(nums = [1,2,3,2,1]) == 0

Answer: assert Solution().beautifulSplits(nums = [1,2,1,3,2,1]) == 0

Answer: assert Solution().beautifulSplits(nums = [5,5,5,5,5,5,5,5,5,5]) == 32

Answer: assert Solution().beautifulSplits(nums = [1,1,1,2,2,2,3,3,3]) == 11

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

Answer: assert Solution().beautifulSplits(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,1,1]) == 370

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

Answer: assert Solution().beautifulSplits(nums = [3,3,3,3,3,3,2,2,2,2,2,1,1,1,1,1]) == 51

Answer: assert Solution().beautifulSplits(nums = [3,3,3,2,2,2,1,1,1,2,2,2,3,3,3]) == 21

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

Answer: assert Solution().beautifulSplits(nums = [4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4]) == 147

Answer: assert Solution().beautifulSplits(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,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50]) == 0

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

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

Answer: assert Solution().beautifulSplits(nums = [1,2,2,1,2,2,1,2,2,1,2,2,1,2,2,1,2,2,1,2,2,1,2,2,1]) == 83

Answer: assert Solution().beautifulSplits(nums = [9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9,9]) == 322

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

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

Answer: assert Solution().beautifulSplits(nums = [1,2,3,2,1,1,2,3,2,1,1,2,3,2,1,1,2,3,2,1]) == 22

Answer: assert Solution().beautifulSplits(nums = [1,2,1,1,2,1,2,1,1,2]) == 8

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

Answer: assert Solution().beautifulSplits(nums = [1,2,1,2,1,2,1,2]) == 7

Answer: assert Solution().beautifulSplits(nums = [1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1]) == 27

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

Answer: assert Solution().beautifulSplits(nums = [1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2]) == 232

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

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

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

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

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

Answer: assert Solution().beautifulSplits(nums = [1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2]) == 54

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

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

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

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

Answer: assert Solution().beautifulSplits(nums = [1,1,2,1,1,2,1,1,2,1,1,2,1,1,2,1,1,2,1,1]) == 66

Answer: assert Solution().beautifulSplits(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]) == 0

Answer: assert Solution().beautifulSplits(nums = [1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2]) == 57

Answer: assert Solution().beautifulSplits(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,9,8,7,6,5,4,3,2,1]) == 2

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

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

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

Answer: assert Solution().beautifulSplits(nums = [1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2,1,1,1,1,1,2,2,2,2,2]) == 103

Answer: assert Solution().beautifulSplits(nums = [4,4,5,5,4,4,6,6,5,5,4,4,7,7,6,6,5,5,4,4,8,8,7,7,6,6,5,5,4,4]) == 42

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

Answer: assert Solution().beautifulSplits(nums = [1,2,1,2,1,2,1,2,1,2]) == 14

Answer: assert Solution().beautifulSplits(nums = [1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2,1,2]) == 72

Answer: assert Solution().beautifulSplits(nums = [3,3,3,3,3,2,2,2,2,2,1,1,1,1,1]) == 38

Answer: assert Solution().beautifulSplits(nums = [1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]) == 147

Answer: assert Solution().beautifulSplits(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,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,2,2,2]) == 2382

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

Answer: assert Solution().beautifulSplits(nums = [50,49,48,47,46,45,44,43,42,41,40,39,38,37,36,35,34,33,32,31,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]) == 0

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

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

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

Answer: assert Solution().beautifulSplits(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]) == 256

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

Answer: assert Solution().beautifulSplits(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]) == 0

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

Answer: assert Solution().beautifulSplits(nums = [1,1,1,1,1,2,2,2,2,2,3,3,3,3,3]) == 38

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

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

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

Answer: assert Solution().beautifulSplits(nums = [1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3,1,2,1,3]) == 91

Answer: assert Solution().beautifulSplits(nums = [3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3]) == 370

Answer: assert Solution().beautifulSplits(nums = [1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2,1]) == 39

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

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

Answer: assert Solution().beautifulSplits(nums = [10,20,10,20,10,20,10,20,10,20]) == 14

Answer: assert Solution().beautifulSplits(nums = [1,1,2,2,1,1,2,2,1,1,2,2,1,1,2,2]) == 35

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

Answer: assert Solution().beautifulSplits(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,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]) == 2269

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

Answer: assert Solution().beautifulSplits(nums = [1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1,1,1]) == 182

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

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

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 beautifulSplits(self, nums: List[int]) -> int:
        n = len(nums)
        lcp = [[0] * (n + 1) for _ in range(n + 1)]
        for i in range(n - 1, -1, -1):
            for j in range(n - 1, i - 1, -1):
                if nums[i] == nums[j]:
                    lcp[i][j] = lcp[i + 1][j + 1] + 1
        ans = 0
        for i in range(1, n - 1):
            for j in range(i + 1, n):
                a = i <= j - i and lcp[0][i] >= i
                b = j - i <= n - j and lcp[i][j] >= j - i
                ans += int(a or b)
        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 a string s.
A string t is called good if all characters of t occur the same number of times.
You can perform the following operations any number of times:

Delete a character from s.
Insert a character in s.
Change a character in s to its next letter in the alphabet.

Note that you cannot change 'z' to 'a' using the third operation.
Return the minimum number of operations required to make s good.

Example 1:

Input: s = "acab"
Output: 1
Explanation:
We can make s good by deleting one occurrence of character 'a'.

Example 2:

Input: s = "wddw"
Output: 0
Explanation:
We do not need to perform any operations since s is initially good.

Example 3:

Input: s = "aaabc"
Output: 2
Explanation:
We can make s good by applying these operations:

Change one occurrence of 'a' to 'b'
Insert one occurrence of 'c' into s

Constraints:

3 <= s.length <= 2 * 104
s contains only lowercase English letters.

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

SOLUTION:

Question:
PROBLEM:
You are given a string s.
A string t is called good if all characters of t occur the same number of times.
You can perform the following operations any number of times:

Delete a character from s.
Insert a character in s.
Change a character in s to its next letter in the alphabet.

Note that you cannot change 'z' to 'a' using the third operation.
Return the minimum number of operations required to make s good.

Example 1:

Input: s = "acab"
Output: 1
Explanation:
We can make s good by deleting one occurrence of character 'a'.

Example 2:

Input: s = "wddw"
Output: 0
Explanation:
We do not need to perform any operations since s is initially good.

Example 3:

Input: s = "aaabc"
Output: 2
Explanation:
We can make s good by applying these operations:

Change one occurrence of 'a' to 'b'
Insert one occurrence of 'c' into s

Constraints:

3 <= s.length <= 2 * 104
s contains only lowercase English letters.

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

SOLUTION:

assert Solution().makeStringGood(s = "acab") == 1

assert Solution().makeStringGood(s = "aaabc") == 2

assert Solution().makeStringGood(s = "aabbbccc") == 1

assert Solution().makeStringGood(s = "zzzz") == 0

assert Solution().makeStringGood(s = "aabbcc") == 0

assert Solution().makeStringGood(s = "abcdefghijklmnopqrstuvwxyz") == 0

assert Solution().makeStringGood(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz") == 0

assert Solution().makeStringGood(s = "abc") == 0

assert Solution().makeStringGood(s = "zyxwvutsrqponmlkjihgfedcba") == 0

assert Solution().makeStringGood(s = "aabbbcc") == 1

assert Solution().makeStringGood(s = "abcde") == 0

assert Solution().makeStringGood(s = "aabbbcccc") == 2

assert Solution().makeStringGood(s = "zzz") == 0

assert Solution().makeStringGood(s = "wddw") == 0

assert Solution().makeStringGood(s = "aabbbcccddddeeeee") == 4

assert Solution().makeStringGood(s = "aabbbcccdddd") == 2

assert Solution().makeStringGood(s = "zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx") == 0

assert Solution().makeStringGood(s = "abacabadabacabadabacabad") == 9

assert Solution().makeStringGood(s = "zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == 28

assert Solution().makeStringGood(s = "ababababababababababab") == 0

assert Solution().makeStringGood(s = "aabbaa") == 1

assert Solution().makeStringGood(s = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == 0

assert Solution().makeStringGood(s = "aabbbcccddddeeeeefffffgggg") == 5

assert Solution().makeStringGood(s = "abcdabcde") == 1

assert Solution().makeStringGood(s = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz") == 0

assert Solution().makeStringGood(s = "aabbbccccddddeeeeeffffffffgggggggg") == 10

assert Solution().makeStringGood(s = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz") == 0

assert Solution().makeStringGood(s = "aabbaaabbbaaaabbbbaaaa") == 2

assert Solution().makeStringGood(s = "aaaaabbbbbcccc") == 1

assert Solution().makeStringGood(s = "aabbaabbaabbaabb") == 0

assert Solution().makeStringGood(s = "mnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyz") == 0

assert Solution().makeStringGood(s = "aaaabbbbccccddddaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz") == 16

assert Solution().makeStringGood(s = "aabccccdddddeeeeeeeeeee") == 9

assert Solution().makeStringGood(s = "abcdabcdabcdabcd") == 0

assert Solution().makeStringGood(s = "qqqwwweeeerrrrttttyyyyuuuuiiiiooooppppllllnnnnmmmmbbbb") == 2

assert Solution().makeStringGood(s = "aabbccdd") == 0

assert Solution().makeStringGood(s = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == 0

assert Solution().makeStringGood(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == 26

assert Solution().makeStringGood(s = "zzzzzzzzzzzzzzzzzzzzzzzzzzzz") == 0

Answer: assert Solution().makeStringGood(s = "acab") == 1

Answer: assert Solution().makeStringGood(s = "aaabc") == 2

Answer: assert Solution().makeStringGood(s = "aabbbccc") == 1

Answer: assert Solution().makeStringGood(s = "zzzz") == 0

Answer: assert Solution().makeStringGood(s = "aabbcc") == 0

Answer: assert Solution().makeStringGood(s = "abcdefghijklmnopqrstuvwxyz") == 0

Answer: assert Solution().makeStringGood(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz") == 0

Answer: assert Solution().makeStringGood(s = "abc") == 0

Answer: assert Solution().makeStringGood(s = "zyxwvutsrqponmlkjihgfedcba") == 0

Answer: assert Solution().makeStringGood(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz") == 0

Answer: assert Solution().makeStringGood(s = "aabbbcc") == 1

Answer: assert Solution().makeStringGood(s = "abcde") == 0

Answer: assert Solution().makeStringGood(s = "aabbbcccc") == 2

Answer: assert Solution().makeStringGood(s = "zzz") == 0

Answer: assert Solution().makeStringGood(s = "wddw") == 0

Answer: assert Solution().makeStringGood(s = "aabbbcccddddeeeee") == 4

Answer: assert Solution().makeStringGood(s = "aabbbcccdddd") == 2

Answer: assert Solution().makeStringGood(s = "zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyx") == 0

Answer: assert Solution().makeStringGood(s = "abacabadabacabadabacabad") == 9

Answer: assert Solution().makeStringGood(s = "zyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyxzyzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == 28

Answer: assert Solution().makeStringGood(s = "ababababababababababab") == 0

Answer: assert Solution().makeStringGood(s = "aabbaa") == 1

Answer: assert Solution().makeStringGood(s = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == 0

Answer: assert Solution().makeStringGood(s = "aabbbcccddddeeeeefffffgggg") == 5

Answer: assert Solution().makeStringGood(s = "abcdabcde") == 1

Answer: assert Solution().makeStringGood(s = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz") == 0

Answer: assert Solution().makeStringGood(s = "aabbbccccddddeeeeeffffffffgggggggg") == 10

Answer: assert Solution().makeStringGood(s = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz") == 0

Answer: assert Solution().makeStringGood(s = "aabbaaabbbaaaabbbbaaaa") == 2

Answer: assert Solution().makeStringGood(s = "aaaaabbbbbcccc") == 1

Answer: assert Solution().makeStringGood(s = "aabbaabbaabbaabb") == 0

Answer: assert Solution().makeStringGood(s = "mnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyzmnopqrstuvwxyz") == 0

Answer: assert Solution().makeStringGood(s = "aaaabbbbccccddddaabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz") == 16

Answer: assert Solution().makeStringGood(s = "aabccccdddddeeeeeeeeeee") == 9

Answer: assert Solution().makeStringGood(s = "abcdabcdabcdabcd") == 0

Answer: assert Solution().makeStringGood(s = "qqqwwweeeerrrrttttyyyyuuuuiiiiooooppppllllnnnnmmmmbbbb") == 2

Answer: assert Solution().makeStringGood(s = "aabbccdd") == 0

Answer: assert Solution().makeStringGood(s = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == 0

Answer: assert Solution().makeStringGood(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzzzzzzzzzzzzzzzzzzzzzzzzzzzz") == 26

Answer: assert Solution().makeStringGood(s = "zzzzzzzzzzzzzzzzzzzzzzzzzzzz") == 0

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 makeStringGood(self, s: str) -> int:
    count = [0] * 26
    for c in s:
      count[ord(c) - ord('a')] += 1
    return min(self._getMinOperations(count, target)
               for target in range(1, max(count) + 1))

  def _getMinOperations(self, count: list[int], target: int) -> int:
    # dp[i] represents the minimum number of operations to make the frequency of
    # (i..25)-th (0-indexed) letters equal to `target`.
    dp = [0] * 27

    for i in range(25, -1, -1):
      # 1. Delete all the i-th letters.
      deleteAllToZero = count[i]
      # 2. Insert/delete the i-th letters to have `target` number of letters.
      deleteOrInsertToTarget = abs(target - count[i])
      dp[i] = min(deleteAllToZero, deleteOrInsertToTarget) + dp[i + 1]
      if i + 1 < 26 and count[i + 1] < target:
        nextDeficit = target - count[i + 1]
        # Make the frequency of the i-th letter equal to the `target` or 0.
        needToChange = count[i] if count[i] <= target else count[i] - target
        changeToTarget = (
            # 3. Change all the i-th letters to the next letter and then
            # insert the remaining deficit for the next letter.
            needToChange + (nextDeficit - needToChange) if nextDeficit > needToChange
            # 4. Change `nextDeficit` i-th letters to the next letter and
            # then delete the remaining i-th letters.
            else nextDeficit + (needToChange - nextDeficit)
        )
        dp[i] = min(dp[i], changeToTarget + dp[i + 2])

    return dp[0]


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 a 2D integer array grid with size m x n. You are also given an integer k.
Your task is to calculate the number of paths you can take from the top-left cell (0, 0) to the bottom-right cell (m - 1, n - 1) satisfying the following constraints:

You can either move to the right or down. Formally, from the cell (i, j) you may move to the cell (i, j + 1) or to the cell (i + 1, j) if the target cell exists.
The XOR of all the numbers on the path must be equal to k.

Return the total number of such paths.
Since the answer can be very large, return the result modulo 109 + 7.

Example 1:

Input: grid = [[2, 1, 5], [7, 10, 0], [12, 6, 4]], k = 11
Output: 3
Explanation:
The 3 paths are:

(0, 0) → (1, 0) → (2, 0) → (2, 1) → (2, 2)
(0, 0) → (1, 0) → (1, 1) → (1, 2) → (2, 2)
(0, 0) → (0, 1) → (1, 1) → (2, 1) → (2, 2)

Example 2:

Input: grid = [[1, 3, 3, 3], [0, 3, 3, 2], [3, 0, 1, 1]], k = 2
Output: 5
Explanation:
The 5 paths are:

(0, 0) → (1, 0) → (2, 0) → (2, 1) → (2, 2) → (2, 3)
(0, 0) → (1, 0) → (1, 1) → (2, 1) → (2, 2) → (2, 3)
(0, 0) → (1, 0) → (1, 1) → (1, 2) → (1, 3) → (2, 3)
(0, 0) → (0, 1) → (1, 1) → (1, 2) → (2, 2) → (2, 3)
(0, 0) → (0, 1) → (0, 2) → (1, 2) → (2, 2) → (2, 3)

Example 3:

Input: grid = [[1, 1, 1, 2], [3, 0, 3, 2], [3, 0, 2, 2]], k = 10
Output: 0

Constraints:

1 <= m == grid.length <= 300
1 <= n == grid[r].length <= 300
0 <= grid[r][c] < 16
0 <= k < 16

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

SOLUTION:

Question:
PROBLEM:
You are given a 2D integer array grid with size m x n. You are also given an integer k.
Your task is to calculate the number of paths you can take from the top-left cell (0, 0) to the bottom-right cell (m - 1, n - 1) satisfying the following constraints:

You can either move to the right or down. Formally, from the cell (i, j) you may move to the cell (i, j + 1) or to the cell (i + 1, j) if the target cell exists.
The XOR of all the numbers on the path must be equal to k.

Return the total number of such paths.
Since the answer can be very large, return the result modulo 109 + 7.

Example 1:

Input: grid = [[2, 1, 5], [7, 10, 0], [12, 6, 4]], k = 11
Output: 3
Explanation:
The 3 paths are:

(0, 0) → (1, 0) → (2, 0) → (2, 1) → (2, 2)
(0, 0) → (1, 0) → (1, 1) → (1, 2) → (2, 2)
(0, 0) → (0, 1) → (1, 1) → (2, 1) → (2, 2)

Example 2:

Input: grid = [[1, 3, 3, 3], [0, 3, 3, 2], [3, 0, 1, 1]], k = 2
Output: 5
Explanation:
The 5 paths are:

(0, 0) → (1, 0) → (2, 0) → (2, 1) → (2, 2) → (2, 3)
(0, 0) → (1, 0) → (1, 1) → (2, 1) → (2, 2) → (2, 3)
(0, 0) → (1, 0) → (1, 1) → (1, 2) → (1, 3) → (2, 3)
(0, 0) → (0, 1) → (1, 1) → (1, 2) → (2, 2) → (2, 3)
(0, 0) → (0, 1) → (0, 2) → (1, 2) → (2, 2) → (2, 3)

Example 3:

Input: grid = [[1, 1, 1, 2], [3, 0, 3, 2], [3, 0, 2, 2]], k = 10
Output: 0

Constraints:

1 <= m == grid.length <= 300
1 <= n == grid[r].length <= 300
0 <= grid[r][c] < 16
0 <= k < 16

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

SOLUTION:

assert Solution().countPathsWithXorValue(grid = [[15, 15], [15, 15]], k = 14) == 0

assert Solution().countPathsWithXorValue(grid = [[1], [1], [1]], k = 1) == 1

assert Solution().countPathsWithXorValue(grid = [[1]], k = 1) == 1

assert Solution().countPathsWithXorValue(grid = [[0]], k = 0) == 1

assert Solution().countPathsWithXorValue(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k = 15) == 2

assert Solution().countPathsWithXorValue(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]], k = 0) == 6

assert Solution().countPathsWithXorValue(grid = [[1, 2], [3, 4]], k = 7) == 1

assert Solution().countPathsWithXorValue(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]], k = 3) == 0

assert Solution().countPathsWithXorValue(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k = 7) == 1

assert Solution().countPathsWithXorValue(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k = 0) == 0

assert Solution().countPathsWithXorValue(grid = [[2, 1, 5], [7, 10, 0], [12, 6, 4]], k = 11) == 3

assert Solution().countPathsWithXorValue(grid = [[0, 0], [0, 0]], k = 0) == 2

assert Solution().countPathsWithXorValue(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1]], k = 0) == 0

assert Solution().countPathsWithXorValue(grid = [[8, 5, 7], [5, 8, 5], [7, 5, 8]], k = 7) == 2

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 3, 3, 3], [0, 3, 3, 2], [3, 0, 1, 1]], k = 2) == 5

Answer: assert Solution().countPathsWithXorValue(grid = [[15, 15], [15, 15]], k = 14) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[1], [1], [1]], k = 1) == 1

Answer: assert Solution().countPathsWithXorValue(grid = [[1]], k = 1) == 1

Answer: assert Solution().countPathsWithXorValue(grid = [[0]], k = 0) == 1

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k = 15) == 2

Answer: assert Solution().countPathsWithXorValue(grid = [[0, 0, 0], [0, 0, 0], [0, 0, 0]], k = 0) == 6

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 2], [3, 4]], k = 7) == 1

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1]], k = 3) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 1, 1, 2], [3, 0, 3, 2], [3, 0, 2, 2]], k = 10) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0], [0, 0, 0, 0]], k = 0) == 20

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k = 7) == 1

Answer: assert Solution().countPathsWithXorValue(grid = [[15, 15, 15], [15, 15, 15], [15, 15, 15]], k = 0) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 2, 3], [4, 5, 6], [7, 8, 9]], k = 0) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[2, 1, 5], [7, 10, 0], [12, 6, 4]], k = 11) == 3

Answer: assert Solution().countPathsWithXorValue(grid = [[0, 0], [0, 0]], k = 0) == 2

Answer: assert Solution().countPathsWithXorValue(grid = [[15, 15, 15], [15, 15, 15], [15, 15, 15]], k = 15) == 6

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

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 0, 1], [0, 1, 0], [1, 0, 1]], k = 0) == 0

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

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 2, 3, 4, 5, 6, 7, 8], [8, 7, 6, 5, 4, 3, 2, 1], [1, 3, 5, 7, 9, 11, 13, 15], [15, 13, 11, 9, 7, 5, 3, 1]], k = 4) == 7

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 3, 5, 7], [9, 11, 13, 15], [1, 3, 5, 7], [9, 11, 13, 15]], k = 7) == 5

Answer: assert Solution().countPathsWithXorValue(grid = [[0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0]], k = 7) == 0

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

Answer: assert Solution().countPathsWithXorValue(grid = [[8, 6, 4, 2, 0], [1, 3, 5, 7, 9], [10, 12, 14, 16, 18], [19, 21, 23, 25, 27]], k = 10) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[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]], k = 3) == 8

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 3, 2, 0], [4, 5, 6, 7], [8, 9, 10, 11], [12, 13, 14, 15]], k = 30) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[8, 7, 6], [5, 4, 3], [2, 1, 0], [9, 8, 7], [6, 5, 4]], k = 5) == 1

Answer: assert Solution().countPathsWithXorValue(grid = [[10, 11, 12, 13, 14], [15, 16, 17, 18, 19], [20, 21, 22, 23, 24], [25, 26, 27, 28, 29]], k = 12) == 2

Answer: assert Solution().countPathsWithXorValue(grid = [[14, 2, 10], [1, 3, 13], [12, 8, 4], [6, 14, 10]], k = 5) == 2

Answer: assert Solution().countPathsWithXorValue(grid = [[2, 1, 5, 7], [10, 0, 12, 6], [4, 3, 3, 3], [3, 0, 1, 1]], k = 11) == 3

Answer: assert Solution().countPathsWithXorValue(grid = [[8, 8, 8, 8, 8], [8, 8, 8, 8, 8], [8, 8, 8, 8, 8], [8, 8, 8, 8, 8], [8, 8, 8, 8, 8]], k = 0) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[15, 14, 13, 12, 11, 10], [9, 8, 7, 6, 5, 4], [3, 2, 1, 0, 15, 14], [13, 12, 11, 10, 9, 8], [7, 6, 5, 4, 3, 2], [1, 0, 15, 14, 13, 12]], k = 15) == 17

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 3, 3, 3, 2], [3, 3, 2, 2, 1], [2, 2, 1, 1, 3], [1, 1, 3, 3, 2]], k = 4) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[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]], k = 5) == 2

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

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5], [5, 4, 3, 2, 1], [1, 2, 3, 4, 5]], k = 5) == 7

Answer: assert Solution().countPathsWithXorValue(grid = [[0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0]], k = 5) == 0

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

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

Answer: assert Solution().countPathsWithXorValue(grid = [[0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5]], k = 3) == 28

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

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12], [13, 14], [15, 16]], k = 7) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[5, 3, 2, 1], [6, 0, 4, 5], [7, 8, 9, 1], [10, 11, 12, 13]], k = 10) == 1

Answer: assert Solution().countPathsWithXorValue(grid = [[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]], k = 1) == 0

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

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 1, 1, 1, 1], [2, 2, 2, 2, 2], [3, 3, 3, 3, 3], [4, 4, 4, 4, 4]], k = 0) == 1

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

Answer: assert Solution().countPathsWithXorValue(grid = [[14, 14, 14, 14], [14, 14, 14, 14], [14, 14, 14, 14], [14, 14, 14, 14]], k = 14) == 20

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

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

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 1, 1], [1, 0, 1], [1, 1, 1], [1, 0, 1], [1, 1, 1]], k = 0) == 8

Answer: assert Solution().countPathsWithXorValue(grid = [[2, 4, 8, 16], [32, 64, 128, 256], [512, 1024, 2048, 4096], [8192, 16384, 32768, 65536]], k = 2) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[5, 9, 10], [9, 8, 1], [10, 1, 3], [1, 3, 5]], k = 13) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 0, 1, 1], [0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1]], k = 14) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[3, 3, 3, 3, 3], [3, 3, 3, 3, 3], [3, 3, 3, 3, 3], [3, 3, 3, 3, 3], [3, 3, 3, 3, 3]], k = 3) == 70

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

Answer: assert Solution().countPathsWithXorValue(grid = [[2, 4, 8, 16, 32, 64], [128, 256, 512, 1024, 2048, 4096], [8192, 16384, 32768, 65536, 131072, 262144]], k = 1023) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[2, 4, 6, 8, 10], [1, 3, 5, 7, 9], [0, 0, 0, 0, 0], [15, 13, 11, 9, 7]], k = 7) == 2

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

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 0, 0, 1], [0, 1, 1, 0], [0, 1, 1, 0], [1, 0, 0, 1]], k = 0) == 8

Answer: assert Solution().countPathsWithXorValue(grid = [[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]], k = 0) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0], [0, 1, 0, 1, 0, 1], [1, 0, 1, 0, 1, 0]], k = 1) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[2, 2, 2, 2, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2], [2, 2, 2, 2, 2]], k = 2) == 70

Answer: assert Solution().countPathsWithXorValue(grid = [[11, 12, 13], [14, 15, 10], [9, 8, 7], [6, 5, 4]], k = 9) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[2, 3, 1, 5], [1, 4, 2, 3], [5, 6, 7, 8], [0, 1, 2, 3]], k = 7) == 1

Answer: assert Solution().countPathsWithXorValue(grid = [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5, 6, 7, 8, 9], [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]], k = 5) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]], k = 0) == 35

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

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 2, 3], [0, 1, 2], [3, 0, 1], [2, 3, 0]], k = 3) == 6

Answer: assert Solution().countPathsWithXorValue(grid = [[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]], k = 2) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[15, 0, 1, 1], [1, 15, 1, 1], [1, 1, 15, 1], [1, 1, 1, 15]], k = 15) == 4

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

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 3, 5, 7, 9], [2, 4, 6, 8, 10], [1, 3, 5, 7, 9]], k = 15) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 3, 3, 3, 3], [0, 3, 3, 2, 2], [3, 0, 1, 1, 1], [1, 1, 2, 2, 3]], k = 2) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[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]], k = 0) == 252

Answer: assert Solution().countPathsWithXorValue(grid = [[14, 4, 14, 4], [14, 4, 14, 4], [14, 4, 14, 4], [14, 4, 14, 4]], k = 8) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1], [1, 1, 1, 1]], k = 0) == 0

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

Answer: assert Solution().countPathsWithXorValue(grid = [[0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0], [0, 1, 2, 3, 4, 5], [5, 4, 3, 2, 1, 0]], k = 5) == 68

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 3, 5, 7], [9, 11, 13, 15], [17, 19, 21, 23], [25, 27, 29, 31]], k = 10) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[2, 1, 5, 7], [7, 10, 0, 12], [12, 6, 4, 3], [3, 14, 1, 8]], k = 11) == 1

Answer: assert Solution().countPathsWithXorValue(grid = [[2, 4, 6, 8, 10], [12, 14, 16, 18, 20], [22, 24, 26, 28, 30], [32, 34, 36, 38, 40]], k = 7) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]], k = 1) == 15

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

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1], [1, 2, 3, 4, 5, 6, 7, 8, 9, 10], [10, 9, 8, 7, 6, 5, 4, 3, 2, 1]], k = 4) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[0, 1, 2, 3, 4], [4, 3, 2, 1, 0], [0, 1, 2, 3, 4], [4, 3, 2, 1, 0]], k = 6) == 6

Answer: assert Solution().countPathsWithXorValue(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]], k = 1) == 70

Answer: assert Solution().countPathsWithXorValue(grid = [[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]], k = 0) == 70

Answer: assert Solution().countPathsWithXorValue(grid = [[2, 3, 5, 7, 11], [13, 17, 19, 23, 29], [31, 37, 41, 43, 47], [53, 59, 61, 67, 71]], k = 60) == 0

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

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

Answer: assert Solution().countPathsWithXorValue(grid = [[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]], k = 0) == 126

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 0], [0, 1, 0, 1]], k = 3) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[15, 0, 15, 0], [0, 15, 0, 15], [15, 0, 15, 0], [0, 15, 0, 15]], k = 14) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[2, 3, 1, 4], [1, 2, 3, 4], [4, 3, 2, 1], [3, 4, 1, 2]], k = 5) == 4

Answer: assert Solution().countPathsWithXorValue(grid = [[15, 15, 15, 15], [15, 15, 15, 15], [15, 15, 15, 15], [15, 15, 15, 15]], k = 15) == 20

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 1, 1], [1, 1, 1], [1, 1, 1], [1, 1, 1]], k = 2) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[3, 3, 3, 3, 3, 3, 3], [3, 3, 3, 3, 3, 3, 3], [3, 3, 3, 3, 3, 3, 3], [3, 3, 3, 3, 3, 3, 3]], k = 14) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[8, 5, 7], [5, 8, 5], [7, 5, 8]], k = 7) == 2

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 1, 1, 1, 1], [1, 1, 1, 1, 1], [1, 1, 1, 1, 1]], k = 5) == 0

Answer: assert Solution().countPathsWithXorValue(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]], k = 0) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[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]], k = 15) == 0

Answer: assert Solution().countPathsWithXorValue(grid = [[1, 1, 1, 1], [1, 0, 1, 0], [0, 1, 0, 1], [1, 0, 1, 1]], k = 1) == 16

Answer: assert Solution().countPathsWithXorValue(grid = [[5, 9, 15], [10, 7, 11], [8, 12, 14]], k = 13) == 1

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

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 countPathsWithXorValue(self, grid: list[list[int]], k: int) -> int:
    MOD = 1_000_000_007
    m = len(grid)
    n = len(grid[0])

    @functools.lru_cache(None)
    def count(i: int, j: int, xors: int) -> int:
      """
      Return the number of paths from (i, j) to (m - 1, n - 1) with XOR value
      `xors`.
      """
      if i == m or j == n:
        return 0
      xors ^= grid[i][j]
      if i == m - 1 and j == n - 1:
        return int(xors == k)
      right = count(i, j + 1, xors)
      down = count(i + 1, j, xors)
      return (right + down) % MOD

    return count(0, 0, 0)