Problem: 2052A - Adrenaline Rush
Language: java

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

public class Main {
    public static int INF = 0x3f3f3f3f, mod = 1000000007, mod9 = 998244353;
    public static void main(String args[]){
        try {
            PrintWriter o = new PrintWriter(System.out);
            boolean multiTest = false;
            // init
            if(multiTest) {
                int t = nextInt(), loop = 0;
                while (loop < t) {loop++;solve(o);}
            } else solve(o);
            o.close();
        } catch (Exception e) {e.printStackTrace();}
    }
    static void solve(PrintWriter o) {
        try {
            int n = nextInt();
            int[] c = new int[n];
            for(int i=0;i<n;i++) c[i] = nextInt();
            List<int[]> li = new ArrayList<>();
            int[] a = new int[n];
            Map<Integer, Integer> idxMap = new HashMap<>();
            for(int i=0;i<n;i++) {
                a[i] = i+1;
                idxMap.put(a[i], i);
            }
            for(int i=n-1;i>=0;i--) {
                int x = idxMap.get(c[i]);
                for(int j=x-1;j>=0;j--) li.add(new int[]{a[x], a[j]});
                for(int j=0;j<x;j++) li.add(new int[]{a[j], a[x]});
                for(int j=x+1;j<i+1;j++) {
                    a[j-1] = a[j];
                    idxMap.put(a[j], j-1);
                    li.add(new int[]{a[j], c[i]});
                }
                a[i] = c[i];
                idxMap.put(c[i], i);
            }
            o.println(li.size());
            for(int[] it: li) o.println(it[0] + " " + it[1]);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public static int upper_bound(List<Integer> a, int val){
        int l = 0, r = a.size();
        while(l < r){
            int mid = l + (r - l) / 2;
            if(a.get(mid) <= val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static int lower_bound(List<Integer> a, int val){
        int l = 0, r = a.size();
        while(l < r){
            int mid = l + (r - l) / 2;
            if(a.get(mid) < val) l = mid + 1;
            else r = mid;
        }
        return l;
    }
    public static long gcd(long a, long b){
        return b == 0 ? a : gcd(b, a%b);
    }
    public static long lcm(long a, long b){
        return a / gcd(a,b)*b;
    }
    public static long qpow(long a, long n, int md){
        a %= md;
        long ret = 1l;
        while(n > 0){
            if((n & 1) == 1){
                ret = ret * a % md;
            }
            n >>= 1;
            a = a * a % md;
        }
        return ret;
    }
    public static class FenWick {
        int n;
        long[] a;
        long[] tree;
        public FenWick(int n){
            this.n = n;
            a = new long[n+1];
            tree = new long[n+1];
        }
        private void add(int x, long val){
            while(x <= n){
                tree[x] += val;
                x += x&-x;
            }
        }
        private void addMx(int x, long val) {
            a[x] += val;
            tree[x] = a[x];
            while(x <= n) {
                for(int i=1;i<(x&-x);i<<=1) {
                    tree[x] = Math.max(tree[x], tree[x-i]);
                }
                x += x&-x;
            }
        }
        private long query(int x){
            long ret = 0l;
            while(x > 0){
                ret += tree[x];
                x -= x&-x;
            }
            return ret;
        }
        private long queryMx(int l, int r) {
            long res = 0l;
            while(l <= r) {
                if(r-(r&-r) >= l) {
                    res = Math.max(res, tree[r]);
                    r -= r&-r;
                }
                else {
                    res = Math.max(res, a[r]);
                    r--;
                }
            }
            return res;
        }
    }
    public static class Pair{
        Integer c1;
        Integer c2;
        public Pair(Integer c1, Integer c2) {
            this.c1 = c1;
            this.c2 = c2;
        }
        @Override
        public int hashCode() {
            int prime = 31, ret = 1;
            ret = ret*prime + c1.hashCode();
            ret = ret*prime + c2.hashCode();
            return ret;
        }
        @Override
        public boolean equals(Object obj) {
            if(obj instanceof Pair) {
                return c1.equals(((Pair) obj).c1) && c2.equals(((Pair) obj).c2);
            }
            return false;
        }
    }
    private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer tokenizer = new StringTokenizer("");
    private static String next() throws IOException{
        while(!tokenizer.hasMoreTokens()){tokenizer = new StringTokenizer(reader.readLine());}
        return tokenizer.nextToken();
    }
    public static int nextInt() throws IOException {return Integer.parseInt(next());}
    public static Long nextLong() throws IOException {return Long.parseLong(next());}
    public static double nextDouble() throws IOException {return Double.parseDouble(next());}
    public static char nextChar() throws IOException {return next().toCharArray()[0];}
    public static String nextString() throws IOException {return next();}
    public static String nextLine() throws IOException {return reader.readLine();}
}

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