Problem: 2052A - Adrenaline Rush
Language: java

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

public class A_Adrenaline_Rush {

    int mod = (int) 1e9 + 7;
    
    public static void main(String[] args) {
        int n = sc.nextInt();
        int[] f = new int[n];
        input(f);
        int[] a = new int[n];
        for(int i=0;i<n;i++) a[i] = i+1;
        List<int[]> l = new ArrayList<>();
        for(int i=1;i<n;i++){
            int j = i;
            while(j>0){
                int temp = a[j];
                a[j] = a[j-1];
                a[j-1] = temp;
                l.add(new int[]{a[j-1],a[j]});
                j--;
            }
        }
        for(int i=0;i<n;i++){
            int pl = f[i];
            // System.out.println(pl);
            int idx = -1;
            for(int j=0;j<n;j++){
                if(a[j]==pl){
                    idx = j;
                    break;
                }
            }
            // System.out.println(idx);
            if(i<idx)    {int j = idx;
                while(j>i){
                    int temp = a[j];
                    a[j] = a[j-1];
                    a[j-1] = temp;
                    l.add(new int[]{a[j-1],a[j]});
                    j--;
                }
                // if(dest>0){
                //     while(j<dest){
                //         int temp = a[j];
                //         a[j] = a[j+1];
                //         a[j+1] = temp;
                //         l.add(new int[]{a[j],a[j+1]});
                //         j++;
                //     }
                // }
            }
            // printArr(a);
        }
        System.out.println(l.size());
        for(int i=0;i<l.size();i++){
            System.out.println(l.get(i)[0] + " " + l.get(i)[1]);
        }
        // printArr(a);
    }
    
    public static void input(Object array) {
        if (array instanceof int[])
            for (int i = 0; i < ((int[]) array).length; i++)
                ((int[]) array)[i] = sc.nextInt();
        else if (array instanceof long[])
            for (int i = 0; i < ((long[]) array).length; i++)
                ((long[]) array)[i] = sc.nextLong();
    }
    
    public static void printArr(Object array) {
        if (array instanceof int[])
            for (int x : (int[]) array)
                System.out.print(x + " ");
        else if (array instanceof long[])
            for (long x : (long[]) array)
                System.out.print(x + " ");
        System.out.println();
    }
    
    public static <T extends Number> long gcd(T a, T b) {
        return b.longValue() == 0 ? a.longValue() : gcd(b, a.longValue() % b.longValue());
    }
    
    static FastReader sc = new FastReader();
    
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
    
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
    
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
    
        int nextInt() {
            return Integer.parseInt(next());
        }
    
        long nextLong() {
            return Long.parseLong(next());
        }
    
        double nextDouble() {
            return Double.parseDouble(next());
        }
    
        String nextLine() {
            String str = "";
            try {
                str = br.readLine().trim();
            } catch (Exception e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Solution 2 (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);
        }
    }
}