Farmer John has N cows (1≤N≤100), numbered 1 through N, standing in a row. Their current order is given by array A, where A(i) is the cow in position i. He wants a new order described by array B, where B(i) is the cow that should be in position i.
To go from order A to order B, the cows perform cyclic shifts. One cyclic shift starts when a cow moves to her target position in B, displacing another cow, who then moves to her target position, and so on, until a cow returns to the position where the shift began. The cows keep performing cyclic shifts until every cow is in her correct position in B. A cow that already occupies the same position in both A and B does not participate in a cyclic shift; every other cow participates in exactly one cyclic shift.
Compute the number of cyclic shifts and the length of the longest one.
From each position i, cow A(i) moves to the position where she belongs in B. Following these moves on positions forms cycles; a cycle of length 1 means the cow is already correct.