Problem: 2052A - Adrenaline Rush
Language: java

Solution 1 (runtime: 968 ms):
//package Practice;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class AdrenalineRush {
    public static void swap(int[] arr, int l) {
        int temp = arr[l];
        arr[l] = arr[l+1];
        arr[l+1] = temp;
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw = new PrintWriter(System.out);
        int n = Integer.parseInt(br.readLine());
        int[] arr = new int[n];
        StringTokenizer st = new StringTokenizer(br.readLine());
        HashMap<Integer, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(st.nextToken());
            map.put(arr[i], i);
         }
        if (n == 1) {
            pw.println("0");
            pw.close();
            return;
        }
        HashMap<Integer, Integer> map2 = new HashMap<>();
        int[] arr2 = new int[n];
        for (int i = 0; i < n; i++) {
            arr2[i] = i+1;
            map2.put(i+1, i);
        }
        ArrayList<String> moves= new ArrayList<>();
        for (int i = n-1; i >= 0; i--) {
            int curNum = arr[i];
            int startIdx = map2.get(curNum);
            int endIdx = map.get(curNum);
            // pass everything that starts in front
           // System.out.println("starting passing phase, arr2 is " + Arrays.toString(arr2) + " and curNum is " + curNum + " and start: " + startIdx);
            for (int j = startIdx-1; j >= 0; j--) {
                moves.add(arr2[j+1] + " " +  arr2[j]);
                swap(arr2, j);
                //System.out.println("passed 1, move was " + moves.getLast());
            }
            for (int j = 0; j < startIdx; j++) {
                map2.put(arr2[j], j);
            }
            startIdx = map2.get(curNum);
            // then get passed by everything that ends in front
            //System.out.println("at i="+i+", curNum is " + curNum + " and start:" + startIdx + " and end:" + endIdx);
            if (startIdx < endIdx) {
                //System.out.println("starting going back phase");
                while (startIdx < endIdx) {
                    //System.out.println("one move with num = " + curNum);
                    moves.add(arr2[startIdx+1] + " " + arr2[startIdx]);
                    int temp = arr2[startIdx];
                    map2.put(arr2[startIdx], map2.get(arr2[startIdx]) + 1);
                    map2.put(arr2[startIdx+1], map2.get(arr2[startIdx+1]) - 1);
                    arr2[startIdx] = arr2[startIdx+1];
                    arr2[startIdx+1] = temp;
                    startIdx++;
            //        pw.println("arr2:" + Arrays.toString(arr2) + " and last move was " + moves.getLast());
                }
            }
            for (int j = 0; j < startIdx; j++) {
                map2.put(arr2[j], j);
            }
          //  System.out.println("arr2 at the end of the process:" + Arrays.toString(arr2));
        }
        //System.out.println("arr2:" + Arrays.toString(arr2));
        /*HashSet<String> moveSet = new HashSet<>();
        moveSet.addAll(moves);
        for (int i = 0; i < n - 1; i++) {
            if (!moveSet.contains(arr2[i] + " " + arr2[i+1]) && !moveSet.contains(arr2[i+1] + " " + arr2[i])) {
                moves.add(arr2[i+1] + " " + arr2[i]);
                moves.add(arr2[i] + " " + arr2[i+1]);
            }
        }*/
        pw.println(moves.size());
        for (String move: moves) {
            pw.println(move);
        }
        // do extra stuff

        pw.close();
        br.close();
    }
}


Solution 2 (runtime: 2171 ms):
import java.io.*;
import java.util.*;

public class Main
{
    public static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    public static  BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    public static StringTokenizer tokenizer;
    public static void read() throws IOException {
        tokenizer = new StringTokenizer(br.readLine());
    }
    public static int Int() throws IOException {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) read();
        return Integer.parseInt(tokenizer.nextToken());
    }
    public static long Long() throws IOException {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) read();
        return Long.parseLong(tokenizer.nextToken());
    }
    public static String Str() throws IOException {
        return br.readLine();
    }

    public static Character Char() throws IOException {
        return (char)br.read();
    }

    public static long[] read(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = Long() - 1;
        }
        return a;
    }

    //-----------------------------------------------

    public static long MOD = (long) 1e9 + 7;
    public static long quickPow(long pow, long num, long MOD) {
        if (pow == 0) {
            return 1;
        }
        if (pow == 1) {
            return num % MOD;
        }
        long half = quickPow(pow / 2, num, MOD);
        long twoHalf = (half * half) % MOD;
        return (twoHalf * quickPow(pow % 2, num, MOD)) % MOD;
    }

    public static void remove(TreeMap<Long, Long> map, long key) {
        map.put(key, map.get(key) - 1);
        if (map.get(key) == 0) map.remove(key);
    }

    public static void remove(HashMap<Long, Long> map, long key) {
        map.put(key, map.get(key) - 1);
        if (map.get(key) == 0) map.remove(key);
    }

    public static void add(TreeMap<Long, Long> map, long key) {
        map.put(key, map.getOrDefault(key, 0L) + 1);
    }

    public static void add(HashMap<Long, Long> map, long key) {
        map.put(key, map.getOrDefault(key, 0L) + 1);
    }




    public static void main(String[] args) throws IOException {
        int T = 1;
        while (T > 0) {
            T--;
            int n = Int();
            int[] a = new int[n];
            int[] start = new int[n];
            HashMap<Integer, Integer> pos = new HashMap<>();
            for (int i = 0; i < n; i++) {
                a[i] = Int();
                start[i] = i + 1;
                pos.put(i + 1, i);
            }
            ArrayList<int[]> res = new ArrayList<>();
            for (int i = n - 1; i >= 0; i--) {
                int position = pos.get(a[i]);
                for (int j = position; j > 0; j--) {
                    res.add(new int[] {start[j], start[j - 1]});
                    pos.put(start[j], j - 1);
                    pos.put(start[j - 1], j);
                    int tmp = start[j];
                    start[j] = start[j - 1];
                    start[j - 1] = tmp;
                }
            }
            System.out.println(res.size());
            for (int i = 0; i < res.size(); i++) {
                System.out.println(res.get(i)[0] + " " + res.get(i)[1]);
            }
        }
    }
}