# include <stdio.h>
# include <stdlib.h>
struct node{
    int data;
    struct node *next;
};
struct node *head=NULL;
struct node *createnode(int data)
{
   struct node *new=(struct node*)malloc(sizeof(struct node));
   new->data=data;
   new->next=NULL;
   return new;
}
void insertend(struct node**head,int data)
{
    struct node *new= createnode(data);
    if(*head==NULL){
        *head=new;
        return;
    }
struct node *temp=*head;
while(temp->next!=NULL)
{
    temp=temp->next;
}
temp->next=new;
}
void insert(struct node **head,int data,int pos,int n){
    if (pos<1||pos>n+1)
    {
        printf("Invalid input");
        return;
    }

struct node *temp=*head;
for(int i=1;i<pos-1&& temp!=NULL;i++){
    temp=temp->next;
}
if(temp==NULL){
    printf(" Invalid input\n");
    return;
}
struct node *new=temp->next;
temp->next=new;

void printlist(struct node *head){
    struct node *temp=head;
    while(temp!=NULL){
        printf("%d",temp->data);
        temp=temp->next;
    }
}
int main() {
    int n,val,pos;
    scanf("%d",&n);
    struct node *head=NULL;
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        insertend(&head,x);
    }
    scanf("%d %d",&val,&pos);
    insert(&head,val,pos,n);
    printlist(head);
    return 0;
}