# Jaguar King

In a deep forest, a war is going to begin. Like other animals, the jaguars are preparing for this ultimate battle. Though they are mighty strong and lightening fast, they have an extra advantage over other animals. Its their wise and brave king, the Jaguar King. The king knows that only speed and strength is not enough for winning the war. They have to make a perfect formation. The king has set up a nice formation and placed all the Jaguar Warriors according to that forma- tion. There are N positions for N jaguar war- riors (including the king). The king is marked by 1 and the other jaguar warriors are marked by a number from 2 to N. The warriors are placed according to their number. But then the king realizes that to make the formation perfect and effective, some positions should have stronger jaguars and some should have faster jaguars. Since the strength and speed of all the jaguars are not equal, the king decided to change the positions of some jaguars. The wise king knows the ability of each and every jaguar, so his decision is perfect but the problem is how to change the jaguars. One of the wise jaguars has given an idea. The idea is simple. All the jaguars will wait for the king’s signal, all eyes upon the king. Suppose the king is in the ith position. The king jumps to jth position and when the jaguar at jth position sees the king coming, he immediately jumps to ith position. The king repeats this procedure until they are formatted like the new formation. Now there is another problem. Collision can occur while jumping. So, some wise jaguars have made a jumping scheme so that no collision can occur. The scheme is noted below: If the king is in the ith position If (i % 4 = 1) The king can jump to position (i+1), (i+3), (i+4), (i-4) If (i % 4 = 2) The king can jump to position (i+1), (i-1), (i+4), (i-4) If (i % 4 = 3) The king can jump to position (i+1), (i-1), (i+4), (i-4) If (i % 4 = 0) The king can jump to position (i-3), (i-1), (i+4), (i-4) Any position is valid if it lies in between 1 and N. Actually the king can jump much higher between these positions so, no collision can occur. Now you are one of the prisoners (actually they kept you to eat after the war). You have got a chance to get out alive. You know all their ideas and the new formation. If you can tell the king the minimum number of times the king has to jump to gain the new formation, they could be generous and release you.

2/2 Input The input file contains several sets of inputs. The total number of sets will be less than 50. The description of each set is given below: Each set starts with one integer N (4 ≤ N ≤ 40) which indicates the total number of jaguar warriors. You can assume that N is multiple of 4. The next line will contain N numbers which indicates the final formation of the jaguars. Consecutive numbers will be separated by a single space. The input will be terminated by the set where N = 0. And this set should not be processed. Output For each set in the input, you should first print the set number starting from 1. And the next line should be the minimum number of times the king has to jump to gain the new formation. Check the sample input-output for more details. Output should be formatted like the sample output. Hope you get out alive. Sample Input 4 1234 4 4231 8 52348671 8 52836714 0 Sample Output Set 1: 0 Set 2: 1 Set 3: 2 Set 4: 7