#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 value, int pos, int n){
    if(pos < 1 || pos > n + 1){
        printf("Invalid input");
        return NULL;
    }
    struct Node* newNode = createNode(value);
    if(pos == 1){
        newNode->next = head;
        head = newNode;
        return head;
    }
    struct Node*temp = head;
    for(int i = 1; i < pos - 1 && temp != NULL; i++){
        temp = temp->next;
    }
    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);
        if(temp->next != NULL)
            printf(" ");
        temp = temp->next;
    }
}
int main(){
    int n, value, pos;
    if(!(scanf("%d", &num)) || n < 1 || n > 100){
        printf("Invalid input");
        return 0;
    }
    struct Node* head = NULL;
    struct Node* tail = NULL;
    int num;
    for(int i=0; i<n; i++){
        if(!(scanf("%d", &num))  || num < 0 || num > 1000)
        {
            printf("Invalid input");
            return 0;
        }
        struct Node* newNode = createNode(num);
        if(head == NULL)
            head = tail = newNode;
        else{
            tail->next = newNode;
            tail = newNode;
        }
    }
    if(!(scanf("%d", &num)) || pos < 0 || pos > n + 1){
        printf("Invalid input");
        return 0;
    }
    struct Node* updatedHead = insertAtPosition(head, value, pos, n);
    if(updatedHead == NULL && (pos < 1 || pos > n + 1))
        return 0;
    printList(updatedHead);
    return 0;
}