#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(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){
        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 input\n"); 
        free(newNode);
        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 = new
        } else {
            tail->next = newNode;
            tail = newNode;
        }
    }
    int val, pos;
    scanf("%d %d", &val, &pos);
    
    if(pos < 0 || pos > n) {
        printf("Inavalid input\n");
        return 0;
    }
    head = insertATPosition(head, pos, val);
    
    printlist(head);
    
    struct Node* temp;
    while (head !=NULL) {
        temp = head;
        head = head->next;
        free(temp);
    }
    return 0;
}