{"problem":{"name":"Arrangement","description":{"content":"Niwango has $N$ cards, numbered $1,2,\\ldots,N$. He will now arrange these cards in a row. Niwango wants to know if there is a way to arrange the cards while satisfying all the $N$ conditions below. To","description_type":"Markdown"},"platform":"AtCoder","limit":{"time_limit":2525,"memory_limit":262144},"difficulty":"None","is_remote":true,"is_sync":true,"sync_url":null,"sign":"dwacon6th_prelims_d"},"statements":[{"statement_type":"Markdown","content":"Niwango has $N$ cards, numbered $1,2,\\ldots,N$. He will now arrange these cards in a row.\nNiwango wants to know if there is a way to arrange the cards while satisfying all the $N$ conditions below. To help him, determine whether such a way exists. If the answer is yes, also find the lexicographically smallest such arrangement.\n\n*   To the immediate right of Card $1$ (if any) is NOT Card $a_1$.\n*   To the immediate right of Card $2$ (if any) is NOT Card $a_2$.\n*   $\\vdots$\n*   To the immediate right of Card $N$ (if any) is NOT Card $a_N$.\n\n## Constraints\n\n*   $2 \\leq N \\leq 10^{5}$\n*   $1 \\leq a_i \\leq N$\n*   $a_i \\neq i$\n\n## Input\n\nInput is given from Standard Input in the following format:\n\n$N$\n$a_1$ $a_2$ $\\ldots$ $a_N$\n\n[samples]","is_translate":false,"language":"English"}],"meta":{"iden":"dwacon6th_prelims_d","tags":[],"sample_group":[["4\n2 3 4 1","1 3 2 4\n\n*   The arrangement $(1,2,3,4)$ is lexicographically smaller than $(1,3,2,4)$, but is invalid, since it violates the condition \"to the immediate right of Card $1$ is not Card $2$.\""],["2\n2 1","\\-1\n\n*   If no arrangements satisfy the conditions, print `-1`."],["13\n2 3 4 5 6 7 8 9 10 11 12 13 12","1 3 2 4 6 5 7 9 8 10 12 11 13"]],"created_at":"2026-03-03 11:01:14"}}