#include <bits/stdc++.h>
using namespace std;
class node{
public:
int data;
node* next;
node(int data){
this->data=data;
this->next=NULL;
}
};
void insertathead(node* &head,int data){
node* temp=new node(data);
temp->next=head;
head=temp;
}
node* gettail(node* tail){
while(tail->next){
tail=tail->next;
}
return tail;
}
void insertattail(node* &head,int data){
if(head==NULL){
insertathead(head,data);
return;
}
node* tail=gettail(head);
node* n=new node(data);
tail->next=n;
tail=n;
return ;
}
void printlist(node* head){
while(head!=NULL){
cout<<head->data<<" ";
head=head->next;
}
cout<<endl;
}
void kappend(node* &head,int k){
node* slow=head;
node* fast=head;
for(int i=0;i<k;i++){
fast=fast->next;
}
while(fast->next!=NULL && fast!=NULL){
fast=fast->next;
slow=slow->next;
}
fast->next=head;
head=slow->next;
slow->next=NULL;
}
int main() {
node *head=NULL;
int n;
cin>>n;
int now=n;
while(nā){
int data;
cin>>data;
insertattail(head,data);
}
int k;
cin>>k;
kappend(head,k);
printlist(head);
return 0;
}