2
def memLeak(self, memory1: int, memory2: int) -> List[int]:6
memory2, memory1 = memory1, memory29
# Compute the number of steps in first stage - 110
i_start = solve_quadratic(1, 2 * (memory1 - memory2))12
# Memory1 after the end of first stage is computed using the sum of arithmetic sequence13
memory1 -= i_start * (i_start + 1) // 217
): # Special case (if we end up with equal numbers after stage - 1 - undo inversion)20
# Compute number of steps in stage - 221
n_end = solve_quadratic((i_start + 1), memory2)23
# Compute sums of respective arithmetic sequences24
i_end_1 = i_start - 1 + 2 * n_end25
i_end_2 = i_start + 2 * n_end27
sum1 = n_end * (i_start + 1 + i_end_1) // 228
sum2 = n_end * (i_start + 2 + i_end_2) // 230
# Compute updated memories34
full_cnt = 2 * n_end + i_start37
memory1 >= i_end_2 + 138
): # If we can still make one removal from the first stick - perform it.39
memory1 -= i_end_2 + 143
[full_cnt + 1, memory2, memory1]45
else [full_cnt + 1, memory1, memory2]