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 squares. Each squares[i] = [xi, yi, li] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.
Find the minimum y-coordinate value of a horizontal line such that the total area of the squares above the line equals the total area of the squares below the line.
Answers within 10-5 of the actual answer will be accepted.
Note: Squares may overlap. Overlapping areas should be counted multiple times.

Example 1:

Input: squares = [[0,0,1],[2,2,1]]
Output: 1.00000
Explanation:

Any horizontal line between y = 1 and y = 2 will have 1 square unit above it and 1 square unit below it. The lowest option is 1.

Example 2:

Input: squares = [[0,0,2],[1,1,1]]
Output: 1.16667
Explanation:

The areas are:

Below the line: 7/6 * 2 (Red) + 1/6 (Blue) = 15/6 = 2.5.
Above the line: 5/6 * 2 (Red) + 5/6 (Blue) = 15/6 = 2.5.

Since the areas above and below the line are equal, the output is 7/6 = 1.16667.

Constraints:

1 <= squares.length <= 5 * 104
squares[i] = [xi, yi, li]
squares[i].length == 3
0 <= xi, yi <= 109
1 <= li <= 109
The total area of all the squares will not exceed 1012.

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

SOLUTION:

Question:
PROBLEM:
You are given a 2D integer array squares. Each squares[i] = [xi, yi, li] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.
Find the minimum y-coordinate value of a horizontal line such that the total area of the squares above the line equals the total area of the squares below the line.
Answers within 10-5 of the actual answer will be accepted.
Note: Squares may overlap. Overlapping areas should be counted multiple times.

Example 1:

Input: squares = [[0,0,1],[2,2,1]]
Output: 1.00000
Explanation:

Any horizontal line between y = 1 and y = 2 will have 1 square unit above it and 1 square unit below it. The lowest option is 1.

Example 2:

Input: squares = [[0,0,2],[1,1,1]]
Output: 1.16667
Explanation:

The areas are:

Below the line: 7/6 * 2 (Red) + 1/6 (Blue) = 15/6 = 2.5.
Above the line: 5/6 * 2 (Red) + 5/6 (Blue) = 15/6 = 2.5.

Since the areas above and below the line are equal, the output is 7/6 = 1.16667.

Constraints:

1 <= squares.length <= 5 * 104
squares[i] = [xi, yi, li]
squares[i].length == 3
0 <= xi, yi <= 109
1 <= li <= 109
The total area of all the squares will not exceed 1012.

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

SOLUTION:

assert Solution().separateSquares(squares = [[0,0,3],[3,3,3],[6,6,3]]) == 4.5

assert Solution().separateSquares(squares = [[0,0,3],[3,3,3]]) == 3.0

assert Solution().separateSquares(squares = [[1,1,2],[2,2,2],[3,3,2]]) == 3.0

assert Solution().separateSquares(squares = [[0,0,3],[1,1,2],[2,2,1]]) == 1.8

assert Solution().separateSquares(squares = [[0,0,1],[2,2,1]]) == 1.0

assert Solution().separateSquares(squares = [[0,0,3],[1,1,2],[4,4,1]]) == 1.8

Answer: assert Solution().separateSquares(squares = [[0,0,10],[5,5,10],[10,10,10]]) == 10.0

Answer: assert Solution().separateSquares(squares = [[0,0,4],[2,2,2],[4,4,1]]) == 2.4166666666666665

Answer: assert Solution().separateSquares(squares = [[0,0,3],[3,3,3],[6,6,3]]) == 4.5

Answer: assert Solution().separateSquares(squares = [[0,0,3],[3,3,3]]) == 3.0

Answer: assert Solution().separateSquares(squares = [[0,0,5],[5,5,5],[2,2,2],[3,3,3]]) == 4.5625

Answer: assert Solution().separateSquares(squares = [[5,5,5],[10,10,5],[15,15,5]]) == 12.5

Answer: assert Solution().separateSquares(squares = [[1,1,2],[2,2,2],[3,3,2]]) == 3.0

Answer: assert Solution().separateSquares(squares = [[0,0,10],[5,5,5],[10,0,10]]) == 5.5

Answer: assert Solution().separateSquares(squares = [[0,0,3],[1,1,2],[2,2,1]]) == 1.8

Answer: assert Solution().separateSquares(squares = [[0,0,2],[1,1,1]]) == 1.1666666666666667

Answer: assert Solution().separateSquares(squares = [[0,0,5],[1,1,3],[2,2,2],[3,3,1]]) == 2.65

Answer: assert Solution().separateSquares(squares = [[0,0,4],[2,2,2],[1,1,2]]) == 2.25

Answer: assert Solution().separateSquares(squares = [[0,0,3],[3,3,3],[1,1,1]]) == 2.8333333333333335

Answer: assert Solution().separateSquares(squares = [[0,0,1],[2,2,1]]) == 1.0

Answer: assert Solution().separateSquares(squares = [[0,0,5],[5,5,5],[10,10,5]]) == 7.5

Answer: assert Solution().separateSquares(squares = [[0,0,3],[1,1,2],[4,4,1]]) == 1.8

Answer: assert Solution().separateSquares(squares = [[0, 0, 2], [0, 2, 2], [2, 0, 2], [2, 2, 2], [1, 1, 2], [3, 3, 2]]) == 2.3333333333333335

Answer: assert Solution().separateSquares(squares = [[0,0,5],[3,3,5],[6,6,5],[9,9,5]]) == 7.0

Answer: assert Solution().separateSquares(squares = [[0,0,1000],[100,100,500],[200,200,300],[300,300,200],[400,400,100],[0,500,1000],[100,600,500],[200,700,300],[300,800,200],[400,900,100]]) == 717.8571428571429

Answer: assert Solution().separateSquares(squares = [[0,0,7],[2,1,5],[4,2,3],[6,3,1],[8,4,1],[10,5,1]]) == 3.5625

Answer: assert Solution().separateSquares(squares = [[0,0,1000000000],[1,1,1000000000],[2,2,1000000000],[3,3,1000000000],[4,4,1000000000]]) == 500000002.0

Answer: assert Solution().separateSquares(squares = [[0,0,10],[5,5,5],[10,10,3],[15,15,2]]) == 6.266666666666667

Answer: assert Solution().separateSquares(squares = [[0,0,10],[5,5,5],[10,10,1],[12,12,3],[15,15,2]]) == 6.3

Answer: assert Solution().separateSquares(squares = [[0,0,10],[5,5,5],[10,10,1],[15,15,2],[20,20,3]]) == 6.3

Answer: assert Solution().separateSquares(squares = [[10,10,10],[10,20,10],[10,30,10],[20,10,10],[20,20,10],[20,30,10],[30,10,10],[30,20,10],[30,30,10]]) == 25.0

Answer: assert Solution().separateSquares(squares = [[0,0,3],[3,3,3],[6,6,3],[9,9,3],[12,12,3],[15,15,3],[18,18,3],[21,21,3],[24,24,3]]) == 13.5

Answer: assert Solution().separateSquares(squares = [[0,0,100],[50,50,100],[100,0,100],[150,50,100]]) == 75.0

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

Answer: assert Solution().separateSquares(squares = [[1,1,2],[1,3,2],[1,5,2],[1,7,2],[1,9,2],[1,11,2],[1,13,2],[1,15,2],[1,17,2],[1,19,2]]) == 11.0

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

Answer: assert Solution().separateSquares(squares = [[0,0,7],[7,7,7],[3,3,3],[5,5,5],[1,1,1],[9,9,1]]) == 6.833333333333333

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

Answer: assert Solution().separateSquares(squares = [[0,0,5],[3,2,3],[1,4,2],[6,1,4]]) == 3.083333333333333

Answer: assert Solution().separateSquares(squares = [[0,0,100],[20,0,90],[40,0,80],[60,0,70],[80,0,60],[100,0,50],[120,0,40],[140,0,30],[160,0,20],[180,0,10]]) == 36.42857142857143

Answer: assert Solution().separateSquares(squares = [[0,0,100],[20,20,50],[40,40,25],[60,60,12.5],[80,80,6.25]]) == 49.48660714285714

Answer: assert Solution().separateSquares(squares = [[1,1,3],[4,4,3],[7,7,3],[10,10,3],[13,13,3],[16,16,3]]) == 10.0

Answer: assert Solution().separateSquares(squares = [[0,0,10],[10,0,10],[5,5,5],[15,5,5],[20,0,10],[25,0,10]]) == 5.5

Answer: assert Solution().separateSquares(squares = [[0,0,500000],[500000,500000,500000],[1000000,1000000,500000],[1500000,1500000,500000],[2000000,2000000,500000]]) == 1250000.0

Answer: assert Solution().separateSquares(squares = [[10,10,10],[15,15,10],[20,20,10],[25,25,10],[30,30,10],[35,35,10],[40,40,10],[45,45,10],[50,50,10]]) == 35.0

Answer: assert Solution().separateSquares(squares = [[0,0,1],[2,0,1],[4,0,1],[6,0,1],[8,0,1],[10,0,1],[12,0,1],[14,0,1],[16,0,1],[18,0,1],[20,0,1]]) == 0.5

Answer: assert Solution().separateSquares(squares = [[10,10,5],[15,15,5],[20,20,5],[25,25,5],[30,30,5],[35,35,5],[40,40,5],[45,45,5]]) == 30.0

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

Answer: assert Solution().separateSquares(squares = [[0,0,20],[5,5,10],[10,10,5],[15,15,2.5],[20,20,1.25]]) == 10.46875

Answer: assert Solution().separateSquares(squares = [[0,0,50],[10,10,40],[20,20,30],[30,30,20],[40,40,10],[50,50,5]]) == 31.160714285714285

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

Answer: assert Solution().separateSquares(squares = [[0,0,100],[25,25,50],[50,50,25],[75,75,12.5]]) == 52.232142857142854

Answer: assert Solution().separateSquares(squares = [[0,0,10],[5,5,10],[10,0,10],[5,10,10]]) == 8.333333333333334

