#include<stdio.h>
#include<stdlib.h>

struct Node{
    int data;
    struct Node* next;
};
struct Node* createNode(int data){
    struct Node* newNode = (struct Node*)malloc(sizeof(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 || pos > n){
        newNode->next = head;
        return newNode;
    }

    struct Node* temp = head;
    for (int i = 0; i < pos - 1; i++){
        if (temp == NULL){
            printf("Invalid input\n"); 
            return head;
        }
        temp = temp->next;
    }
    if (temp == NULL) {
        printf("Invalid input\n");
        return head;
    }
    
    newNode->next = temp->next;
    temp->next = newNode;
    
    return head;
}

void printlist(struct Node*head){
    struct Node* temp = head;
    while (temp != NULL) {
        printf("%d ",temp->data);
        temp = temp->next;
    }
    printf("\n");
}
    
int main() {
    int n;
    (scanf("%d", &n));
    struct Node* head = NULL;
    struct Node* tail = NULL;
        
    for (int i = 0; i < n; i++) {
        int num;
        (scanf("%d", &num));
        struct Node* newNode = createNode(num);
        if (head == NULL) {
            head = newNode;
            tail = newNode;
        }
        else {
            tail->next = newNode;
            tail = newNode;
        }
    }
    int val, pos;
    scanf("%d", &val);
    scanf("%d", &pos);
    head = insertATPosition(head, pos, val);
    
    printlist(head);
    
    return 0;
}