#include <stdlib.h>
#include <string.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));
    if (!newNode) {
        exit(1);
    }
    newNode->data = data;
    newNode->next = NULL;
    return newNode;
}
int isNumeric(char* str) {
    if (str == NULL || *str == '\0') return 0;

    int i = 0;

    if (str[0] == '-') i = 1;  

    for (; str[i] != '\0' && str[i] != '\n'; i++) {
        if (!isdigit(str[i])) return 0;
    }
    return 1;
}

int main() {
    int n, val;
    char buffer[5000];

    if (!fgets(buffer, sizeof(buffer), stdin) || !isNumeric(buffer)) {
        printf("Invalid input\n");
        return 0;
    }
    n = atoi(buffer);

    if (!fgets(buffer, sizeof(buffer), stdin)) {
        printf("Invalid input\n");
        return 0;
    }

    char* token = strtok(buffer, " \n");
    struct Node* head = NULL;
    struct Node* tail = NULL;
    int count = 0;

    while (token != NULL && count < n) {
        if (!isNumeric(token)) {
            printf("Invalid input\n");
            return 0;
        }
        int value = atoi(token);
        struct Node* newNode = createNode(value);
        if (!head) {
            head = tail = newNode;
        } else {
            tail->next = newNode;
            tail = newNode;
        }
        token = strtok(NULL, " \n");
        count++;
    }

    if (count != n) {
        printf("Invalid input\n");
        return 0;
    }

    if (!fgets(buffer, sizeof(buffer), stdin) || !isNumeric(buffer)) {
        printf("Invalid input\n");
        return 0;
    }
    val = atoi(buffer);

  struct Node* newNode = createNode(val);

    if (!head) {
        head = newNode;
    } else {
        int mid = n / 2;
        struct Node* temp = head;

        if (mid == 0) {
            
            newNode->next = head;
            head = newNode;
        } else {
            
            int i;
            for (i = 1; i < mid; i++) {
                temp = temp->next;
            }
            
            newNode->next = temp->next;
            temp->next = newNode;
        }
    }

     while (curr) {
        printf("%d", curr->data);
        if (curr->next) printf(" ");
        curr = curr->next;
    }

    return 0;
}