Answer: assert Solution().separateSquares(squares = [[0, 0, 5], [1, 1, 3], [2, 2, 4], [3, 3, 2], [4, 4, 1]]) == 3.1785714285714284

Answer: assert Solution().separateSquares(squares = [[0,0,10],[0,10,10],[0,20,10],[10,0,10],[10,10,10],[10,20,10],[20,0,10],[20,10,10],[20,20,10]]) == 15.0

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

Answer: assert Solution().separateSquares(squares = [[2,0,6],[8,0,4],[5,5,3],[1,1,5]]) == 3.2

Answer: assert Solution().separateSquares(squares = [[0,0,100],[50,0,50],[100,0,25],[125,0,12.5]]) == 39.0625

Answer: assert Solution().separateSquares(squares = [[1,1,1],[2,2,1],[3,3,1],[4,4,1],[5,5,1],[6,6,1]]) == 4.0

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

Answer: assert Solution().separateSquares(squares = [[1, 1, 3], [4, 4, 3], [7, 7, 3], [10, 10, 3], [2, 2, 2], [5, 5, 2], [8, 8, 2], [11, 11, 2]]) == 7.0

Answer: assert Solution().separateSquares(squares = [[0,0,10],[2,1,10],[4,2,10],[6,3,10],[8,4,10],[10,5,10]]) == 7.5

Answer: assert Solution().separateSquares(squares = [[0, 0, 100], [20, 20, 50], [40, 40, 30], [60, 60, 20], [80, 80, 10], [10, 10, 80], [30, 30, 60], [50, 50, 40], [70, 70, 20]]) == 54.861111111111114

Answer: assert Solution().separateSquares(squares = [[0,0,1000000000],[1000000000,0,1000000000],[2000000000,0,1000000000]]) == 500000000.0

Answer: assert Solution().separateSquares(squares = [[1,1,3],[2,2,3],[1,4,3],[3,5,3]]) == 4.5

Answer: assert Solution().separateSquares(squares = [[0,0,5],[5,0,5],[10,0,5],[15,0,5],[20,0,5],[25,0,5],[30,0,5],[35,0,5],[40,0,5]]) == 2.5

Answer: assert Solution().separateSquares(squares = [[0, 0, 5], [0, 5, 5], [5, 0, 5], [5, 5, 5], [2.5, 2.5, 1], [7.5, 7.5, 1]]) == 5.0

Answer: assert Solution().separateSquares(squares = [[0,0,10],[5,0,10],[10,0,10],[15,0,10],[20,0,10],[25,0,10],[30,0,10],[35,0,10],[40,0,10],[45,0,10]]) == 5.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 1000], [100, 100, 500], [200, 200, 300], [300, 300, 200], [400, 400, 100], [500, 500, 50], [600, 600, 25], [700, 700, 10], [800, 800, 5], [900, 900, 1]]) == 431.7264285714286

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

Answer: assert Solution().separateSquares(squares = [[0,0,10],[0,10,10],[0,20,10],[0,30,10],[0,40,10],[0,50,10],[0,60,10],[0,70,10],[0,80,10],[0,90,10],[0,100,10],[0,110,10],[0,120,10],[0,130,10],[0,140,10],[0,150,10]]) == 80.0

Answer: assert Solution().separateSquares(squares = [[0,0,5],[1,1,4],[2,2,3],[3,3,2],[4,4,1]]) == 3.107142857142857

Answer: assert Solution().separateSquares(squares = [[0,0,5],[2,1,4],[4,2,3],[6,3,2],[8,4,1],[10,5,0.5],[12,5.5,0.25]]) == 3.1183035714285716

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

Answer: assert Solution().separateSquares(squares = [[1,1,5],[2,2,5],[3,3,5],[4,4,5],[5,5,5]]) == 5.5

Answer: assert Solution().separateSquares(squares = [[0,0,6],[1,3,4],[3,0,4],[5,1,4]]) == 3.2222222222222223

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

Answer: assert Solution().separateSquares(squares = [[0,0,10],[5,5,10],[10,10,10],[15,15,10]]) == 12.5

Answer: assert Solution().separateSquares(squares = [[0, 0, 10], [2, 0, 5], [5, 5, 3], [7, 7, 2], [8, 8, 1]]) == 4.633333333333334

Answer: assert Solution().separateSquares(squares = [[10, 10, 5], [15, 15, 4], [20, 20, 3], [25, 25, 2], [30, 30, 1]]) == 15.625

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

Answer: assert Solution().separateSquares(squares = [[0,0,1000000000],[500000000,500000000,1000000000],[1000000000,0,1000000000],[1000000000,1000000000,1000000000]]) == 833333333.3333333

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

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

Answer: assert Solution().separateSquares(squares = [[0, 0, 10], [5, 5, 10], [10, 10, 10], [15, 15, 10], [20, 20, 10]]) == 15.0

Answer: assert Solution().separateSquares(squares = [[0,0,5],[5,5,5],[10,10,5],[15,15,5]]) == 10.0

Answer: assert Solution().separateSquares(squares = [[0,0,8],[1,1,7],[2,2,6],[3,3,5],[4,4,4],[5,5,3],[6,6,2],[7,7,1]]) == 5.0606060606060606

Answer: assert Solution().separateSquares(squares = [[0, 0, 7], [3, 3, 5], [6, 6, 3], [9, 9, 1], [1, 1, 6], [4, 4, 4], [7, 7, 2]]) == 4.863636363636363

Answer: assert Solution().separateSquares(squares = [[0,0,20],[5,10,10],[10,20,5],[15,30,2.5],[20,40,1.25]]) == 12.213541666666666

Answer: assert Solution().separateSquares(squares = [[0,0,1],[1,1,1],[2,2,1],[3,3,1],[4,4,1],[5,5,1]]) == 3.0

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

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

Answer: assert Solution().separateSquares(squares = [[0,0,1],[1,2,1],[2,4,1],[3,6,1],[4,8,1],[5,10,1],[6,12,1]]) == 6.5

Answer: assert Solution().separateSquares(squares = [[1,1,4],[1,5,4],[5,1,4],[5,5,4]]) == 5.0

Answer: assert Solution().separateSquares(squares = [[0,0,100],[20,0,80],[40,0,60],[60,0,40],[80,0,20]]) == 37.85714285714286

Answer: assert Solution().separateSquares(squares = [[0,0,10],[1,2,3],[4,6,2],[7,8,4]]) == 5.55

Answer: assert Solution().separateSquares(squares = [[1,1,1],[1,2,1],[1,3,1],[1,4,1],[1,5,1],[1,6,1],[1,7,1],[1,8,1],[1,9,1]]) == 5.5

Answer: assert Solution().separateSquares(squares = [[0,0,20],[5,5,20],[10,10,20],[15,15,20],[20,20,20],[0,20,20],[5,25,20],[10,30,20],[15,35,20],[20,40,20]]) == 30.0

Answer: assert Solution().separateSquares(squares = [[0,0,10],[5,5,5],[10,10,2],[15,15,1]]) == 6.0

Answer: assert Solution().separateSquares(squares = [[0,0,8],[4,4,4],[8,0,8],[12,4,4],[16,0,8],[20,4,4]]) == 4.666666666666667

Answer: assert Solution().separateSquares(squares = [[0,0,1],[1,1,2],[2,2,3],[3,3,4],[4,4,5]]) == 5.055555555555555

Answer: assert Solution().separateSquares(squares = [[1,1,2],[3,3,2],[5,5,2],[7,7,2],[9,9,2]]) == 6.0

Answer: assert Solution().separateSquares(squares = [[0,0,1000000000],[500000000,500000000,500000000],[1000000000,1000000000,100000000]]) == 586666666.6666666

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

Answer: assert Solution().separateSquares(squares = [[0,0,1],[0,1,1],[0,2,1],[0,3,1],[0,4,1]]) == 2.5

Answer: assert Solution().separateSquares(squares = [[0,0,10],[5,5,5],[10,10,2]]) == 5.966666666666667

Answer: assert Solution().separateSquares(squares = [[0,0,5],[5,0,5],[10,0,5],[15,0,5]]) == 2.5

Answer: assert Solution().separateSquares(squares = [[0,0,5],[3,0,5],[6,0,5],[9,0,5]]) == 2.5

Answer: assert Solution().separateSquares(squares = [[0,0,10],[0,10,10],[0,20,10],[0,30,10],[0,40,10],[0,50,10],[0,60,10],[0,70,10],[0,80,10],[0,90,10]]) == 50.0

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

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

Answer: assert Solution().separateSquares(squares = [[1,1,1],[1,2,1],[1,3,1],[1,4,1],[1,5,1]]) == 3.5

