Under construction

Still being built. Things may change

Selecting Numbers

Interview

Time limit1sMemory limit128 MB

Summary
Given a functional graph i->A_i on 1..N, find the maximum set of indices closed under this mapping (union of cycles) and print it.
Level

Medium4 of 10

Topics
Graph, Array, Implementation
Solved
No attempts yet

Problem

There is a table with 2 rows and N columns. The first row contains the integers from 1 to N in order. In the i-th cell of the second row, there is an integer A_i between 1 and N.

Choose some integers from the first row and let them form a set S. The values A_i directly below the chosen integers form another set T. The choice is valid when S and T are the same set.

Find a valid choice with maximum |S|, and output the chosen integers.

Input

The first line contains an integer N (1 <= N <= 100). The next N lines contain A_1, A_2, ..., A_N in order, one integer per line. Each A_i is between 1 and N.

Output

Print the number of chosen integers on the first line. Then print the chosen integers in increasing order, one per line.

Examples1

  1. Example 1

    Input
    7
    3
    1
    1
    5
    5
    4
    6
    
    Expected output
    3
    1
    3
    5