#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>

struct Node{
    int data;
    struct Node*next;
};
struct Node*createNode(int data){
    struct Node*newNode = (struct Node*)malloc(size of(struct Node));
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}

struct Node*insertATPosition(struct Node*head,int pos,int val){
    struct Node*newNode = createNode(val);
    if(pos == 0){
        newNode->next = head;
        return newNode;
    }
    
    struct Node*temp = head;
    for(int i = 0; i < pos - 1 && temp != NULL; i++){
        temp = temp->next;
    }
    if(temp ==NULL){
        printf("Invalid Position\n");
        return head;
    }
    newNode->next = temp->next;
    temp->next = newNode;
}

void printlist(struct Node*head){
    struct Node*temp = head;
    while(temp != NULL) {
        printf("%d",temp->data);
        temp = temp->next;
    }
}

int isValidNumber(char*str){
    for (int i = 0; str[i]; i++){
        if(!isdigit(str[i]) && str[i] != '-'){
            return 0;
        }
    }
    return 1;
    }
    
    int main() {
        int n;
        if(scanf("%d", &n) != 1){
            printf("Invalid input\n");
            return 0;
        }
        
        struct Node*head = NULL;
        struct Node*tail = NULL;
        
        for (int i =0; i < n; i++) {
            int num;
            if(scanf("%d", &num) != 1) {
                printf("Invalid input\n");
                return 0;
            }
            
            struct Node*newNode = createNode(num);
            if(!head){
                head = tail = newNode;
            }
            else{
                tail->next = newNode;
                tail = newNode;
            }
        }
        int pos, val;
        if(scanf("%d %d", &pos, &val) != 2 || pos < 0 || pos > n){
            printf("Invalid input\n");
            return 0;
        }
        
        head = insertATPosition(head, pos, val);
        printlist(head);
        
        return 0;
}