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

Solution 1 (runtime: 1124 ms):
#pragma GCC optimize("O3,unroll-loops") // To reduce execution time
// #define ONLINE_JUDGE

// Header files
#include<bits/stdc++.h>
// #include<ext/pb_ds/assoc_container.hpp> // PBDS
// #include<ext/pb_ds/tree_policy.hpp> // PBDS

// Namespace
using namespace std;
// using namespace __gnu_pbds; // PBDS

// Define shortcuts for common types
typedef long long ll;
// typedef __int128 ell; // 128 bit integer
typedef unsigned long long ull;
typedef long double lld;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<pll> vpll;
typedef vector<string> vs;
// typedef tree<pair<ll, ll>, null_type, less<pair<ll, ll>>, rb_tree_tag, tree_order_statistics_node_update > pbds; // find_by_order, order_of_key
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define F first
#define S second
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define umap unordered_map
#define uset unordered_set

// Fast input/output
#define FAST_IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

// Debugging stuff
#ifndef ONLINE_JUDGE
#define debug_level(x, lvl) if (DEBUG_LEVEL >= lvl) cout << "[DEBUG] " << ":" << __LINE__ << " " << #x << " = ", _print(x), cout << endl;
#define debug(x) debug_level(x, 1)
#else
#define debug_level(x, lvl);
#define debug(x);
#endif

const int DEBUG_LEVEL = 3; // Set your debug level (1 = minimal, 3 = verbose)

void _print(ll t) {cout << t;}
void _print(int t) {cout << t;}
void _print(string t) {cout << '"' << t << '"';}
void _print(char t) { cout << "'" << t << "'"; }
void _print(lld t) {cout << t;}
void _print(double t) {cout << t;}
void _print(ull t) {cout << t;}
// For nested or complex data types
template <class T, class V> void _print(pair<T, V> p);
template <class T> void _print(vector<T> v);
template <class T> void _print(set<T> v);
template <class T> void _print(unordered_set<T> v);
template <class T, class V> void _print(map<T, V> v);
template <class T, class V> void _print(unordered_map<T, V> v);
template <class T> void _print(multiset<T> v);
// Definitions for printing complex data types
template <class T, class V> void _print(pair<T, V> p) {cout << "{"; _print(p.first); cout << ", "; _print(p.second); cout << "}";}
template <class T> void _print(vector<T> v) {cout << "[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";}
template <class T> void _print(set<T> v) {cout << "{ "; for (T i : v) {_print(i); cout << " ";} cout << "}";}
template <class T> void _print(unordered_set<T> v) {cout << "{ "; for (T i : v) {_print(i); cout << " ";} cout << "}";}
template <class T, class V> void _print(map<T, V> v) {cout << "{ "; for (auto i : v) {_print(i.first); cout << ": "; _print(i.second); cout << ", ";} cout << "}";}
template <class T, class V> void _print(unordered_map<T, V> v) {cout << "{ "; for (auto i : v) {_print(i.first); cout << ": "; _print(i.second); cout << ", ";} cout << "}";}
template <class T> void _print(multiset<T> v) {cout << "[ "; for (T i : v) {_print(i); cout << " ";} cout << "]";}
// void _print(pbds v) {cout << "[ "; for (auto i : v) {_print(i); cout << " ";} cout << "]";}

// Timer
struct Timer {
#ifndef ONLINE_JUDGE
    chrono::high_resolution_clock::time_point start{chrono::high_resolution_clock::now()};
    ~Timer() {auto end = chrono::high_resolution_clock::now();
        cout << "Execution Time: " << chrono::duration_cast<chrono::milliseconds>(end - start).count() << " ms" << endl;}
#endif
};

void solve()
{
    int n;
    cin >> n;
    vll c(n);
    vll temp(n);
    vpll ans;
    for( int i = 0; i < n ; i++)
    {
        cin >> c[i];
        temp[i] = i+1;
    }
    vvll mat(n + 1, vll(n + 1, 0));

    for ( int i = 0; i < n; i++)
    {
        for ( int j = i+1; j < n; j++)
        {
            mat[c[i]][c[j]] = 1;
        }
    }
    ll count = 0;
    for ( int i = 1; i < n; i++)
    {
        int key = temp[i];
        int j = i - 1;
        while( j >= 0 && (mat[key][temp[j]]))
        {
            temp[j+1] = temp[j];
            j--;
            debug(temp)
            ans.pb({key, temp[j+1]});
            count++;
        }
        debug(j);
        for( int k = j; k >= 0; k--)
        {
            ans.pb({key, temp[k]});
            count++;
        }
        for( int k = 0; k <= j; k++){
            ans.pb({temp[k], key});
            count++;
        }
        temp[j+1] = key;
    }
    cout<<count<<endl;
    for( auto i : ans)
        cout<<i.first<<" "<<i.second<<endl;
}

int main()
{
    {
        Timer timer;
        FAST_IO
        solve();
    }
}

Solution 2 (runtime: 406 ms):
#include<bits/stdc++.h>
using namespace std;

#define ll          long long

#define vi          vector<int>
#define vl          vector<long long>
#define vll          vector<vector<long long>>
#define vii         vector<vector<int>>

#define pb          push_back
#define pf          push_front
#define fr          front
#define eb          emplace_back
#define ff          first
#define ss          second
#define endl        "\n"

#define FAST_IO             (ios_base:: sync_with_stdio(false),cin.tie(NULL));

template<typename A, typename B> ostream& operator<<(ostream &os, const pair<A, B> &p) { return os << '(' << p.first << ", " << p.second << ')'; }
template<typename... Args> ostream& operator<<(ostream& os, const tuple<Args...>& t) { os << '('; apply([&os](const Args&... args) { size_t n = 0; ((os << args << (++n != sizeof...(Args) ? ", " : "")), ...); }, t); return os << ')'; }
template<typename T_container, typename T = typename enable_if<!is_same<T_container, string>::value, typename T_container::value_type>::type> ostream& operator<<(ostream &os, const T_container &v) { os << '{'; string sep; for (const T &x : v) os << sep << x, sep = ", "; return os << '}'; }
 

#define MOD         1e9 + 7

// ------------------------------- //

void solve(){
    ll n;cin>>n;
    vl arr(n);
    for(ll &x : arr) cin>>x;

    vll steps;
    
    // cout<<arr<<endl;
    for(int i=0;i<n;i++){
        for(int j=i-1;j>=0;j--){
            steps.push_back({arr[j],arr[j+1]});
            swap(arr[j],arr[j+1]);
            // cout<<arr<<endl;
        }
    }

    for(int num=1;num<=n;num++){
        for(int i=0;i<n;i++){
            if(arr[i]!=num) continue;

            for(int j=i-1;j>=num-1;j--){
                steps.push_back({arr[j],arr[j+1]});
                swap(arr[j],arr[j+1]);
                // cout<<arr<<endl;
            }
        }
        // cout<<arr<<endl;
    }
    // cout<<endl;
    // cout<<steps<<endl;

    cout<<steps.size()<<endl;
    for(int i=steps.size()-1;i>=0;i--){
        for(auto x : steps[i]) cout<<x<<' ';
        cout<<endl;
    }


}

int main()
{
    FAST_IO;
    int TC = 1;
    // cin >> TC;
    while (TC--) solve();
    return 0;
}