Dishes

5

1 votes
Medium
Problem

Lucas wants to surprise his family with a fabulous dinner to demonstrate that he is independent and well organized boy. He knows that each familiar only will eat his favorite food, so Lucas has the plates enumerated according to each familiar (1,2,3,4..D) , but he has a problem. Marco, his little brother wants to make the dinner more difficult, he proposes to change the dishes of Luke given to sequence of movements and challenge his big bro to repeat the same sequence of movements until the dishes return the original position.

Help Lucas to calculate the times that he must repeat the movements to return the dishes to the original position.

Input

There are several test cases, each one contains two lines, the first one the numbers of dishes ( 1D105 ) and the second line contains D integers with the order of the dishes doing the movement of Marco.

Output

For each case print the number of times that Lucas must repeat the movements to return the dishes to the original position.

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?