You are given two integers memory1 and memory2 representing the available memory in bits on two memory sticks. There is currently a faulty program running that consumes an increasing amount of memory every second.

At the ith second (starting from 1), i bits of memory are allocated to the stick with more available memory (or from the first memory stick if both have the same available memory). If neither stick has at least i bits of available memory, the program crashes.

Return an array containing [crashTime, memory1crash, memory2crash], where crashTime is the time (in seconds) when the program crashed and memory1crash and memory2crash are the available bits of memory in the first and second sticks respectively.

&nbsp;
Example 1:

Input: memory1 = 2, memory2 = 2
Output: [3,1,0]
Explanation: The memory is allocated as follows:
- At the 1st second, 1 bit of memory is allocated to stick 1. The first stick now has 1 bit of available memory.
- At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 0 bits of available memory.
- At the 3rd second, the program crashes. The sticks have 1 and 0 bits available respectively.


Example 2:

Input: memory1 = 8, memory2 = 11
Output: [6,0,4]
Explanation: The memory is allocated as follows:
- At the 1st second, 1 bit of memory is allocated to stick 2. The second stick now has 10 bit of available memory.
- At the 2nd second, 2 bits of memory are allocated to stick 2. The second stick now has 8 bits of available memory.
- At the 3rd second, 3 bits of memory are allocated to stick 1. The first stick now has 5 bits of available memory.
- At the 4th second, 4 bits of memory are allocated to stick 2. The second stick now has 4 bits of available memory.
- At the 5th second, 5 bits of memory are allocated to stick 1. The first stick now has 0 bits of available memory.
- At the 6th second, the program crashes. The sticks have 0 and 4 bits available respectively.


&nbsp;
Constraints:


	0 &lt;= memory1, memory2 &lt;= 231 - 1


class Solution:
    def memLeak(self, memory1: int, memory2: int) -> List[int]:
        
        inverted = False 
        if memory2>memory1:
            memory2, memory1 = memory1, memory2
            inverted = True 

		#Compute the number of steps in first stage - 1
        i_start = solve_quadratic(1,2*(memory1-memory2))
        
        memory1-= i_start*(i_start+1)//2
		
		if memory1 == memory2: #Special case (if we end up with equal numbers after stage - 1 - undo inversion)
            inverted = False 
       
        #Compute number of steps in stage - 2
        n_end = solve_quadratic((i_start+1), memory2)
        
		#Compute sums of respective arithmetic sequences
        i_end_1 = i_start - 1 + 2*n_end
        i_end_2 = i_start + 2*n_end
        
        sum1 = n_end * (i_start+1 + i_end_1)//2
        sum2 = n_end * (i_start+2 + i_end_2)//2
        
		#Compute updated memories 
        memory1-=sum1
        memory2-=sum2
        
        full_cnt=2*n_end+i_start
        
        if memory1>=i_end_2+1: #If we can still make one removal from the first stick - perform it.
            memory1-=(i_end_2+1)
            full_cnt+=1
            
        return [full_cnt+1, memory2, memory1] if inverted else [full_cnt+1, memory1, memory2]
            
		 ```
class Solution {
    public int[] memLeak(int memory1, int memory2) {
        int i = 1;
        while(Math.max(memory1, memory2) >= i){
            if(memory1 >= memory2)
                memory1 -= i;
            else
                memory2 -= i;
            i++;
        }
        return new int[]{i, memory1, memory2};
    }
}
class Solution {
public:
    vector<int> memLeak(int memory1, int memory2) {
        int time = 1;
        while (max(memory1, memory2) >= time) {
            if (memory1 >= memory2) {
                memory1 -= time;
            } else {
                memory2 -= time;
            }
            ++time;
        }
        return {time, memory1, memory2};
    }
};
var memLeak = function(memory1, memory2) {
    var count=1;
    while(true)
        {
            if(memory1>=memory2 && memory1>=count)
                memory1-=count;
            else if(memory2>=memory1 && memory2>=count)
                memory2-=count
            else
                return [count, memory1, memory2];
            count++;
        }
};
Incremental Memory Leak