#include<stdio.h>
#include<stdlib.h>
int top=-1,size=5,arr[25];
int isFull()
{
    if(top==size-1)    
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
void push(int num)
{
    if(isFull())
    {
        printf("stack is full");
    }
    else
    {
        arr[++top]=num;
    }
}
int isEmpty()
{
    if(top==-1)
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
void pop()
{
    if(isEmpty())
    {
        printf("Stack Underflow\n");
    }
    else
    {
        top--;
    }
}
int peek()
{
    if(isEmpty())
    {
        return -1;
    }
    else
    {
        return arr[top];
    }
}
void display()
{
    for (int i=0;i<=top;i++)
    {
        printf("%d ",arr[i]);
    }
}
int main()
{
    int q,num;
    char ch[20];
    scanf("%d",&q);
    while(q--)
    {
        scanf("%s",ch);
        if(strcmp(ch,"push")==0)
        {
            scanf("%d",&num);
            push(num);
        }
        else if(strcmp(ch,"pop")==0)
        {
            pop();
        }
        else if(strcmp(ch,"peek")==0)
        {
            int ans=peek();
            if(ans==-1)
               printf("Stack Underflow");
               else
               printf("%d",ans);
        }
        else if(strcmp(ch,"display"));
        display();
    }
}