#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 red,blue; deque ret; map mp; void NG(){ cout<<"No"<red.front().ncnt)return; } if(blue.size()!=0){ if(mp[blue.front().ncolor]>blue.front().ncnt)return; } if(red.size()==0){ if(mp[blue.front().ncolor]==blue.front().ncnt){ mp[blue.front().color]++; ret.push_back(blue.front()); blue.pop_front(); solve(); blue.push_front(ret.back()); ret.pop_back(); mp[blue.front().color]--; } } else if(blue.size()==0){ if(mp[red.front().ncolor]==red.front().ncnt){ mp[red.front().color]++; ret.push_back(red.front()); red.pop_front(); solve(); red.push_front(ret.back()); ret.pop_back(); mp[red.front().color]--; } } else{ bool f0 = (mp[red.front().ncolor]==red.front().ncnt); bool f1 = (mp[blue.front().ncolor]==blue.front().ncnt); if(!f0&&!f1)return; if(f0&&!f1){ mp[red.front().color]++; ret.push_back(red.front()); red.pop_front(); solve(); red.push_front(ret.back()); ret.pop_back(); mp[red.front().color]--; } else if(!f0){ mp[blue.front().color]++; ret.push_back(blue.front()); blue.pop_front(); solve(); blue.push_front(ret.back()); ret.pop_back(); mp[blue.front().color]--; } else{ mp[red.front().color]++; ret.push_back(red.front()); red.pop_front(); solve(); red.push_front(ret.back()); ret.pop_back(); mp[red.front().color]--; mp[blue.front().color]++; ret.push_back(blue.front()); blue.pop_front(); solve(); blue.push_front(ret.back()); ret.pop_back(); mp[blue.front().color]--; } } } int main(){ int N; cin>>N; vector Y(N); vector C(N),X(N); rep(i,N){ cin>>C[i]>>X[i]>>Y[i]; } deque B,R; rep(i,N){ if(C[i]=='B')B.push_back(-1); else R.push_back(-1); } rep(i,N){ if(C[i]==X[i]){ int t = Y[i]; if(C[i]=='R')swap(B,R); if(t>=B.size())NG(); if(B[t]!=-1)NG(); B[t] = i; if(C[i]=='R')swap(B,R); } } vector> pB,pR; rep(i,N){ if(C[i]==X[i])continue; if(C[i]=='B')pB.emplace_back(Y[i],i); else pR.emplace_back(Y[i],i); } sort(pB.begin(),pB.end()); sort(pR.begin(),pR.end()); int now = 0; rep(i,pB.size()){ while(B[now]!=-1)now++; B[now] = pB[i].second; } now = 0; rep(i,pR.size()){ while(R[now]!=-1)now++; R[now] = pR[i].second; } rep(i,B.size()){ blue.push_back({'B',X[B[i]],Y[B[i]],B[i]}); } rep(i,R.size()){ red.push_back({'R',X[R[i]],Y[R[i]],R[i]}); } // blue = B,red = R; solve(); NG(); return 0; }