#include
using namespace std;
class Node{
public:
int data;
Node *next;
Node(int d)
{
data=d;
next=NULL;
}
};
void insertattail(Node *&head,int data)
{
if(head==NULL)
{
head=new Node(data);
return;
}
Node *temp=head;
while(temp->next!=NULL)
temp=temp->next;
Node *n=new Node(data);
temp->next=n;
n->next==NULL;
return;
}
void insertlist(Node * &head,int n)
{
int num;
while(n--)
{
cin>>num;
insertattail(head,num);
}
return;
}
int main()
{
int n;
cin>>n;
Node *head=NULL;
insertlist(head,n);
int k;
cin>>k;
Node *temp=head;
for(int i=1;i<n-k;i++)
temp=temp->next;
Node *head1=temp->next;
temp->next=NULL;
temp=head1;
for(int i=1;i<k;i++)
temp=temp->next;
temp->next=head;
while(head1!=NULL)
{
cout<<head1->data<<" ";
head1=head1->next;
}
}