#include <bits/stdc++.h>
using namespace std;
#define boost ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
typedef long long ll;
struct node{
ll val,size,_max,prior;
node *l,*r;
};
typedef node* pnode;
ll sz(pnode t){
return (t)?t->size:0;
}
ll rmax(pnode t){
return (t)?t->_max:-2e9;
}
void operation(pnode t){
if(!t) return;
t->size = sz(t->l)+1+sz(t->r);
t->_max = max(t->val,max(rmax(t->l),rmax(t->r)));
}
void split(pnode t, pnode& l, pnode& r, ll pos, ll add = 0){
if(!t){
l = r = NULL;
return;
}
ll curr_pos = add+sz(t->l);
if(curr_pos <= pos){
split(t->r,t->r,r,pos,curr_pos+1);
l = t;
}else{
split(t->l,l,t->l,pos,add);
r = t;
}
operation(t);
}
void merge(pnode& t, pnode l, pnode r){
if(!l || !r){
t=l?l:r;
return;
}
if(l->prior > r->prior){
merge(l->r,l->r,r);
t = l;
}else{
merge(r->l,l,r->l);
t = r;
}
operation(t);
}
pnode init(ll val){
pnode p = (pnode)malloc(sizeof(node));
p->val=p->_max = val;
p->prior = rand();
p->size = 1;
p->l=p->r=NULL;
return p;
}
pnode insert(pnode t, ll pos, ll val){
pnode L,mid,R;
split(t,L,mid,pos-1);
pnode p = init(val);
merge(R,L,p);
merge(t,R,mid);
return t;
}
ll query(pnode t, ll l, ll r){
pnode L,mid,R;
split(t,L,mid,l-1);
split(mid,t,R,r-l);
ll ans = t->_max;
merge(mid,L,t);
merge(t,mid,R);
return ans;
}
int main(){
boost;
ll T,N,i,j,k,M;
pnode t = NULL;
char op[2];
ll x, y, q;
//freopen("in.txt", "r", stdin);
scanf("%lld", &q);
while(q--) {
scanf("%s %lld %lld", op, &x, &y);
if(*op == 'Q') printf("%lld\n", query(t,x-1,y-1));
else t = insert(t, y-1, x);
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+Cgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKI2RlZmluZSBib29zdCBpb3NfYmFzZTo6c3luY193aXRoX3N0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