class Queue { public: i64 s1[MAXK]; i64 a1[MAXK]; i64 s2[MAXK]; i64 a2[MAXK]; int h1, h2; Queue() { init(); } void init() { h1 = h2 = 0; } void push1(i64 x) { s1[h1] = x; if (h1) a1[h1] = min(a1[h1 - 1], x); else a1[h1] = x; ++h1; } void push2(i64 x) { s2[h2] = x; if (h2) a2[h2] = min(a2[h2 - 1], x); else a2[h2] = x; ++h2; } void push(i64 x) { push2(x); } void pop() { if (h1) { --h1; } else if (h2) { while (h2) { push1(s2[--h2]); } --h1; } else assert(false); } i64 get() { i64 result = -1; if (h1) result = ((result == -1) || (result > a1[h1 - 1]) ? a1[h1 - 1] : result); if (h2) result = ((result == -1) || (result > a2[h2 - 1]) ? a2[h2 - 1] : result); return result; } } queue;