//For higher stack size use g++ -O2 -std=c++11 -Wall -Wl,--stack=268435456 a.cpp -o a.exe in cmd
    #include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;

    class query
    {
    public:
        int c;
        ll a,b;
    };

    vector<query> qr;

    ll tree[5000000],tree2[5000000];


    void update(int node,int l,int r,int i,ll x)
    {
        if(i<l || r<i)
            return;
        if(l==r)
        {
            tree[node]=(tree[node]+x);
            ++tree2[node];
            return;
        }
        update(node*2,l,(l+r)/2,i,x);
        update(node*2+1,(l+r)/2+1,r,i,x);
        tree[node]=(tree[node*2]+tree[node*2+1]);    //Change for min/sum
        tree2[node]=(tree2[node*2]+tree2[node*2+1]);    //Change for min/sum
    }
    
    pll query(int node,int l,int r,int i,int j)
    {
        if(j<l || r<i)
            return {0,0};   //Change for min/sum
        if(i<=l && r<=j)
        {
            return {tree[node],tree2[node]};
        }
        pll q1=query(node*2,l,(l+r)/2,i,j);
        pll q2=query(node*2+1,(l+r)/2+1,r,i,j);
        return {q1.f+q2.f,q1.s+q2.s};  //Change for min/sum
    }   


    ll tree3[5000000];


    void update2(int node,int l,int r,int i,ll x)
    {
        if(i<l || r<i)
            return;
        if(l==r)
        {
            //cout<<l<<" "<<r<<" "<<tree3[node]<<endl;
            ++tree3[node];
            return;
        }
        update2(node*2,l,(l+r)/2,i,x);
        update2(node*2+1,(l+r)/2+1,r,i,x);
        tree3[node]=(tree3[node*2]+tree3[node*2+1]);    //Change for min/sum
    }
    
    ll query2(int node,int l,int r,int i,int j)
    {
        if(j<l || r<i)
            return 0;   //Change for min/sum
        //cout<<l<<" "<<r<<" "<<i<<" "<<j<<" "<<tree3[node]<<endl;
        if(i<=l && r<=j)
        {
            return tree3[node];
        }
        ll q1=query2(node*2,l,(l+r)/2,i,j);
        ll q2=query2(node*2+1,(l+r)/2+1,r,i,j);
        return (q1+q2);  //Change for min/sum
    }   


    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            ll n,m,i,j,q,a,b,c,l,r,mid,ans;
            cin>>q;
            map<ll,ll> mp,mp2;
            int ct=0;
            while(q--)
            {
                cin>>c;
                if(c==2)
                {
                    qr.pb({2,0,0});
                }
                else
                {
                    cin>>a>>b;
                    mp[a]=1;
                    qr.pb({1,a,b});
                }
            }
            ct=1;
            map<ll,ll> mp3;
            for(auto it:mp)
            {
                mp2[it.f]=ct;
                mp3[ct]=it.f;
                ++ct;
            }
            ll sum2=0;
            pll x;
            int ct2=0,ans2=0;
            for(i=0;i<qr.size();++i)
            {
                if(qr[i].c==2)
                {
                    l=1,r=ct;
                    ans2=-1;
                    while(l<=r)
                    {
                        mid=(l+r)/2;
                        //cout<<mid<<" "<<query2(1,1,ct,1,mid)<<endl;
                        if(query2(1,1,ct,1,mid)>=(ct2+1)/2)
                        {
                            ans2=mid;
                            r=mid-1;
                        }
                        else
                            l=mid+1;
                    }
                    x=query(1,1,ct,1,ans2);
                    ans=0;
                    ans=(ans + mp3[ans2]*x.s-(x.f));
                    x=query(1,1,ct,ans2+1,ct);
                    ans=(ans + x.f-mp3[ans2]*x.s);
                    ans=ans+sum2;
                    //cout<<ans2<<endl;
                    cout<<mp3[ans2]<<" "<<ans<<endl;
                }
                else
                {
                    //cout<<qr[i].a<<"...."<<mp2[qr[i].a]<<endl;
                    update2(1,1,ct,mp2[qr[i].a],1);
                    update(1,1,ct,mp2[qr[i].a],qr[i].a);
                    sum2=sum2+qr[i].b;
                    ++ct2;
                }
            }
        }
        return 0;
    }


Measured memory_bytes: 39340