Answer: assert Solution().separateSquares(squares = [[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.583333333333334

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 separateSquares(self, squares: list[list[int]]) -> float:
    halfArea = sum((l**2 for _, _, l in squares)) / 2
    events = sorted([(y, True, l) for _, y, l in squares] +
                    [(y + l, False, l) for _, y, l in squares])
    area = 0
    width = 0
    prevY = 0

    for y, isStart, l in events:
      areaGain = width * (y - prevY)
      if area + areaGain >= halfArea:
        return prevY + (halfArea - area) / width
      area += areaGain
      width += l if isStart else -l
      prevY = y


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 squares. Each squares[i] = [xi, yi, li] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.
Find the minimum y-coordinate value of a horizontal line such that the total area covered by squares above the line equals the total area covered by squares below the line.
Answers within 10-5 of the actual answer will be accepted.
Note: Squares may overlap. Overlapping areas should be counted only once in this version.

Example 1:

Input: squares = [[0,0,1],[2,2,1]]
Output: 1.00000
Explanation:

Any horizontal line between y = 1 and y = 2 results in an equal split, with 1 square unit above and 1 square unit below. The minimum y-value is 1.

Example 2:

Input: squares = [[0,0,2],[1,1,1]]
Output: 1.00000
Explanation:

Since the blue square overlaps with the red square, it will not be counted again. Thus, the line y = 1 splits the squares into two equal parts.

Constraints:

1 <= squares.length <= 5 * 104
squares[i] = [xi, yi, li]
squares[i].length == 3
0 <= xi, yi <= 109
1 <= li <= 109
The total area of all the squares will not exceed 1015.

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

SOLUTION:

Question:
PROBLEM:
You are given a 2D integer array squares. Each squares[i] = [xi, yi, li] represents the coordinates of the bottom-left point and the side length of a square parallel to the x-axis.
Find the minimum y-coordinate value of a horizontal line such that the total area covered by squares above the line equals the total area covered by squares below the line.
Answers within 10-5 of the actual answer will be accepted.
Note: Squares may overlap. Overlapping areas should be counted only once in this version.

Example 1:

Input: squares = [[0,0,1],[2,2,1]]
Output: 1.00000
Explanation:

Any horizontal line between y = 1 and y = 2 results in an equal split, with 1 square unit above and 1 square unit below. The minimum y-value is 1.

Example 2:

Input: squares = [[0,0,2],[1,1,1]]
Output: 1.00000
Explanation:

Since the blue square overlaps with the red square, it will not be counted again. Thus, the line y = 1 splits the squares into two equal parts.

Constraints:

1 <= squares.length <= 5 * 104
squares[i] = [xi, yi, li]
squares[i].length == 3
0 <= xi, yi <= 109
1 <= li <= 109
The total area of all the squares will not exceed 1015.

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

SOLUTION:

assert Solution().separateSquares(squares = [[1,1,2],[2,0,2],[0,2,2]]) == 2.0

assert Solution().separateSquares(squares = [[0,0,3],[1,1,2],[2,2,1]]) == 1.5

assert Solution().separateSquares(squares = [[0,0,2],[1,1,1]]) == 1.0

assert Solution().separateSquares(squares = [[0,0,1],[2,2,1]]) == 1.0

assert Solution().separateSquares(squares = [[0,0,3],[1,1,3],[2,2,3]]) == 2.5

Answer: assert Solution().separateSquares(squares = [[0,0,1],[1,1,1],[2,2,1],[3,3,1]]) == 2.0

Answer: assert Solution().separateSquares(squares = [[1,1,2],[2,0,2],[0,2,2]]) == 2.0

Answer: assert Solution().separateSquares(squares = [[0,0,4],[2,2,2],[1,1,1],[3,3,1]]) == 2.0

Answer: assert Solution().separateSquares(squares = [[0,0,5],[2,2,3],[1,1,2],[3,3,2],[4,4,1]]) == 2.5

Answer: assert Solution().separateSquares(squares = [[0,0,5],[5,5,5],[10,10,5],[15,15,5]]) == 10.0

Answer: assert Solution().separateSquares(squares = [[0,0,3],[1,1,2],[2,2,1]]) == 1.5

Answer: assert Solution().separateSquares(squares = [[0,0,2],[1,1,1]]) == 1.0

Answer: assert Solution().separateSquares(squares = [[0,0,10],[5,5,5],[10,10,1]]) == 5.05

Answer: assert Solution().separateSquares(squares = [[0,0,1],[2,2,1]]) == 1.0

Answer: assert Solution().separateSquares(squares = [[0,0,5],[5,5,5],[10,10,5]]) == 7.5

Answer: assert Solution().separateSquares(squares = [[0,0,4],[1,1,4],[2,2,4],[3,3,4]]) == 3.5

Answer: assert Solution().separateSquares(squares = [[0,0,3],[1,1,3],[2,2,3]]) == 2.5

Answer: assert Solution().separateSquares(squares = [[0,0,3],[1,1,2],[4,4,1]]) == 1.6666666666666665

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

Answer: assert Solution().separateSquares(squares = [[0,0,1000],[100,100,900],[200,200,800],[300,300,700],[400,400,600],[500,500,500],[600,600,400],[700,700,300],[800,800,200],[900,900,100]]) == 500.0

Answer: assert Solution().separateSquares(squares = [[0,0,100],[25,25,50],[50,50,25],[75,75,12.5],[100,100,6.25]]) == 50.1953125

Answer: assert Solution().separateSquares(squares = [[0,0,1000],[500,0,1000],[1000,0,1000],[1500,0,1000],[2000,0,1000]]) == 500.0

Answer: assert Solution().separateSquares(squares = [[0,0,100],[50,50,50],[100,100,25],[150,150,12.5],[200,200,6.25],[250,250,3.125]]) == 54.150390625

Answer: assert Solution().separateSquares(squares = [[0,0,1000],[10,10,500],[20,20,250],[30,30,125],[40,40,62.5],[50,50,31.25],[60,60,15.625]]) == 500.0

Answer: assert Solution().separateSquares(squares = [[0,0,10],[2,3,5],[5,2,3],[7,5,2],[9,3,1]]) == 5.0

Answer: assert Solution().separateSquares(squares = [[1,1,1],[1,3,1],[3,1,1],[3,3,1],[2,2,2],[2,4,2],[4,2,2],[4,4,2],[3,3,3]]) == 3.7

Answer: assert Solution().separateSquares(squares = [[1,1,3],[3,3,3],[5,5,3],[7,7,3],[9,9,3]]) == 6.5

Answer: assert Solution().separateSquares(squares = [[0, 0, 7], [2, 3, 4], [5, 5, 6], [7, 7, 3], [9, 9, 5], [11, 11, 7]]) == 9.222222222222221

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

Answer: assert Solution().separateSquares(squares = [[0,0,100],[50,50,50],[25,25,25],[75,75,25]]) == 50.0

Answer: assert Solution().separateSquares(squares = [[0,0,1],[0,1,1],[1,0,1],[1,1,1],[0.5,0.5,0.5],[0.5,1.5,0.5],[1.5,0.5,0.5],[1.5,1.5,0.5]]) == 1.0

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

Answer: assert Solution().separateSquares(squares = [[0,0,100],[10,10,80],[20,20,60],[30,30,40],[40,40,20]]) == 50.0

Answer: assert Solution().separateSquares(squares = [[0,0,10],[0,10,10],[0,20,10],[0,30,10],[0,40,10]]) == 25.0

Answer: assert Solution().separateSquares(squares = [[0,0,500],[250,250,250],[500,500,125],[750,750,62.5],[1000,1000,31.25]]) == 270.5078125

Answer: assert Solution().separateSquares(squares = [[0,0,20],[5,10,10],[15,5,5],[10,0,15],[25,15,10]]) == 11.5

Answer: assert Solution().separateSquares(squares = [[0,0,20],[0,20,20],[20,0,20],[20,20,20],[10,10,10],[10,30,10],[30,10,10],[30,30,10],[5,5,5],[5,25,5],[25,5,5],[25,25,5],[15,15,5],[15,35,5],[35,15,5],[35,35,5]]) == 20.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 10], [5, 0, 10], [10, 0, 10], [15, 0, 10], [20, 0, 10]]) == 5.0

Answer: assert Solution().separateSquares(squares = [[0,0,10],[1,1,8],[2,2,6],[3,3,4],[4,4,2],[5,5,1]]) == 5.0

Answer: assert Solution().separateSquares(squares = [[10,10,5],[20,20,5],[30,30,5],[10,20,5],[20,10,5],[20,30,5],[30,20,5]]) == 22.5

Answer: assert Solution().separateSquares(squares = [[0,0,100],[10,10,50],[20,20,25],[30,30,12.5],[40,40,6.25]]) == 50.0

Answer: assert Solution().separateSquares(squares = [[1,1,5],[6,1,5],[11,1,5],[16,1,5],[21,1,5],[26,1,5],[31,1,5],[36,1,5],[41,1,5]]) == 3.5

Answer: assert Solution().separateSquares(squares = [[0, 0, 2], [1, 1, 3], [3, 3, 4], [6, 6, 5], [10, 10, 6]]) == 9.4

Answer: assert Solution().separateSquares(squares = [[0,0,5],[5,5,5],[10,10,5],[15,15,5],[20,20,5]]) == 12.5

Answer: assert Solution().separateSquares(squares = [[0,0,20],[10,10,20],[20,20,20],[30,30,20],[40,40,20],[50,50,20]]) == 35.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 100], [25, 25, 50], [50, 50, 25], [75, 75, 12], [100, 100, 6], [125, 125, 3]]) == 50.225

Answer: assert Solution().separateSquares(squares = [[100, 100, 100], [150, 150, 150], [200, 200, 200], [250, 250, 250], [300, 300, 300]]) == 375.0

Answer: assert Solution().separateSquares(squares = [[10,10,10],[20,20,10],[30,30,10],[40,40,10],[50,50,10],[15,15,5],[25,25,5],[35,35,5],[45,45,5]]) == 35.0

Answer: assert Solution().separateSquares(squares = [[0,0,1000],[100,100,900],[200,200,800],[300,300,700],[400,400,600],[500,500,500]]) == 500.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 10], [1, 2, 8], [2, 4, 6], [3, 6, 4], [4, 8, 2]]) == 5.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 100], [10, 10, 100], [20, 20, 100], [30, 30, 100], [40, 40, 100]]) == 70.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 5], [0, 5, 5], [0, 10, 5], [0, 15, 5], [0, 20, 5], [0, 25, 5]]) == 15.0

Answer: assert Solution().separateSquares(squares = [[1,1,6],[3,3,5],[5,5,4],[7,7,3],[9,9,2]]) == 5.5

Answer: assert Solution().separateSquares(squares = [[0,0,10],[0,10,10],[10,0,10],[10,10,10],[5,5,10],[5,15,10],[15,5,10],[15,15,10]]) == 12.5

Answer: assert Solution().separateSquares(squares = [[0,0,100],[10,10,80],[20,20,60],[30,30,40],[40,40,20],[50,50,10]]) == 50.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 1000], [100, 100, 900], [200, 200, 800], [300, 300, 700], [400, 400, 600], [500, 500, 500], [600, 600, 400], [700, 700, 300], [800, 800, 200], [900, 900, 100]]) == 500.0

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

