#include
#include
#include
#include
#include
using namespace std;
int main()
{
int n = 0;
cin >> n;
cin.get();
stackFront;
stackLatter;
vectorarr;
for (int i = 0;i < n;i++)
{
string str;
getline(cin, str);
stringstream sstream(str);
string tmp;
sstream >> tmp;
if (tmp == “add”)
{
int temp;
sstream >> temp;
Front.push(temp);
continue;
}
else if (tmp == “poll”)
{
while (!Front.empty())
{
Latter.push(Front.top());
Front.pop();
}
Latter.pop();
while (!Latter.empty())
{
Front.push(Latter.top());
Latter.pop();
}
}
else if (tmp == “peek”)
{
while (!Front.empty())
{
Latter.push(Front.top());
Front.pop();
}
arr.push_back(Latter.top());
while (!Latter.empty())
{
Front.push(Latter.top());
Latter.pop();
}
}
}
for (int i = 0;i < arr.size();i++)
{
cout << arr[i] << endl;
}
return 0;
}