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: 546 ms):
#include<bits/stdc++.h>
#define LOCAL
#ifdef LOCAL
#if __has_include("C:\Users\HP\Desktop\Codeforces\template.cpp")
#include "C:\Users\HP\Desktop\Codeforces\template.cpp"
#else
#pragma message("template.cpp not found. Proceeding without it.")
#endif
#else
#define debug(...)
#endif
using namespace std;
#define out(x) cout<<x<<endl
#define in(x)  cin>>x
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define int long long
#define pb(x) push_back(x)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<"#"<<x<<endl
#define deb2(x) cout<<"^"<<x<<endl
#define rep(i,x,y) for(int i=x;i<y;i++)
#define nxt cout<<endl;
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
#define vc vector<char>

void solve(){
int n;
in(n);
vi v(n);
rep(i,0,n){
    in(v[i]);
}
if(n==1){
    out(0);
    return;
}
int cnt=0;
vp pp;
map<pair<int,int>,int>mp;
map<pair<int,int>,int>mpp;
for(int i=0;i<n;i++){
    for(int j=i+1;j<n;j++){
        if(v[i]>v[j]){
            cnt++;
            pp.push_back({v[i],v[j]});
        }else{
            cnt+=2;
            pp.push_back({v[i],v[j]});
            pp.push_back({v[j],v[i]});
        }
    }
}
vi tmp(n+1);
for(int i=1;i<=n;i++){
    tmp[i]=i;
}
out(cnt);
set<pair<int,int>>ss;
for(int i=0;i<pp.size();i++){
    ss.insert({pp[i].first,pp[i].second});
}
for(int i=0;i<cnt;i++){ 
    for(auto &it:ss){
        int x = it.first;
        int y = it.second;
        int z2 = tmp[x]-tmp[y];
        if(z2==1){
            cout<<x<<" "<<y<<endl;
            swap(tmp[x],tmp[y]);
            auto it2 = ss.find({x,y});
            ss.erase(it2);
            break;
        }
    }
}
}

signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t=1;
// cin>>t;
while(t--){
solve();
}
}