#include
using namespace std;
class node{
public:
int data;
node *next;
node(int d){
data=d;
next=0;
}
};
void insert_at_tail(node *&head,int data){
if(head==0){
head=new node(data);
return;
}
node *tail=head;
while(tail->next!=0){
tail=tail->next;
}
tail->next=new node(data);
return;
}
void print(node *head){
while(head->next!=0){
cout<<head->data<<" ";
head=head->next;
}
cout<<head->data<<endl;
}
void append(node *&head,int k,int n){
node *temp=head;
node *tail=head;
int i=1;
while(tail->next!=0){
tail=tail->next;
if(n-k>i){
temp=temp->next;
}
i++;
}
tail->next=head;
head=temp->next;
temp->next=0;
return;
}
int main(){
int n;
node *head=0;
cin>>n;
for(int i=0;i<n;i++){
int data;
cin>>data;
insert_at_tail(head,data);
}
int k;
cin>>k;
append(head,k,n);
print(head);
return 0;
}
