Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 1187 ms):
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define Fast_IO() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int N = 1000 + 10;
const int M = 1e9 + 7;
const int inf = 1e12;

int a[N];

void gg(){
    int n; cin >> n;
    vector<int>v(n);
    for(int i=0;i<n;i++){
        cin >> v[i];
        a[v[i]] = i + 1;
    }

    vector<int>ord;
    for(int i=1;i<=n;i++) ord.push_back(i);
    vector<pair<int,int>>ans;
    for(int i=n-1;i>=0;i--){
        int x = v[i];
        int pos;
        for(int j=0;j<n;j++){
            if(ord[j] == x){
                pos = j;
            }
        }

        // overtake fronts
        for(int j=pos-1;j>=0;j--){
            ans.push_back({x, ord[j]});
        }
        // reverse overtake.
        vector<int>nord;
        vector<int>vis(n, 0);
        for(int j=0;j<n;j++){
            if(j == pos) continue;
            int y = ord[j];
            int xf = a[x];
            int yf = a[y];

            if(xf > yf){
                ans.push_back({y, x});
                nord.push_back(y);
                vis[j] = 1;
            }
        }
        nord.push_back(x);
        for(int j=0;j<n;j++){
            if(j == pos or vis[j] == 1) continue;
            nord.push_back(ord[j]);
        }
        // cout << x << " " << ans.size() << " -- ";
        // for(auto i : nord) {
        //     cout << i << " ";
        // } cout << endl;
        ord = nord;
    }

    cout << ans.size() << endl;
    for(auto i : ans){
        cout << i.first << " " << i.second << endl;
    }
}

/* void solve(){

    int n; cin >> n;
    vector<int>v(n);
    for(int i=1;i<=n;i++){
        cin >> v[i];
        a[v[i]] = i;
    }
    vector<pair<int,int>>ans;
    // for(int i=n;i>=1;i--){
    //     int x = v[i];
    //     for(int y=x-1;y>=1;y--){
    //         ans.push_back({x, y});
    //     }
    // }
    // vector<pair<int,int>>ans;
    for(int i=n;i>=1;i--){
        for(int j=i-1;j>=1;j--){
            ans.push_back({i, j});
        }
        for(int j=i-1;j>=1;j--){
            int x = a[i];
            int y = a[j];

            if(y < x){
                ans.push_back({j, i});
            }
        }
    }

    cout << ans.size() << endl;
    for(auto i : ans){
        cout << i.first << " " << i.second << endl;
    }

} */


signed main(){
    Fast_IO()
    int t = 1;
    // cin >> t;
    for(int i=1;i<=t;i++){
        // cout << "Case #" << i << ": ";
        gg();
    }
}

Solution 2 (runtime: 281 ms):
#include<bits/stdc++.h>

#include<map>

#include<queue>

#include<set>

#include<vector>

#define int long long

#define ull unsigned long long

#define endl '\n'

#define all(s) s.begin(),s.end()

#define xx first

#define yy second

#define inf 0x3f3f3f3f3f3f3f3f

#define N 1000005

//#define mod 1000000007

#define mod 998244353

#define double long double

#define lowbit(x) ((x)&(-x))

//#define ll long long

#define ls(x) (x<<1)

#define rs(x) ((x<<1)|1)

#define pll pair<int,int> 

#define __lcm(a,b) (a/__gcd(a,b)*b)

#define forr(i,x,y) for(int i=x;i<=y;i++)

const double pi=acos(-1);

const int P=233333;

const int PP=1313131;

const int mod1=1000001011;

const int mod2=(1ll<<31)-1;

using namespace std;

int arr[N],vis[1005][1005],pos[N],now[N];

void solve()

{

	int n;cin>>n;

    for(int i=1;i<=n;i++) 

    {

        cin>>arr[i];

        pos[arr[i]]=i;

    }

    for(int i=1;i<=n;i++)

    {

        for(int j=i+1;j<=n;j++)

        {

            if(pos[i]>pos[j]) vis[i][j]=vis[j][i]=1;

            else vis[i][j]=vis[j][i]=2;

        }

    }

    vector<pll> ans;

    for(int i=1;i<=n;i++) now[i]=i;

    for(int i=n;i;i--)

    {

        //for(int k=1;k<=n;k++) cout<<now[k]<<" ";

        //cout<<"####\n";

        for(int j=n-1;j>0;j--)

        {

            if(vis[now[j]][now[j+1]]>0)

            {

                ans.push_back({now[j+1],now[j]});

                swap(now[j],now[j+1]);

                vis[now[j]][now[j+1]]--,vis[now[j+1]][now[j]]--;

            }

            else break;

        }

    }

    cout<<ans.size()<<endl;

    for(auto i:ans)

    {

        cout<<i.xx<<" "<<i.yy<<endl;

    }

}

signed main()

{

	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);

    int T=1;

    //cin>>T;

    while(T--)

    {

    	solve();

	}

    return 0;

}

/*





*/