Gondola Replacement
Time limit1sMemory limit256 MB
Given the n cars seen on a circular gondola line, find one possible order of breakdowns that explains the observed numbers.
Problem
A gondola line has cars numbered to moving on a circular track. After car passes the station, car passes next (and car follows car ). A broken car is replaced at the same spot by spare cars numbered , , and so on in order. A gondola sequence lists the car numbers seen at the station starting from some moment. A replacement sequence lists the original car numbers that broke, in breakdown order. Given a valid gondola sequence, output one replacement sequence that could produce it.
Input
The first line contains . The second line contains the gondola sequence of length .
Output
Print the length of the replacement sequence. If , print the sequence on the same line separated by spaces.
Constraints
- The input sequence is always a valid gondola sequence.