#include
using namespace std;
class node{
public:
int data;
node*next;
node(int d){
data=d;
next=NULL;
}
};
void insertattail(nodehead,int d){
if(head==NULL){
head=new node(d);
return;
}
nodetail=head;
while(tail->next!=NULL){
tail=tail->next;
}
tail->next=new node(d);
return;
}
node* append(node &head,int k,int N){
node temp1=head;
while(temp1!=NULL){
temp1=temp1->next;
}
temp1->next=head;
int count=1;
while(count<=(N-k)){
head=head->next;
count++;
}
node*newhead=head->next;
head->next=NULL;
return newhead;
}
void print(nodenewhead){
nodetemp=newhead;
while(temp!=NULL){
cout<data<<" ";
temp=temp->next;
}
}
int main() {
int N,k,value;
cin>>N;
nodehead=NULL;
for(int i=0; i<N; i++){
cin>>value;
insertattail(head,value);
}
cin>>k;
nodenewhead=append(head,k,N);
print(newhead);
return 0;
}