Reordering the Cows

No attempts yetTime limit1sMemory limit128 MB

Problem

Farmer John has NN cows (1N1001 \le N \le 100), numbered 11 through NN, standing in a row. Their current order is given by array AA, where A(i)A(i) is the cow in position ii. He wants a new order described by array BB, where B(i)B(i) is the cow that should be in position ii.

To go from order AA to order BB, the cows perform cyclic shifts. One cyclic shift starts when a cow moves to her target position in BB, 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 BB. A cow that already occupies the same position in both AA and BB 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.

Input

  • Line 1: integer NN
  • Lines 2 through N+1N+1: A(1)A(1) through A(N)A(N)
  • Lines N+2N+2 through 2N+12N+1: B(1)B(1) through B(N)B(N)

Output

  • Line 1: two space-separated integers, the number of cyclic shifts and the length of the longest cyclic shift. If there are no cyclic shifts, print 1-1 for the second number.

Hint

From each position ii, cow A(i)A(i) moves to the position where she belongs in BB. Following these moves on positions forms cycles; a cycle of length 11 means the cow is already correct.