Fixed-point theorem

In the family of mathematical theorems called fixed-point, Brouwer studied one that, apparently, he explained with the analogy of stirring to dissolve sugar in a cup of coffee. Brouwer stated that at any moment, there is a point/molecule in the cup that didn’t change its place. We won’t study that theorem, but we are left with the idea that, when stirring a cup of coffee, molecules exchange their places to end up in a completely different spot of the cup. Let’s take a small example (in which the fixed-point theorem is not even ful- filled): molecule 1 could have occupied the spot that molecule 2 had before, molecule 2 gone to where molecule 3 was and, finally, molecule 3 moved to the original place of 1. If we were capable of replicating the same movement over and over again, a time would come in which the cup of coffee would go back to its original state: The question we ask ourselves is, given the description of the exchange of molecules we achieve with the motion in the cup of coffee, how many times do we have to repeat the movement so that the state of the cup goes back to being the same as the original? Input The input will consist of several test cases. Each of them consists of two lines, the first one containing the number of molecules in the cup of coffee (1 ≤ n ≤ 100) and the other one indicating the movement of molecules that will happen every time that the cup is stirred. The movement is defined by n integers indicating, for each position of one molecule, in which position it will end up the molecule that was occupying that place. The input finishes with an empty cup, which should not be processed. Output For each test case, write the number of times that the cup of coffee should be stirred so that each molecule goes back to the original place. It is ensured that this number won’t exceed 109.

2/2 Sample Input 3 123 3 231 4 2143 0 Sample Output 1 3 2