Outsider, You!
Time limit2sMemory limit512 MB
Given N and M, decide whether Junseo's motion can end up at seat M after a sequence of pointings, and if so, print one such pointing sequence.
- Level
Hard8 of 10
- Topics
- Simulation, Math, Implementation
- Solved
- No attempts yet
Problem
Junseo cannot hold his liquor well. But as the president of a study club, he cannot avoid the drinking games at the freshmen orientation. If he cannot drink, he can just make the others drink more! After much thought, Junseo prepared a very difficult drinking game to trick the freshmen.
Junseo and freshmen sit in a circle and start the drinking game. Seats are numbered 1 to clockwise. Junseo always sits in seat 1. At the start, each person picks a unique motion.
The drinking game proceeds as follows.
- Junseo starts the game by taking his own motion.
- He points at one of the people other than himself.
- The two people to the left of the pointed person swap motions.
- The two people to the right of the pointed person also swap motions.
- The pointed person takes the motion they believe they have.
- If the motion the pointed person has differs from the motion they took, the game ends and they drink a penalty drink.
- If they match, the pointed person points at another person and the game continues.
- Repeat steps 3 to 7.
The freshmen did not fall for it. Junseo, who expected to trap them, had no choice but to panic. Contrary to his expectation, the game keeps going smoothly despite the insane difficulty and never ends. Just when Junseo began to feel faint, he noticed that at some point the motion arrangement became the same circular permutation as the start.

Two arrangements are the same circular permutation if they match after rotation, as shown in <Figure 1>.
Did the freshmen collude and let wrong motions slide? Junseo, drunk, cannot remember every move of the game, but he at least wants to check whether the current motion arrangement can be produced without any cheating.
Input
The number of people playing the game and the seat number of the person who originally held the motion Junseo currently has are given in that order.
Output
Because the game cannot run forever with Junseo's stamina, if the arrangement is impossible within 1,000,000 pointings, print "NO".
If the arrangement is possible, print "YES" on the first line. On the second line, print the number of pointings needed to reach the current arrangement from the start. On the third line, print the seat numbers of the people who were pointed at, in order, separated by spaces.