Median Updates
Difficulty: Hard

The median of $M$ numbers is defined as the middle number after sorting them in order if $M$ is odd. Or it is the average of the middle two numbers if $M$ is even. You start with an empty number list. Then, you can add numbers to the list, or remove existing numbers from it. After each add or remove operation, output the median.

**Example:**    
For a set of $M = 5$ numbers ${9, 2, 8, 4, 1}$ the median is the third number in the sorted set ${1, 2, 4, 8, 9}$, which is $4$. Similarly, for a set of $M = 4$ numbers, ${5, 2, 10, 4}$, the median is the average of the second and the third element in the sorted set ${2, 4, 5, 10}$, which is $(4+5)/2 = 4.5$.  

**Input:**   
The first line is an integer, $N$, that indicates the number of operations. Each of the next $N$ lines is either _a x_ or _r x_. _a x_ indicates that $x$ is added to the set, and _r x_ indicates that $x$ is removed from the set.

**Output:**   
For each operation: If the operation is _add_, output the median after adding $x$ in a single line. If the operation is _remove_ and the number $x$ is not in the list, output *Wrong!* in a single line. If the operation is _remove_ and the number $x$ is in the list, output the median after deleting $x$ in a single line. (If the result is an integer DO NOT output decimal point. And if the result is a real number, DO NOT output trailing 0s.)

**Note**  
If your median is 3.0, print only 3. And if your median is 3.50, print only 3.5. Whenever you need to print the median and the list is empty, print *Wrong!*

**Constraints:**           
$0 \lt N \le 10$<sup>$5$</sup>   
For each _a x_ or _r x_, $x$ will always be a signed integer (which will fit in 32 bits).

**Sample Input:**  

    7  
    r 1  
    a 1  
    a 2  
    a 1  
    r 1  
    r 2  
    r 1  

**Sample Output:**  

    Wrong!  
    1  
    1.5  
    1  
    1.5  
    1  
    Wrong!

**Note:** As evident from the last line of the input, if after remove operation the list becomes empty, you have to print *Wrong!*. 

Input Format:

Output Format:

Sample Input:

Sample Output:

Python 3 starter code:
#!/bin/python
def median(a,x):
    

N = int(input())
s = []
x = []
for i in range(0, N):
   tmp = input().strip().split(' ')
   a, b = [xx for xx in tmp]
   s.append(a)
   x.append(int(b))
median(s,x)



Reference solution (C++):
    #include <cstdio>
    #include <set>
    #include <cstring>
    #include <string>

    using namespace std;

    multiset<int> s1,s2;  //0<=|s1|-|s2|<=1
    char s[55];

    void gao() {
    int a,b;
    bool f1,f2;	
        if (s1.empty()) {
            puts("Wrong!");
            return;
        }
        if (s1.size()==s2.size()) {
            a=*s1.rbegin();
            b=*s2.begin();
            f1=a%2;
            f2=b%2;
            if (f1==f2) {
                printf("%.0lf\n",(a*1.+b)/2.);
            }
            else {
                printf("%.1lf\n",(a*1.+b)/2.);
            }
        }
        else {
            printf("%d\n",*s1.rbegin());
        }
    }

    void gao1(int x) { //add x
        if (s1.empty()) {
            s1.insert(x);
        }
        else if (s1.size()==s2.size()) {
            s2.insert(x);
            s1.insert(*s2.begin());
            s2.erase(s2.begin());
        }
        else {
            s1.insert(x);
            s2.insert(*s1.rbegin());
            s1.erase(s1.find(*s1.rbegin()));
        }
        gao();

    }

    void gao2(int x) {
    multiset<int>::iterator t1=s1.find(x),t2=s2.find(x);
        if ((t1==s1.end()) && (t2==s2.end())) {
            puts("Wrong!");
            return;
        }
        if (s1.size()==s2.size()) {
            if (t2!=s2.end()) {
                s2.erase(t2);
            }
            else {
                s1.erase(t1);
                s1.insert(*s2.begin());
                s2.erase(s2.begin());
            }
        }
        else if (t1!=s1.end()) {
            s1.erase(t1);
        }
        else {
            s2.erase(t2);
            s2.insert(*s1.rbegin());
            s1.erase(s1.find(*s1.rbegin()));
        }
        gao();
    }

    int main() {
    int i,x;

        /*s1.clear();
        s2.clear();*/
        for (scanf("%d",&i);i;--i) {
            scanf("%s%d",s,&x);
            if (s[0]=='a') {
                gao1(x);
            }
            else {
                gao2(x);
            }
        }
        return 0;

    }