#include <iostream>
#include <queue>
#include <cstring>
#include <set>
#define l long long
using namespace std;
queue<string> q;
set<string> s;
int main()
{
l n;
string first = "11111111111", second = "11111111111";
scanf("%lld", &n);
for (l i = 1; i <= n; ++i)
{
while (!q.empty() && s.count("11111111111" + q.front()))
{
s.erase("11111111111" + q.front());
q.pop();
}
string str;
cin >> str;
if (str == "start")
{
if (q.empty() && first == "11111111111")
{
printf("Error\n");
continue;
}
if (first != "11111111111")
{
q.push(first);
s.insert(first);
first = "11111111111";
}
if (second != "11111111111")
{
q.push(second);
s.insert(second);
second = "11111111111";
}
first = q.front();
cout << first << " ";
s.erase(q.front());
q.pop();
while (!q.empty() && s.count("11111111111" + q.front()))
{
s.erase("11111111111" + q.front());
q.pop();
}
if (!q.empty())
{
second = q.front();
cout << second;
s.erase(q.front());
q.pop();
}
printf("\n");
}
else if (str == "arrive")
{
string x;
cin >> x;
if (s.count(x) || first == x || second == x)
{
printf("Error\n");
continue;
}
s.insert(x);
q.push(x);
printf("OK\n");
}
else
{
string x;
cin >> x;
if (!s.count(x) || first == x || second == x)
{
printf("Error\n");
continue;
}
s.erase(x);
s.insert("11111111111" + x);
printf("OK\n");
}
}
return 0;
}
set + queue 50,帮帮蒟蒻QAQ