#include <stdio.h>
#include <stdlib.h>

struct Node {
    int data;
    struct Node* next;
};

int main() {
    int n;
    scanf("%d", &n);

    if (n < 0 || n > 100) {
        printf("Invalid input");
        return 0;
    }

    int arr[100];
    for (int i = 0; i < n; i++) {
        scanf("%d", &arr[i]);
        if (arr[i] <= 0) {
            printf("Invalid input");
            return 0;
        }
    }

    int valueToInsert;
    scanf("%d", &valueToInsert);
    if (valueToInsert <= 0) {
        printf("Invalid input");
        return 0;
    }

    struct Node* head = (struct Node*)malloc(sizeof(struct Node));
    head->data = valueToInsert;
    struct Node* temp = head;

    for (int i = 0; i < n; i++) {
        struct Node* newNode = (struct Node*)malloc(sizeof(struct Node));
        newNode->data = arr[i];
        temp->next = newNode;
        temp = newNode;
    }

    temp->next = head;

    struct Node* ptr = head;
    int first = 1;
    do {
        if (!first)
            printf(" ");
}
            printf("%d", ptr->data);
        first = 0;
        ptr = ptr->next;
    } while (ptr != head);
 printf("\n");
    return 0;
}