#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define repone(i, n) for (int i = 1; i <= n; ++i)
#define reprange(i,a,b) for(int i=(a);i<=(b);++i)
#define si(x) scanf("%d",&x)
#define sl(x) scanf("%lld",&x)
#define ss(s) scanf("%s",&s)
#define pi(x) printf("%d\n",x)
#define pl(x) printf("%lld\n",x)
#define ps(s) printf("%s\n",s)
#define all(x) x.begin(),x.end()
#define sortall(x) sort(all(x))
using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double lld;
const int mod = 1000000007;
const int MOD = 998244353;
const char nline = '\n';
void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}
template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.fi); cerr << ","; _print(p.se); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}
/*-------------------------------------------------------------------------------------------------------------------------------------------*/
void solve() {
int q;
cin >> q;
vector<int> v(2e5 + 5, 0);
int l = 0, r = 0;
for (int i = 0; i < q; i++) {
char c; cin >> c;
int id; cin >> id;
if (i == 0) {
v[id] = l;
l--;
r++;
continue;
}
if (c == 'L') {
v[id] = l;
l--;
}
else if (c == 'R') {
v[id] = r;
r++;
}
else {
cout << min(abs(v[id] - l), abs(v[id] - r)) - 1 << nline;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
freopen("Errorf.in", "w", stderr);
#endif
ios::sync_with_stdio(false);
cin.tie(NULL);
int t = 1;
//cin >> t;
for (ll i = 1; i <= t; i++) {
//cout << "Case " << i << ": " ;
solve();
}
return 0;
}
979A - Pizza Pizza Pizza | 731A - Night at the Museum |
742A - Arpa’s hard exam and Mehrdad’s naive cheat | 1492A - Three swimmers |
1360E - Polygon | 1517D - Explorer Space |
1230B - Ania and Minimizing | 1201A - Important Exam |
676A - Nicholas and Permutation | 431A - Black Square |
474B - Worms | 987B - High School Become Human |
1223A - CME | 1658B - Marin and Anti-coprime Permutation |
14B - Young Photographer | 143A - Help Vasilisa the Wise 2 |
320A - Magic Numbers | 1658A - Marin and Photoshoot |
514A - Chewbaсca and Number | 382A - Ksenia and Pan Scales |
734B - Anton and Digits | 1080A - Petya and Origami |
1642D - Repetitions Decoding | 1440A - Buy the String |
1658F - Juju and Binary String | 478A - Initial Bet |
981A - Antipalindrome | 365A - Good Number |
1204B - Mislove Has Lost an Array | 1409D - Decrease the Sum of Digits |