There are few airlines that don't specify seat numbers before boarding. Instead, each passenger gets a ticket containing a unique integer in the range from to , where indicates the total number of seats in the airplane. Each ticket number belongs to a specified zone. Suppose a zone contains tickets, then tickets with numbers from to are in zone ; tickets with numbers from k+1 to are in zone and so on. The last zone may contain less than tickets if is not divisible by .
Before boarding, all the passengers line up randomly in a straight line. In order to expedite the boarding process, it is convenient that the first passengers in the line belong to zone , the next in zone and so on. There are two ways of rearranging the positions of the passengers.
Adjacent passengers keep swapping places until the required order is accomplished. Every second, only one pair of adjacent passengers can swap their places.
All the passengers walk simultaneously towards their correct positions. To walk from position to position , it takes |x-y| seconds. |x-y| is the absolute difference of and .
As you can guess, the first approach takes more time, but it's less 'noisy'. For this problem, you have to determine how much faster the nd approach is. More specifically, suppose the minimum time required to rearrange the passengers using the first approach is and the minimum time for the second approach is , you have to find X - Y.
As an example, consider a plane of capacity (n = 10) and zones of size (k = 3). Suppose the passengers line up in the following order
3~7~1~2~4~6~5~8~10~9
Each integer represents the ticket number of the corresponding passenger. So, for the above example, the first passenger in the line has a ticket with number . Passengers with ticket numbers , , , and are not in their right positions.
Using the first strategy, it'd take a minimum of swaps (and hence seconds) to achieve the desired order.
I. swap with 3~1~7~2~4~6~5~8~10~9
II. swap with 3~1~2~7~4~6~5~8~10~9
III. swap with 3~1~2~4~7~6~5~8~10~9
IV. swap with 3~1~2~4~6~7~5~8~10~9
V. swap with 3~1~2~4~6~5~7~8~10~9
VI. swap with 3~1~2~4~6~5~7~8~9~10 (now everyone is where they are supposed to be)
Using the second strategy, it'd take a minimum time of seconds if we decide the final order to be (3~2~1~4~6~5~7~8~9~10). Here passengers with ticket , and are already in their right positions; it takes second for passengers with tickets , , , and to get to their right positions; it takes seconds for passenger with ticket to come to her final position; it takes seconds for passenger with ticket to get to her right position. So this means, after seconds, everyone will be at their right places using the nd strategy. There are other arrangements for which we get seconds, but it's not possible to come up with something less.
So nd strategy is second faster.
The first line of input is an integer (T < 50) that indicates the number of test cases. Each case consists of lines. The first line contains positive integers (n \leq 20000) and (k \leq n). The meanings of these variables are mentioned above. The next line contains distinct integers in the range from to . The first integer represents the ticket number of the passenger standing in front of the queue.
For each case, first output the case number followed by the required result (i.e. how much faster the nd approach is).
Örnek 1