Answer: assert Solution().separateSquares(squares = [[0,0,100],[100,100,100],[200,200,100],[300,300,100],[400,400,100],[500,500,100],[600,600,100]]) == 350.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 100], [100, 100, 100], [200, 200, 100], [300, 300, 100], [400, 400, 100], [500, 500, 100], [600, 600, 100], [700, 700, 100], [800, 800, 100], [900, 900, 100]]) == 500.0

Answer: assert Solution().separateSquares(squares = [[0,0,100],[50,50,50],[100,0,100],[150,50,50],[200,0,100],[250,50,50],[300,0,100],[350,50,50]]) == 50.0

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

Answer: assert Solution().separateSquares(squares = [[0,0,1],[1,0,1],[2,0,1],[0,1,1],[1,1,1],[2,1,1],[0,2,1],[1,2,1],[2,2,1],[1.5,0.5,1]]) == 1.5

Answer: assert Solution().separateSquares(squares = [[0,0,1],[0,1,1],[0,2,1],[1,0,1],[1,1,1],[1,2,1],[2,0,1],[2,1,1],[2,2,1]]) == 1.5

Answer: assert Solution().separateSquares(squares = [[0,0,5],[2,2,3],[4,4,2],[6,6,1]]) == 2.9

Answer: assert Solution().separateSquares(squares = [[0, 0, 5], [2, 1, 3], [4, 2, 2], [6, 3, 1], [8, 4, 1]]) == 2.75

Answer: assert Solution().separateSquares(squares = [[0,0,1000000000],[500000000,0,500000000],[0,500000000,500000000],[500000000,500000000,500000000]]) == 500000000.0

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

Answer: assert Solution().separateSquares(squares = [[0,0,100],[10,0,100],[20,0,100],[30,0,100],[40,0,100],[50,0,100]]) == 50.0

Answer: assert Solution().separateSquares(squares = [[50, 50, 20], [60, 60, 30], [70, 70, 40], [80, 80, 50], [90, 90, 60]]) == 105.0

Answer: assert Solution().separateSquares(squares = [[0,0,100],[10,10,10],[20,20,10],[30,30,10],[40,40,10]]) == 50.0

Answer: assert Solution().separateSquares(squares = [[1, 1, 10], [11, 1, 10], [21, 1, 10], [31, 1, 10], [41, 1, 10]]) == 6.0

Answer: assert Solution().separateSquares(squares = [[10,10,20],[15,15,15],[20,20,10],[25,25,5],[30,30,1]]) == 20.025

Answer: assert Solution().separateSquares(squares = [[1,1,2],[3,3,2],[2,2,2],[4,4,2],[5,5,2]]) == 4.0

Answer: assert Solution().separateSquares(squares = [[0,0,20],[5,5,10],[15,15,5],[25,25,2]]) == 10.1

Answer: assert Solution().separateSquares(squares = [[10,10,10],[15,15,10],[20,20,10],[25,25,10],[30,30,10],[35,35,10],[40,40,10],[45,45,10],[50,50,10],[55,55,10]]) == 37.5

Answer: assert Solution().separateSquares(squares = [[0,0,5],[1,2,3],[4,4,2],[6,1,4]]) == 2.888888888888889

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

Answer: assert Solution().separateSquares(squares = [[1, 1, 5], [2, 2, 4], [3, 3, 3], [4, 4, 2], [5, 5, 1], [6, 6, 1], [7, 7, 1]]) == 3.7

Answer: assert Solution().separateSquares(squares = [[0,0,1000],[500,500,500],[250,250,250],[750,750,250],[125,125,125],[375,375,125],[625,625,125],[875,875,125]]) == 500.0

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

Answer: assert Solution().separateSquares(squares = [[0, 0, 10], [5, 5, 10], [10, 10, 10], [15, 15, 10], [20, 20, 10], [25, 25, 10]]) == 17.5

Answer: assert Solution().separateSquares(squares = [[0, 0, 5], [2, 2, 5], [4, 4, 5], [6, 6, 5], [8, 8, 5], [10, 10, 5]]) == 7.5

Answer: assert Solution().separateSquares(squares = [[0,0,100],[50,0,50],[0,50,50],[50,50,50],[25,25,50]]) == 50.0

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

Answer: assert Solution().separateSquares(squares = [[0,0,500],[100,100,400],[200,200,300],[300,300,200],[400,400,100],[500,500,50],[600,600,25],[700,700,12.5]]) == 253.28125

Answer: assert Solution().separateSquares(squares = [[0, 0, 10], [5, 0, 5], [10, 0, 3], [15, 0, 2], [20, 0, 1]]) == 4.3

Answer: assert Solution().separateSquares(squares = [[10,10,5],[20,15,6],[30,20,7],[40,25,8],[50,30,9],[60,35,10],[70,40,11]]) == 36.0

Answer: assert Solution().separateSquares(squares = [[0,0,1000],[100,900,1000],[200,800,1000],[300,700,1000],[400,600,1000],[500,500,1000],[600,400,1000],[700,300,1000],[800,200,1000],[900,100,1000]]) == 855.2631578947369

Answer: assert Solution().separateSquares(squares = [[0, 0, 10], [5, 0, 10], [10, 0, 10], [15, 0, 10], [20, 0, 10], [25, 0, 10]]) == 5.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 1], [1, 0, 2], [3, 0, 3], [6, 0, 4], [10, 0, 5], [15, 0, 6], [21, 0, 7], [28, 0, 8], [36, 0, 9], [45, 0, 10]]) == 3.642857142857143

Answer: assert Solution().separateSquares(squares = [[0,0,500],[100,100,500],[200,200,500],[300,300,500],[400,400,500],[500,500,500],[600,600,500],[700,700,500],[800,800,500],[900,900,500]]) == 700.0

Answer: assert Solution().separateSquares(squares = [[1,1,3],[3,3,2],[5,5,1],[2,2,2],[4,4,2],[6,6,2]]) == 3.875

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

Answer: assert Solution().separateSquares(squares = [[10,10,1],[20,20,1],[30,30,1],[40,40,1],[50,50,1],[60,60,1],[70,70,1],[80,80,1],[90,90,1]]) == 50.5

Answer: assert Solution().separateSquares(squares = [[0,0,3],[0,3,3],[3,0,3],[3,3,3],[1,1,2],[1,4,2],[4,1,2],[4,4,2]]) == 3.0

Answer: assert Solution().separateSquares(squares = [[10, 10, 5], [10, 15, 5], [15, 10, 5], [15, 15, 5], [20, 20, 10]]) == 20.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 10], [0, 10, 10], [0, 20, 10], [10, 0, 10], [10, 10, 10], [10, 20, 10]]) == 15.0

Answer: assert Solution().separateSquares(squares = [[0,0,2],[0,2,2],[0,4,2],[0,6,2],[0,8,2],[0,10,2],[0,12,2],[0,14,2],[0,16,2],[0,18,2]]) == 10.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 20], [5, 5, 10], [10, 10, 5], [15, 15, 2], [20, 20, 1], [25, 25, 1], [30, 30, 1]]) == 10.075

Answer: assert Solution().separateSquares(squares = [[0,0,50],[10,10,40],[20,20,30],[30,30,20],[40,40,10]]) == 25.0

Answer: assert Solution().separateSquares(squares = [[0,0,100],[20,20,50],[40,40,25],[60,60,12.5]]) == 50.0

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

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

Answer: assert Solution().separateSquares(squares = [[1,1,2],[2,2,2],[3,3,2],[4,4,2],[5,5,2],[6,6,2]]) == 4.5

Answer: assert Solution().separateSquares(squares = [[0, 0, 1000000000], [500000000, 500000000, 1000000000]]) == 750000000.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 50], [50, 0, 50], [100, 0, 50], [150, 0, 50], [200, 0, 50], [250, 0, 50], [300, 0, 50], [350, 0, 50], [400, 0, 50]]) == 25.0

Answer: assert Solution().separateSquares(squares = [[0,0,10],[10,0,10],[20,0,10],[30,0,10],[40,0,10],[50,0,10]]) == 5.0

Answer: assert Solution().separateSquares(squares = [[0, 0, 100], [25, 25, 50], [50, 50, 25], [75, 75, 12.5], [100, 100, 6.25], [125, 125, 3.125]]) == 50.244140625

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 Node:
    __slots__ = 'l', 'r', 'min_cover_len', 'min_cover', 'todo'

    def __init__(self):
        self.l = 0
        self.r = 0
        self.min_cover_len = 0  # 区间内被矩形覆盖次数最少的底边长之和
        self.min_cover = 0      # 区间内被矩形覆盖的最小次数
        self.todo = 0           # 子树内的所有节点的 min_cover 需要增加的量，注意这可以是负数

class SegmentTree:
    def __init__(self, xs: List[int]):
        n = len(xs) - 1  # xs.size() 个横坐标有 xs.size()-1 个差值
        self.seg = [Node() for _ in range(2 << (n - 1).bit_length())]
        self.build(xs, 1, 0, n - 1)

    def get_uncovered_length(self) -> int:
        return 0 if self.seg[1].min_cover else self.seg[1].min_cover_len

    # 根据左右儿子的信息，更新当前节点的信息
    def maintain(self, o: int) -> None:
        lo = self.seg[o * 2]
        ro = self.seg[o * 2 + 1]
        mn = min(lo.min_cover, ro.min_cover)
        self.seg[o].min_cover = mn
        # 只统计等于 min_cover 的底边长之和
        self.seg[o].min_cover_len = (lo.min_cover_len if lo.min_cover == mn else 0) +                                     (ro.min_cover_len if ro.min_cover == mn else 0)

    # 仅更新节点信息，不下传懒标记 todo
    def do(self, o: int, v: int) -> None:
        self.seg[o].min_cover += v
        self.seg[o].todo += v

    # 下传懒标记 todo
    def spread(self, o: int) -> None:
        v = self.seg[o].todo
        if v:
            self.do(o * 2, v)
            self.do(o * 2 + 1, v)
            self.seg[o].todo = 0

    # 建树
    def build(self, xs: List[int], o: int, l: int, r: int) -> None:
        self.seg[o].l = l
        self.seg[o].r = r
        if l == r:
            self.seg[o].min_cover_len = xs[l + 1] - xs[l]
            return
        m = (l + r) // 2
        self.build(xs, o * 2, l, m)
        self.build(xs, o * 2 + 1, m + 1, r)
        self.maintain(o)

    # 区间更新
    def update(self, o: int, l: int, r: int, v: int) -> None:
        if l <= self.seg[o].l and self.seg[o].r <= r:
            self.do(o, v)
            return
        self.spread(o)
        m = (self.seg[o].l + self.seg[o].r) // 2
        if l <= m:
            self.update(o * 2, l, r, v)
        if m < r:
            self.update(o * 2 + 1, l, r, v)
        self.maintain(o)

