PivotOJ

Exchange Students

시간 제한: 4000ms메모리 제한: 1024MB출처: NWERC 2021BOJ 23771

문제

A group of nn exchange students at Reykjavik University is lining up to get their group photo taken. From left to right, the heights of the students are g1,g2,,gng_1, g_2, \ldots, g_n. However, the photographer would like to rearrange the students such that the order of their heights becomes h1,h2,,hnh_1, h_2, \ldots, h_n. In order to do this, the photographer will repeatedly exchange two exchange students. Two exchange students can only be exchanged if they can see each other, that is, if every student in between them has strictly smaller height than the two students to be exchanged.

Determine the minimum number of exchanges needed to arrange the students in the photographer's preferred order, and find a suitable sequence of exchanges of this minimal length. The photographer only has time for at most 21052\cdot 10^5 exchanges. If more are needed, you only need to determine the first 21052\cdot 10^5 exchanges.

입력

The input consists of:

  • One line with an integer nn (1n31051\leq n \leq 3\cdot 10^5), the number of students.
  • One line with nn integers g1,g2,,gng_1, g_2, \ldots, g_n (1gi1091\leq g_i\leq 10^9), the heights of the students.
  • One line with nn integers h1,h2,,hnh_1, h_2, \ldots, h_n (1hi1091\leq h_i\leq 10^9), the order of heights the photographer prefers.

It is guaranteed that (h1,,hn)(h_1, \ldots, h_n) is a permutation of (g1,,gn)(g_1, \ldots, g_n).

출력

First output an integer ss, the minimum number of exchanges needed. Then print min(s,2105)\min(s, 2\cdot 10^5) exchanges, each consisting of two integers ii and jj, the one-based positions of the students that must be exchanged in this step.

If there are multiple valid solutions, you may print any one of them.

예제

예제 1

입력
3
2 1 3
3 1 2
출력
1
1 3

예제 2

입력
5
6 7 5 9 6
9 6 7 6 5
출력
4
3 4
4 5
1 2
1 3
이 문제는 채점 준비 중입니다. 테스트 데이터가 확보되면 제출이 가능합니다.