#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 1000001
#define mmax 1000001
vector <ll> V,VV;
ll B[nmax], S[nmax], C[3][nmax];
char c;
ll n,ss,price,sl, tmp, gt;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price]+=sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }
    vector < pair<ll,ll> > M;
    Rep(i,VV.size())
    {
        tmp = VV[i];
        gt = tmp * S[tmp];
        M.pb(mp(gt,i));
    }
    sort(M.begin(), M.end());
    tmp = M.size();
    Ford(i,M.size()-1,tmp-ss) cout<<"S "<<VV[ M[i].second ]<<" "<<S[ VV[ M[i].second ] ]<<endl;
    M.clear();
    //------------------------------------------
    Rep(i,V.size())
    {
        tmp = V[i];
        gt = tmp * B[tmp];
        M.pb(mp(gt,i));
    }
    sort(M.begin(), M.end());
    tmp = M.size();
    Ford(i,M.size()-1,tmp-ss) cout<<"B "<<V[ M[i].second ]<<" "<<B[ V[ M[i].second ] ]<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 100001
#define mmax 1000001
vector <ll> V,VV;
vector < pair<ll,ll> > M;
ll B[nmax], S[nmax], C[3][nmax];
char c;
ll n,ss,price,sl, tmp, gt;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   // freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price] += sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }
    if (!VV.empty())
    {
        Rep(i,VV.size())
        {
            tmp = VV[i];
            gt = tmp * S[tmp];
            M.pb(mp(gt,i));
        }
        sort(M.begin(), M.end());
        tmp = M.size();
        if (tmp >= ss)
        {
            Ford(i,ss-1,0) cout<<"S "<<VV[ M[i].second ]<<" "<<S[ VV[ M[i].second ] ]<<endl;
        }
        else
            Repd(i,M.size()) cout<<"S "<<VV[ M[i].second ]<<" "<<S[ VV[ M[i].second ] ]<<endl;
    M.clear();
    }

    //------------------------------------------
    if (!V.empty())
    {
        Rep(i,V.size())
        {
            tmp = V[i];
            gt = tmp * B[tmp];
            M.pb(mp(gt,i));
        }
        sort(M.begin(), M.end());
        tmp = M.size();
        if (tmp>=ss)
        {
        Ford(i,M.size()-1,tmp-ss) cout<<"B "<<V[ M[i].second ]<<" "<<B[ V[ M[i].second ] ]<<endl;
        }
        else
        {
            Repd(i,M.size()) cout<<"B "<<V[ M[i].second ]<<" "<<B[ V[ M[i].second ] ]<<endl;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 100001
#define mmax 1000001
vector <ll> V,VV;
vector < pair<ll,ll> > M;
ll B[nmax], S[nmax], C[3][nmax];
char c;
ll n,ss,price,sl, tmp, gt;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price] += sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }

    if (!VV.empty())
    {
        sort(VV.begin(), VV.end(), greater<ll>());
        tmp = VV.size();
        if (tmp > ss)
        {
            For(i,tmp-ss,tmp-1) cout<<"S "<<VV[ i ]<<" "<<S[ VV[ i ] ]<<endl;
        }
        else
            Rep(i,VV.size()) cout<<"S "<<VV[ i ]<<" "<<S[ VV[ i ] ]<<endl;
    M.clear();
    }

    //------------------------------------------
    if (!V.empty())
    {
        sort(V.begin(), V.end(), greater<ll>());
        tmp = V.size();
        if (tmp>=ss)
        {
            Rep(i,ss) cout<<"B "<<V[ i ]<<" "<<B[ V[ i ] ]<<endl;
        }
        else
        {
            Rep(i,V.size()) cout<<"B "<<V[ i ]<<" "<<B[ V[ i ] ]<<endl;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 100001
#define mmax 1000001
vector <int> V,VV;
int B[nmax], S[nmax], C[3][nmax];
char c;
int n,ss,price,sl, tmp, gt;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price]+=sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }
    vector < pair<int,int> > M;
    Rep(i,VV.size())
    {
        tmp = VV[i];
        gt = tmp * S[tmp];
        M.pb(mp(gt,i));
    }
    sort(M.begin(), M.end());
    tmp = M.size();
    Ford(i,M.size()-1,tmp-ss) cout<<"S "<<VV[ M[i].second ]<<" "<<S[ VV[ M[i].second ] ]<<endl;
    M.clear();
    //------------------------------------------
    Rep(i,V.size())
    {
        tmp = V[i];
        gt = tmp * B[tmp];
        M.pb(mp(gt,i));
    }
    sort(M.begin(), M.end());
    tmp = M.size();
    Ford(i,M.size()-1,tmp-ss) cout<<"B "<<V[ M[i].second ]<<" "<<B[ V[ M[i].second ] ]<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 1000001
#define mmax 1000001
vector <ll> V,VV;
vector < pair<ll,ll> > M;
ll B[nmax], S[nmax], C[3][nmax];
char c;
ll n,ss,price,sl, tmp, gt;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price]+=sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }

    Rep(i,VV.size())
    {
        tmp = VV[i];
        gt = tmp * S[tmp];
        M.pb(mp(gt,i));
    }
    sort(M.begin(), M.end());
    tmp = M.size();
    Ford(i,M.size()-1,tmp-ss) cout<<"S "<<VV[ M[i].second ]<<" "<<S[ VV[ M[i].second ] ]<<endl;
    M.clear();
    //------------------------------------------
    Rep(i,V.size())
    {
        tmp = V[i];
        gt = tmp * B[tmp];
        M.pb(mp(gt,i));
    }
    sort(M.begin(), M.end());
    tmp = M.size();
    Ford(i,M.size()-1,tmp-ss) cout<<"B "<<V[ M[i].second ]<<" "<<B[ V[ M[i].second ] ]<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 100001
#define mmax 1000001
vector <ll> V,VV;
vector < pair<ll,ll> > M;
ll B[nmax], S[nmax], C[3][nmax];
char c;
ll n,ss,price,sl, tmp, gt;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price] += sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }

    if (!VV.empty())
    {
        sort(VV.begin(), VV.end(), greater<ll>());
        tmp = VV.size();
        if (tmp >= ss)
        {
            Rep(i,ss) cout<<"S "<<VV[ i ]<<" "<<S[ VV[ i ] ]<<endl;
        }
        else
            Rep(i,VV.size()) cout<<"S "<<VV[ i ]<<" "<<S[ VV[ i ] ]<<endl;
    M.clear();
    }

    //------------------------------------------
    if (!V.empty())
    {
        sort(V.begin(), V.end(), greater<ll>());
        tmp = V.size();
        if (tmp>=ss)
        {
            Rep(i,ss) cout<<"B "<<V[ i ]<<" "<<B[ V[ i ] ]<<endl;
        }
        else
        {
            Rep(i,V.size()) cout<<"B "<<V[ i ]<<" "<<B[ V[ i ] ]<<endl;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 100001
#define mmax 1000001
vector <ll> V,VV;
vector < pair<ll,ll> > M;
ll B[nmax], S[nmax], C[3][nmax];
char c;
ll n,ss,price,sl, tmp, gt;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price] += sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }

    if (!VV.empty())
    {
        sort(VV.begin(), VV.end(), greater<ll>());
        tmp = VV.size();
        if (tmp > ss)
        {
            For(i,tmp-ss-1,tmp-1) cout<<"S "<<VV[ i ]<<" "<<S[ VV[ i ] ]<<endl;
        }
        else
            Rep(i,VV.size()) cout<<"S "<<VV[ i ]<<" "<<S[ VV[ i ] ]<<endl;
    M.clear();
    }

    //------------------------------------------
    if (!V.empty())
    {
        sort(V.begin(), V.end(), greater<ll>());
        tmp = V.size();
        if (tmp>=ss)
        {
            Rep(i,ss) cout<<"B "<<V[ i ]<<" "<<B[ V[ i ] ]<<endl;
        }
        else
        {
            Rep(i,V.size()) cout<<"B "<<V[ i ]<<" "<<B[ V[ i ] ]<<endl;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 100001
#define mmax 1000001
vector <ll> V,VV;
vector < pair<ll,ll> > M;
ll B[nmax], S[nmax], C[3][nmax];
char c;
ll n,ss,price,sl, tmp, gt;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   // freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price] += sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }
    if (!VV.empty())
    {
        Rep(i,VV.size())
        {
            tmp = VV[i];
            gt = tmp * S[tmp];
            M.pb(mp(gt,i));
        }
        sort(M.begin(), M.end());
        tmp = M.size();
        if (tmp >= ss)
        {
            Ford(i,M.size()-1,tmp-ss) cout<<"S "<<VV[ M[i].second ]<<" "<<S[ VV[ M[i].second ] ]<<endl;
        }
        else
            Repd(i,M.size()) cout<<"S "<<VV[ M[i].second ]<<" "<<S[ VV[ M[i].second ] ]<<endl;
    M.clear();
    }

    //------------------------------------------
    if (!V.empty())
    {
        Rep(i,V.size())
        {
            tmp = V[i];
            gt = tmp * B[tmp];
            M.pb(mp(gt,i));
        }
        sort(M.begin(), M.end());
        tmp = M.size();
        if (tmp>=ss)
        {
        Ford(i,M.size()-1,tmp-ss) cout<<"B "<<V[ M[i].second ]<<" "<<B[ V[ M[i].second ] ]<<endl;
        }
        else
        {
            Repd(i,M.size()) cout<<"B "<<V[ M[i].second ]<<" "<<B[ V[ M[i].second ] ]<<endl;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 1000001
#define mmax 1000001
vector <int> V,VV;
int B[nmax], S[nmax], C[3][nmax];
char c;
int n,ss,price,sl;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price]+=sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }

    Rep(i,VV.size())
    {
        int tmp = VV[i];
        int gt = tmp * S[tmp];
        C[1][i] = gt;
        C[2][i] = i;
        //cout<<C[1][i]<<" "<<C[2][i]<<endl;
    }

    Rep(i,VV.size()-1)
        For(j,i+1,VV.size()-1)
        if (C[1][i] < C[1][j])
        {
            int tmp = C[1][i]; C[1][i] = C[1][j]; C[1][j] = tmp;
            tmp = C[2][i]; C[2][i] = C[2][j]; C[2][j] = tmp;
        };

    For(i,0,ss-1) cout<<"S "<<VV[ C[2][i] ]<<" "<<S[ VV[ C[2][i]] ]<<endl;
    //------------------------------------------
    Rep(i,V.size())
    {
        int tmp = V[i];
        int gt = tmp * B[tmp];
        C[1][i] = gt;
        C[2][i] = i;
        //cout<<C[1][i]<<" "<<C[2][i]<<endl;
    }

    Rep(i,V.size()-1)
        For(j,i+1,V.size()-1)
        if (C[1][i] < C[1][j])
        {
            int tmp = C[1][i]; C[1][i] = C[1][j]; C[1][j] = tmp;
            tmp = C[2][i]; C[2][i] = C[2][j]; C[2][j] = tmp;
        };
    //Rep(i,V.size()) cout<<C[1][i]<<" "<<C[2][i]<<endl;

    For(i,0,ss-1) cout<<"B "<<V[ C[2][i] ]<<" "<<B[ V[ C[2][i]] ]<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 100001
#define mmax 1000001
vector <ll> V,VV;
vector < pair<ll,ll> > M;
ll B[nmax], S[nmax], C[3][nmax];
char c;
ll n,ss,price,sl, tmp, gt;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price] += sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }

        sort(VV.begin(), VV.end(), greater<ll>());
        tmp = VV.size();
        if (tmp >= ss)
            Rep(i,ss) cout<<"S "<<VV[ i ]<<" "<<S[ VV[i] ]<<endl;
        else
            Rep(i,VV.size()) cout<<"S "<<VV[ i ]<<" "<<S[ VV[ i ] ]<<endl;
        //-----------------------
        sort(V.begin(), V.end(), greater<ll>());
        tmp = V.size();
        if (tmp >= ss)
            Rep(i,ss) cout<<"B "<<V[ i ]<<" "<<B[ V[ i ] ]<<endl;
        else
            Rep(i,V.size()) cout<<"B "<<V[ i ]<<" "<<B[ V[ i ] ]<<endl;

}


