#include<iostream>
#include<queue>
#include<stack>
#include<deque>
using namespace std;
int main()
{
stack <int> q; deque <int> a;
int n; cin>>n;
while(n--)
{
int x;
cin>>x;
if(x==0)
{
int l;
cin>>l;
q.push(l);
if(a.empty())
{
a.push_front(l);
}
else
{
if(l>a.back()&&!a.empty())
{
a.push_back(l);
}
}
}
else if(x==1)
{
if(!q.empty())
{
if(q.top()==a.back()) a.pop_back();
q.pop();
}
}
else if(x==2)
{
if(q.empty()) printf("0\n");
else
printf("%d\n",a.back());
}
}
return 0;
}
#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 20;
string s, t, u, a;
int b[30];
stack<char> sta;
int main()
{
while (cin>>s)
{
memset(b, 0, sizeof(b));
for (int i = 0;s[i]>=97;i++)
b[s[i] - 'a']++;//¼ÆËã26¸ö×ÖĸµÄ·Ö±ðÓжàÉÙ¸ö;
int i = 0,k;
while (s[i])//´ú±íÓÐ×Öĸ£»
{
int k1 = 26;//¾¡¿ÉÄܵôó£¬k1È¡¸Ãֵʱ£¬staΪ¿Õ£¬²¢ÇÒºóÃæҪȡ½ÏСµÄÊý ;
if (!sta.empty()) //sta ²»Îª¿ÕµÄ»° sta.top()Ϊ sta¶¥¶ËµÄÔªËØ ;
k1 = sta.top() - 'a';
for (k = 0; k < 26; k++)
{
if (b[k])// ´ÓСµ½´ó¼ìÑé×Öĸ£¬Èç¹ûb[k]²»Îª 0 Ö±½ÓÍ˳öÑ»·;
break;
}
k = min(k1, k);
while (1)
{
if (!sta.empty() && sta.top() - 'a' == k) //¸ÃÌõ¼þÏÞÖÆÁËÖ»ÓÐСµÄ×Öĸ²ÅÄÜ
break; //ʵÏÖ´òÓ¡,·ñÔòÂÖ»»ÏÂÒ»¸ö×Öĸ;
b[s[i] - 'a']--;
sta.push(s[i++]);
if (s[i] == '\0')
break;
}
printf("%d\n",i);
if (!sta.empty())
{
printf("%c", sta.top());
sta.pop();
}
}
while (!sta.empty())
{
printf("%c",sta.top());
sta.pop();
}
cout << endl;
}
return 0;
}
#include<iostream>
#include<deque>
using namespace std;
deque <int> a,b;
int main()
{
int n,i=0,p=0,l;
cin>>n;
cin>>l;
for(int i=1;i<=l;i++)
{
int x; cin>>x;
a.push_back(x);
}
cin>>p;
for(int i=1;i<=p;i++)
{
int x;cin>>x;
b.push_back(x);
}
int k=0,r=2,w=1;
for(;k<1000000;)
{
if(a.front()>b.front()) // ½»Á˺ܶà´Î¶¼Ã»¹ý£¬a.front()>b.frontÓëa.front()<b.front()
// Ó¦¸ÃÊÇ ifÓëelse µÄ¹Øϵ£¬ÏÈǰд³ÉifÓëifµÄ¹Øϵ
// ´¿´¿µÄnt£»
{
a.push_back(b.front()); b.pop_front();
a.push_back(a.front()); a.pop_front();
k++;
}
else
{
b.push_back(a.front()); a.pop_front();
b.push_back(b.front()); b.pop_front();
k++;
}
if(a.empty())
{
printf("%d %d\n",k,r);return 0;
}
if(b.empty())
{
printf("%d %d\n",k,w);
return 0;
}
}
printf("-1\n");
return 0;
}