#include <stdio.h>
#include <stdlib.h>
struct node
{
    int data;
    struct node* next;
}*head,*tail,*temp;
int main()
{
    int n,i;
    scanf("%d",&n);
    if(n<0||n>1000)
    {
        printf("Invalid input");
        return 0;
    }
    for(i=0;i<n;i++)
    {
        struct node* newnode=(struct node*)malloc(sizeof(struct node));
       if( scanf("%d",&newnode->data)!=1)
       {
           printf("Invalid input");
           return 0;
       }
       
        if(head==NULL)
        {
            head=newnode;
            tail=newnode;
            head->next=NULL;
        }else
        {
            tail->next=newnode;
            tail=newnode;
            newnode->next=NULL;
        }
    }
    int x,y;
    scanf("%d %d",&x,&y);
    if(x<0||x>n)
    {
        printf("Invalid input");
        return 0;
    }
    temp=head;
    if(x==0)
    {
        struct node* newnode=(struct node*)malloc(sizeof(struct node));
        newnode->data=y;
        newnode->next=head;
        head=newnode;
    }
    else if(x==1)
    {
        struct node* newnode=(struct node*)malloc(sizeof(struct node));
        newnode->data=y;
        newnode->next=head->next;
        head->next=newnode;
    }
    else
    {
    for(i=0;i<x-1;i++)
        temp=temp->next;
     struct node* newnode=(struct node*)malloc(sizeof(struct node));
     newnode->data=y;
     newnode->next=temp->next;
     temp->next=newnode;
    }
    for(i=0;i<n+1;i++)
    {
        printf("%d ",head->data);
        head=head->next;
    }
}