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