11741번 - Generators스페셜 저지

시간 제한

메모리 제한

제출

정답

맞은 사람

정답 비율

1 초

256 MB

60

16

15

25.424%

문제

Little Roman is studying linear congruential generators — one of the oldest and best known pseudorandom number generator algorithms. Linear congruential generator (LCG) starts with a non-negative integer number x0 also known as seed and produces an infinite sequence of non-negative integer numbers xi (0 ≤ xi < c) which are given by the following recurrence relation:

xi+1 = (axi + b) mod c

here a, b, and c are non-negative integer numbers and 0 ≤ x0 < c.

Roman is curious about relations between sequences generated by different LCGs. In particular, he has n different LCGs with parameters a(j), b(j), and c(j) for 1 ≤ j ≤ n, where the j-th LCG is generating a sequence xi(j). He wants to pick one number from each of the sequences generated by each LCG so that the sum of the numbers is the maximum one, but is not divisible by the given integer number k.

출력

If Roman’s problem has a solution, then write on the first line of the output file a single integer s — the maximum sum not divisible by k, followed on the next line by n integer numbers tj (0 ≤ tj ≤ 109) specifying some solution with this sum.