// editor1
#include<stdio.h>
#include<stdlib.h>

struct Node {
    int data;
    struct Node* next;
};
void insertNode(struct Node** head_ref, int value, int pos) {
    if (pos <= 0) {
        printf("Invalid input");
        return n;
    }
    struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
    newNode->data = value;
    newNode->next = NULL;
    
    if (pos == 1) {
        newNode->next = *head_ref;
        *head_ref = newNode;
        return;
    }
    struct Node* temp = *head_ref;
    for (int i = 1; i < pos - 1 && temp != NULL; i++) {
        temp = temp->next;
    }
    if (temp == NULL) {
        printf("Invalid input");
        return n;
    }
    newNode->next = temp->next;
    temp->next = newNode;
}
void printlist(struct Node* node) {
    while (node != NULL) {
        printf("%d ", node->data);
        node = node->next;
    }
    printf(" ");
}
int main() {
    int n, value, pos;
    struct Node* head = NULL;
    struct Node* current = NULL;
    
    scanf("%d", &n);
    
    for(int i = 0; i < n; i++) {
        int data;
        scanf("%d ", &data);
        struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
        newNode->data = data;
        newNode->next = NULL;
        if (head == NULL) {
            head = newNode;
            current = head;
        }else{
            current->next = newNode;
            current = newNode;
        }
    }
    scanf("%d ", &value);
    scanf("%d ", &pos);
    
    insertNode(&head, value, pos);
    
    printlist(head);
    
    return 0;
}