//탑
/*
#include <stdio.h>
int stack[500001][2] = {};
int top = -1;
void push(int a, int b)
{
top++;
stack[top][0] = a;
stack[top][1] = b;
}
void pop()
{
if (top > -1)
{
top--;
}
}
int main()
{
int n, h, i;
scanf("%d", &n);
for (i = 1; i <= n; i++)
{
scanf("%d", &h);
while (top > -1 && stack[top][0] < h)
{
pop();
}
if (top == -1)
{
printf("0 ");
}
else
{
printf("%d ", stack[top][1]);
}
push(h, i);
}
return 0;
}
a 0 1 2 3 4 5 6 7 8
a%5 0 1 2 3 4 0 1 2 3
*/
//STL queue
/*
#include <stdio.h>
#include <string.h>
int queue[201]={};
int bback=-1;
int ffront=-1;
void push(int a)
{
bback++;
queue[bback]=a;
}
void pop()
{
if(bback-ffront!=0) ffront++;
}
void front()
{
if(bback-ffront!=0) printf("%d\n", queue[ffront+1]);
else printf("-1\n");
}
void back()
{
if(bback-ffront!=0) printf("%d\n", queue[bback]);
else printf("-1\n");
}
void size()
{
printf("%d\n", bback-ffront);
}
void empty()
{
if(ffront==bback) printf("true\n");
else printf("false\n");
}
int main()
{
int n;
char c[201]={};
scanf("%d",&n);
getchar();
for(int i=0;i<n;i++)
{
gets(c);
if(c[0]=='p'&&c[1]=='u')
{
int num;
sscanf(c, "push( %d", &num);
push(num);
}
else if(c[0]=='p'&&c[1]=='o')
{
pop();
}
else if(c[0]=='f')
{
front();
}
else if(c[0]=='b')
{
back();
}
else if(c[0]=='s')
{
size();
}
else if(c[0]=='e')
{
empty();
}
}
return 0;
}
*/
//원형 큐 이용해서 풀어보기 - STL queue
#include <stdio.h>
#include <string.h>
int queue[201]={};
int bback=-1;
int ffront=-1;
int size=5;
void push(int a)
{
bback = (bback+1)%ssize;
queue[bback]=a;
}
void pop()
{
if(bback-ffront!=0) ffront = (ffront+1)%ssize;
}
void front()
{
if(bback-ffront!=0) printf("%d\n", queue[ffront+1]);
else printf("-1\n");
}
void back()
{
if(bback-ffront!=0) printf("%d\n", queue[bback]);
else printf("-1\n");
}
void size()
{
printf("%d\n", bback-ffront);
}
//front 하고 back 하고 순환하면 한바퀴 돌아서 둘이 같아질때 어카누;;
void empty()
{
if(ffront==bback) printf("true\n");
else printf("false\n");
}
int main()
{
int n;
char c[201]={};
scanf("%d",&n);
getchar();
for(int i=0;i<n;i++)
{
gets(c);
if(c[0]=='p'&&c[1]=='u')
{
int num;
sscanf(c, "push( %d", &num);
push(num);
}
else if(c[0]=='p'&&c[1]=='o')
{
pop();
}
else if(c[0]=='f')
{
front();
}
else if(c[0]=='b')
{
back();
}
else if(c[0]=='s')
{
size();
}
else if(c[0]=='e')
{
empty();
}
}
return 0;
}



