#include<stdio.h>
#include<stdlib.h>
struct Node 
{
    int data;
    struct Node *next;
};
struct Node *create(int data)
{
    struct Node newnode=(struct Node)malloc(sizeof(struct Node));
    newnode->data=data;
    newnode->next=NULL;
    return newnode;
}
void insert(int data,struct Node **head)
{
    struct Node *newnode=create(data),*temp=*head;
    if(*head==NULL)
    {
        *head=newnode;
    }
    else
    {
        while(temp->next!=NULL)
        {
            temp=temp->next;
        }
        temp->next=newnode;
    }
}
void update(int data,int pos,struct Node **head)
{
   struct Node *newnode=create(data),*temp=*head;
    int i=0;
    if(pos==0)
    {
        newnode->next=temp;
        *head=newnode;
        return ;
    }
    while(i<pos-1)
    {
        temp=temp->next;
        i++;
    }
    newnode->next=temp->next;
    temp->next=newnode;
}
void print(struct Node*temp)
{
    while(temp!=NULL)
    {
        printf("%d ",temp->data);
        temp=temp->next;
    }
}
int main()
{
    int n;
    scanf("%d",&n);
    struct Node *head;
    for(int i=0;i<n;i++)
    {
        int data;
        scanf("%d",&data);
        insert(data,&head);
    }
    int pos,data;
    scanf("%d\n%d",&pos,&data);
    if(pos<0||pos>n)
    {
        printf("Invalid input");
        return 0;
    }
    update(data,pos,&head);
    print(head);
}