import java.util.Scanner;

class Node {
    int data;
    Node next;
    Node prev;

    Node(int data) {
        this.data = data;
        this.next = null;
        this.prev = null;
    }
}

class CircularLinkedList {
    Node head;

    // Adds a new node to the circular linked list
    void addNode(int data) {
        Node newNode = new Node(data);
        if (head == null) {
            head = newNode;
            head.next = head;
            head.prev = head;
        } else {
            Node tail = head.prev;
            tail.next = newNode;
            newNode.prev = tail;
            newNode.next = head;
            head.prev = newNode;
        }
    }

    // Rotate the list by k positions to the right
    void rotateList(int k) {
        if (head == null || k == 0) {
            return;
        }

        Node temp = head;
        int length = 0;
        // Calculate the length of the circular list
        do {
            length++;
            temp = temp.next;
        } while (temp != head);

        // If k is greater than the length, reduce it
        k = k % length;
        if (k == 0) return;

        // Find the new tail after k rotations
        Node newTail = head;
        for (int i = 1; i < length - k; i++) {
            newTail = newTail.next;
        }

        // Set the new head and update the circular links
        head = newTail.next;
        newTail.next = head;
        head.prev = newTail;
    }

    // Prints the last k elements of the list
    void printLastKElements(int k) {
        if (head == null || k <= 0) {
            System.out.println("Invalid input");
            return;
        }

        Node temp = head;
        int length = 0;
        do {
            length++;
            temp = temp.next;
        } while (temp != head);

        // If k is greater than the length, set k to the length
        k = Math.min(k, length);

        // Find the starting point of the last k elements
        Node start = head;
        for (int i = 1; i < length - k + 1; i++) {
            start = start.next;
        }

        // Print the last k elements
        Node current = start;
        for (int i = 0; i < k; i++) {
            System.out.print(current.data);
            if (i < k - 1) {
                System.out.print(" ");
            }
            current = current.next;
        }
        System.out.println();
    }
}

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        try {
            int numNodes = sc.nextInt();
            if (numNodes <= 0) {
                System.out.println("Invalid input");
                return;
            }

            CircularLinkedList circularList = new CircularLinkedList();
            for (int i = 0; i < numNodes; i++) {
                if (sc.hasNextInt()) {
                    circularList.addNode(sc.nextInt());
                } else {
                    throw new NoSuchElementException();
                }
            }

            int k = sc.nextInt();
            circularList.rotateList(k);  // Rotate the list by k positions
            circularList.printLastKElements(k);  // Print the last k elements

        } catch (NoSuchElementException | IllegalStateException e) {
            System.out.println("Invalid input");
        } finally {
            sc.close();
        }
    }
}