#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 100001
#define mmax 1000001
vector <ll> V,VV;
vector < pair<ll,ll> > M;
ll B[nmax], S[nmax], C[3][nmax];
char c;
ll n,ss,price,sl, tmp, gt;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price] += sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }

    if (!VV.empty())
    {
        Rep(i,VV.size())
        {
            tmp = VV[i];
            gt = tmp * S[tmp];
            M.pb(mp(gt,i));
        }
        sort(M.begin(), M.end());
        tmp = M.size();
        if (tmp >= ss)
        {
            Ford(i,ss-1,0) cout<<"S "<<VV[ M[i].second ]<<" "<<S[ VV[ M[i].second ] ]<<endl;
        }
        else
            Repd(i,M.size()) cout<<"S "<<VV[ M[i].second ]<<" "<<S[ VV[ M[i].second ] ]<<endl;
    M.clear();
    }

    //------------------------------------------
    if (!V.empty())
    {
        Rep(i,V.size())
        {
            tmp = V[i];
            gt = tmp * B[tmp];
            M.pb(mp(gt,i));
        }
        sort(M.begin(), M.end());
        tmp = M.size();
        if (tmp>=ss)
        {
        Ford(i,M.size()-1,tmp-ss) cout<<"B "<<V[ M[i].second ]<<" "<<B[ V[ M[i].second ] ]<<endl;
        }
        else
        {
            Repd(i,M.size()) cout<<"B "<<V[ M[i].second ]<<" "<<B[ V[ M[i].second ] ]<<endl;
        }
    }
}


#include <bits/stdc++.h>

using namespace std;

