Checker for Array Shuffling solution codeforces

Checker for Array Shuffling solution codeforces

 

oolimry has an array aa of length nn which he really likes. Today, you have changed his array to bb, a permutation of aa, to make him sad.

Because oolimry is only a duck, he can only perform the following operation to restore his array:

  • Choose two integers i,ji,j such that 1i,jn1≤i,j≤n.
  • Swap bibi and bjbj.

The sadness of the array bb is the minimum number of operations needed to transform bb into aa.

Given the arrays aa and bb, where bb is a permutation of aa, determine if bb has the maximum sadness over all permutations of aa.

ALSO READ:-   PermutationForces solution codeforces
Input

Each test contains multiple test cases. The first line contains a single integer tt (1t1041≤t≤104)  — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1n21051≤n≤2⋅105)  — the length of the array.

The second line of each test case contains nn integers a1,a2,,ana1,a2,…,an (1ain1≤ai≤n)  — the elements of the array aa.

The third line of each test case contains nn integers b1,b2,,bnb1,b2,…,bn (1bin1≤bi≤n)  — the elements of the array bb.

ALSO READ:-   Unequal Array solution codeforces

It is guaranteed that bb is a permutation of aa.

It is guaranteed that the sum of nn over all test cases does not exceed 21052⋅105.

Output

For each test case, print “AC” (without quotes) if bb has the maximum sadness over all permutations of aa, and “WA” (without quotes) otherwise.

Example
input

Copy
4
2
2 1
1 2
4
1 2 3 3
3 3 2 1
2
2 1
2 1
4
1 2 3 3
3 2 3 1
output

Copy
AC
AC
WA
WA
Note

In the first test case, the array [1,2][1,2] has sadness 11. We can transform [1,2][1,2] into [2,1][2,1] using one operation with (i,j)=(1,2)(i,j)=(1,2).

ALSO READ:-   [Ans] Maximum Total Beauty of the Gardens solution leetcode

In the second test case, the array [3,3,2,1][3,3,2,1] has sadness 22. We can transform [3,3,2,1][3,3,2,1] into [1,2,3,3][1,2,3,3] with two operations with (i,j)=(1,4)(i,j)=(1,4) and (i,j)=(2,3)(i,j)=(2,3) respectively.

In the third test case, the array [2,1][2,1] has sadness .

In the fourth test case, the array [3,2,3,1][3,2,3,1] has sadness 11.

ANSWER

Click Here

Leave a Comment