# 代码逻辑同 850 题，增加一个 records 数组记录关键数据
class Solution:
    def separateSquares(self, squares: List[List[int]]) -> float:
        xs = []
        events = []
        for lx, y, l in squares:
            rx = lx + l
            xs.append(lx)
            xs.append(rx)
            events.append((y, lx, rx, 1))
            events.append((y + l, lx, rx, -1))

        # 排序，方便离散化
        xs = sorted(set(xs))

        # 初始化线段树
        t = SegmentTree(xs)

        # 模拟扫描线从下往上移动
        events.sort(key=lambda e: e[0])
        records = []
        tot_area = 0
        for (y, lx, rx, delta), e2 in pairwise(events):
            l = bisect_left(xs, lx)  # 离散化
            r = bisect_left(xs, rx) - 1  # r 对应着 xs[r] 与 xs[r+1]=rx 的差值
            t.update(1, l, r, delta)  # 更新被 [lx, rx] 覆盖的次数
            sum_len = xs[-1] - xs[0] - t.get_uncovered_length()  # 减去没被矩形覆盖的长度
            records.append((tot_area, sum_len))  # 记录关键数据
            tot_area += sum_len * (e2[0] - y)  # 新增面积 = 被至少一个矩形覆盖的底边长之和 * 矩形高度

        # 二分找最后一个 < tot_area / 2 的面积
        i = bisect_left(records, tot_area, key=lambda r: r[0] * 2) - 1
        area, sum_len = records[i]
        return events[i][0] + (tot_area - area * 2) / (sum_len * 2)


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

PROBLEM:
You are given an integer array pizzas of size n, where pizzas[i] represents the weight of the ith pizza. Every day, you eat exactly 4 pizzas. Due to your incredible metabolism, when you eat pizzas of weights W, X, Y, and Z, where W <= X <= Y <= Z, you gain the weight of only 1 pizza!

On odd-numbered days (1-indexed), you gain a weight of Z.
On even-numbered days, you gain a weight of Y.

Find the maximum total weight you can gain by eating all pizzas optimally.
Note: It is guaranteed that n is a multiple of 4, and each pizza can be eaten only once.

Example 1:

Input: pizzas = [1,2,3,4,5,6,7,8]
Output: 14
Explanation:

On day 1, you eat pizzas at indices [1, 2, 4, 7] = [2, 3, 5, 8]. You gain a weight of 8.
On day 2, you eat pizzas at indices [0, 3, 5, 6] = [1, 4, 6, 7]. You gain a weight of 6.

The total weight gained after eating all the pizzas is 8 + 6 = 14.

Example 2:

Input: pizzas = [2,1,1,1,1,1,1,1]
Output: 3
Explanation:

On day 1, you eat pizzas at indices [4, 5, 6, 0] = [1, 1, 1, 2]. You gain a weight of 2.
On day 2, you eat pizzas at indices [1, 2, 3, 7] = [1, 1, 1, 1]. You gain a weight of 1.

The total weight gained after eating all the pizzas is 2 + 1 = 3.

Constraints:

4 <= n == pizzas.length <= 2 * 105
1 <= pizzas[i] <= 105
n is a multiple of 4.

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

SOLUTION:

Question:
PROBLEM:
You are given an integer array pizzas of size n, where pizzas[i] represents the weight of the ith pizza. Every day, you eat exactly 4 pizzas. Due to your incredible metabolism, when you eat pizzas of weights W, X, Y, and Z, where W <= X <= Y <= Z, you gain the weight of only 1 pizza!

On odd-numbered days (1-indexed), you gain a weight of Z.
On even-numbered days, you gain a weight of Y.

Find the maximum total weight you can gain by eating all pizzas optimally.
Note: It is guaranteed that n is a multiple of 4, and each pizza can be eaten only once.

Example 1:

Input: pizzas = [1,2,3,4,5,6,7,8]
Output: 14
Explanation:

On day 1, you eat pizzas at indices [1, 2, 4, 7] = [2, 3, 5, 8]. You gain a weight of 8.
On day 2, you eat pizzas at indices [0, 3, 5, 6] = [1, 4, 6, 7]. You gain a weight of 6.

The total weight gained after eating all the pizzas is 8 + 6 = 14.

Example 2:

Input: pizzas = [2,1,1,1,1,1,1,1]
Output: 3
Explanation:

On day 1, you eat pizzas at indices [4, 5, 6, 0] = [1, 1, 1, 2]. You gain a weight of 2.
On day 2, you eat pizzas at indices [1, 2, 3, 7] = [1, 1, 1, 1]. You gain a weight of 1.

The total weight gained after eating all the pizzas is 2 + 1 = 3.

Constraints:

4 <= n == pizzas.length <= 2 * 105
1 <= pizzas[i] <= 105
n is a multiple of 4.

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

SOLUTION:

assert Solution().maxWeight(pizzas = [1,2,3,4,5,6,7,8]) == 14

assert Solution().maxWeight(pizzas = [5,5,5,5,5,5,5,5]) == 10

assert Solution().maxWeight(pizzas = [2,1,1,1,1,1,1,1]) == 3

assert Solution().maxWeight(pizzas = [8,7,6,5,4,3,2,1]) == 14

Answer: assert Solution().maxWeight(pizzas = [10,20,30,40,50,60,70,80,90,100,110,120]) == 320

Answer: assert Solution().maxWeight(pizzas = [10,20,30,40,50,60,70,80,90,100]) == 180

Answer: assert Solution().maxWeight(pizzas = [5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5]) == 20

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

Answer: assert Solution().maxWeight(pizzas = [1,3,2,4,7,6,9,8,13,12,11,10,15,14,17,16]) == 59

Answer: assert Solution().maxWeight(pizzas = [1,2,3,4,5,6,7,8]) == 14

Answer: assert Solution().maxWeight(pizzas = [5,5,5,5,5,5,5,5]) == 10

Answer: assert Solution().maxWeight(pizzas = [5,5,5,5,5,5,5,5,5,5,5,5]) == 15

Answer: assert Solution().maxWeight(pizzas = [2,1,1,1,1,1,1,1]) == 3

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

Answer: assert Solution().maxWeight(pizzas = [5,1,9,1,5,1,9,1,5,1,9,1,5,1,9,1]) == 32

Answer: assert Solution().maxWeight(pizzas = [3,3,3,3,4,4,4,4,5,5,5,5]) == 15

Answer: assert Solution().maxWeight(pizzas = [8,7,6,5,4,3,2,1]) == 14

Answer: assert Solution().maxWeight(pizzas = [1,3,5,7,9,11,13,15,17,19,21,23]) == 61

Answer: assert Solution().maxWeight(pizzas = [1,2,3,4,10,20,30,40,50,60,70,80,90,100,110,120]) == 390

Answer: assert Solution().maxWeight(pizzas = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230, 240, 250, 260, 270, 280, 290, 300]) == 1830

Answer: assert Solution().maxWeight(pizzas = [1,2,3,4,2,3,4,5,3,4,5,6,4,5,6,7,5,6,7,8,6,7,8,9,7,8,9,10,8,9,10,11]) == 72

Answer: assert Solution().maxWeight(pizzas = [34,12,45,23,67,89,21,56,78,90,32,14,67,89,12,34]) == 324

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

Answer: assert Solution().maxWeight(pizzas = [1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4, 1, 2, 3, 4]) == 26

Answer: assert Solution().maxWeight(pizzas = [29, 28, 27, 26, 25, 24, 23, 22, 21, 20, 19, 18, 17, 16, 15, 14]) == 107

Answer: assert Solution().maxWeight(pizzas = [123, 456, 789, 101, 234, 567, 890, 12, 235, 468, 791, 13, 346, 579, 802, 14, 457, 690, 903, 15]) == 3963

Answer: assert Solution().maxWeight(pizzas = [1,100000,2,99999,3,99998,4,99997,5,99996,6,99995,7,99994,8,99993,9,99992,10,99991]) == 499987

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

Answer: assert Solution().maxWeight(pizzas = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000]) == 180000

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

Answer: assert Solution().maxWeight(pizzas = [100000, 90000, 80000, 70000, 60000, 50000, 40000, 30000, 20000, 10000, 9000, 8000, 7000, 6000, 5000, 4000]) == 310000

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

Answer: assert Solution().maxWeight(pizzas = [8, 7, 6, 5, 4, 3, 2, 1, 16, 15, 14, 13, 24, 23, 22, 21, 32, 31, 30, 29, 40, 39, 38, 37]) == 203

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

Answer: assert Solution().maxWeight(pizzas = [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]) == 176

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

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

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

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

Answer: assert Solution().maxWeight(pizzas = [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]) == 63

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

Answer: assert Solution().maxWeight(pizzas = [100000,90000,80000,70000,60000,50000,40000,30000,20000,10000,1000,900,800,700,600,500,400,300,200,100]) == 370000

Answer: assert Solution().maxWeight(pizzas = [10000, 20000, 30000, 40000, 50000, 60000, 70000, 80000, 90000, 100000, 110000, 120000, 130000, 140000, 150000, 160000]) == 550000

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

Answer: assert Solution().maxWeight(pizzas = [1, 2, 3, 4, 1000, 1001, 1002, 1003, 5, 6, 7, 8, 1004, 1005, 1006, 1007, 9, 10, 11, 12, 1008, 1009, 1010, 1011]) == 6045

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

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

