Algebra
Time limit1sMemory limit128 MB
Decide whether a target permutation can be reached from the identity using only rotations of three distinct positions.
Problem
The little math students have a hard time with algebraic structures, so the kindergarten decided to practice operations on permutations. To give the exercise some content, the teachers defined an unusual operation, the triangular operation.
A triangular operation takes three parameters , , , and the three are pairwise different (, , ). Applying it to a permutation moves the number at position to position , the number at position to position , and the number at position to position .
The identity permutation is the permutation that holds the number at position . The students have to decide whether the identity permutation can be turned into a given permutation by applying triangular operations repeatedly. You write the program that checks their answer.
Input
The input consists of several blocks. The first line of each block holds the number of elements of the permutation (). The second line holds pairwise distinct integers from to , and that sequence is the target permutation.
The last line of the input holds a single . Do not process that line.
Output
Print one line for each block. Print Permutaci lze prevest. if the given permutation can be obtained from the identity permutation by a sequence of triangular operations, and print Matfyzacci maji smulu. if it cannot.