Problem: 2052A - Adrenaline Rush
Language: java

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

Solution 2 (runtime: 1093 ms):

import java.io.*;
import java.util.*;

/**
 * Problem    = cf2052a
 * Date       = Mon Jan 27 23:11:17 PST 2025
 */
public class cf2052a {

  static class Pair {
    int x,y;
    Pair(int x, int y){
      this.x=x;this.y=y;
    }
  }

  public void run() {
    int n = in.nextInt();
    int[] p = new int[n+1];
    for(int i = 1; i <= n; ++i){
      p[i]=in.nextInt();
    }
    Set<Integer> s = new HashSet<>();
    
    var pairs = new LinkedList<Pair>();
    for(int i = 1; i <= n; ++i){
      for(int j = p[i]+1; j <= n; ++j){
        if (!s.contains(j)){
          pairs.add(new Pair(j,p[i]));
        }
      }
      for(int j = n; j > 0; j--){
        if (p[i]==j) continue;
        if (!s.contains(j)){
          pairs.add(new Pair(p[i],j));
        }
      }
      s.add(p[i]);
    }
    out.println(pairs.size());
    for(var pair : pairs)
      out.println(pair.x + " " + pair.y);
  }

  /////////////////////////////////////////////////////////////////////////////////
  static InputStream in(){try{if(file!=null)return new FileInputStream(file+".in");
  return System.in;}catch(Exception e){throw new RuntimeException(e);}}static
  OutputStream out(){try{if(file!=null)return new FileOutputStream(file+".out");
  return System.out;}catch(Exception e){throw new RuntimeException(e);}}IR in=new
  IR(in());PrintWriter out=new PrintWriter(out());void c(){out.close();}static
  class IR{BufferedReader r;StringTokenizer t=null;IR(InputStream s){r=new
  BufferedReader(new InputStreamReader(s),32768);}boolean p(){while(t==null||
  !t.hasMoreTokens()){try{String l=r.readLine();if(l==null)return false;t=new
  StringTokenizer(l);}catch(IOException e){throw new RuntimeException(e);}}return
  true;}boolean hasNext(){return p();}String next(){p();return t.nextToken();}int
  nextInt(){return Integer.parseInt(next());}long nextLong(){return Long.parseLong(
  next());}double nextDouble(){return Double.parseDouble(next());}}public static
  void main(String[]args){cf2052a t=new cf2052a();t.run();t.c();}
  /////////////////////////////////////////////////////////////////////////////////
  static String file;
}