#include <iostream>
using namespace std;

class node{
public:
    int data;
    node* next;
    
    //Constructor
    node(int d){
        data = d;
        next = NULL;
    }
};

void insertAtHead(node*&head,int data){
    node*n = new node(data);
    n->next = head;
    head = n;
}

int length(node*head){
    
    int len=0;
    while(head!=NULL){
        head = head->next;
        len += 1;
    }
    return len;
}

void insertAtTail(node*&head,int data){
    
    if(head==NULL){
        head = new node(data);
        return;
    }
    node*tail = head;
    while(tail->next!=NULL){
        tail = tail->next;
    }
    tail->next = new node(data);
    return;
}





void print(node*head){
    //node*temp = head;
    
    while(head!=NULL){
        cout<<head->data<<" ";
        head = head->next;
    }
    cout<<endl;
}

 

node* append(node* head , int k){

	int len = length(head) - k;;
	node* temp = head;
	int count=0;
	while(temp && count<len-1){
		temp=temp->next;
		count++;
	}
	
	//cout<<temp->data;
	node* prevKth = temp;
	//cout<<prevKth->data;
	
	node* kThNode = temp->next;
	//cout<<kThNode->data;
	temp = kThNode;
	 while(temp->next)
	  	temp=temp->next;
	
	//cout<<temp->data;
	  temp->next = head;
	  head = kThNode;
		
	prevKth->next = NULL;
	return head;
}

int main() {

	
		node*head1 = NULL;
		//node* head2 = NULL;
		int x=0;
		int n1 =0,k=0;
		cin>>n1;
		for(int i=0;i<n1;i++){
			cin>>x;
			insertAtTail(head1,x);
		}
		cin>>k;
		

	// print(head); 
		head1 = append(head1 , k);
		print(head1);
    return 0;
}