Surely you have seen insane videos of South Korean rapper PSY, such as
“Gangnam Style”, “Gentleman” and “Daddy”. But you are unlikely to
know that right now PSY records new video “Oppa Funcan Style”!
It happens like this: on the ground there are n platforms, which are
numbered with integers from 1 to n, on i-th platform there is a
dancer with number i. Further, every second all the dancers, standing on
the platform with number i, jump to the platform with a number f(i).
The moving rule f is selected in advance and is not changed throughout
The duration of the clip is k seconds, but PSY wants more! If after k
seconds all dancers will be in their initial positions (i.e. i-th dancer
will stand on the platform with the number i), then the clip can be
looped and collect even more “likes”.
Some values of f(i) has been already determined due to the technical
limitations, but other values can be any one (except that the platform
with such number must exist).
Help PSY to blow up the Internet once again, choosing indefinite values of
f(i) in such a way that through k seconds all dancers will return to
their initial positions.
The first line contains integers n and k that are the number of
dancers in the clip and the duration of the clip in seconds (1 ≤ n ≤
35; 1 ≤ k ≤ 109).
The second line contains n integers f(i) determining the moving rule
for the platforms with numbers from 1 to n (0 ≤ f(i) ≤ n). If
f(i) = 0, then the rule for the platform i is indefinite.
Output “Yes” in the first line if you can choose suitable indefinite
values of f(i); otherwise output “No”. In the first case output the
required function in the second line in the same format as in the input
(but now all values must be defined). If the problem has several
solutions, output any of them.
1 2 3
1 2 3
0 0 0
1 2 3
2 2 2
Problem Author: Alexey Danilyuk
Problem Source: Ural FU Junior Championship 2016