Task
You oversee Internet-of-Things devices arranged on a ring consisting of residues. Device currently shows an integer phase with . Whenever you broadcast the instruction , all devices whose phase is exactly simultaneously advance to . You may choose your future broadcasts after observing the new phases. Your goal is to make every device show the same phase using as few broadcasts as possible.
Input data
The input file consists of:
- a line containing integers .
- a line containing the integers .
Output data
The output file must contain lines:
- a line containing integer : the minimum number of broadcasts required to synchronize all devices.
- a line containing integers describing an optimal sequence of broadcasts.
Constraints and clarifications
- .
- .
- for every .
- Note: any optimal sequence is accepted as long as the broadcasts are printed in the order they are performed.
| # | Score | Constraints |
|---|---|---|
| 1 | 0 | Examples |
| 2 | 10 | Either or . |
| 3 | 15 | . |
| 4 | 25 | . |
| 5 | 20 | Either every residue in appears or all occupied residues form one contiguous arc. |
| 6 | 30 | No additional limitations. |
Example 1
stdin
5 2
1 0 1 0 0
stdout
1
0
Explanation
In the first sample case, a single broadcast of residue synchronizes all devices, and broadcasting residue would also work.
Example 2
stdin
5 6
1 0 3 5 1
stdout
4
3 4 5 0
Explanation
In the second sample case, the broadcasts , , , sweep through all occupied residues and align every device at phase .
Example 3
stdin
4 4
3 3 3 3
stdout
0
Explanation
In the third sample case, every device already shows the same phase, so no broadcast is needed.