#include
using namespace std;
class node{
public:
node next;
int data;
node(int d){
next = NULL;
data=d;
}
};
void print(node&head){
node* temp= head;
while(temp->next!=NULL){
temp=temp->next;
cout<data<<" ";
}
}
void appendbyk(node*&head,int n,int k){
node *P = head;
node *C = head;
node *H = head;
node *temp = head;
int jumps = 1;
while(jumps<n-k){
temp=temp->next;
C=C->next;
jumps++;
}
C=C->next;
head=C;
while(P->next!=NULL){
P=P->next;
}
P->next = H;
// temp->next = NULL;
print(head);
}
void insertAtTail(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 buildList(node*&head,int n){
node temp = head;
int data =0;
while(n>0){
cin>>data;
insertAtTail(head,data);
nā;
}
}
int main() {
node head=NULL;
int n,k;
cin>>n;
buildList(head,n);
cin>>k;
appendbyk(head,n,k);
return 0;
}