#include <stdio.h>
#include <stdlib.h>
#include <ctype.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;
}
void printList(struct Node* head) 
{
    struct Node* temp = head;
    while (temp != NULL) 
    {
        printf("%d", temp->data);
        temp = temp->next;
        if (temp != NULL) printf(" ");
    }
}
void insertMiddle(struct Node **head, int val, int n) 
{
    struct Node* newNode = createNode(val);
    if (*head == NULL) 
    {
        *head = newNode;
        return;
    }
    int mid = k/ 2; 
    struct Node *temp = *head;
    for (int i = 0; i < mid - 1; i++) 
    {
        temp = temp->next;
    }
    if (n == 0) 
    { 
        *head = newNode;
        return;
    } 
    else if (mid == 0) 
    {
        newNode->next = *head;
        *head = newNode;
        return;
    }
    newNode->next = temp->next;
    temp->next = newNode;  
}
int main() 
{
    int k, val;
    if (scanf("%d", &k) != 1 || k < 0 || k> 1000) {
        
        printf("Invalid input");
        return 0;
    }
    struct Node* head = NULL;
    struct Node* tail = NULL;
    for (int i = 0; i < k; i++) 
    {
        int x;
        if (scanf("%d", &x) != 1) 
        {
            printf("Invalid input");
            return 0;
        }
        struct Node* newNode = createNode(x);
        if (head == NULL) 
        {
            head = tail = newNode;
        }
        else 
        {
            tail->next = newNode;
            tail = newNode;
        }
    }
    if (scanf("%d", &val) != 1) 
    {
        printf("Invalid input");
        return 0;
    }
    insertMiddle(&head, val, k);
    printList(head);
    return 0;
}