#include <bits/stdc++.h>
using namespace std;
int _queue[20010], wrong[10010];
int main()
{
char str[5];
int n, data;
int mid = 10000, l = mid, r = mid, k = 0, flag = 0;
cin >> n;
for(int i = 1; i <= n; i++)
{
scanf("%s", str);
if(strcmp(str, "LIN") == 0)
{
cin >> data;
if(flag == 0)
{
flag = 1;
_queue[l] = data;
}
else
{
_queue[--l] = data;
}
}
else if(strcmp(str, "RIN") == 0)
{
cin >> data;
if(flag == 0)
{
flag = 1;
_queue[r] = data;
}
else
{
_queue[++r] = data;
}
}
else if(strcmp(str, "LOUT") == 0)
{
if(flag == 0)
{
wrong[++k] = i;
}
else if(l <= r)
{
l++;
}
else if(l > r)
{
wrong[++k] = i;
}
}
else if(strcmp(str, "ROUT") == 0)
{
if(flag == 0)
{
wrong[++k] = i;
}
else if(r >= l)
{
r--;
}
else if(r < l)
{
wrong[++k] = i;
}
}
}
for(int i = l; i <= r; i++)
{
if(i == l)
{
cout << _queue[i];
}
else
{
cout << ' ' << _queue[i];
}
}
cout << endl;
if(k!=0)
{
for(int i = 1; i <= k; i++)
{
cout << wrong[i] << ' ' << "ERROR" << endl;
}
}
return 0;
}