Problem: 2052A - Adrenaline Rush
Language: java

Solution 1 (runtime: 359 ms):
import java.util.*;

public class Main {
    public static HashMap<Long,Long> map;
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int tes=1;
        label:while(tes-->0){
           int n=sc.nextInt(),i,j,ans=0;
           int a[]=new int[n+1];
           int idx[]=new int[n+1];
           for(i=1;i<=n;i++) a[i]=sc.nextInt();
           for(i=1;i<=n;i++) idx[a[i]]=i;
           StringBuilder sb=new StringBuilder();
           for(i=1;i<=n;i++){
                for(j=n;j>idx[i];j--){
                    if(a[j]>i) continue;
                    ans++;
                    sb.append(i+" "+a[j]+"\n");
                }
                for(j=idx[i]-1;j>=1;j--){
                    if(a[j]>i) continue;
                    ans++;
                    sb.append(i+" "+a[j]+"\n");
                }
                for(j=1;j<idx[i];j++){
                    if(a[j]>i) continue;
                    ans++;
                    sb.append(a[j]+" "+i+"\n");
                }
           }
           System.out.println(ans+"\n"+sb);
        }
    }
}

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]);
            }
        }
    }
}