Problem: 2052A - Adrenaline Rush
Language: java

Solution 1 (runtime: 1983 ms):
import java.util.*;
public class AdrenalinRush{
public static void print(Object print){
    System.out.print(print);
}
public static void println(Object print){
    System.out.println(print);
}
public static void println(){
    System.out.println();
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    HashMap<Integer, Integer> map = new HashMap<>();
    HashMap<Integer, Integer> map2 = new HashMap<>();
    ArrayList<int[]> arr = new ArrayList<>();
    int ans=0;
    for(int i=0; i<n; i++){
        a[i]=sc.nextInt();
        map.put(i, a[i]);
        map2.put(i+1, n-i-1);
        b[i]=n-i;
    }
    for(int i=1; i<=n; i++){
        for(int j=i+1; j<=n; j++){
            arr.add(new int[]{j, i});
            // println(j+" "+i);
        }
    }
    ans+=n*(n-1)/2;
    for(int j=n-1; j>=0; j--){
        int tar = map.get(j);
        int curr = map2.get(tar);
        for(int i=curr; i<j; i++){
            ans++;
            // println(b[i+1]+" "+b[i]);
            arr.add(new int[]{b[i+1], b[i]});
            int temp=b[i];
            b[i]=b[i+1];
            b[i+1]=temp;
            map2.put(b[i], i);
            map2.put(b[i+1], i+1);
        }
    }
    println(ans);
    for(int[] i: arr){
        println(i[0]+" "+i[1]);
    }

}
}


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