atcoder#ARC111C. [ARC111C] Too Heavy

[ARC111C] Too Heavy

Score : 600600 points

Problem Statement

There are NN people numbered 11 to NN and NN pieces of baggage numbered numbered 11 to NN. Person ii has a weight of aia_i, and Baggage jj has a weight of bjb_j. Initially, Person ii has Baggage pip_i. We want to do the operation below zero or more times so that each Person ii will have Baggage ii.

  • Choose i,j(ij)i,j (i \neq j), and swap the baggages of Person ii and Person jj.

However, when a person has a piece of baggage with a weight greater than or equal to his/her own weight, the person gets tired and becomes unable to take part in a future operation (that is, we cannot choose him/her as Person ii or jj). Particularly, if aibpia_i \leq b_{p_i}, Person ii cannot take part in any operation.

Determine whether there is a sequence of operations that achieves the objective, and if so, construct one such sequence with the minimum possible number of operations.

Constraints

  • 1N2000001 \leq N \leq 200000
  • 1ai,bi1091 \leq a_i,b_i \leq 10^9
  • pp is a permutation of 1,,N1, \ldots, N.
  • All numbers in input are integers.

Input

Input is given from Standard Input in the following format:

NN

a1a_1 a2a_2 \ldots aNa_N

b1b_1 b2b_2 \ldots bNb_N

p1p_1 p2p_2 \ldots pNp_N

Output

If no sequence of operations achieves the objective, print -1. Otherwise, print a sequence of operations in the following format:

KK

i1i_1 j1j_1

i2i_2 j2j_2

::

iKi_K jKj_K

Here, KK is the number of operations, and it,jti_t, j_t represent the people chosen in the tt-th operation.

If there are multiple solutions, any of them will be accepted.

4
3 4 8 6
5 3 1 3
3 4 2 1
3
3 4
1 3
4 2

Initially, People 1,2,3,41, 2, 3, 4 has pieces of baggage with weights 1,3,3,51, 3, 3, 5, respectively, so no one is tired.

First, we do the operation choosing Person 33 and 44. Now, people 1,2,3,41, 2, 3, 4 has pieces of baggage with weights 1,3,5,31, 3, 5, 3, so no one is tired yet.

Second, we do the operation choosing Person 11 and 33. Now, people 1,2,3,41, 2, 3, 4 has pieces of baggage with weights 5,3,1,35, 3, 1, 3, so Person 11 gets tired.

Lastly, we do the operation choosing Person 44 and 22. Now, people 1,2,3,41, 2, 3, 4 has pieces of baggage with weights 5,3,1,35, 3, 1, 3, so no one gets tired.

This sequence of operations has made everyone have the right piece of baggage, with the minimum possible number of operations, so it is valid.

4
1 2 3 4
4 3 2 1
4 3 2 1
-1

No sequence of operations achieves the objective.

1
58
998244353
1
0

The objective is already achieved in the initial state.