Given two permutations A and B of length N. You have to select an index x (1≤x≤N) and swap the values of Ax and Bx. Count the number of indices x that allows A and B to remain as permutations after swapping the index.
Note: A permutation of length N is a sequence of N integers from 1 to N such that each element appears exactly once in the sequence.
N A1 A2 … AN B1 B2 … BN
A single integer representing the number of indices such that A and B remain as permutations after swapping.
5
1 2 3 4 5
5 2 3 1 4
2
We can select indices 2 or 3, and both A and B will remain as permutations after swapping.
Subtask | Score |
---|---|
1 | 100 |