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