#define ms(a,x) memset(a, x, sizeof(a))
#define trace(x) cout << #x ": " << x << endl;
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)
#define ll long long
#define pb push_back
#define mp make_pair
ll gcd(ll a, ll b) {ll r; while (b != 0) {r = a % b; a = b; b = r;} return a;}
ll lcm(ll a, ll b) {return a / gcd(a, b) * b;}
#define mod  1000000007
#define oo   1000000000
#define nmax 100001
#define mmax 1000001
vector <ll> V,VV;
ll B[nmax], S[nmax], C[3][nmax];
char c;
ll n,ss,price,sl, tmp, gt;
int main()
{   ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("data.txt", "r", stdin);
    cin>>n>>ss;
    For(i,1,n)
    {
        cin>>c>>price>>sl;
        if (c == 'B')
        {
            if (B[price] == 0) { B[price]+=sl; V.pb(price); }
            else B[price] += sl;
        };
        if ( c == 'S')
        {
            if (S[price] == 0) { S[price]+=sl; VV.pb(price); }
            else S[price]+=sl;
        }
    }
    vector < pair<ll,int> > M;
    Rep(i,VV.size())
    {
        tmp = VV[i];
        gt = tmp * S[tmp];
        M.pb(mp(gt,i));
    }
    sort(M.begin(), M.end());
    tmp = M.size();
    Ford(i,M.size()-1,tmp-ss) cout<<"S "<<VV[ M[i].second ]<<" "<<S[ VV[ M[i].second ] ]<<endl;
    M.clear();
    //------------------------------------------
    Rep(i,V.size())
    {
        tmp = V[i];
        gt = tmp * B[tmp];
        M.pb(mp(gt,i));
    }
    sort(M.begin(), M.end());
    tmp = M.size();
    Ford(i,M.size()-1,tmp-ss) cout<<"B "<<V[ M[i].second ]<<" "<<B[ V[ M[i].second ] ]<<endl;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char ch;
long long x,y,i,n,s,num;
long long a[100100],b[100100];
inline long long read()
{
    long long x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
        {
            if (ch=='-') f=-1;
            ch=getchar();
        }
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(long long x)
{
    if (x<0) putchar('-'),write(-x);
    if (x>=10) write(x/10);
    putchar(x%10+'0');
}
int main()
{
    n=read();
    s=read();
    for (i=1;i<=n;i++)
        {
            ch=getchar();
            if (ch=='\n') ch=getchar();
            x=read();
            y=read();
            if (ch=='B') a[x]+=y;
            else b[x]+=y;
        }
    for (i=0;i<=100000;i++)
        {
            if (!b[i]) continue;
            num++;
            printf("S %I64d %I64d\n",i,b[i]);
            if (num==s) break;
        }
    num=0;
    for (i=100000;i>=0;i--)
        {
            if (!a[i]) continue;
            num++;
            printf("B %I64d %I64d\n",i,a[i]);
            if (num==s) break;
        }
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char ch;
long long x,y,i,n,s,num;
long long a[100100],b[100100];
struct aa{long long x,y;
}ans[100100];
inline long long read()
{
    long long x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
        {
            if (ch=='-') f=-1;
            ch=getchar();
        }
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(long long x)
{
    if (x<0) putchar('-'),write(-x);
    if (x>=10) write(x/10);
    putchar(x%10+'0');
}
int main()
{
    n=read();
    s=read();
    for (i=1;i<=n;i++)
        {
            ch=getchar();
            if (ch=='\n') ch=getchar();
            x=read();
            y=read();
            if (ch=='B') a[x]+=y;
            else b[x]+=y;
        }
    for (i=0;i<=100000;i++)
        {
            if (!b[i]) continue;
            num++;
           // printf("S %I64d %I64d\n",i,b[i]);
            ans[num].x=i,ans[num].y=b[i];
            if (num==s) break;
        }
    for (i=num;i;i--)
        printf("S %I64d %I64d\n",ans[i].x,ans[i].y);
    num=0;
    for (i=100000;i>=0;i--)
        {
            if (!a[i]) continue;
            num++;
            printf("B %I64d %I64d\n",i,a[i]);
            if (num==s) break;
        }
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char ch;
int x,y,i,n,s,num;
int a[100100],b[100100];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
        {
            if (ch=='-') f=-1;
            ch=getchar();
        }
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if (x<0) putchar('-'),write(-x);
    if (x>=10) write(x/10);
    putchar(x%10+'0');
}
int main()
{
    n=read();
    s=read();
    for (i=1;i<=n;i++)
        {
            ch=getchar();
            if (ch=='\n') ch=getchar();
            x=read();
            y=read();
            if (x==0) continue;
            if (ch=='B') a[x]+=y;
            else b[x]+=y;
        }
    for (i=100000;i>=0;i--)
        {
            if (!b[i]) continue;
            num++;
            printf("S %d %d\n",i,b[i]);
            if (num==s) break;
        }
    num=0;
    for (i=100000;i>=0;i--)
        {
            if (!a[i]) continue;
            num++;
            printf("B %d %d\n",i,a[i]);
            if (num==s) break;
        }
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char ch;
int x,y,i,n,s,num;
int a[100100],b[100100];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
        {
            if (ch=='-') f=-1;
            ch=getchar();
        }
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if (x<0) putchar('-'),write(-x);
    if (x>=10) write(x/10);
    putchar(x%10+'0');
}
int main()
{
    n=read();
    s=read();
    for (i=1;i<=n;i++)
        {
            ch=getchar();
            if (ch=='\n') ch=getchar();
            x=read();
            y=read();
            if (ch=='B') a[x]+=y;
            else b[x]+=y;
        }
    for (i=100000;i>=0;i--)
        {
            if (!b[i]) continue;
            num++;
            printf("S %d %d\n",i,b[i]);
            if (num==s) break;
        }
    num=0;
    for (i=100000;i>=0;i--)
        {
            if (!a[i]) continue;
            num++;
            printf("B %d %d\n",i,a[i]);
            if (num==s) break;
        }
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char ch;
int x,y,i,n,s,num;
int a[100100],b[100100];
struct aa{int x,y;char ch;
}ans[200];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
        {
            if (ch=='-') f=-1;
            ch=getchar();
        }
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if (x<0) putchar('-'),write(-x);
    if (x>=10) write(x/10);
    putchar(x%10+'0');
}
bool cmp(aa a,aa b)
{
    if (a.x==b.x) return a.y>b.y;
    return a.x>b.x;
}
int main()
{
    n=read();
    s=read();
    for (i=1;i<=n;i++)
        {
            ch=getchar();
            if (ch=='\n') ch=getchar();
            x=read();
            y=read();
            if (ch=='B') a[x]+=y;
            else b[x]+=y;
        }
    for (i=100000;i>=0;i--)
        {
            if (!b[i]) continue;
            num++;
            ans[num].ch='S';
            ans[num].x=i;
            ans[num].y=b[i];
            if (num==s) break;
        }
    num=s;
    for (i=100000;i>=0;i--)
        {
            if (!a[i]) continue;
            num++;
            ans[num].ch='B';
            ans[num].x=i;
            ans[num].y=a[i];
            if (num==2*s) break;
        }
    sort(ans+1,ans+1+num,cmp);
    for (i=1;i<=num;i++)
        {
            putchar(ans[i].ch);
            putchar(' ');
            write(ans[i].x);
            putchar(' ');
            write(ans[i].y);
            puts("");
        }
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char ch;
int x,y,i,n,s,num;
int a[100100],b[100100];
struct aa{int x,y;char ch;
}ans[100100];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
        {
            if (ch=='-') f=-1;
            ch=getchar();
        }
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if (x<0) putchar('-'),write(-x);
    if (x>=10) write(x/10);
    putchar(x%10+'0');
}
bool cmp(aa a,aa b)
{
    return a.x*a.y>b.x*b.y;
}
int main()
{
    n=read();
    s=read();
    for (i=1;i<=n;i++)
        {
            ch=getchar();
            if (ch=='\n') ch=getchar();
            x=read();
            y=read();
            if (ch=='B') a[x]+=y;
            else b[x]+=y;
        }
    for (i=100000;i>=0;i--)
        {
            if (!b[i]) continue;
            num++;
            ans[num].x=i;
            ans[num].y=b[i];
        }
    sort(ans+1,ans+1+num,cmp);
    for (i=1;i<=s;i++)
        {
            printf("S ");
            write(ans[i].x);
            putchar(' ');
            write(ans[i].y);
            puts("");
        }
    num=0;
    for (i=100000;i>=0;i--)
        {
            if (!a[i]) continue;
            num++;
            ans[num].x=i;
            ans[num].y=a[i];
        }
    sort(ans+1,ans+1+num,cmp);
    for (i=1;i<=s;i++)
        {
            printf("B ");
            write(ans[i].x);
            putchar(' ');
            write(ans[i].y);
            puts("");
        }
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char ch;
int x,y,i,n,s,num;
int a[100100],b[100100];
struct aa{int x,y;char ch;
}ans[200];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
        {
            if (ch=='-') f=-1;
            ch=getchar();
        }
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if (x<0) putchar('-'),write(-x);
    if (x>=10) write(x/10);
    putchar(x%10+'0');
}
bool cmp(aa a,aa b)
{
    if (a.x==b.x)
        {
            if (a.y==b.y) return a.ch>b.ch;
            return a.y>b.y;
        }
    return a.x>b.x;
}
int main()
{
    n=read();
    s=read();
    for (i=1;i<=n;i++)
        {
            ch=getchar();
            if (ch=='\n') ch=getchar();
            x=read();
            y=read();
            if (ch=='B') a[x]+=y;
            else b[x]+=y;
        }
    for (i=100000;i>=0;i--)
        {
            if (!b[i]) continue;
            num++;
            ans[num].ch='S';
            ans[num].x=i;
            ans[num].y=b[i];
            if (num==s) break;
        }
    num=s;
    for (i=100000;i>=0;i--)
        {
            if (!a[i]) continue;
            num++;
            ans[num].ch='B';
            ans[num].x=i;
            ans[num].y=a[i];
            if (num==2*s) break;
        }
    sort(ans+1,ans+1+num,cmp);
    for (i=1;i<=num;i++)
        {
            putchar(ans[i].ch);
            putchar(' ');
            write(ans[i].x);
            putchar(' ');
            write(ans[i].y);
            puts("");
        }
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char ch;
long long x,y,i,n,s,num;
long long a[100100],b[100100];
inline long long read()
{
    long long x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
        {
            if (ch=='-') f=-1;
            ch=getchar();
        }
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(long long x)
{
    if (x<0) putchar('-'),write(-x);
    if (x>=10) write(x/10);
    putchar(x%10+'0');
}
int main()
{
    n=read();
    s=read();
    for (i=1;i<=n;i++)
        {
            ch=getchar();
            if (ch=='\n') ch=getchar();
            x=read();
            y=read();
            if (ch=='B') a[x]+=y;
            else b[x]+=y;
        }
    for (i=100000;i>=0;i--)
        {
            if (!b[i]) continue;
            num++;
            printf("S %I64d %I64d\n",i,b[i]);
            if (num==s) break;
        }
    num=0;
    for (i=100000;i>=0;i--)
        {
            if (!a[i]) continue;
            num++;
            printf("B %I64d %I64d\n",i,a[i]);
            if (num==s) break;
        }
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
char ch;
int x,y,i,n,s,num;
struct aa{int x,y;
}a[100100],b[100100];
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while (ch<'0'||ch>'9')
        {
            if (ch=='-') f=-1;
            ch=getchar();
        }
    while (ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*f;
}
inline void write(int x)
{
    if (x<0) putchar('-'),write(-x);
    if (x>=10) write(x/10);
    putchar(x%10+'0');
}
bool cmp(aa a,aa b)
{
    return a.x*a.y>b.x*b.y;
}
int main()
{
    n=read();
    s=read();
    for (i=1;i<=n;i++)
        {
            ch=getchar();
            if (ch=='\n') ch=getchar();
            x=read();
            y=read();
            if (ch=='B') a[x].x=x,a[x].y+=y;
            else b[x].x=x,b[x].y+=y;
        }
    sort(a+1,a+100001,cmp);
    sort(b+1,b+100001,cmp);
    for (i=1;i<=s;i++)
        printf("S %d %d\n",b[i].x,b[i].y);
    for (i=1;i<=s;i++)
        printf("B %d %d\n",a[i].x,a[i].y);
}


#include<stdio.h>
#include<iostream>
#include<cmath>
#include<memory.h>
#include<conio.h>
#include<algorithm>
#include<stack>
#include<iomanip>
#include<queue>
#include<vector>
#include<climits>
#include<string>

#define push_back pb
#define MAXN 1050
#define EPS 1e-9
#define INF MAX_INT
#define task a
#define PI acos(-1)

using namespace std;

int z[MAXN];
int n, s;
char d;
int p;
int q;
int pok[100500];
int pro[100500];

int main ()
{
	/*freopen("a.txt", "r", stdin);
	freopen("task.out", "w", stdout);*/
	cin >> n >> s;
	for(int i = 0; i < n; i++)
    {
        cin >> d >> p >> q;
        if(d == 'B')
            pok[p] += q;
        else
            pro[p] += q;
    }
    int it = 0;
    for(int i = 0, t = 0; i < 100450 && t < s; i++)
    {
        if(pro[i])
        {
            t++;
            it = i;
        }
    }
    for(int i = it; i >= 0; i--)
        if(pro[i])
            cout << 'S' << ' ' << i << ' ' << pro[i] << endl;
    for(int i = 100450, t = 0; i >= 0 && t < s; i--)
    {
        if(pok[i])
        {
            cout << 'B' << ' ' << i << ' ' << pok[i] << endl;
            t++;
        }
    }
	return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
using namespace std;

int main()
{
	char c;
	int kol=0,kol1=0;
	int n,s,p,q,a;
	int sb[50],ss[50],qb[50],qs[50];
	cin >> n >> s;
	for (int i=0;i<s;i++)
	{
		ss[i]=100000;sb[i]=0;
		qs[i]=100000;qb[i]=0;
	}
	for(int k=0; k<n; k++)
	{
		cin >> c >> p >> q;
		if ( c == 'S') { kol1+=1;
			int i=0;
			while ((i<s) && (ss[i]<p))
				i++;
			if (ss[i]==p) {
				qs[i]+=q;}
			else
			{
				for (int j=i+1;j<s; j++)
				{
					ss[j]=ss[j-1];
					qs[j]=qs[j-1];
				}
			ss[i]=p;
			qs[i]=q;
			}
		}
		else { kol+=1;
			int i=0;
			while ((i<s)&&(sb[i]>p) )
				i++;
			if (sb[i]==p)  {

				qb[i]+=q;
			}
			else
			{
				for (int j=i+1;j<s;j++)
				{
					sb[j]=sb[j-1];
					qb[j]=qb[j-1];
				}
				sb[i]=p;
				qb[i]=q;
			}
		}

	}
	a=min(kol1,s);
	for (int i=a-1;i>=0;i--)
	{
	 cout << "S ";
	 cout << ss[i] << " " << qs[i];
	 cout << endl;
	}
	a=min(kol,s);
	for (int i=0;i<a;i++)
	{
	 cout << "B ";
	 cout << sb[i] << " " << qb[i];
	 cout << endl;
	}

return 0;
}


#include<iostream>
#include<string>
using namespace std;

int main()
{
	char c;
	int n,s,p,q;
	int sb[50],ss[50],qb[50],qs[50];
	cin >> n >> s;
	for (int i=0;i<s;i++)
	{
		ss[i]=100000;sb[i]=0;
		qs[i]=100000;qb[i]=0;
	}
	for(int k=0; k<n; k++)
	{
		cin >> c >> p >> q;
		if ( c == 'S') {
			int i=0;
			while ((i<s) && (ss[i]<p))
				i++;
			if (ss[i]==p) {
				qs[i]+=q;}
			else
			{
				for (int j=i+1;j<s; j++)
				{
					ss[j]=ss[j-1];
					qs[j]=qs[j-1];
				}
			ss[i]=p;
			qs[i]=q;
			}
		}
		else {
			int i=0;
			while ((i<s)&&(sb[i]>p) )
				i++;
			if (sb[i]==p)  {

				qb[i]+=q;
			}
			else
			{
				for (int j=i+1;j<s;j++)
				{
					sb[j]=sb[j-1];
					qb[j]=qb[j-1];
				}
				sb[i]=p;
				qb[i]=q;
			}
		}

	}
	for (int i=s-1;i>=0;i--)
	{
	 cout << "S ";
	 cout << ss[i] << " " << qs[i];
	 cout << endl;
	}
	for (int i=0;i<s;i++)
	{
	 cout << "B ";
	 cout << sb[i] << " " << qb[i];
	 cout << endl;
	}

return 0;
}


#include <cstdio>
#include <cstring>
int book[2][100005];
int sign[2][100005];
int main()
{
	int cnts,cntb;
	cnts = cntb = 0;
	memset(book,0,sizeof(book));
	memset(sign,0,sizeof(sign));
	int n,s; scanf("%d%d",&n,&s);
	for(int i = 0;i < n;i++){
		char dir;
		int pri,vol;
		scanf(" %c%d%d",&dir,&pri,&vol);
		if(dir == 'B'){
			book[1][pri] += vol;
			sign[1][pri]++;
		}
		else{
			book[0][pri] += vol;
			sign[0][pri]++;
		}
	}
	for(int i = 10004;i < -1;i--){
		if(sign[0][i] > 1)
			cnts++;
		if(sign[1][i] > 1)
			cntb++;
	}
	int pos,tmp;
	tmp = 0;
	for(int i = 0;i < 100004;i++){
		if(book[0][i] > 0)
			tmp++;
		if(tmp <= s)
			pos = i;
	}
	int cnt = 0;
	/*if(cnts > s){
	for(int i = 1;i < 100005;i++){
		if(cnt == s)
			break;
		if(book[0][i] != 0 && sign[0][i] > 1){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	//}
	else{*/
	for(int i = pos;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	//}
	cnt = 0;
	/*if(cntb > s){
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0 && sign[1][i] > 1){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	}
	else{
	*/for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	//}
	return 0;
}


#include <cstdio>
#include <cstring>
int book[2][100005];
int sign[2][100005];
int main()
{
	int cnts,cntb;
	cnts = cntb = 0;
	memset(book,0,sizeof(book));
	memset(sign,0,sizeof(sign));
	int n,s; scanf("%d%d",&n,&s);
	for(int i = 0;i < n;i++){
		char dir;
		int pri,vol;
		scanf(" %c%d%d",&dir,&pri,&vol);
		if(dir == 'B'){
			book[1][pri] += vol;
			sign[1][pri]++;
			if(sign[1][pri] > 1)
				cntb++;
		}
		else{
			book[0][pri] += vol;
			sign[0][pri]++;
			if(sign[0][pri] > 1)
				cnts++;
		}
	}
	int cnt = 0;
	if(cnts > s){
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0 && sign[0][i] > 1){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	}
	else{
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	}
	cnt = 0;
	if(cntb > s){
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0 && sign[1][i] > 1){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	}
	else{
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
int book[2][100005];
int sign[2][100005];
int main()
{
	memset(book,0,sizeof(book));
	memset(sign,0,sizeof(sign));
	int n,s; scanf("%d%d",&n,&s);
	for(int i = 0;i < n;i++){
		char dir;
		int pri,vol;
		scanf(" %c%d%d",&dir,&pri,&vol);
		if(dir == 'B'){
			book[1][pri] += vol;
			sign[1][pri]++;
		}
		else{
			book[0][pri] += vol;
			sign[0][pri]++;
		}
	}
	int cnt = 0;
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0 && sign[0][i] > 1){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0 && sign[0][i] == 1){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	cnt = 0;
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0 && sign[1][i] > 1){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0 && sign[1][i] == 1){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
int book[2][100005];
int main()
{
	memset(book,0,sizeof(book));
	int n,s; scanf("%d%d",&n,&s);
	for(int i = 0;i < n;i++){
		char dir;
		int pri,vol;
		scanf(" %c%d%d",&dir,&pri,&vol);
		if(dir == 'B')
			book[1][pri] += vol;
		else
			book[0][pri] += vol;
	}
	int cnt = 0;
	for(int i = 1005;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	cnt = 0;
	for(int i = 1005;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
int book[2][100005];
int sign[2][100005];
int main()
{
	int cnts,cntb;
	cnts = cntb = 0;
	memset(book,0,sizeof(book));
	memset(sign,0,sizeof(sign));
	int n,s; scanf("%d%d",&n,&s);
	for(int i = 0;i < n;i++){
		char dir;
		int pri,vol;
		scanf(" %c%d%d",&dir,&pri,&vol);
		if(dir == 'B'){
			book[1][pri] += vol;
			sign[1][pri]++;
		}
		else{
			book[0][pri] += vol;
			sign[0][pri]++;
		}
	}
	for(int i = 10004;i < -1;i--){
		if(sign[0][i] > 1)
			cnts++;
		if(sign[1][i] > 1)
			cntb++;
	}
	int pos,tmp;
	tmp = 0;
	for(int i = 0;i < 100004;i++){
		if(book[0][i] > 0)
			tmp++;
		if(tmp == s)
			pos = i;
	}
	int cnt = 0;
	/*if(cnts > s){
	for(int i = 1;i < 100005;i++){
		if(cnt == s)
			break;
		if(book[0][i] != 0 && sign[0][i] > 1){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	//}
	else{*/
	for(int i = pos;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	//}
	cnt = 0;
	/*if(cntb > s){
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0 && sign[1][i] > 1){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	}
	else{
	*/for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	//}
	return 0;
}


#include <cstdio>
#include <cstring>
int book[2][1000005];
int main()
{
	memset(book,0,sizeof(book));
	int n,s; scanf("%d%d",&n,&s);
	for(int i = 0;i < n;i++){
		char dir;
		int pri,vol;
		scanf(" %c%d%d",&dir,&pri,&vol);
		if(dir == 'B')
			book[1][pri] += vol;
		else
			book[0][pri] += vol;
	}
	int cnt = 0;
	for(int i = 1000005;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	cnt = 0;
	for(int i = 1000005;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
int book[2][100005];
int sign[2][100005];
int main()
{
	int cnts,cntb;
	cnts = cntb = 0;
	memset(book,0,sizeof(book));
	memset(sign,0,sizeof(sign));
	int n,s; scanf("%d%d",&n,&s);
	for(int i = 0;i < n;i++){
		char dir;
		int pri,vol;
		scanf(" %c%d%d",&dir,&pri,&vol);
		if(dir == 'B'){
			book[1][pri] += vol;
			sign[1][pri]++;
		}
		else{
			book[0][pri] += vol;
			sign[0][pri]++;
		}
	}
	for(int i = 10004;i < -1;i--){
		if(sign[0][i] > 1)
			cnts++;
		if(sign[1][i] > 1)
			cntb++;
	}
	int cnt = 0;
	if(cnts > s){
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0 && sign[0][i] > 1){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	}
	else{
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	}
	cnt = 0;
	if(cntb > s){
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0 && sign[1][i] > 1){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	}
	else{
	for(int i = 100004;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
int book[2][100005];
int main()
{
	memset(book,0,sizeof(book));
	int n,s; scanf("%d%d",&n,&s);
	for(int i = 0;i < n;i++){
		char dir;
		int pri,vol;
		getchar();
		scanf("%c%d%d",&dir,&pri,&vol);
		if(dir == 'B'){
			book[1][pri] += vol;
		}
		else
			book[0][pri] += vol;
	}
	int cnt = 0;
	for(int i = 1005;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	cnt = 0;
	for(int i = 1005;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	return 0;
}


#include <cstdio>
#include <cstring>
int book[2][100005];
int main()
{
	memset(book,0,sizeof(book));
	int n,s; scanf("%d%d",&n,&s);
	for(int i = 0;i < n;i++){
		char dir;
		int pri,vol;
		scanf(" %c%d%d",&dir,&pri,&vol);
		if(dir == 'B')
			book[1][pri] += vol;
		else
			book[0][pri] += vol;
	}
	int cnt = 0;
	for(int i = 100005;i > -1;i--){
		if(cnt == s)
			break;
		if(book[0][i] != 0){
			printf("S %d %d\n",i,book[0][i]);
			cnt++;
		}
	}
	cnt = 0;
	for(int i = 100005;i > -1;i--){
		if(cnt == s)
			break;
		if(book[1][i] != 0){
			printf("B %d %d\n",i,book[1][i]);
			cnt++;
		}
	}
	return 0;
}


#include <iostream>
#include <map>
using namespace std;

int main()
{
    map <int,int> buy;
map <int,int> sell;
int n,s,price,volume;
cin>>n>>s;
char c;
for(int i=0;i<n;i++)
{
    cin>>c>>price>>volume;
    if(c=='B')
        buy[price]+=volume;
    else
        sell[price]+=volume;
    }  int counter=0;
    for(map < int ,int >  ::reverse_iterator it = sell.rbegin(); it != sell.rend(),counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    }
counter=0;
for(map < int ,int >  ::reverse_iterator it = buy.rbegin(); it != buy.rend(),counter < s; ++it,counter++)
    {
cout<<"B"<<" "<<it->first<<" "<< it->second<<endl;
    }

    return 0;
}


#include <iostream>
#include <map>
using namespace std;

int main()
{
    map <int,int> buy;
map <int,int> sell;
int n,s,price,volume;
cin>>n>>s;
char c;
for(int i=0;i<n;i++)
{
    cin>>c>>price>>volume;
    if(c=='B')
        buy[price]+=volume;
    else
        sell[price]+=volume;
    }  int counter=0;
if(sell.size()==s) {
    for(map < int ,int >  ::reverse_iterator it = sell.rbegin(); it != sell.rend() &&counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    } }
    else if(sell.size()>s) {
       for(map < int ,int >  ::const_iterator it = sell.begin(); it != sell.end() &&counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    } }
counter=0;
for(map < int ,int >  ::reverse_iterator it = buy.rbegin(); it != buy.rend()&&counter < s; ++it,counter++)
    {
cout<<"B"<<" "<<it->first<<" "<< it->second<<endl;
    }

    return 0;
}


#include <iostream>
#include <map>
using namespace std;

int main()
{
    map <int,int> buy;
map <int,int> sell;
int n,s,price,volume;
cin>>n>>s;
char c;
for(int i=0;i<n;i++)
{
    cin>>c>>price>>volume;
    if(c=='B')
        buy[price]+=volume;
    else
        sell[price]+=volume;
    }  int counter=0;

    for(map < int ,int >  ::reverse_iterator it = sell.rbegin(); it != sell.rend() &&counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    }
counter=0;
for(map < int ,int >  ::reverse_iterator it = buy.rbegin(); it != buy.rend()&&counter < s; ++it,counter++)
    {
cout<<"B"<<" "<<it->first<<" "<< it->second<<endl;
    }

    return 0;
}


#include <iostream>
#include <map>
using namespace std;

int main()
{
    map <int,int> buy;
map <int,int> sell;
int n,s,price,volume;
cin>>n>>s;
char c;
for(int i=0;i<n;i++)
{
    cin>>c>>price>>volume;
    if(c=='B')
        buy[price]+=volume;
    else
        sell[price]+=volume;
    }

    int counter=0;
if(sell.size()==s || sell.size()<s) {
    for(map < int ,int >  ::reverse_iterator it = sell.rbegin(); it != sell.rend() &&counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    } }
    else if(sell.size()>s ) {
       for(map < int ,int >  ::const_iterator it = sell.begin(); it != sell.end() &&counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    } }
counter=0;
for(map < int ,int >  ::reverse_iterator it = buy.rbegin(); it != buy.rend()&&counter < s; ++it,counter++)
    {
cout<<"B"<<" "<<it->first<<" "<< it->second<<endl;
    }

    return 0;
}


#include <iostream>
#include <map>
using namespace std;

int main()
{
    map <int,int> buy;
map <int,int> sell;
int n,s,price,volume;
cin>>n>>s;
char c;
for(int i=0;i<n;i++)
{
    cin>>c>>price>>volume;
    if(c=='B')
        buy[price]+=volume;
    else
        sell[price]+=volume;
    }  int counter=0;

    for(map < int ,int >  ::const_iterator it = sell.begin(); it != sell.end() &&counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    }
counter=0;
for(map < int ,int >  ::reverse_iterator it = buy.rbegin(); it != buy.rend()&&counter < s; ++it,counter++)
    {
cout<<"B"<<" "<<it->first<<" "<< it->second<<endl;
    }

    return 0;
}


#include <iostream>
#include <map>
#include <vector>
using namespace std;

int main()
{
    map <int,int> buy;
map <int,int> sell;
int n,s,price,volume;
cin>>n>>s;
char c;
for(int i=0;i<n;i++)
{
    cin>>c>>price>>volume;
    if(c=='B')
        buy[price]+=volume;
    else
        sell[price]+=volume;
    }

    int counter=0;
if(sell.size()==s || sell.size()<s) {
    for(map < int ,int >  ::reverse_iterator it = sell.rbegin(); it != sell.rend() &&counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    } }
    else if(sell.size()>s ) { vector < pair<int,int> > v;
       for(map < int ,int >  ::const_iterator it = sell.begin(); it != sell.end() &&counter < s; ++it,counter++)
    {   v.push_back(make_pair(it->first,it->second));
//cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    }
    for(int i=v.size()-1;i>=0;i--)
        cout<<"S"<<" "<<v[i].first<<" "<<v[i].second<<endl;
    }

counter=0;
for(map < int ,int >  ::reverse_iterator it = buy.rbegin(); it != buy.rend()&&counter < s; ++it,counter++)
    {
cout<<"B"<<" "<<it->first<<" "<< it->second<<endl;
    }

    return 0;
}


#include <iostream>
#include <map>
using namespace std;

int main()
{
    map <int,int> buy;
map <int,int> sell;
int n,s,price,volume;
cin>>n>>s;
char c;
for(int i=0;i<n;i++)
{
    cin>>c>>price>>volume;
    if(c=='B')
        buy[price]+=volume;
    else
        sell[price]+=volume;
    }

    int counter=0;
if(sell.size()==s || sell.size<s) {
    for(map < int ,int >  ::reverse_iterator it = sell.rbegin(); it != sell.rend() &&counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    } }
    else if(sell.size()>s ) {
       for(map < int ,int >  ::const_iterator it = sell.begin(); it != sell.end() &&counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    } }
counter=0;
for(map < int ,int >  ::reverse_iterator it = buy.rbegin(); it != buy.rend()&&counter < s; ++it,counter++)
    {
cout<<"B"<<" "<<it->first<<" "<< it->second<<endl;
    }

    return 0;
}


#include <iostream>
#include <map>
using namespace std;

int main()
{
    map <int,int> buy;
map <int,int> sell;
int n,s,price,volume;
cin>>n>>s;
char c;
for(int i=0;i<n;i++)
{
    cin>>c>>price>>volume;
    if(c=='B')
        buy[price]+=volume;
    else
        sell[price]+=volume;
    }

    int counter=0;
if(sell.size()==s) {
    for(map < int ,int >  ::reverse_iterator it = sell.rbegin(); it != sell.rend() &&counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    } }
    else if(sell.size()>s || sell.size()<s) {
       for(map < int ,int >  ::const_iterator it = sell.begin(); it != sell.end() &&counter < s; ++it,counter++)
    {
cout<<"S"<<" "<<it->first<<" " << it->second<<endl;
    } }
counter=0;
for(map < int ,int >  ::reverse_iterator it = buy.rbegin(); it != buy.rend()&&counter < s; ++it,counter++)
    {
cout<<"B"<<" "<<it->first<<" "<< it->second<<endl;
    }

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{

	ios_base::sync_with_stdio(false);
    cin.tie(false);
	vector<pair<int, int> > b,s;
	int n,p;
	char a;
	int q,w;
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b.push_back(make_pair(q,w));
		else s.push_back(make_pair(q,w));
	}
	sort(s.begin(), s.end());
	sort(b.begin(), b.end());
	int th = p;
	int i = s.size()-1,j;
	while(p>0 && i>=0)
	{
		long long s1 = s[i].second;
		j = i-1;
		while(j>=0)
		{
			if(s[j].first == s[i].first)
			{
				s1+=s[j].second;
				j--;
			}
			else
			{
				break;
			}
		}
		p--;
		cout<<"S "<<s[i].first<<" "<<s1<<"\n";
		i = j;
	}
	i = b.size()-1;
	while(th>0 && i>=0)
	{
		long long s1 = b[i].second;
		j = i-1;
		while(j>=0)
		{
			if(b[j].first == b[i].first)
			{
				s1+=b[j].second;
				j--;
			}
			else
			{
				break;
			}
		}
		th--;
		cout<<"B "<<b[i].first<<" "<<s1<<"\n";
		i = j;
	}
	// map<int, int> ::iterator i = s.end();
	// i--;
	// for(int j=0;j<p;j++)
	// {
	// 	cout <<"S "<<i->first<<" "<< i->second<< "\n";
	// 	i--;
	// }
	// i = b.end();
	// i--;
	// for(int j=0;j<p;j++)
	// {
	// 	cout <<"B "<<i->first<<" "<< i->second<< "\n";
	// 	i--;
	// }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	//int b[100017], s[100017];
	map<int, int> b,s;
	int n,p;
	char a;
	int q,w;
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b[q]+=w;
		else s[q]+=w;
	}
	map<int, int> ::iterator i = s.end();
	i--;
	for(int j=0;j<p;j++)
	{
		cout <<"S "<<i->first<<" "<< i->second<< "\n";
		i--;
	}
	i = b.end();
	i--;
	for(int j=0;j<p;j++)
	{
		cout <<"B "<<i->first<<" "<< i->second<< "\n";
		i--;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{

	ios_base::sync_with_stdio(false);
    cin.tie(false);
	vector<pair<int, int> > b,s;
	int n,p;
	char a;
	int q,w;
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b.push_back(make_pair(q,w));
		else s.push_back(make_pair(q,w));
	}
	sort(s.begin(), s.end());
	sort(b.begin(), b.end());
	int th = p;
	int i = 0,j;
	vector<pair<int, int > > ans;
	while(p>0 && i<s.size())
	{
		int s1 = s[i].second;
		j = i+1;
		while(j>=0)
		{
			if(s[j].first == s[i].first)
			{
				s1+=s[j].second;
				j++;
			}
			else
			{
				break;
			}
		}
		p--;
		ans.push_back(make_pair(s[i].first, s1));
		i = j;
	}
	int gg = ans.size()-1;
	for(int i=gg;i>=0;i--)
	{
		cout<<"S "<<ans[i].first<<" "<<ans[i].second<<"\n";
	}
	i = b.size()-1;
	while(th>0 && i>=0)
	{
		int s1 = b[i].second;
		j = i-1;
		while(j>=0)
		{
			if(b[j].first == b[i].first)
			{
				s1+=b[j].second;
				j--;
			}
			else
			{
				break;
			}
		}
		th--;
		cout<<"B "<<b[i].first<<" "<<s1<<"\n";
		i = j;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	//int b[100017], s[100017];
	map<int, int> b,s;
	int n,p;
	char a;
	int q,w;
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b[q]+=w;
		else s[q]+=w;
	}
	map<int, int> ::iterator i = s.end();
	int j = 0;
	int t1 = s.size();
	if(t1>0) i--;
	if(t1>p)
	{
		while(t1>p)
		{
			i--;
			t1--;
		}
		for(j=0;j<t1;j++)
		{
			cout <<"S "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}
	else
	{
		for(j=0;j<t1;j++)
		{
			cout <<"S "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}

	i = b.end();
	t1 = b.size();
	if(t1>0) i--;
	for(int j=0;j<p;j++)
	{
		cout <<"B "<<i->first<<" "<< i->second<< "\n";
		i--;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{

	ios_base::sync_with_stdio(false);
    cin.tie(false);
	vector<pair<long long, long long> > b,s;
	long long n,p;
	char a;
	long long q,w;
	cin>>n>>p;
	for(long long i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b.push_back(make_pair(q,w));
		else s.push_back(make_pair(q,w));
	}
	sort(s.begin(), s.end());
	sort(b.begin(), b.end());
	long long th = p;
	long long i = s.size()-1,j;
	while(p>0 && i>=0)
	{
		long long s1 = s[i].second;
		j = i-1;
		while(j>=0)
		{
			if(s[j].first == s[i].first)
			{
				s1+=s[j].second;
				j--;
			}
			else
			{
				break;
			}
		}
		p--;
		cout<<"S "<<s[i].first<<" "<<s1<<"\n";
		i = j;
	}
	i = b.size()-1;
	while(th>0 && i>=0)
	{
		long long s1 = b[i].second;
		j = i-1;
		while(j>=0)
		{
			if(b[j].first == b[i].first)
			{
				s1+=b[j].second;
				j--;
			}
			else
			{
				break;
			}
		}
		th--;
		cout<<"B "<<b[i].first<<" "<<s1<<"\n";
		i = j;
	}
	// map<int, int> ::iterator i = s.end();
	// i--;
	// for(int j=0;j<p;j++)
	// {
	// 	cout <<"S "<<i->first<<" "<< i->second<< "\n";
	// 	i--;
	// }
	// i = b.end();
	// i--;
	// for(int j=0;j<p;j++)
	// {
	// 	cout <<"B "<<i->first<<" "<< i->second<< "\n";
	// 	i--;
	// }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	//int b[100017], s[100017];
	map<long long, long long> b,s;
	long long n,p;
	char a;
	long long q,w;
	cin>>n>>p;
	for(long long i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b[q]+=w;
		else s[q]+=w;
	}
	map<long long, long long> ::iterator i = s.end();
	long long j = 0;
	long long t1 = s.size();
	if(t1>0) i--;
	if(t1>p)
	{
		while(t1>p)
		{
			i--;
			t1--;
		}
		for(j=0;j<t1;j++)
		{
			cout <<"S "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}
	else
	{
		for(j=0;j<t1;j++)
		{
			cout <<"S "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}

	i = b.end();
	t1 = b.size();
	if(t1>0) i--;
	if(t1>p)
	{
		for(long long j=0;j<p;j++)
		{
			cout <<"B "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}
	else
	{
		for(long long j=0;j<t1;j++)
		{
			cout <<"B "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{

	ios_base::sync_with_stdio(false);
    cin.tie(false);
	map<int, int> b,s;
	int n,p;
	char a;
	int q,w;
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b[q]+=w;
		else s[q]+=w;
	}
	map<int, int> ::iterator i = s.end();
	i--;
	for(int j=0;j<p;j++)
	{
		cout <<"S "<<i->first<<" "<< i->second<< "\n";
		i--;
	}
	i = b.end();
	i--;
	for(int j=0;j<p;j++)
	{
		cout <<"B "<<i->first<<" "<< i->second<< "\n";
		i--;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{

	ios_base::sync_with_stdio(false);
    cin.tie(false);
	vector<pair<int, int> > b,s;
	int n,p;
	char a;
	int q,w;
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b.push_back(make_pair(q,w));
		else s.push_back(make_pair(q,w));
	}
	sort(s.begin(), s.end());
	sort(b.begin(), b.end());
	int th = p;
	int i = 0,j;
	vector<pair<int, int > > ans;
	while(p>0 && i>=0)
	{
		long s1 = s[i].second;
		j = i+1;
		while(j>=0)
		{
			if(s[j].first == s[i].first)
			{
				s1+=s[j].second;
				j++;
			}
			else
			{
				break;
			}
		}
		p--;
		ans.push_back(make_pair(s[i].first, s1));
		i = j;
	}
	int gg = ans.size()-1;
	for(int i=gg;i>=0;i--)
	{
		cout<<"S "<<ans[i].first<<" "<<ans[i].second<<"\n";
	}
	i = b.size()-1;
	while(th>0 && i>=0)
	{
		long s1 = b[i].second;
		j = i-1;
		while(j>=0)
		{
			if(b[j].first == b[i].first)
			{
				s1+=b[j].second;
				j--;
			}
			else
			{
				break;
			}
		}
		th--;
		cout<<"B "<<b[i].first<<" "<<s1<<"\n";
		i = j;
	}
	// map<int, int> ::iterator i = s.end();
	// i--;
	// for(int j=0;j<p;j++)
	// {
	// 	cout <<"S "<<i->first<<" "<< i->second<< "\n";
	// 	i--;
	// }
	// i = b.end();
	// i--;
	// for(int j=0;j<p;j++)
	// {
	// 	cout <<"B "<<i->first<<" "<< i->second<< "\n";
	// 	i--;
	// }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	//int b[100017], s[100017];
	map<int, int> b,s;
	int n,p;
	char a;
	int q,w;
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b[q]+=w;
		else s[q]+=w;
	}
	map<int, int> ::iterator i = s.end();
	int j = 0;
	int t1 = s.size();
	if(t1>0) i--;
	if(t1>p)
	{
		while(t1>p)
		{
			i--;
			t1--;
		}
		for(j=0;j<t1;j++)
		{
			cout <<"S "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}
	else
	{
		for(j=0;j<t1;j++)
		{
			cout <<"S "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}

	i = b.end();
	t1 = b.size();
	if(t1>0) i--;
	for(int j=0;j<p && i!=b.begin();j++)
	{
		cout <<"B "<<i->first<<" "<< i->second<< "\n";
		i--;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{

	ios_base::sync_with_stdio(false);
    cin.tie(false);
	vector<pair<int, int> > b,s;
	int n,p;
	char a;
	int q,w;
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b.push_back(make_pair(q,w));
		else s.push_back(make_pair(q,w));
	}
	sort(s.begin(), s.end());
	sort(b.begin(), b.end());
	int th = p;
	int i = s.size()-1,j;
	while(p>0 && i>=0)
	{
		int s1 = s[i].second;
		j = i-1;
		while(j>=0)
		{
			if(s[j].first == s[i].first)
			{
				s1+=s[j].second;
				j--;
			}
			else
			{
				break;
			}
		}
		p--;
		cout<<"S "<<s[i].first<<" "<<s1<<"\n";
		i = j;
	}
	i = b.size()-1;
	while(th>0 && i>=0)
	{
		int s1 = b[i].second;
		j = i-1;
		while(j>=0)
		{
			if(b[j].first == b[i].first)
			{
				s1+=b[j].second;
				j--;
			}
			else
			{
				break;
			}
		}
		th--;
		cout<<"B "<<b[i].first<<" "<<s1<<"\n";
		i = j;
	}
	// map<int, int> ::iterator i = s.end();
	// i--;
	// for(int j=0;j<p;j++)
	// {
	// 	cout <<"S "<<i->first<<" "<< i->second<< "\n";
	// 	i--;
	// }
	// i = b.end();
	// i--;
	// for(int j=0;j<p;j++)
	// {
	// 	cout <<"B "<<i->first<<" "<< i->second<< "\n";
	// 	i--;
	// }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{

	ios_base::sync_with_stdio(false);
    cin.tie(false);
	vector<pair<long long, long long> > b,s;
	int n,p;
	char a;
	long long q,w;
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b.push_back(make_pair(q,w));
		else s.push_back(make_pair(q,w));
	}
	sort(s.begin(), s.end());
	sort(b.begin(), b.end());
	long long th = p;
	long long i = s.size()-1,j;
	while(p>0 && i>=0)
	{
		long long s1 = s[i].second;
		j = i-1;
		while(j>=0)
		{
			if(s[j].first == s[i].first)
			{
				s1+=s[j].second;
				j--;
			}
			else
			{
				break;
			}
		}
		p--;
		cout<<"S "<<s[i].first<<" "<<s1<<"\n";
		i = j;
	}
	i = b.size()-1;
	while(th>0 && i>=0)
	{
		long long s1 = b[i].second;
		j = i-1;
		while(j>=0)
		{
			if(b[j].first == b[i].first)
			{
				s1+=b[j].second;
				j--;
			}
			else
			{
				break;
			}
		}
		th--;
		cout<<"B "<<b[i].first<<" "<<s1<<"\n";
		i = j;
	}
	// map<int, int> ::iterator i = s.end();
	// i--;
	// for(int j=0;j<p;j++)
	// {
	// 	cout <<"S "<<i->first<<" "<< i->second<< "\n";
	// 	i--;
	// }
	// i = b.end();
	// i--;
	// for(int j=0;j<p;j++)
	// {
	// 	cout <<"B "<<i->first<<" "<< i->second<< "\n";
	// 	i--;
	// }
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	//int b[100017], s[100017];
	map<int, int> b,s;
	int n,p;
	char a;
	int q,w;
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b[q]+=w;
		else s[q]+=w;
	}
	map<int, int> ::iterator i = s.end();
	i--;
	int j = 0;
	int t1 = s.size();
	if(t1>p)
	{
		while(t1>p)
		{
			i--;
			t1--;
		}
		for(j=0;j<t1;j++)
		{
			cout <<"S "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}
	else
	{
		for(j=0;j<t1;j++)
		{
			cout <<"S "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}

	i = b.end();
	i--;
	for(int j=0;j<p;j++)
	{
		cout <<"B "<<i->first<<" "<< i->second<< "\n";
		i--;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
	//int b[100017], s[100017];
	map<int, int> b,s;
	int n,p;
	char a;
	int q,w;
	cin>>n>>p;
	for(int i=0;i<n;i++)
	{
		cin>>a>>q>>w;
		if(a=='B') b[q]+=w;
		else s[q]+=w;
	}
	map<int, int> ::iterator i = s.end();
	int j = 0;
	int t1 = s.size();
	if(t1>0) i--;
	if(t1>p)
	{
		while(t1>p)
		{
			i--;
			t1--;
		}
		for(j=0;j<t1;j++)
		{
			cout <<"S "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}
	else
	{
		for(j=0;j<t1;j++)
		{
			cout <<"S "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}

	i = b.end();
	t1 = b.size();
	if(t1>0) i--;
	if(t1>p)
	{
		for(int j=0;j<p;j++)
		{
			cout <<"B "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}
	else
	{
		for(int j=0;j<t1;j++)
		{
			cout <<"B "<<i->first<<" "<< i->second<< "\n";
			i--;
		}
	}
	return 0;
}


#include<bits/stdc++.h>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector < ii >
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define cl(v) memset(v,0,sizeof v)
#define set(a,v) memset(v,a,sizeof v)
#define vl vector<long>
#define vll vector<long long>
#define mp make_pair
#define endl '\n'
using  namespace std;

map<int , long>b,sl;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,s;
    cin>>n>>s;
    char c;
    for(int i=0;i<n;i++)
    {

        int p,q;
        cin>>c>>p>>q;
      if(c=='B')b[-p]+=q;
      else sl[p]+=q;

    }
map<int , long>::iterator it;
int i=0;
for(it=sl.begin();it!=sl.end()&&i<s;i++,it++)
    cout<<'S'<<" "<<it->first<<" "<<it->second<<endl;
    i=0;
for(it=b.begin();it!=b.end()&&i<s;i++,it++)
 cout<<'B'<<" "<<-(it->first)<<" "<<it->second<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector < ii >
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define cl(v) memset(v,0,sizeof v)
#define set(a,v) memset(v,a,sizeof v)
#define vl vector<long>
#define vll vector<long long>
#define mp make_pair
#define endl '\n'
using  namespace std;

map<int , long>b,sl;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,s;
    cin>>n>>s;
    char c;
    for(int i=0;i<n;i++)
    {

        int p,q;
        cin>>c>>p>>q;
      if(c=='B')b[-p]+=q;
      else sl[p]+=q;

    }
map<int , long>::iterator it;
int i=0;
if(sl.begin()!=sl.end())
{

it=sl.end();it--;
while(i<s)
{
     i++;
     cout<<'S'<<" "<<it->first<<" "<<it->second<<endl;
     if(it==sl.begin())break;
     it--;
}
}
    i=0;
for(it=b.begin();it!=b.end()&&i<s;i++,it++)
 cout<<'B'<<" "<<-(it->first)<<" "<<it->second<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector < ii >
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define cl(v) memset(v,0,sizeof v)
#define set(a,v) memset(v,a,sizeof v)
#define vl vector<long>
#define vll vector<long long>
#define mp make_pair
#define endl '\n'
using  namespace std;

map<int , long>b,sl;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,s;
    cin>>n>>s;
    char c;
    for(int i=0;i<n;i++)
    {

        int p,q;
        cin>>c>>p>>q;
      if(c=='B')b[-p]+=q;
      else sl[p]+=q;

    }
map<int , long>::iterator it;
int i=0;

if(sl.begin()!=sl.end())
{

it=sl.begin();
for(i=0;i<s;i++)
{
    it++;
    if(it==sl.end())break;
}

while(it!=sl.begin())
    {
     it--;
     cout<<'S'<<" "<<it->first<<" "<<it->second<<endl;

    }
}

   i=0;
for(it=b.begin();it!=b.end()&&i<s;i++,it++)
 cout<<'B'<<" "<<-(it->first)<<" "<<it->second<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector < ii >
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define cl(v) memset(v,0,sizeof v)
#define set(a,v) memset(v,a,sizeof v)
#define vl vector<long>
#define vll vector<long long>
#define mp make_pair
#define endl '\n'
using  namespace std;

map<int , long>b,sl;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,s;
    cin>>n>>s;
    char c;
    for(int i=0;i<n;i++)
    {

        int p,q;
        cin>>c>>p>>q;
      if(c=='B')b[-p]+=q;
      else sl[p]+=q;

    }
map<int , long>::iterator it;
int i=0;
it=sl.begin();
while(i<s&&it!=sl.end())it++;
while(true)
{

     cout<<'S'<<" "<<it->first<<" "<<it->second<<endl;
     if(it==sl.begin())break;
     it--;
}

    i=0;
for(it=b.begin();it!=b.end()&&i<s;i++,it++)
 cout<<'B'<<" "<<-(it->first)<<" "<<it->second<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector < ii >
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define cl(v) memset(v,0,sizeof v)
#define set(a,v) memset(v,a,sizeof v)
#define vl vector<long>
#define vll vector<long long>
#define mp make_pair
#define endl '\n'
using  namespace std;

map<int , long>b,sl;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,s;
    cin>>n>>s;
    char c;
    for(int i=0;i<n;i++)
    {

        int p,q;
        cin>>c>>p>>q;
      if(c=='B')b[-p]+=q;
      else sl[p]+=q;

    }
map<int , long>::iterator it;
int i=0;

it=sl.begin();
for(i=0;i<s;i++)
{
    it++;
    if(it==sl.end())break;
}

while(it!=sl.begin())
    {
     it--;
     cout<<'S'<<" "<<it->first<<" "<<it->second<<endl;

    }

   i=0;
for(it=b.begin();it!=b.end()&&i<s;i++,it++)
 cout<<'B'<<" "<<-(it->first)<<" "<<it->second<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector < ii >
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define cl(v) memset(v,0,sizeof v)
#define set(a,v) memset(v,a,sizeof v)
#define vl vector<long>
#define vll vector<long long>
#define mp make_pair
#define endl '\n'
using  namespace std;

map<int , long>b,sl;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,s;
    cin>>n>>s;
    char c;
    for(int i=0;i<n;i++)
    {

        int p,q;
        cin>>c>>p>>q;
      if(c=='B')b[-p]+=q;
      else sl[p]+=q;

    }
map<int , long>::iterator it;
int i=0;
it=sl.begin();
while(i<s&&it!=sl.end())it++,i++;
while(true)
{

     cout<<'S'<<" "<<it->first<<" "<<it->second<<endl;
     if(it==sl.begin())break;
     it--;
}

    i=0;
for(it=b.begin();it!=b.end()&&i<s;i++,it++)
 cout<<'B'<<" "<<-(it->first)<<" "<<it->second<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector < ii >
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define cl(v) memset(v,0,sizeof v)
#define set(a,v) memset(v,a,sizeof v)
#define vl vector<long>
#define vll vector<long long>
#define mp make_pair
#define endl '\n'
using  namespace std;

map<int , long>b,sl;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,s;
    cin>>n>>s;
    char c;
    for(int i=0;i<n;i++)
    {

        int p,q;
        cin>>c>>p>>q;
      if(c=='B')b[-p]+=q;
      else sl[p]+=q;

    }
map<int , long>::iterator it;
int i=0;
if(sl.begin()!=sl.end())

{

it=sl.begin();
for(i=0;i<s;i++)
if(it++==sl.end())break;

while(it!=sl.begin())
    {
 it--;
     cout<<'S'<<" "<<it->first<<" "<<it->second<<endl;

    }

}
   i=0;
for(it=b.begin();it!=b.end()&&i<s;i++,it++)
 cout<<'B'<<" "<<-(it->first)<<" "<<it->second<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector < ii >
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define cl(v) memset(v,0,sizeof v)
#define set(a,v) memset(v,a,sizeof v)
#define vl vector<long>
#define vll vector<long long>
#define mp make_pair
#define endl '\n'
using  namespace std;

map<int , long>b,sl;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,s;
    cin>>n>>s;
    char c;
    for(int i=0;i<n;i++)
    {

        int p,q;
        cin>>c>>p>>q;
      if(c=='B')b[-p]+=q;
      else sl[p]+=q;

    }
map<int , long>::iterator it;
int i=0;
if(sl.begin()!=sl.end())

{

it=sl.begin();
while(it!=sl.end()&&i<s-1){it++;i++;}
while(true)
    {

     cout<<'S'<<" "<<it->first<<" "<<it->second<<endl;
     if(it==sl.begin())break;
     it--;
    }

}
   i=0;
for(it=b.begin();it!=b.end()&&i<s;i++,it++)
 cout<<'B'<<" "<<-(it->first)<<" "<<it->second<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector < ii >
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define cl(v) memset(v,0,sizeof v)
#define set(a,v) memset(v,a,sizeof v)
#define vl vector<long>
#define vll vector<long long>
#define mp make_pair
#define endl '\n'
using  namespace std;

map<int , long>b,sl;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,s;
    cin>>n>>s;
    char c;
    for(int i=0;i<n;i++)
    {

        int p,q;
        cin>>c>>p>>q;
      if(c=='B')b[-p]+=q;
      else sl[p]+=q;

    }
map<int , long>::iterator it;
int i=0;
it=sl.end();it--;
while(i<s)
{
     i++;
     cout<<'S'<<" "<<it->first<<" "<<it->second<<endl;
     if(it==sl.begin())break;
     it--;
}
    i=0;
for(it=b.begin();it!=b.end()&&i<s;i++,it++)
 cout<<'B'<<" "<<-(it->first)<<" "<<it->second<<endl;

    return 0;
}


#include<bits/stdc++.h>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector < ii >
#define pb push_back
#define fi first
#define se second
#define all(v) v.begin(),v.end()
#define cl(v) memset(v,0,sizeof v)
#define set(a,v) memset(v,a,sizeof v)
#define vl vector<long>
#define vll vector<long long>
#define mp make_pair
#define endl '\n'
using  namespace std;

map<int , long>b,sl;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n,s;
    cin>>n>>s;
    char c;
    for(int i=0;i<n;i++)
    {

        int p,q;
        cin>>c>>p>>q;
      if(c=='B')b[-p]+=q;
      else sl[p]+=q;

    }
map<int , long>::iterator it;
int i=0;
if(sl.begin()!=sl.end())

{

it=sl.begin();
for(i=0;i<s;i++)
if(it++==sl.end())break;

while(it!=sl.begin())
    {

     cout<<'S'<<" "<<it->first<<" "<<it->second<<endl;
     it--;
    }

}
   i=0;
for(it=b.begin();it!=b.end()&&i<s;i++,it++)
 cout<<'B'<<" "<<-(it->first)<<" "<<it->second<<endl;

    return 0;
}


#include<stdio.h>
int main()
{
	long long int n,i,j,k,l,x,count=0;
	j=k=0;
	scanf("%lld",&n);
	for(i=0;i<n;i++)
	{
		scanf("%lld",&x);
		if(x==25)
		{
			j++;
			count++;
		}
		else if(x==50)
		{
			k++;
			if(j>=1)
			{
				count++;
				j-=1;
			}
		}
		else
		{
			if(j>=1 && k>=1)
			{
				count++;
				j=j-1;
				k=k-1;
			}
			if(j>=3)
			{
				count++;
				j=j-3;
			}
		}
	}
	if(count==n)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include<stdio.h>
int main()
{
	int n,i,j,k,l,x,count=0;
	j=k=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&x);
		if(x==25)
		{
			j++;
			count++;
		}
		else if(x==50)
		{
			k++;
			if(j>=1)
			{
				count++;
				j-=1;
			}
		}
		else
		{
			if(j>=3)
			{
				count++;
				j=j-3;
			}
			else if(j>=1 && k>=1)
			{
				count++;
				j=j-1;
				k=k-1;
			}
		}
	}
	if(count==n)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include<stdio.h>

int a[100005];

int main(void)
{
	int n,i,sum=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
		scanf("%d",&a[i]);
	if(a[0]>25) {
		printf("NO");
		return 0;
	}
	sum=25;
	for(i=1;i<n;i++) {
		if(sum+25<a[i]) {
			printf("NO");
			return 0;
		}
		sum+=25;
	}
	printf("YES");

	return 0;
}


#include<stdio.h>

int count100,count25,count50;

int main(void)
{
	int n,i,val,trap=1;
	scanf("%d",&n);

	for(i=0;i<n;i++) {
		scanf("%d",&val);
		if(val==25)
			count25++;
		else if(val==50) {
			if(count25<=0) {
				trap=0;
				break;
			}
			count25--;
			count50++;
		}
		else {
			if(count25<=0) {
				trap=0;
				break;
			}
			if(count50<=0) {
				if(count25<3) {
					trap=0;
					break;
				}
				count25-=3;
				count100++;
			}
			else {
				count50--;
				count25--;
				count100++;
			}
		}
	}

	printf(trap==1 ? "YES" : "NO");

	return 0;
}


#include<stdio.h>
int a,b,c,n,x,w;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&x);
		if(x==25)      a++;
		else if(x==50) if(!a)  w++; else { b++; a--; }
		else           if(!a || !b) w++; else { c++; a--; b--; }
    }
	printf(w ? "NO" : "YES");
	return 0;
}


#include<stdio.h>
int t,n,x;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&x);
	    if(x != 25 && t < x - 25) { printf("NO"); return 0; }
		t += 25;
    }
	printf("YES");
	return 0;
}


#include<stdio.h>
int t,n,x;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&x);
	    if(x != 25 && t < x) { printf("NO"); return 0; }
		t += 25;
    }
	printf("YES");
	return 0;
}


#include<stdio.h>
int n,x,a,b,c,w;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&x);
		if(x==25)      a++;
		else if(x==50) if(!a) {w++; break;} else {b++; a--;}
   		else           if(!a || (!b && a < 3)) {w++;break;} else {c++; a--; b--;}
	}
	printf(w ? "NO" : "YES");
	return 0;
}


#include<stdio.h>
int n,x,a,b,c,w;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&x);
		if(x==25)      a++;
		else if(x==50) if(a) {b++; a--;} else w++;
   		else           if(b && a) {c++; a--; b--;} else if(a > 2) { c++; a -= 3;} else w++;
	}
	printf(w ? "NO" : "YES");
	return 0;
}


#include<stdio.h>
int n,x,a,b,c,w;
int main(){
	scanf("%d",&n);
	while(n--){
		scanf("%d",&x);
		if(x==25)      a++;
		else if(x==50) if(!a)  w++; else { b++; a--; }
   		else           if(!a || (!b && a < 3)) w++; else { c++; a--; b--; }
	}
	printf("YES");
	return 0;
}


#include<stdio.h>

int main(){
	int n,m=0,temp,flag=1;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&temp);
		if(temp==25)
			m+=25;
		if(temp==50){
			if(m>=25)
				m-=25;
			else
				flag=0;
		}
		if(temp==100){
			if(m>=75)
				m-=75;
			else
				flag=0;
		}
	}
	if(flag==1)
		printf("YES");
	else
	    printf("NO");
	return 0;
}


#include<stdio.h>

int main(){
	int n,m=0,temp,flag=1,q=0;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&temp);
		if(temp==25)
			m++;
		if(temp==50){
			q++;
			if(m>0)
				m--;
			else
				flag=0;
		}
		if(temp==100){
			if(q>0&&m>0){
				q--;
			    m--;
			}
			else if(q==0&&m>=3)
				m=m-3;
			else
				flag=0;
		}
	}
	if(flag==1)
		printf("YES");
	else
	    printf("NO");
	return 0;
}


#include<stdio.h>

int main(){
	int n,m=0,temp,flag=1;
	scanf("%d",&n);
	n--;
	while(n--){
		scanf("%d",&temp);
		if(temp==25)
			m+=25;
		if(temp==50){
			if(m>=25)
				m-=25;
			else
				flag=0;
		}
		if(temp==100){
			if(m>=75)
				m-=75;
			else
				flag=0;
		}
	}
	scanf("%d",&temp);
	if(flag==1)
		printf("YES");
	else
	    printf("NO");
	return 0;
}


#include<stdio.h>

int main(){
	long long n,m=0,temp,flag=1;
	scanf("%I64d",&n);
	while(n--){
		scanf("%I64d",&temp);
		if(temp==25)
			m+=25;
		if(temp==50){
			if(m>=25)
				m+=25;
			else
				flag=0;
		}
		if(temp==100){
			if(m>=75)
				m+=75;
			else
				flag=0;
		}
	}
	if(flag==1)
		printf("YES");
	else
	    printf("NO");
	return 0;
}


#include<stdio.h>

int main(){
	int n,m=0,temp,flag=1;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&temp);
		if(temp==25)
			m+=25;
		if(temp==50){
			if(m>=25)
				m+=25;
			else
				flag=0;
		}
		if(temp==100){
			if(m>=75)
				m+=75;
			else
				flag=0;
		}
	}
	if(flag==1)
		printf("YES");
	else
	    printf("NO");
	return 0;
}


#include<stdio.h>

int main(){
	int n,m=0,temp,flag=1,q=0;
	scanf("%d",&n);
	while(n--){
		scanf("%d",&temp);
		if(temp==25)
			m++;
		if(temp==50){
			q++;
			if(m>0)
				m--;
			else
				flag=0;
		}
		if(temp==100){
			if(q>=2)
				q-=2;
			else if(q==1&&m>=2){
				q--;
				m=m-2;
			}
			else if(q==0&&m>=4)
				m=m-4;
			else
				flag=0;
		}
	}
	if(flag==1)
		printf("YES");
	else
	    printf("NO");
	return 0;
}


#include<stdio.h>

int main(){
	long long n,m=0,temp,flag=1,q=0;
	scanf("%I64d",&n);
	while(n--){
		scanf("%I64d",&temp);
		if(temp==25)
			m++;
		if(temp==50){
			q++;
			if(m>0)
				m--;
			else
				flag=0;
		}
		if(temp==100){
			if(q>=2)
				q-=2;
			else if(q==1&&m>=2){
				q--;
				m-=2;
			}
			else if(q==0&&m>=4)
				m-=4;
			else
				flag=0;
		}
	}
	if(flag==1)
		printf("YES");
	else
	    printf("NO");
	return 0;
}


#include<stdio.h>
int main()
{
long int n;
int i,a[100001],count1=0,count2=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
    scanf("%d",&a[i]);
if(a[i]==25)
count1++;
else if(a[i]==50)
{count2++;
count1--;}
else
{
    if(count2>0)
        {count2--;count1--;}
    else {count1-=3;}
    }
if(count1<0||count2<0)
{printf("NO");
break;}
}
if(count1>=0&&count2>=0)
printf("YES");
return 0;
}


#include<stdio.h>
int main()
{
long int n;
int i,a[100001],count1=0,count2=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
    scanf("%d",&a[i]);
if(a[i]==25)
count1++;
else if(a[i]==50)
count2++;
else
{count1--;
count2--;}
if(count1<0||count2<0)
{printf("NO");
break;}
}
if(count1>=0&&count2>=0)
printf("YES");
return 0;
}


#include<stdio.h>
int main()
{
long int n;
int i,a[100001],count1=0,count2=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
    scanf("%d",&a[i]);
if(a[i]==25)
count1++;
else if(a[i]==50)
{count2++;
count1--;}
else
{count1--;
count2--;}
if(count1<0||count2<0)
{printf("NO");
break;}
}
if(count1>=0&&count2>=0)
printf("YES");
return 0;
}


#include<stdio.h>
int main()
{
long int n;
int i,a[100001],count1=0,count2=0;
scanf("%d",&n);
for(i=0;i<n;i++)
{
    scanf("%d",&a[i]);
if(a[i]==25)
count1++;
else if(a[i]==50)
count2++;
else
{count1--;
count2--;}
if(count1<0||count2<0)
{printf("NO");
break;}
}
if(count1>=0||count2>=0)
printf("YES");
return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int a[200000];
	int i,n,count1 = 0,count2 = 0,flag = 1;
	for(i = 0 ; i < n ; i ++)
		scanf("%d",&a[i]);
	for(i = 0 ; i < n ; i ++)
	{
		if(a[i] == 25)
			count1++;
		if(a[i] == 50)
		{
			count2++;
			count1--;
		}
		if(a[i] == 100)
		{
			if(count2 == 0)
			{
				count1--;
				count1--;
				count1--;
			}
			else
			{
				count2--;
				count1--;
			}
		}
		if(count1 < 0 || count2 < 0)
		{
			flag = 0;
			break;
		}
	}
	if(count1 < 0 || count2 < 0)
	{
		flag = 0;
	}
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int a[200000];
	int i,n,count1 = 0,count2 = 0,flag = 1;
	for(i = 0 ; i < n ; i ++)
		scanf("%d",&a[i]);
	for(i = 0 ; i < n ; i ++)
	{
		if(a[i] == 25)
			count1++;
		if(a[i] == 50)
		{
			count2++;
			count1--;
		}
		if(a[i] == 100)
		{
			if(count2 == 0)
			{
				count1--;
				count1--;
				count1--;
			}
			else
			{
				count2--;
				count1--;
			}
		}
		if(count1 < 0 || count2 < 0)
		{
			flag = 0;
			break;
		}
	}
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include<stdio.h>
#include<stdlib.h>

int main(void)
{
	int a[200000];
	int i,n,count1 = 0,count2 = 0,flag = 1;
	scanf("%d",&n);
	for(i = 0 ; i < n ; i ++)
		scanf("%d",&a[i]);
	for(i = 0 ; i < n ; i ++)
	{
		if(a[i] == 25)
			count1++;
		if(a[i] == 50)
		{
			count2++;
			count1--;
		}
		if(a[i] == 100)
		{
			if(count2 == 0)
			{
				count1-=3;
			}
			else
			{
				count2--;
				count1--;
			}
		}
		if(count1 < 0 || count2 < 0)
		{
			flag = 0;
			break;
		}
	}

	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include<stdio.h>
int main(void)
{
	int a[300000];
	int i,n,count25 = 0 , count50 = 0 , flag = 1;
	scanf("%d",&n);
	for(i = 0 ; i < n ; i ++)
		scanf("%d",&a[i]);
	for(i = 0 ; i < n ; i ++)
	{
		if(a[i] == 25)
			count25++;
		if(a[i] == 50)
		{
			count25--;
			count50++;
			if(count25 < 0)
			{
				flag = 0;
				break;
			}
		}
		if(a[i] == 100)
		{
			if(count50 == 0)
				count25-=3;
			if(count50 >= 1)
			{
				count50--;
				count25--;
			}
			if(count25 < 3 || (count25 <= 2 && count50 == 0))
			{
				flag = 0;
				break;
			}
		}
	}
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include<stdio.h>
int main(void)
{
	int a[300000];
	int i,n,count25 = 0 , count50 = 0 , flag = 1;
	scanf("%d",&n);
	for(i = 0 ; i < n ; i ++)
		scanf("%d",&a[i]);
	for(i = 0 ; i < n ; i ++)
	{
		if(a[i] == 25)
			count25++;
		if(a[i] == 50)
		{
			count25--;
			count50++;
			if(count25 < 0)
			{
				flag = 0;
				break;
			}
		}
		if(a[i] == 100)
		{
			if(count50 == 0)
			{
				count25-=3;
			}
			if(count50 >= 1)
			{
				count50--;
				count25--;
				continue;
			}
			if(count25 < 3 || (count25 <= 2 && count50 == 0))
			{
				flag = 0;
				break;
			}
		}
	}
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include<stdio.h>
int main(void)
{
	int a[300000];
	int i,n,count25 = 0 , count50 = 0 , flag = 1;
	scanf("%d",&n);
	for(i = 0 ; i < n ; i ++)
		scanf("%d",&a[i]);
	for(i = 0 ; i < n ; i ++)
	{
		if(a[i] == 25)
			count25++;
		if(a[i] == 50)
		{
			count25--;
			count50++;
			if(count25 < 0)
			{
				flag = 0;
				break;
			}
		}
		if(a[i] == 100)
		{
			if(count50 == 0)
			{
				count25-=3;
			}
			if(count50 >= 1)
			{
				count50--;
				count25--;
				continue;
			}
			if(count25 < 0 || (count25 <= 2 && count50 == 0))
			{
				flag = 0;
				break;
			}
		}
	}
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include<stdio.h>
int main(void)
{
    int a[300000];
    int i,n,count25 = 0 , count50 = 0 , flag = 1;
    scanf("%d",&n);
    for(i = 0 ; i < n ; i ++)
        scanf("%d",&a[i]);
    for(i = 0 ; i < n ; i ++)
    {
        if(a[i] == 25)
            count25++;
        if(a[i] == 50)
        {
            count25--;
            count50++;
            if(count25 < 0)
            {
                flag = 0;
                break;
            }
        }
        if(a[i] == 100)
        {
            count25--;
            count50--;
            if(count25 < 0 || count50 < 0)
            {
                flag = 0;
                break;
            }
        }
    }
    if(flag)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


#include<stdio.h>
int main(void)
{
    int a[300000];
    int i,n,count25 = 0 , count50 = 0 , flag = 1;
    scanf("%d",&n);
    for(i = 0 ; i < n ; i ++)
        scanf("%d",&a[i]);
    for(i = 0 ; i < n ; i ++)
    {
        if(a[i] == 25)
            count25++;
        if(a[i] == 50)
        {
            count25--;
            count50++;
            if(count25 < 1)
            {
                flag = 0;
                break;
            }
        }
        if(a[i] == 100)
        {
            if(count25 < 3 || (count25 <= 2 && count50 == 0))
            {
                flag = 0;
                break;
            }
            if(count50 == 0)
                count25-=3;
            if(count50 >= 1)
            {
                count50--;
                count25--;
            }
        }
    }
    if(flag)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


#include<stdio.h>
int main(void)
{
	int a[300000];
	int i,n,count25 = 0 , count50 = 0 , flag = 1;
	scanf("%d",&n);
	for(i = 0 ; i < n ; i ++)
		scanf("%d",&a[i]);
	for(i = 0 ; i < n ; i ++)
	{
		if(a[i] == 25)
			count25++;
		if(a[i] == 50)
		{
			count25--;
			count50++;
			if(count25 < 0)
			{
				flag = 0;
				break;
			}
		}
		if(a[i] == 100)
		{
			if(count50 == 0)
			{
				count25-=3;
				continue;
			}
			if(count50 >= 1)
			{
				count50--;
				count25--;
				continue;
			}
			if(count25 < 3 || (count25 <= 2 && count50 == 0))
			{
				flag = 0;
				break;
			}
		}
	}
	if(flag)
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}


#include<stdio.h>
int main(void)
{
    int a[300000];
    int i,n,count25 = 0 , count50 = 0 , flag = 1;
    scanf("%d",&n);
    for(i = 0 ; i < n ; i ++)
        scanf("%d",&a[i]);
    for(i = 0 ; i < n ; i ++)
    {
        if(a[i] == 25)
            count25++;
        if(a[i] == 50)
        {
            count25--;
            count50++;
            if(count25 < 0)
            {
                flag = 0;
                break;
            }
        }
        if(a[i] == 100)
        {
            if(count50 == 0)
            {
                count25-=3;
            }
            if(count50 >= 1)
            {
                count50--;
                count25--;
            }
            if(count25 < 0 || (count25 < 3 && count50 < 1))
            {
                flag = 0;
                break;
            }
        }
    }
    if(flag)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}


#include<stdio.h>
#include<string.h>

int main()
{
    int a[1000],i,n,count=0;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    if(a[0]==25)
    {
        for(i=0;i<n;i++)
        {
            if(a[i]==25){count+=25;}
            else if(a[i]==50){count-=25;}
            else if(a[i]==100){count-=75;}
        }
    }
    else {
        printf("NO");
        return 0;
    }

    if(count>=0){printf("YES");}
    else {
        printf("NO");}
    return 0;

}


#include <stdio.h>

int main ()
{
    int i, j=1,k , l;
    scanf("%d", &l);

    int a[l];

    for(i=0; i<l; i++)
    {
        scanf("%d", &a[i]);
        if(a[i]/25==1)
        j++;
        else if(a[i]/25<=j)
        j=j-(a[i]/25)+1;
        else
            break;

    }
    if(i==l)
    {
        printf("YES\n");
    }
    else
        printf("NO\n");
    return 0;
}


#include <stdio.h>

int main ()
{
    int i, j=1,k , l;
    scanf("%d", &l);

    int a[l];

    for(i=0; i<l; i++)
    {
        scanf("%d", &a[i]);
        if(a[i]/25==1)
        j++;
        else if(a[i]/25<=j)
        j++;
        else
            break;

    }
    if(i==l)
    {
        printf("YES\n");
    }
    else
        printf("NO\n");
    return 0;
}


#include <stdio.h>

int main ()
{
    int i, j=0,k , l;
    scanf("%d", &l);

    int a[l];

    for(i=0; i<l; i++)
    {
        scanf("%d", &a[i]);
        if(a[i]/25==1)
        j++;
        else if((a[i]/25)-1<=j)
        j++;
        else
            break;

    }
    if(i==l)
    {
        printf("YES\n");
    }
    else
        printf("NO\n");
    return 0;
}


#include<stdio.h>
int main()
{
    long n,money=25,a[150000];
    scanf("%ld",&n);
    for (long i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    if (a[0]>25)
    {
        printf("NO");
    }
    else
    {
        for (long i=1;i<n;i++)
        {
            if (a[i]==25)
            {
                money=money+25;
            }
            else
            {
                money=money-(a[i]-25);
                if (money<0)
                {
                    break;
                }
                money=money+a[i];
            }
        }
    }
    if (money<0)
    {
        printf("NO");
    }
    else
    {
        printf("YES");
    }
}


#include<stdio.h>
int main()
{
    long n,money=25,a[150000];
    scanf("%ld",&n);
    for (long i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    if (a[0]>25)
    {
        printf("NO");
    }
    else
    {
        for (long i=1;i<n;i++)
        {
            if (a[i]==25)
            {
                money=money+25;
            }
            else
            {
                money=money-(a[i]-25);
                if (money<0)
                {
                    break;
                }
                money=money+a[i];
            }
        }
        if (money<0)
        {
        printf("NO");
        }
        else
        {
        printf("YES");
        }
    }
}


#include<stdio.h>
int main()
{
    long n,money=0,a[150000];
    scanf("%ld",&n);
    for (long i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for (long i=0;i<n;i++)
    {
        if (a[i]==25)
        {
            money=money+25;
        }
        else
        {
            money=money-a[i];
            if (money<0)
            {
                break;
            }
            money=money+a[i]+25;
        }
    }
        if (money<0)
        {
        printf("NO");
        }
        else
        {
        printf("YES");
        }
}


#include<stdio.h>
int main()
{
    long n,money=25,a[150000];
    scanf("%ld",&n);
    for (long i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    if (a[0]>25)
    {
        printf("NO");
    }
    else
    {
        for (long i=1;i<n;i++)
        {
            if (a[i]==25)
            {
                money=money+25;
            }
            else
            {
                money=money-(a[i]-25);
                if (money<0)
                {
                    break;
                }
                money=money+a[i];
            }
        }
        printf("%d ",money);
    }
}


#include<stdio.h>
int main()
{
    long n,money=0,a[150000];
    scanf("%ld",&n);
    for (long i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for (long i=0;i<n;i++)
    {
        if (a[i]==25)
        {
            money=money+25;
        }
        else
        {
            money=money-a[i];
            if (money<0)
            {
                break;
            }
            money=money+a[i];
        }
    }
        if (money<0)
        {
        printf("NO");
        }
        else
        {
        printf("YES");
        }
}


#include<stdio.h>
int main()
{
    long n,money=0,money1=0,a[150000],count=1,flag=0;
    scanf("%ld",&n);
    for (long i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for (long i=0;i<n;)
    {
        if (a[i]==25)
        {
            money=money+25;
            i++;
        }
        else
        {
            if (a[i]==a[i+1])
            {
                count++;
                i++;
                if (i==n-1)
                {
                    money1=money-(a[i]-25)*count;
                    if (money1<0)
                    {
                        flag=1;break;
                    }
                }
            }
            else
            {
                money1=money-(a[i]-25)*count;
                if (money1<0)
                {
                    flag=1;break;
                }
                else
                {
                    count=1;
                    i++;
                }
            }
        }
    }
    if (flag==1)
    {
        printf("NO");
    }
    else
    {
        printf("YES");
    }
}


#include<stdio.h>
int main()
{
    long long n,myarray;
    scanf("%I64d %I64d",&n,&myarray);
    int sum=25,t=1,f=0,i;
    if(myarray!=25)
    {
        printf("NO");
        return 0;
    }
    n--;
    while(n--)
    {
         scanf("%I64d",&myarray);
         if(myarray>sum)
        {
            printf("NO");
            return 0;
        }
        else if(myarray==50&&t==0)
        {
            printf("NO");
            return 0;
        }
        else if(myarray==100&&(t==0||f==0))
        {
            printf("NO");
            return 0;
        }
        else
        {
            if(myarray==25) t++;
            else if(myarray==50)
            {
                f++;
                t--;
            }
            else if(myarray==100)
            {
                f--;
                t--;
            }
            sum+=25;
        }
    }
    printf("YES");
    return 0;
}


#include<stdio.h>
int main()
{
    long long n,myarray;
    scanf("%I64d %I64d",&n,&myarray);
    int sum=25,t=1,f=0,i;
    if(myarray!=25)
    {
        printf("NO");
        return 0;
    }
    n--;
    while(n--)
    {
        scanf("%I64d",&myarray);
        if(myarray==25){
            t++;
        }
        else if(myarray==50)
        {
            t--;
            f++;
        }
        else
        {
            if(f!=0)
            {
                f--;
                t--;
            }
            else t-=3;
        }
        if(t<0 || f<0)
        {
            printf("NO");
            return 0;
        }

    }
    printf("YES");
    return 0;
}


#include<stdio.h>
int main()
{
    int n,myarray;
    scanf("%d %d",&n,&myarray);
    int sum=25,t=1,f=0,i;
    if(myarray!=25)
    {
        printf("NO");
    }
    n--;
    while(n--)
    {
         scanf("%d",&myarray);
         if(myarray>sum)
        {
            printf("NO");
            return 0;
        }
        else if(myarray==50&&t==0)
        {
            printf("NO");
            return 0;
        }
        else if(myarray==100&&(t==0||f==0))
        {
            printf("NO");
            return 0;
        }
        else
        {
            if(myarray==25) t++;
            else if(myarray==50)
            {
                f++;
                t--;
            }
            else if(myarray==100)
            {
                f--;
                t--;
            }
            sum+=25;
        }
    }
    printf("YES");
    return 0;
}


#include<stdio.h>
int main()
{
    long long n,myarray;
    scanf("%I64d %I64d",&n,&myarray);
    int sum=25,t=1,f=0,i;
    if(myarray!=25)
    {
        printf("NO");
    }
    n--;
    while(n--)
    {
         scanf("%I64d",&myarray);
         if(myarray>sum)
        {
            printf("NO");
            return 0;
        }
        else if(myarray==50&&t==0)
        {
            printf("NO");
            return 0;
        }
        else if(myarray==100&&(t==0||f==0))
        {
            printf("NO");
            return 0;
        }
        else
        {
            if(myarray==25) t++;
            else if(myarray==50)
            {
                f++;
                t--;
            }
            else if(myarray==100)
            {
                f--;
                t--;
            }
            sum+=25;
        }
    }
    printf("YES");
    return 0;
}


#include<stdio.h>
int main()
{
    long long int i,n,sum=0,temp=0;
    int a[100000];
    scanf("%I64d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]==25)
        {
            sum=sum+25;
        }
        else if(sum-(a[i]-25)<0)
        {
            temp=1; printf("NO");break;
        }
        else if(sum-(a[i]-25)>=0)
        {
            temp=0;
            sum=sum-(a[i]-25)+a[i];
        }
    }
    if(temp==0)
    {
        printf("YES");
    }
}


#include<stdio.h>
int main()
{
    long long int i,n,sum=0,temp=0;
    int a[100000];
    scanf("%I64d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]==25)
        {
            sum=sum+25;
        }
        else if(sum-(a[i]-25)<0)
        {
            temp=1; printf("NO");break;
        }
        else if(sum-(a[i]-25)>=0)
        {
            temp=0;
            sum=sum-(a[i]-25)+25;
        }
    }
    if(temp==0)
    {
        printf("YES");
    }
}