// editor1
#include<stdio.h>
#include<stdlib.h>
struct node{
    int data;
    struct node *prev;
    struct node *next;
}nd;
nd *head=NULL;
void create(int num){
    nd *newnode=(nd*)malloc(1*sizeof(nd));
    newnode->data=num;
    newnode->next=NULL;
    newnode->prev=NULL;
if(head==NULL){
    newnode->next=newnode;
    newnode->prev=newnode;
    head=newnode;
}else{
    nd *last=head->prev;
    newnode->prev=last;
    newnode->next=head;
    last->next=newnode;
    head->prev=newnode;
}
}
void insert(int x){
    create(x);
    head=head->next;
}
void insert(int x){
  if(head==NULL){
      return ;
      nd *temp=head;
      do{
          printf("%d",temp->data);
          temp=temp->prev;
      }while(temp!=head);
  }
int main(){
    int n,val,x;
    scanf("%d",&n);
    if(n<=0)
{
    printf("Invalid input");
    return 0;
}
for(int i=0;i<n;i++){
    scanf("%d",&val);
    create(val);
}
scanf("%d",&x);
insert(x);
return 0;
}