{"raw_statement":[{"iden":"problem statement","content":"There is a directed graph with $N$ vertices and $N$ edges.  \nThe $i$\\-th edge goes from vertex $i$ to vertex $A_i$. (The constraints guarantee that $i \\neq A_i$.)  \nFind a directed cycle without the same vertex appearing multiple times.  \nIt can be shown that a solution exists under the constraints of this problem.\n\n#### Notes\n\nThe sequence of vertices $B = (B_1, B_2, \\dots, B_M)$ is called a directed cycle when all of the following conditions are satisfied:\n\n*   $M \\geq 2$\n*   The edge from vertex $B_i$ to vertex $B_{i+1}$ exists. $(1 \\leq i \\leq M-1)$\n*   The edge from vertex $B_M$ to vertex $B_1$ exists.\n*   If $i \\neq j$, then $B_i \\neq B_j$."},{"iden":"constraints","content":"*   All input values are integers.\n*   $2 \\le N \\le 2 \\times 10^5$\n*   $1 \\le A_i \\le N$\n*   $A_i \\neq i$"},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$\n$A_1$ $A_2$ $\\dots$ $A_N$"},{"iden":"sample input 1","content":"7\n6 7 2 1 3 4 5"},{"iden":"sample output 1","content":"4\n7 5 3 2\n\n$7 \\rightarrow 5 \\rightarrow 3 \\rightarrow 2 \\rightarrow 7$ is indeed a directed cycle.\nHere is the graph corresponding to this input:\n![image](https://img.atcoder.jp/abc311/0ab396c54e276edb27de02ad3b20cf7f.png)\nHere are other acceptable outputs:\n\n4\n2 7 5 3\n\n3\n4 1 6\n\nNote that the graph may not be connected."},{"iden":"sample input 2","content":"2\n2 1"},{"iden":"sample output 2","content":"2\n1 2\n\nThis case contains both of the edges $1 \\rightarrow 2$ and $2 \\rightarrow 1$.  \nIn this case, $1 \\rightarrow 2 \\rightarrow 1$ is indeed a directed cycle.\nHere is the graph corresponding to this input, where $1 \\leftrightarrow 2$ represents the existence of both $1 \\rightarrow 2$ and $2 \\rightarrow 1$:\n![image](https://img.atcoder.jp/abc311/97e8121c1e36bbcefae0b68e1b8fbfd2.png)"},{"iden":"sample input 3","content":"8\n3 7 4 7 3 3 8 2"},{"iden":"sample output 3","content":"3\n2 7 8\n\nHere is the graph corresponding to this input:\n![image](https://img.atcoder.jp/abc311/c31a7153e0ca36e8c0e1dd4c7bfe5329.png)"}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}