#include<iostream>
using namespace std;
struct Node{
    int data;
    Node* next;
    Node(int data){
        this->data=data;
        this->next=nullptr;
    }
    
};
void insertatfirst(Node **head,int bookid1){
    Node* nn=new Node(bookid1);
    if(*head==NULL){
        *head=nn;
        return;
    }
    else{
        nn->next=*head;
        nn=*head;
        return;
    }
}
void insertatend(Node **head,int bookid2)
{
    Node* nn=new Node(bookid2);
    if(*head==NULL)
    {
        *head=nn;
    
    }
    else
    {
        Node* temp=*head;
        while(temp->next!=NULL)
        {
            temp=temp->next;
        }
        temp->next=nn;
    }
}
void insertatpos(Node **head,int bookid3,int pos)
{
    Node* nn=new Node(bookid3);
    if (pos==0){
        nn->next=*head;
        *head=nn;
    }
    Node* temp=*head;
    for(int i=0;temp!=nullptr&&i<pos-1;i++){
        temp=temp->next;
    }
    nn->next=temp->next;
    temp->next=nn;
}
//if(temp==pos-1)
//{
  //  nn->next=temp->next;
    //temp->next=nn;
//}

void display(Node **head){
    Node* temp=head;
    
    while(temp!=nullptr){
        cout<<temp->data<<" ";
        temp=temp->next;
    }
    return;
}
int main()
{
    int N;
    
    cin>>N;
    Node* head=nullptr;
    int bookid,bookid1,bookid2,bookid3,pos;
    int arr[bookid];
    for(int i=0;i<N;i++){
        cin>>arr[i];
    }
    for(int i=0;i<N;i++){
        insertatfirst(&head,arr[i]);
    }
    cin>>bookid1;
    cin>>bookid2;
    cin>>pos;
    cin>>bookid3;
    insertatfirst(&head,bookid1);
    insertatend(&head,bookid2);
    insertatpos(&head,pos,bookid3);
    display(&head);
    return 0;
}