#include<stdio.h>
#include<stdlib.h>
struct Node {
    int data;
    struct Node* next;
};
struct Node* createNode(int value)   {
    struct Node* newNode =  (struct Node*)malloc(sizeof(struct Node));
    newNode->data = value;
    newNode->next = NULL;
    return newNode;
}
void printlist(struct Node* head) {
    struct Node* temp = head;
    while(temp != NULL){
        printf("%d ", temp->data);
        temp = temp->next;
    }
    printf("\n");
}
struct Node* insertAtPosition(struct Node* head, int value, int pos, int n) {
    if (pos < 1 || pos > n + 1) {
        printf("Invalid input\n");
        exit(0);
    }
    struct Node* newNode = createNode(value);
    if (pos == 1) {
        newNode->next = head;
        return newNode;
    }
    struct node* temp = head;
    for (int i = 1; i < pos - 1; i++) {
        temp = temp->next;
    }
    newNode->next = temp->next;
    temp->next = newNode;
    return head;
}
int main() {
    int n;
    scanf("%d", &n);
    if (n < 1 || n > 100) {
        printf("Invalid input\n");
        return 0;
    }
    struct Node* head = NULL;
    struct Node* tail = NULL;
    for (int i = 0; i < n; i++) {
        int value;
        scanf("%d", &value);
        struct Node* newNode = createNode(value);
        if (head == NULL) {
            head = tail = newNode;
        } else {
            tail->next = newNode;
            tail = newNode;
        }
    }
    int insertValue;
    scanf("%d", &insertValue);
    int pos;
    scanf("%d", &pos);
    head = insertAtPosition(head, insertValue, pos, n);
    printList(head);
    return 0;
}