Sleepwalker
In the story "Comrades of San Rosario" by O. Henry, Major Thomas B. Kingman, the president of the First National Bank, developed an unusual habit of rearranging the contents of the safes in the same way every night, where clients store their valuables.
Write a program to determine after how many days all the valuables will first return to their original positions.
Input
The first line contains the number of safes, n, in the bank, which does not exceed 15500. Following this, starting from the second line, is a sequence of n distinct natural numbers ranging from 1 to n inclusive. The k-th element of this sequence indicates the number of the safe to which Major transfers the contents of the k-th safe on the first night.
Output
Output the number of days, in decimal notation, it takes for all the valuables to return to their original positions. The result will contain no more than 1000 digits.