Answer: assert Solution().maxWeight(pizzas = [1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8]) == 58

Answer: assert Solution().maxWeight(pizzas = [5, 15, 10, 20, 25, 50, 40, 60, 30, 75, 65, 85, 45, 90, 80, 100]) == 335

Answer: assert Solution().maxWeight(pizzas = [8, 12, 15, 18, 1, 5, 7, 9, 21, 22, 23, 24, 3, 6, 11, 14]) == 83

Answer: assert Solution().maxWeight(pizzas = [100, 90, 80, 70, 60, 50, 40, 30, 20, 10, 100, 90, 80, 70, 60, 50]) == 370

Answer: assert Solution().maxWeight(pizzas = [100,90,80,70,60,50,40,30,20,10,100,90,80,70,60,50,40,30,20,10]) == 440

Answer: assert Solution().maxWeight(pizzas = [3, 1, 4, 1, 5, 9, 2, 6, 5, 3, 5, 9, 2, 6, 5, 3]) == 29

Answer: assert Solution().maxWeight(pizzas = [1, 2, 3, 4, 10, 9, 8, 7, 13, 12, 11, 10, 19, 18, 17, 16]) == 65

Answer: assert Solution().maxWeight(pizzas = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200]) == 870

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

Answer: assert Solution().maxWeight(pizzas = [15, 10, 25, 30, 35, 20, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85]) == 295

Answer: assert Solution().maxWeight(pizzas = [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30, 32]) == 110

Answer: assert Solution().maxWeight(pizzas = [100000, 99999, 99998, 99997, 99996, 99995, 99994, 99993, 99992, 99991, 99990, 99989, 99988, 99987, 99986, 99985]) == 399991

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

Answer: assert Solution().maxWeight(pizzas = [25, 35, 45, 55, 65, 75, 85, 95, 105, 115, 125, 135, 145, 155, 165, 175, 185, 195, 205, 215]) == 945

Answer: assert Solution().maxWeight(pizzas = [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]) == 183

Answer: assert Solution().maxWeight(pizzas = [100000, 1, 99999, 2, 99998, 3, 99997, 4, 99996, 5, 99995, 6, 99994, 7, 99993, 8]) == 399991

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

Answer: assert Solution().maxWeight(pizzas = [4, 3, 2, 1, 12, 11, 10, 9, 16, 15, 14, 13, 20, 19, 18, 17, 24, 23, 22, 21, 28, 27, 26, 25, 32, 31, 30, 29]) == 197

Answer: assert Solution().maxWeight(pizzas = [50,40,30,20,10,90,80,70,60,50,40,30,20,10,90,80]) == 320

Answer: assert Solution().maxWeight(pizzas = [15, 10, 5, 1, 20, 12, 6, 2, 25, 14, 7, 3, 30, 16, 8, 4, 35, 18, 9, 5, 40, 20, 10, 6, 45, 22, 11, 7, 50, 24, 12, 8]) == 253

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

Answer: assert Solution().maxWeight(pizzas = [100,50,150,200,300,400,500,600,700,800,900,1000,1100,1200,1300,1400]) == 4700

Answer: assert Solution().maxWeight(pizzas = [100, 1, 99, 2, 98, 3, 97, 4, 96, 5, 95, 6, 94, 7, 93, 8, 92, 9, 91, 10, 90, 11, 89, 12]) == 579

Answer: assert Solution().maxWeight(pizzas = [29, 15, 37, 12, 45, 23, 51, 34, 59, 28, 67, 41, 75, 50, 83, 62]) == 271

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

Answer: assert Solution().maxWeight(pizzas = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100, 110, 120, 130, 140, 150, 160]) == 550

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

Answer: assert Solution().maxWeight(pizzas = [2,3,4,5,6,7,8,9,1,1,1,1,1,1,1,1,1,1,1,1]) == 32

Answer: assert Solution().maxWeight(pizzas = [5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]) == 35

Answer: assert Solution().maxWeight(pizzas = [1000, 900, 800, 700, 600, 500, 400, 300, 200, 100, 50, 40, 30, 20, 10, 5]) == 3100

Answer: assert Solution().maxWeight(pizzas = [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]) == 183

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

Answer: assert Solution().maxWeight(pizzas = [3,1,4,1,5,9,2,6,5,3,5,9,7,9,3,2,3,8,4,6,2,6,4,3,3,8,3,2,7,9]) == 57

Answer: assert Solution().maxWeight(pizzas = [1, 2, 3, 4, 100, 200, 300, 400, 500, 600, 700, 800, 900, 1000, 1100, 1200]) == 3900

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

Answer: assert Solution().maxWeight(pizzas = [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]) == 183

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

Answer: assert Solution().maxWeight(pizzas = [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]) == 340

Answer: assert Solution().maxWeight(pizzas = [50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000, 50000]) == 200000

Answer: assert Solution().maxWeight(pizzas = [100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000, 100000]) == 400000

Answer: assert Solution().maxWeight(pizzas = [50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50, 50]) == 350

Answer: assert Solution().maxWeight(pizzas = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993, 9, 99992, 10, 99991]) == 499987

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

Answer: assert Solution().maxWeight(pizzas = [50, 20, 30, 10, 90, 80, 70, 60, 110, 120, 130, 140, 150, 160, 170, 180]) == 630

Answer: assert Solution().maxWeight(pizzas = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14]) == 87

Answer: assert Solution().maxWeight(pizzas = [1, 10, 100, 1000, 1, 10, 100, 1000, 1, 10, 100, 1000, 1, 10, 100, 1000]) == 3100

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

Answer: assert Solution().maxWeight(pizzas = [100, 99, 98, 97, 96, 95, 94, 93, 92, 91, 90, 89, 88, 87, 86, 85]) == 391

Answer: assert Solution().maxWeight(pizzas = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8]) == 58

Answer: assert Solution().maxWeight(pizzas = [10,20,30,40,50,60,70,80,90,100,110,120,130,140,150,160]) == 550

Answer: assert Solution().maxWeight(pizzas = [30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11]) == 137

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

Answer: assert Solution().maxWeight(pizzas = [8,8,8,8,7,7,7,7,6,6,6,6,5,5,5,5,4,4,4,4,3,3,3,3,2,2,2,2,1,1,1,1]) == 58

Answer: assert Solution().maxWeight(pizzas = [1, 100000, 2, 99999, 3, 99998, 4, 99997, 5, 99996, 6, 99995, 7, 99994, 8, 99993]) == 399991

Answer: assert Solution().maxWeight(pizzas = [10, 20, 15, 10, 25, 30, 35, 40, 5, 45, 50, 55, 60, 65, 70, 75]) == 255

Answer: assert Solution().maxWeight(pizzas = [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]) == 218

Answer: assert Solution().maxWeight(pizzas = [100000, 1, 99999, 2, 99998, 3, 99997, 4, 99996, 5, 99995, 6, 99994, 7, 99993, 8, 99992, 9, 99991, 10, 99990, 11, 99989, 12]) == 599979

Answer: assert Solution().maxWeight(pizzas = [1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8]) == 29

Answer: assert Solution().maxWeight(pizzas = [100,200,150,300,10,20,30,40,1000,2000,1500,3000,5,15,25,35]) == 6200

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

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 maxWeight(self, pizzas: List[int]) -> int:
        days = len(pizzas) // 4
        pizzas.sort()
        odd = (days + 1) // 2
        even = days - odd
        ans = sum(pizzas[-odd:])
        i = len(pizzas) - odd - 2
        for _ in range(even):
            ans += pizzas[i]
            i -= 2
        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:
Given a string s of length n and an integer k, determine whether it is possible to select k disjoint special substrings.
A special substring is a substring where:

Any character present inside the substring should not appear outside it in the string.
The substring is not the entire string s.

Note that all k substrings must be disjoint, meaning they cannot overlap.
Return true if it is possible to select k such disjoint special substrings; otherwise, return false.

Example 1:

Input: s = "abcdbaefab", k = 2
Output: true
Explanation:

We can select two disjoint special substrings: "cd" and "ef".
"cd" contains the characters 'c' and 'd', which do not appear elsewhere in s.
"ef" contains the characters 'e' and 'f', which do not appear elsewhere in s.

Example 2:

Input: s = "cdefdc", k = 3
Output: false
Explanation:
There can be at most 2 disjoint special substrings: "e" and "f". Since k = 3, the output is false.

Example 3:

Input: s = "abeabe", k = 0
Output: true

Constraints:

2 <= n == s.length <= 5 * 104
0 <= k <= 26
s consists only of lowercase English letters.

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

SOLUTION:

Question:
PROBLEM:
Given a string s of length n and an integer k, determine whether it is possible to select k disjoint special substrings.
A special substring is a substring where:

Any character present inside the substring should not appear outside it in the string.
The substring is not the entire string s.

Note that all k substrings must be disjoint, meaning they cannot overlap.
Return true if it is possible to select k such disjoint special substrings; otherwise, return false.

Example 1:

Input: s = "abcdbaefab", k = 2
Output: true
Explanation:

We can select two disjoint special substrings: "cd" and "ef".
"cd" contains the characters 'c' and 'd', which do not appear elsewhere in s.
"ef" contains the characters 'e' and 'f', which do not appear elsewhere in s.

Example 2:

Input: s = "cdefdc", k = 3
Output: false
Explanation:
There can be at most 2 disjoint special substrings: "e" and "f". Since k = 3, the output is false.

Example 3:

Input: s = "abeabe", k = 0
Output: true

Constraints:

2 <= n == s.length <= 5 * 104
0 <= k <= 26
s consists only of lowercase English letters.

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

SOLUTION:

assert Solution().maxSubstringLength(s = "single", k = 0) == True

assert Solution().maxSubstringLength(s = "abeabe", k = 0) == True

assert Solution().maxSubstringLength(s = "cdefdc", k = 3) == False

assert Solution().maxSubstringLength(s = "abacabadabacaba", k = 3) == False

