#include <stdio.h>
#include <stdlib.h>
struct Node 
{
    int data;
    struct Node *next;
    struct Node *prev;
};
struct Node* newNode(int data) 
{
    struct Node* node = (struct Node*) malloc(sizeof(struct Node));
    node->data = data;
    node->next = NULL;
    node->prev = NULL;
    return node;
}
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 o;
    scanf("%d", &o);
    struct Node *head = NULL, *tail = NULL;
    for (int i = 0; i < o; i++) 
    {
        int v;
        scanf("%d", &v);
        struct Node *node = newNode(v);
        if (head == NULL) 
        {
            head = tail = node;
        } 
        else 
        {
            tail->next = node;
            node->prev = tail;
            tail = node;
        }
    }
    int p, value;
    scanf("%d", &p);
    scanf("%d", &value);
    if (p < 0 || p > o) 
    {  
        printf("Invalid input");
        return 0;
    }
    struct Node *node = newNode(value);
    if (p == 0) 
    {
        node->next = head; 
        if (head != NULL)
            head->prev = node;
        head = node;
        if (tail == NULL) tail = node;  
    }
    else if (p == n) 
    {
        tail->next = node;
        node->prev = tail;
        tail = node;
    }
    else 
    {
        struct Node *current = head;
        for (int i = 0; i < p; i++) 
        {
            current = current->next;
        }
        node->next = current;      
        node->prev = current->prev;
        current->prev->next = node;
        current->prev = node;
    }
    printList(head);
    return 0;
}