Given permutations A and B, find the minimum number of swaps within A that turn it into B.
You are given arrays AAA and BBB. Each one holds the numbers 111 through NNN exactly once, but the two orders may differ.
One operation swaps two numbers inside AAA.
Find the minimum number of operations that makes AAA equal to BBB.
Print on the first line the minimum number of operations that makes AAA equal to BBB.
For A=[1,4,2,3]A = [1, 4, 2, 3]A=[1,4,2,3] and B=[4,3,1,2]B = [4, 3, 1, 2]B=[4,3,1,2], swapping 111 with 444, then 222 with 333, then 111 with 333 turns AAA into BBB in three operations.
For A=[3,6,4,7,1,2,5]A = [3, 6, 4, 7, 1, 2, 5]A=[3,6,4,7,1,2,5] and B=[4,3,7,6,1,5,2]B = [4, 3, 7, 6, 1, 5, 2]B=[4,3,7,6,1,5,2], swapping 222 with 555, then 333 with 666, then 444 with 666, then 666 with 777 takes four operations.