#include
using namespace std;
class node{
public:
int data;
node* next;
node(int d){
data=d;
next=NULL;
}
};
void addattail(node* &head,int data){
if(head==NULL){
head=new node(data);
return;
}
node* temp=head;
while(temp->next!=NULL){
temp=temp->next;
}
temp->next=new node(data);
return;
}
void formlist(node* &head,int n){
int data;
while(n!=0){
cin>>data;
addattail(head,data);
n–;
}
return;
}
void print(node* head){
node* temp=head;
while(temp!=NULL){
cout<data<<" ";
temp=temp->next;
}
cout<<endl;
}
void appendktofront(node* &head,int k){
node* slow=head;
node* fast=head;
while(k!=0){
fast=fast->next;
k–;
}
while(fast->next!=NULL){
fast=fast->next;
slow=slow->next;
}
fast->next=head;
node* temp=slow->next;
slow->next=NULL;
head=temp;
return;
}
int main() {
int n;
cin>>n;
node* head;
formlist(head,n);
int k;
cin>>k;
appendktofront(head,k);
print(head);
return 0;
}