CF53D.Physical Education

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya is a school PE teacher. Unlike other PE teachers, Vasya doesn't like it when the students stand in line according to their height. Instead, he demands that the children stand in the following order: a1,a2,...,ana_{1},a_{2},...,a_{n} , where aia_{i} is the height of the ii -th student in the line and nn is the number of students in the line. The children find it hard to keep in mind this strange arrangement, and today they formed the line in the following order: b1,b2,...,bnb_{1},b_{2},...,b_{n} , which upset Vasya immensely. Now Vasya wants to rearrange the children so that the resulting order is like this: a1,a2,...,ana_{1},a_{2},...,a_{n} . During each move Vasya can swap two people who stand next to each other in the line. Help Vasya, find the sequence of swaps leading to the arrangement Vasya needs. It is not required to minimize the number of moves.

输入格式

The first line contains an integer nn ( 1<=n<=3001<=n<=300 ) which is the number of students. The second line contains nn space-separated integers aia_{i} ( 1<=ai<=1091<=a_{i}<=10^{9} ) which represent the height of the student occupying the ii -th place must possess. The third line contains nn space-separated integers bib_{i} ( 1<=bi<=1091<=b_{i}<=10^{9} ) which represent the height of the student occupying the ii -th place in the initial arrangement. It is possible that some students possess similar heights. It is guaranteed that it is possible to arrange the children in the required order, i.e. aa and bb coincide as multisets.

输出格式

In the first line print an integer kk ( 0<=k<=1060<=k<=10^{6} ) which is the number of moves. It is not required to minimize kk but it must not exceed 10610^{6} . Then print kk lines each containing two space-separated integers. Line pip_{i} , pi+1p_{i}+1 ( 1<=pi<=n11<=p_{i}<=n-1 ) means that Vasya should swap students occupying places pip_{i} and pi+1p_{i+1} .

输入输出样例

  • 输入#1

    4
    1 2 3 2
    3 2 1 2
    

    输出#1

    4
    2 3
    1 2
    3 4
    2 3
    
  • 输入#2

    2
    1 100500
    1 100500
    

    输出#2

    0
    
首页