P1826 Monkey King Selection: Further Strengthened Testdata Version

Description

There are $n$ monkeys standing in a circle, numbered clockwise as $1, 2, 3, \cdots, n$. Starting from the first monkey, repeatedly perform the following: count exactly $m$ monkeys clockwise, make that monkey leave the circle, then start counting again from the next monkey. Continue this process until only one monkey remains. The last remaining monkey is the winner of the game. Now, for $n = a, a + 1, \cdots, b$, determine which monkey ID becomes the winner the most times, and output its ID. If multiple monkeys tie for the most wins, output their IDs in increasing order.

Input Format

A single line containing three numbers $a, b, m$, as described.

Output Format

Output two lines. The first line outputs the maximum number of wins among all monkeys. The second line outputs several numbers, which are the monkeys' IDs.

Explanation/Hint

### Sample Explanation | $n=$ | $1$ | $2$ | $3$ | $4$ | $5$ | $6$ | $7$ | $8$ | $9$ | $10$ | | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | :-: | | Winner ID | $1$ | $2$ | $2$ | $1$ | $4$ | $1$ | $4$ | $7$ | $1$ | $4$ | Therefore, monkey $1$ has the most wins, with $4$ wins. ### Constraints For $100\%$ of the testdata, it is guaranteed that $1 \leq a \leq b \leq 10^6$, $m \leq 3000$. Translated by ChatGPT 5