Implementing running median of integer stream

my code is giving wrong output with run error :

#include
#include
using namespace std;

int main() {
/* code here */
int t;
cin>>t;
int d;
while(t–){
priority_queue left;
priority_queue<int,vector,greater> right;

    int n;
    cin>>n;
    cin>>d;
    left.push(d);
    int med=d;
    cout<<med<<" ";
    for(int i=1;i<n;i++){
      cin>>d;
        if(left.size()>right.size()){
            if(d<med){
                right.push(right.top());
                left.pop();
                left.push(d);
                
            }
            else{
                right.push(d);
            }
            med=(left.top()+right.top())/2;
        }
        else if(left.size()==right.size()){
            if(d<med){
                left.push(d);
                med=left.top();

            }
            else{
                right.push(d);
                med=right.top();
            }
        }
        else{
            if(d>med){
                left.push(right.top());
                right.pop();
                right.push(d);
            }
            else{
                left.push(d);
            }
            med=(left.top()+right.top())/2;
        }
        cout<<med<<" ";
          

    }
    cout<<endl;
}

return 0;

}

you can see this: