import java.util.*;

class Node {
    int data;
    Node next;
    Node(int data) {
        this.data = data;
        this.next = null;
    }
}

public class Main {

    // Detect and remove cycle using Floyd’s algorithm
    static boolean detectAndRemoveCycle(Node head) {
        if (head == null || head.next == null)
            return false;

        Node slow = head, fast = head;

        // Step 1: Detect cycle
        while (fast != null && fast.next != null) {
            slow = slow.next;
            fast = fast.next.next;
            if (slow == fast) {
                removeCycle(head, slow);
                return true;
            }
        }
        return false;
    }

    // Step 2: Remove the cycle
    static void removeCycle(Node head, Node meet) {
        Node start = head;
        while (start.next != meet.next) {
            start = start.next;
            meet = meet.next;
        }
        meet.next = null; // Break the cycle
    }

    // Print linked list
    static void printList(Node head) {
        Node temp = head;
        while (temp != null) {
            System.out.print(temp.data + " ");
            temp = temp.next;
        }
        System.out.println();
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();

        if (n < 0) {
            System.out.println("Invalid input");
            return;
        }

        if (n == 0) {
            System.out.println("No cycle is present");
            return;
        }

        Node head = null, tail = null;
        Node[] nodes = new Node[n];

        // Create linked list
        for (int i = 0; i < n; i++) {
            int val = sc.nextInt();
            nodes[i] = new Node(val);
            if (head == null) {
                head = nodes[i];
                tail = nodes[i];
            } else {
                tail.next = nodes[i];
                tail = nodes[i];
            }
        }

        // Take extra input: cycle connection position
        int pos = sc.nextInt();

        // Create cycle if pos > 0
        if (pos > 0 && pos <= n) {
            tail.next = nodes[pos - 1];
        }

        boolean hasCycle = detectAndRemoveCycle(head);

        if (hasCycle) {
            printList(head);
        } else {
            System.out.println("No cycle is present");
        }
    }
}
