New entertainment
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Zenyk and Marichka have long been the owners of an array \(a\) of \(n\) positive integers, each ranging from 1 to \(k\). Today they got a permutation \(p\) of length \(k\), and instantly came up with a new game. It consists of \(n\) rounds, numbered from 1 to \(n\).
Each round looks as follows: first, Marichka quickly determines whether the permutation \(p\) appears in the array \(a\) as a subsequence. After that, Zenyk moves the first element of the array \(a\) to its end. Thus, after \(n\) rounds, the array \(a\) will return to its original state.
Zenyk and Marichka consider each round in which the permutation turns out to be a subsequence of the array to be successful. Your task is to find the numbers of all successful rounds.
Input
The first line contains two integers \(n\) and \(k\). The second line contains \(n\) integers — the array \(a\). The third line contains \(k\) integers — the permutation \(p\).
Output
In the first line, output a single number — the number of successful rounds. If this number is not equal to zero, then in the second line, output the numbers of all successful rounds in ascending order.
Constraints
\(1 \le k \le n \le 10^6\),
\(1 \le a_i, p_i \le k\),
all numbers from 1 to \(k\) appear in \(p\) exactly once.
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 6 3 1 2 3 1 2 3 3 2 1 | 4 2 3 5 6 |
| Input (stdin) | Output (stdout) |
|---|---|
| 7 4 1 3 1 2 4 4 3 1 4 2 3 | 0 |
| Input (stdin) | Output (stdout) |
|---|---|
| 4 4 2 1 4 3 3 2 1 4 | 1 4 |
Notes
A permutation of length \(k\) is a sequence of \(k\) numbers in which each number from 1 to \(k\) appears exactly once.
A subsequence of an array is a sequence of array elements left after removing some number (possibly 0) of array elements.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|