Олимпиадный тренинг

Задача 27021. "Coffins" from the 43rd


Задача

Темы:
At the informatics lesson, Anton Vitalievich asked me to come up with tasks for permutations. The guys in room 43 were very happy about this task and decided to come up with n coffins for their class. The complexity of each task – is a number from 1 to n. The guys want to know how, they "destroyed" contest, coefficient of "burrowing" (KZ) is considered as the number of the permutation that was submitted for input. The guys rejoice if the short circuit is greater than the sum of the differences between two consecutive elements in this permutation modulo multiplied by the number of coffins in the contest.
 
Output “positumque loculum” (coffin), if the guys are happy with their work, otherwise print the smallest suitable permutation (separate elements with spaces), whose number is |КЗ – current number| <= k, and if this is not possible, print “easily”.
 
The first line contains the number of coffins in the contest n <= 7 and k, 0 <= k <= n!
 
The second line introduces the permutation itself.
Enter Output
7 2518
7 5 2 4 1 6 3
positumque loculum
4 1
3 2 4 1
easily
4 2
3 2 4 1
3 4 2 1


Have a nice day ♥♥
(c) Elizabeth Yastreba