assert Solution().maxSubstringLength(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz", k = 2) == True

assert Solution().maxSubstringLength(s = "abcdbaefab", k = 2) == True

assert Solution().maxSubstringLength(s = "unique", k = 6) == False

assert Solution().maxSubstringLength(s = "xyzzxyzz", k = 1) == False

assert Solution().maxSubstringLength(s = "abcdefghijklmnopqrstuvwxyz", k = 26) == True

assert Solution().maxSubstringLength(s = "repeatedletters", k = 3) == True

assert Solution().maxSubstringLength(s = "mississippi", k = 1) == True

assert Solution().maxSubstringLength(s = "aaaaabbbbccccdddddeeeeeffffffggggghhhhhh", k = 6) == True

assert Solution().maxSubstringLength(s = "abcdefgabcdefgabcdefg", k = 3) == False

assert Solution().maxSubstringLength(s = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg", k = 7) == False

assert Solution().maxSubstringLength(s = "alphabet", k = 0) == True

assert Solution().maxSubstringLength(s = "xyzxyzxyzxyz", k = 1) == False

assert Solution().maxSubstringLength(s = "xyzxyzxyzxyzxyzxyzxyzxyz", k = 2) == False

assert Solution().maxSubstringLength(s = "zzzzzzzzzzzzzzzzzzzzzzzzzz", k = 0) == True

assert Solution().maxSubstringLength(s = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg", k = 7) == False

assert Solution().maxSubstringLength(s = "specialsubstringsspecialsubstring", k = 1) == False

assert Solution().maxSubstringLength(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz", k = 13) == True

assert Solution().maxSubstringLength(s = "mnopqrstuvwxyzabcdefghijkl", k = 13) == True

assert Solution().maxSubstringLength(s = "banana", k = 2) == True

assert Solution().maxSubstringLength(s = "thisisanexamplestringwithnospacetospare", k = 0) == True

assert Solution().maxSubstringLength(s = "uniquecharactersaregreat", k = 5) == True

assert Solution().maxSubstringLength(s = "mnopqrspomn", k = 1) == True

assert Solution().maxSubstringLength(s = "zzzzzzzzzzzzzzzzzzzz", k = 0) == True

assert Solution().maxSubstringLength(s = "xyzxyzxyzxyzxyz", k = 5) == False

assert Solution().maxSubstringLength(s = "verylongstringwithvariouscharactersvariouscharactersvariouscharacters", k = 5) == False

assert Solution().maxSubstringLength(s = "qwertyuiopasdfghjklzxcvbnmqwerty", k = 10) == True

assert Solution().maxSubstringLength(s = "mississippi", k = 2) == True

assert Solution().maxSubstringLength(s = "qwertypoiuytrewqasdfghjklzxcvbnmasdfghjklzxcvbnm", k = 5) == True

assert Solution().maxSubstringLength(s = "abcdefghijklmnopqrstuvwxyza", k = 26) == False

assert Solution().maxSubstringLength(s = "pppppppppppppppppppp", k = 1) == False

assert Solution().maxSubstringLength(s = "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef", k = 20) == False

assert Solution().maxSubstringLength(s = "mnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopq", k = 10) == False

assert Solution().maxSubstringLength(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz", k = 26) == True

assert Solution().maxSubstringLength(s = "xyzxyzxyzxyzxyzxyzxyzxyzxyzxyz", k = 1) == False

assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd", k = 4) == False

assert Solution().maxSubstringLength(s = "uniquecharactershere", k = 3) == True

assert Solution().maxSubstringLength(s = "thisisaverylongstringwithuniquecharacters", k = 15) == False

assert Solution().maxSubstringLength(s = "abcabcabcabcabcabcabcabcabcabcabc", k = 10) == False

assert Solution().maxSubstringLength(s = "verylongstringwithsomeuniquecharsandmanyrepeatsababababab", k = 4) == True

assert Solution().maxSubstringLength(s = "abcdeabcdeabcde", k = 5) == False

assert Solution().maxSubstringLength(s = "abacabadabacaba", k = 2) == False

assert Solution().maxSubstringLength(s = "abcdef", k = 0) == True

assert Solution().maxSubstringLength(s = "abracadabra", k = 3) == False

assert Solution().maxSubstringLength(s = "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde", k = 5) == False

assert Solution().maxSubstringLength(s = "abcabcabc", k = 3) == False

assert Solution().maxSubstringLength(s = "abcabcabcabcabcabcabcabc", k = 3) == False

assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcdabcd", k = 12) == False

assert Solution().maxSubstringLength(s = "abcdefghijabcdefghijabcdefghijabcdefghij", k = 5) == False

assert Solution().maxSubstringLength(s = "abacabadabacabadabacabad", k = 1) == False

assert Solution().maxSubstringLength(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz", k = 10) == True

assert Solution().maxSubstringLength(s = "abcabcabcabcabcabc", k = 1) == False

assert Solution().maxSubstringLength(s = "aabbccddeeffgg", k = 7) == True

assert Solution().maxSubstringLength(s = "aaaaabbbbccccdddd", k = 4) == True

assert Solution().maxSubstringLength(s = "abacabadabacabad", k = 4) == False

assert Solution().maxSubstringLength(s = "onlyoneuniquecharx", k = 1) == True

assert Solution().maxSubstringLength(s = "abcdefghijklimnopqrstuvwxyz", k = 25) == True

assert Solution().maxSubstringLength(s = "aabbaaccdd", k = 2) == True

assert Solution().maxSubstringLength(s = "aaaabbbbccccdddd", k = 2) == True

assert Solution().maxSubstringLength(s = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", k = 1) == False

assert Solution().maxSubstringLength(s = "abcdefgabcdefg", k = 7) == False

assert Solution().maxSubstringLength(s = "thisisaverylongstringwithnoseparatespecialsubstrings", k = 0) == True

assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcdabcdabcdabcd", k = 4) == False

assert Solution().maxSubstringLength(s = "abababababababab", k = 1) == False

assert Solution().maxSubstringLength(s = "aaabbbcccdddeeefffggghhhiiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz", k = 13) == True

assert Solution().maxSubstringLength(s = "abcdefg", k = 3) == True

assert Solution().maxSubstringLength(s = "thisisaverylongstringwithsomeuniquerandomcharacters", k = 8) == False

assert Solution().maxSubstringLength(s = "abacabadabacaba", k = 1) == True

assert Solution().maxSubstringLength(s = "aaabbbccc", k = 3) == True

assert Solution().maxSubstringLength(s = "nooverlapstring", k = 0) == True

assert Solution().maxSubstringLength(s = "aaaaabbbbbcccccdddddeeeeee", k = 5) == True

assert Solution().maxSubstringLength(s = "abacabadaba", k = 3) == False

assert Solution().maxSubstringLength(s = "abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad", k = 3) == False

assert Solution().maxSubstringLength(s = "abababababababababab", k = 10) == False

assert Solution().maxSubstringLength(s = "abacabadabacabad", k = 3) == False

assert Solution().maxSubstringLength(s = "abcabcabcabcabcabcabcabc", k = 1) == False

assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcd", k = 4) == False

assert Solution().maxSubstringLength(s = "abcdefghiabcdefghij", k = 5) == False

assert Solution().maxSubstringLength(s = "mnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopqrs", k = 13) == False

assert Solution().maxSubstringLength(s = "abcdefghijabcdefghijabcdefghij", k = 9) == False

assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcdabcdabcd", k = 4) == False

assert Solution().maxSubstringLength(s = "zzzyyyxxxwwwvvvuuutttsssrqqppoonnmmlkkkjjjiiihhhgggfffeeedddcccbbaaa", k = 13) == True

assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcdabcd", k = 3) == False

assert Solution().maxSubstringLength(s = "mnopqrspqomn", k = 6) == False

assert Solution().maxSubstringLength(s = "xyxyxyxyxyxyxy", k = 1) == False

assert Solution().maxSubstringLength(s = "uniquelettersarehere", k = 10) == False

assert Solution().maxSubstringLength(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz", k = 0) == True

assert Solution().maxSubstringLength(s = "abcdabcdeabcdefabcdefgabcdefgabcdef", k = 5) == False

assert Solution().maxSubstringLength(s = "hellotherehellothere", k = 3) == False

assert Solution().maxSubstringLength(s = "thisisaverylongstringwithrepeatedcharactersaaaaaaaaa", k = 5) == True

assert Solution().maxSubstringLength(s = "abcdefgabcdefgabcdefgabcdefgabcdefg", k = 7) == False

assert Solution().maxSubstringLength(s = "zyxwvutsrqponmlkjihgfedcba", k = 26) == True

Answer: assert Solution().maxSubstringLength(s = "single", k = 0) == True

Answer: assert Solution().maxSubstringLength(s = "abeabe", k = 0) == True

Answer: assert Solution().maxSubstringLength(s = "cdefdc", k = 3) == False

Answer: assert Solution().maxSubstringLength(s = "abacabadabacaba", k = 3) == False

Answer: assert Solution().maxSubstringLength(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz", k = 2) == True

Answer: assert Solution().maxSubstringLength(s = "abcdbaefab", k = 2) == True

Answer: assert Solution().maxSubstringLength(s = "unique", k = 6) == False

Answer: assert Solution().maxSubstringLength(s = "xyzzxyzz", k = 1) == False

Answer: assert Solution().maxSubstringLength(s = "abcdefghijklmnopqrstuvwxyz", k = 26) == True

Answer: assert Solution().maxSubstringLength(s = "repeatedletters", k = 3) == True

Answer: assert Solution().maxSubstringLength(s = "mississippi", k = 1) == True

Answer: assert Solution().maxSubstringLength(s = "aaaaabbbbccccdddddeeeeeffffffggggghhhhhh", k = 6) == True

Answer: assert Solution().maxSubstringLength(s = "abcdefgabcdefgabcdefg", k = 3) == False

Answer: assert Solution().maxSubstringLength(s = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg", k = 7) == False

Answer: assert Solution().maxSubstringLength(s = "alphabet", k = 0) == True

Answer: assert Solution().maxSubstringLength(s = "xyzxyzxyzxyz", k = 1) == False

Answer: assert Solution().maxSubstringLength(s = "xyzxyzxyzxyzxyzxyzxyzxyz", k = 2) == False

Answer: assert Solution().maxSubstringLength(s = "zzzzzzzzzzzzzzzzzzzzzzzzzz", k = 0) == True

Answer: assert Solution().maxSubstringLength(s = "abcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefgabcdefg", k = 7) == False

Answer: assert Solution().maxSubstringLength(s = "specialsubstringsspecialsubstring", k = 1) == False

Answer: assert Solution().maxSubstringLength(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz", k = 13) == True

Answer: assert Solution().maxSubstringLength(s = "mnopqrstuvwxyzabcdefghijkl", k = 13) == True

Answer: assert Solution().maxSubstringLength(s = "banana", k = 2) == True

Answer: assert Solution().maxSubstringLength(s = "thisisanexamplestringwithnospacetospare", k = 0) == True

Answer: assert Solution().maxSubstringLength(s = "uniquecharactersaregreat", k = 5) == True

Answer: assert Solution().maxSubstringLength(s = "mnopqrspomn", k = 1) == True

Answer: assert Solution().maxSubstringLength(s = "zzzzzzzzzzzzzzzzzzzz", k = 0) == True

Answer: assert Solution().maxSubstringLength(s = "xyzxyzxyzxyzxyz", k = 5) == False

Answer: assert Solution().maxSubstringLength(s = "verylongstringwithvariouscharactersvariouscharactersvariouscharacters", k = 5) == False

Answer: assert Solution().maxSubstringLength(s = "qwertyuiopasdfghjklzxcvbnmqwerty", k = 10) == True

Answer: assert Solution().maxSubstringLength(s = "mississippi", k = 2) == True

Answer: assert Solution().maxSubstringLength(s = "qwertypoiuytrewqasdfghjklzxcvbnmasdfghjklzxcvbnm", k = 5) == True

Answer: assert Solution().maxSubstringLength(s = "abcdefghijklmnopqrstuvwxyza", k = 26) == False

Answer: assert Solution().maxSubstringLength(s = "pppppppppppppppppppp", k = 1) == False

Answer: assert Solution().maxSubstringLength(s = "abcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdefabcdef", k = 20) == False

Answer: assert Solution().maxSubstringLength(s = "mnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopq", k = 10) == False

Answer: assert Solution().maxSubstringLength(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz", k = 26) == True

Answer: assert Solution().maxSubstringLength(s = "xyzxyzxyzxyzxyzxyzxyzxyzxyzxyz", k = 1) == False

Answer: assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcdabcd", k = 4) == False

Answer: assert Solution().maxSubstringLength(s = "uniquecharactershere", k = 3) == True

Answer: assert Solution().maxSubstringLength(s = "thisisaverylongstringwithuniquecharacters", k = 15) == False

Answer: assert Solution().maxSubstringLength(s = "abcabcabcabcabcabcabcabcabcabcabc", k = 10) == False

Answer: assert Solution().maxSubstringLength(s = "verylongstringwithsomeuniquecharsandmanyrepeatsababababab", k = 4) == True

Answer: assert Solution().maxSubstringLength(s = "abcdeabcdeabcde", k = 5) == False

Answer: assert Solution().maxSubstringLength(s = "abacabadabacaba", k = 2) == False

Answer: assert Solution().maxSubstringLength(s = "abcdef", k = 0) == True

Answer: assert Solution().maxSubstringLength(s = "abracadabra", k = 3) == False

Answer: assert Solution().maxSubstringLength(s = "abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde", k = 5) == False

Answer: assert Solution().maxSubstringLength(s = "abcabcabc", k = 3) == False

Answer: assert Solution().maxSubstringLength(s = "abcabcabcabcabcabcabcabc", k = 3) == False

Answer: assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcdabcd", k = 12) == False

Answer: assert Solution().maxSubstringLength(s = "abcdefghijabcdefghijabcdefghijabcdefghij", k = 5) == False

Answer: assert Solution().maxSubstringLength(s = "abacabadabacabadabacabad", k = 1) == False

Answer: assert Solution().maxSubstringLength(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz", k = 10) == True

Answer: assert Solution().maxSubstringLength(s = "abcabcabcabcabcabc", k = 1) == False

Answer: assert Solution().maxSubstringLength(s = "aabbccddeeffgg", k = 7) == True

Answer: assert Solution().maxSubstringLength(s = "aaaaabbbbccccdddd", k = 4) == True

Answer: assert Solution().maxSubstringLength(s = "abacabadabacabad", k = 4) == False

Answer: assert Solution().maxSubstringLength(s = "onlyoneuniquecharx", k = 1) == True

Answer: assert Solution().maxSubstringLength(s = "abcdefghijklimnopqrstuvwxyz", k = 25) == True

Answer: assert Solution().maxSubstringLength(s = "aabbaaccdd", k = 2) == True

Answer: assert Solution().maxSubstringLength(s = "aaaabbbbccccdddd", k = 2) == True

Answer: assert Solution().maxSubstringLength(s = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz", k = 1) == False

Answer: assert Solution().maxSubstringLength(s = "abcdefgabcdefg", k = 7) == False

Answer: assert Solution().maxSubstringLength(s = "thisisaverylongstringwithnoseparatespecialsubstrings", k = 0) == True

Answer: assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcdabcdabcdabcd", k = 4) == False

Answer: assert Solution().maxSubstringLength(s = "abababababababab", k = 1) == False

Answer: assert Solution().maxSubstringLength(s = "aaabbbcccdddeeefffggghhhiiiijjjkkklllmmmnnnooopppqqqrrrssstttuuuvvvwwwxxxyyyzzz", k = 13) == True

Answer: assert Solution().maxSubstringLength(s = "abcdefg", k = 3) == True

Answer: assert Solution().maxSubstringLength(s = "thisisaverylongstringwithsomeuniquerandomcharacters", k = 8) == False

Answer: assert Solution().maxSubstringLength(s = "abacabadabacaba", k = 1) == True

Answer: assert Solution().maxSubstringLength(s = "aaabbbccc", k = 3) == True

Answer: assert Solution().maxSubstringLength(s = "nooverlapstring", k = 0) == True

Answer: assert Solution().maxSubstringLength(s = "aaaaabbbbbcccccdddddeeeeee", k = 5) == True

Answer: assert Solution().maxSubstringLength(s = "abacabadaba", k = 3) == False

Answer: assert Solution().maxSubstringLength(s = "abacabadabacabadabacabadabacabadabacabadabacabadabacabadabacabad", k = 3) == False

Answer: assert Solution().maxSubstringLength(s = "abababababababababab", k = 10) == False

Answer: assert Solution().maxSubstringLength(s = "abacabadabacabad", k = 3) == False

Answer: assert Solution().maxSubstringLength(s = "abcabcabcabcabcabcabcabc", k = 1) == False

Answer: assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcd", k = 4) == False

Answer: assert Solution().maxSubstringLength(s = "abcdefghiabcdefghij", k = 5) == False

Answer: assert Solution().maxSubstringLength(s = "mnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopqrstuvmnopqrs", k = 13) == False

Answer: assert Solution().maxSubstringLength(s = "abcdefghijabcdefghijabcdefghij", k = 9) == False

Answer: assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcdabcdabcd", k = 4) == False

Answer: assert Solution().maxSubstringLength(s = "zzzyyyxxxwwwvvvuuutttsssrqqppoonnmmlkkkjjjiiihhhgggfffeeedddcccbbaaa", k = 13) == True

Answer: assert Solution().maxSubstringLength(s = "abcdabcdabcdabcdabcdabcd", k = 3) == False

Answer: assert Solution().maxSubstringLength(s = "mnopqrspqomn", k = 6) == False

Answer: assert Solution().maxSubstringLength(s = "xyxyxyxyxyxyxy", k = 1) == False

Answer: assert Solution().maxSubstringLength(s = "uniquelettersarehere", k = 10) == False

Answer: assert Solution().maxSubstringLength(s = "aabbccddeeffgghhiijjkkllmmnnooppqqrrssttuuvvwwxxyyzz", k = 0) == True

Answer: assert Solution().maxSubstringLength(s = "abcdabcdeabcdefabcdefgabcdefgabcdef", k = 5) == False

Answer: assert Solution().maxSubstringLength(s = "hellotherehellothere", k = 3) == False

Answer: assert Solution().maxSubstringLength(s = "thisisaverylongstringwithrepeatedcharactersaaaaaaaaa", k = 5) == True

Answer: assert Solution().maxSubstringLength(s = "abcdefgabcdefgabcdefgabcdefgabcdefg", k = 7) == False

Answer: assert Solution().maxSubstringLength(s = "zyxwvutsrqponmlkjihgfedcba", k = 26) == True

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

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

inf = float('inf')

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

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

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

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

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

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

class Solution:
  def maxSubstringLength(self, s: str, k: int) -> bool:
    n = len(s)
    first = [n] * 26
    last = [-1] * 26
    # dp[i] := the maximum disjoint special substrings for the first i letters
    dp = [0] * (n + 1)
    seenOrder = []

    for i, c in enumerate(s):
      a = ord(c) - ord('a')
      if first[a] == n:
        first[a] = i
        seenOrder.append(c)
      last[a] = i

    for c in seenOrder:
      a = ord(c) - ord('a')
      for j in range(first[a], last[a]):
        b = ord(s[j]) - ord('a')
        first[a] = min(first[a], first[b])
        last[a] = max(last[a], last[b])

    for i, c in enumerate(s):
      a = ord(c) - ord('a')
      if last[a] != i or (first[a] == 0 and i == n - 1):
        dp[i + 1] = dp[i]
      else:  # Start a new special substring.
        dp[i + 1] = max(dp[i], 1 + dp[first[a]])

    return dp[n] >= k

class Solution:
    def maxSubstringLength(self, s: str, k: int) -> bool: