#include<stdio.h>
#include<string.h>
#define max 100
int top=0;
int arr[max];
int isFull()
{
    if(top==size-1)    
    {
        return 1;
    }
    else
    {
        return 0;
    }
}
void push(int num)
{
    if(isFull())
    {
        printf("stack is full");
    }
    else
    {
        top++;
        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 n,x;
    char ch[20];
    scanf("%d",&n);
    if(n<0)
    {
        printf("Invalid input");
        return 0;
    }
   for(int i=0;i<n;i++)
   {
       scanf("%s%d",ch,&x);
       if(!strcmp("PUSH",ch))
       {
           push(x);
       }
       else
       {
           if(!strcmp("POP",ch))
           {
               pop();
           }
           else
           {
               if(!strcmp("DISPLAY",ch))
               {
                   display();
               }
               else
               {
                   if(!strcmp("PEEK",ch))
                   {
                       printf("\n%d",arr[top]);
                   }
                   else
                   {
                       printf("Invalid input");
                       return 0;
                   }
               }
           }
       }
       
   }
}