define _CRT_SECURE_NO_WARNINGS
// #pragma comment(linker, “/stack:200000000”)
// #pragma GCC optimize(“Ofast”)
// #pragma GCC optimize(3)
// #pragma GCC target(“sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native”)
// #pragma GCC target(“sse3”,”sse2”,”sse”)
// #pragma GCC target(“avx”,”sse4”,”sse4.1”,”sse4.2”,”ssse3”)
// #pragma GCC target(“f16c”)
// #pragma GCC optimize(“inline”,”fast-math”,”unroll-loops”,”no-stack-protector”)
// #pragma GCC diagnostic error “-fwhole-program”
// #pragma GCC diagnostic error “-fcse-skip-blocks”
// #pragma GCC diagnostic error “-funsafe-loop-optimizations”
// #pragma GCC diagnostic error “-std=c++14”
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
// 时间够不要用unordered_map,unordered_set
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
include [HTML_REMOVED]
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair[HTML_REMOVED] PII;
typedef pair[HTML_REMOVED]> PIII;
typedef pair[HTML_REMOVED] PLI;
typedef pair[HTML_REMOVED] PUI;
typedef vector[HTML_REMOVED] VI;
typedef vector[HTML_REMOVED] VVI;
typedef vector[HTML_REMOVED] VL;
typedef vector[HTML_REMOVED] VPII;
typedef pair[HTML_REMOVED] PLL;
typedef vector[HTML_REMOVED] VPLL;
typedef priority_queue[HTML_REMOVED], greater[HTML_REMOVED]> minheap;
typedef priority_queue[HTML_REMOVED] maxheap;
typedef priority_queue[HTML_REMOVED], greater[HTML_REMOVED]> pi_minheap;
typedef priority_queue[HTML_REMOVED] pi_maxheap;
typedef priority_queue[HTML_REMOVED], greater[HTML_REMOVED]> pii_minheap;
typedef priority_queue[HTML_REMOVED] pii_maxheap;
// 常用操作的简写
define PB push_back
define PF push_front
define se second
define fi first
define sz(x) ((int)x.size())
define fr(x) freopen(x,”r”, stdin)
define fw(x) freopen(x,”w”, stdout)
define REP(x, l, u) for (int x = l; x <= u; x ++)
define RREP(x, u, l) for (int x = u; x >= l; x –)
define sqr(x) (x * x)
// 给静态数组设值
define setZE(x) memset(x, 0, sizeof x)
define setMAX(x) memset(x, 0x3f, sizeof x)
define setMIN(x) memset(x, -0x3f, sizeof x)
// lowbit操作,树状数组
define lowbit(x) ((x)&(-(x)))
// 直接输出x的二进制表示中的1的个数
define bitcnt(x) (__builtin_popcountll(x))
// 方格问题中的方位
int dx4[4] = { 0, 0, -1, 1 };
int dy4[4] = { -1, 1, 0, 0 };
int dx8[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy8[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
LL MOD_F(LL a, LL M)
{
a %= M;
return a < 0 ? a + M : a;
}
/
* 数学板子
/
// 最大公约数
LL gcd(LL a, LL b)
{
return b ? gcd(b, a % b) : a;
}
// 快速幂
LL qmi(LL a, LL b, LL mod)
{
if (!b) return 1;
LL tmp = qmi(a, b >> 1, mod);
tmp = (tmp * tmp) % mod;
if (b & 1) tmp *= a;
return tmp % mod;
}
/
* 输出输出优化
/
void IO()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
}
/
* 并查集函数
* 使用的时候需要先根据打下定义好fa数组
/
int UFfind(int f[], int a)
{
return a == f[a] ? f[a] : f[a] = UFfind(f, f[a]);
}
void UFinit(int f[], int n)
{
REP(i, 1, n) f[i] = i;
}
// 常用的取模
const int mN = 1e2 + 10;
const int N = 1e6 + 10;
constexpr int MOD = 1e9 + 7;
/******
* 代码开始
*/
//#define kickstart
define niuke
// #define custom
// #define multiTask
// #define duipai
/
* 数据初始定义
/
ifdef kickstart
int T;
int l, r, n, m;
int res;
int f[N];
endif
ifdef niuke
int n, x;
string s;
stack[HTML_REMOVED] stk, cache;
endif
// 每个测试数据的方法
void solve()
{
cin >> n;
for (int i = 0; i < n; i++)
{
cin >> s;
if (s == “add”)
{
cin >> x;
stk.push(x);
}
else if (s == “poll”)
{
if (stk.empty()) cout << -1 << endl;
while (stk.size())
{
cache.push(stk.top());
stk.pop();
}
cache.pop();
while (cache.size())
{
stk.push(cache.top());
cache.pop();
}
}
else
{
if (stk.empty()) cout << -1 << endl;
while (stk.size())
{
cache.push(stk.top());
stk.pop();
}
int res = cache.top();
while (cache.size())
{
stk.push(cache.top());
cache.pop();
}
cout << res << endl;
}
}
}
int main()
{
IO();
ifdef kickstart
// scanf("%d", &T);
cin >> T;
for (int cas = 1; cas <= T; cas ++)
{
solve();
cout << "Case #" << cas << ": " << res << endl;
}
return 0;
else
solve();
return 0;
}
endif
ifdef duipai
int main()
{
for (int T = 0; T < 10000; ++T)
{
system(“./random > ./data.in”);
double st = clock();
system(“./sol < ./data.in > ./data.ans”);
double et = clock();
system(“./bf < ./data.in > ./data.out”);
if (system(“diff ./data.out ./ data.ans”))
{
puts(“Wrong Answer\n”);
return 0;
}
else
{
printf(“Accepted, 测试点 #%d, 用时 %.0lfms\n”, T, et - st);
}
}
return 0;
}