#include<stdio.h>
#include<stdlib.h>
typedef struct Node{
    int data;
    struct Node*next;
}Node;
Node*createNode(int value){
    Node*newNode=(Node*)malloc(sizeof(Node));
    if(!newNode){
        printf("Memory error\n");
        return NULL;
    }
    newNode->data=value;
    newNode->next=NULL;
    return newNode;
}
Node*insertNode(Node*head,int value,int pos,int n){
    if(pos<1||pos>n+1){
        printf("Invalid input\n");
        return head;
    }
    Node*newNode=createNode(value);
    if(pos==1){
        newNode->next=head;
        return newNode;
    }
    Node*temp=head;
    for(int i=1;i<pos-1;i++){
        if(temp==NULL)break;
        temp=temp->next;
    }
    if(temp==NULL){
        printf("Invalid input\n");
        return head;
    }
    newNode->next=temp->next;
    temp->next=newNode;
    return head;
    }
    void freeList(Node*head){
        while(head!=NULL){
            Node*temp=head;
            head*head->next;
            free(temp);
        }
    }
    int main(){
        int n;
        scanf("%d",&n);
        Node*head=NULL;
        Node*temp=NULL;
        int val;
        for(int i=0;i<n;i++){
            scanf("%d",&val);
            if(!head){
                head=createNode(val);
                temp=head;
            }else{
                temp->next=createNode(val);
                temp=temp->next;
            }
        }
        int value,pos;
        scanf("%d",&value);
        scanf("%d",&pos);
        head=insertNode(head,value,pos,n);
        printList(head);
        freeList(head);
        return 0;
    }