#include using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf 1000000000000000000 struct Ball{ char color,ncolor; int ncnt; int ind; }; deque solve(deque red,deque blue){ deque ret; map mp; while(red.size()!=0||blue.size()!=0){ if(red.size()==0){ if(mp['B']==blue.front().ncnt){ mp[blue.front().color]++; ret.push_back(blue.front()); blue.pop_front(); } else{ return ret; } } else if(blue.size()==0){ if(mp['R']==red.front().ncnt){ mp[red.front().color]++; ret.push_back(red.front()); red.pop_front(); } else{ return ret; } } else{ bool f0 = (mp['R']==red.front().ncnt); bool f1 = (mp['B']==blue.front().ncnt); if(!f0&&!f1)return ret; if(f0&&!f1){ mp[red.front().color]++; ret.push_back(red.front()); red.pop_front(); } else if(!f0){ mp[blue.front().color]++; ret.push_back(blue.front()); blue.pop_front(); } else{ if(red.front().color=='R'){ mp[red.front().color]++; ret.push_back(red.front()); red.pop_front(); } else if(blue.front().color=='B'){ mp[blue.front().color]++; ret.push_back(blue.front()); blue.pop_front(); } else{ return ret; } } } } return ret; } int main(){ int N; cin>>N; deque red,blue; rep(i,N){ char c,x; int y; cin>>c>>x>>y; Ball b; b.color = c; b.ncolor = x; b.ncnt = y; b.ind = i; if(x=='R')red.push_back(b); else blue.push_back(b); } sort(red.begin(),red.end(),[&](Ball a,Ball b){ if(a.ncnt!=b.ncnt)return a.ncntb.color; }); deque ans = solve(red,blue); //cout<