310723: CF1876C. Autosynthesis

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

C. Autosynthesistime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Chaneka writes down an array $a$ of $n$ positive integer elements. Initially, all elements are not circled. In one operation, Chaneka can circle an element. It is possible to circle the same element more than once.

After doing all operations, Chaneka makes a sequence $r$ consisting of all uncircled elements of $a$ following the order of their indices.

Chaneka also makes another sequence $p$ such that its length is equal to the number of operations performed and $p_i$ is the index of the element that is circled in the $i$-th operation.

Chaneka wants to do several operations such that sequence $r$ is equal to sequence $p$. Help her achieve this, or report if it is impossible! Note that if there are multiple solutions, you can print any of them.

Input

The first line contains a single integer $n$ ($1 \leq n \leq 2\cdot10^5$) — the size of array $a$.

The second line contains $n$ integers $a_1,a_2,a_3,\ldots,a_n$ ($1\leq a_i\leq n$).

Output

A single line containing $-1$ if it is impossible.

Otherwise, the output consists of two lines. The first line contains an integer $z$ representing the number of operations performed. The second line contains $z$ integers, the $i$-th integer represents the index of the element circled in the $i$-th operation. If there are multiple solutions, you can print any of them.

ExamplesInput
5
3 4 2 2 3
Output
3
3 2 3
Input
3
1 2 3
Output
-1
Note

In the first example, doing the operations like the example output gives the following results:

  • Element $a_2$ gets circled $1$ time.
  • Element $a_3$ gets circled $2$ times.
  • The uncircled elements (ordered by their indices) are $a_1$, $a_4$, and $a_5$. So $r=[3,2,3]$.
  • $p=[3,2,3]$

Therefore, $r=p$.

In the second example, it is impossible.

Output

题目大意:
Chaneka 写下一个由 n 个正整数元素组成的数组 a。最初,所有元素都没有被圈出。每次操作中,Chaneka 可以圈出一个元素,同一个元素可以被圈出多次。

在完成所有操作后,Chaneka 会得到一个序列 r,它由数组 a 中所有未圈出的元素组成,按照它们的索引顺序排列。

Chaneka 还会得到另一个序列 p,其长度等于执行的操作次数,p_i 是第 i 次操作中圈出的元素的索引。

Chaneka 想要执行几次操作,使得序列 r 等于序列 p。帮助她实现这一点,或者报告如果不可能实现的情况。注意,如果有多个解决方案,您可以输出其中任何一个。

输入输出数据格式:
输入:
- 第一行包含一个整数 n(1 ≤ n ≤ 2·10^5),表示数组 a 的大小。
- 第二行包含 n 个整数 a_1, a_2, a_3, …, a_n(1 ≤ a_i ≤ n)。

输出:
- 如果不可能实现,输出一行包含 -1。
- 否则,输出两行。第一行包含一个整数 z,表示执行的操作次数。第二行包含 z 个整数,第 i 个整数表示第 i 次操作中圈出的元素的索引。如果有多个解决方案,您可以输出其中任何一个。

示例:
输入:
```
5
3 4 2 2 3
```
输出:
```
3
3 2 3
```
解释:按照输出示例进行操作,得到未圈出的元素序列 r=[3,2,3],操作序列 p 也为 [3,2,3],因此 r=p。

输入:
```
3
1 2 3
```
输出:
```
-1
```
解释:在这种情况下,无法通过任何操作使得序列 r 等于序列 p。题目大意: Chaneka 写下一个由 n 个正整数元素组成的数组 a。最初,所有元素都没有被圈出。每次操作中,Chaneka 可以圈出一个元素,同一个元素可以被圈出多次。 在完成所有操作后,Chaneka 会得到一个序列 r,它由数组 a 中所有未圈出的元素组成,按照它们的索引顺序排列。 Chaneka 还会得到另一个序列 p,其长度等于执行的操作次数,p_i 是第 i 次操作中圈出的元素的索引。 Chaneka 想要执行几次操作,使得序列 r 等于序列 p。帮助她实现这一点,或者报告如果不可能实现的情况。注意,如果有多个解决方案,您可以输出其中任何一个。 输入输出数据格式: 输入: - 第一行包含一个整数 n(1 ≤ n ≤ 2·10^5),表示数组 a 的大小。 - 第二行包含 n 个整数 a_1, a_2, a_3, …, a_n(1 ≤ a_i ≤ n)。 输出: - 如果不可能实现,输出一行包含 -1。 - 否则,输出两行。第一行包含一个整数 z,表示执行的操作次数。第二行包含 z 个整数,第 i 个整数表示第 i 次操作中圈出的元素的索引。如果有多个解决方案,您可以输出其中任何一个。 示例: 输入: ``` 5 3 4 2 2 3 ``` 输出: ``` 3 3 2 3 ``` 解释:按照输出示例进行操作,得到未圈出的元素序列 r=[3,2,3],操作序列 p 也为 [3,2,3],因此 r=p。 输入: ``` 3 1 2 3 ``` 输出: ``` -1 ``` 解释:在这种情况下,无法通过任何操作使得序列 r 等于序列 p。

加入题单

上一题 下一题 算法标签: