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

Solution 1 (runtime: 1718 ms):
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define ll long long
#define fr(i,a,b) for (ll i = a; i < b; i++)
#define fr1(i,a,b) for (ll i = a-1; i>=b; i--)
#define fi first
#define se second
#define mp(j, k) make_pair(j, k)
#define pb(x) push_back(x)
#define in(x) insert(x)
#define vec vector<ll>
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define ac 1000000007;
#define fauto(a) for(auto i:a) cout<<i<<" ";
#define fautop(a) for(auto i:a) cout<<i.fi<<" "<<i.se<<endl;
using namespace std;
bool comp(vec a,vec b){
  return a[1]>b[1];
}

ll dp[1010][1010];

void solve(){
ll n; cin>>n;
vec v(n+1);
for(ll i=1;i<=n;i++){cin>>v[i];}
vec a(n+1);
fr(i,1,n+1){a[i]=i;}
vector<pair<ll,ll>> p;
set<pair<ll,ll>> m;
vec vis(n+1,0);

for(ll i=n;i>=1;i--){
    ll z=v[i];
    for(ll i=z;i>=1;i--){
        if(i!=z && m.find({z,i})==m.end() && vis[i]==0){
            m.insert({z,i});
            p.push_back({z,i});

        }
        }

         for(ll i=1;i<=n;i++){
        if(i!=z && m.find({i,z})==m.end() && vis[i]==0){
            m.insert({i,z});
            p.push_back({i,z});

        }
        }
        vis[z]=1;


}
cout<<m.size()<<endl;
// reverse(all(p));
for(auto x:p){
    cout<<x.fi<<" "<<x.se<<endl;
}



}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    // ll tc;
    // cin >> tc;
    // while (tc--) {
        solve();
    // }
    
}

Solution 2 (runtime: 1077 ms):
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> oset;
#define int long long
#define MOD 1000000007
#define M 998244353
#define vi vector<int> 
#define vvi vector<vector<int>> 
#define pi pair<int,int> 
#define pb push_back
#define all(x) x.begin(),x.end()
#define nline "\n"
#define frn(i,n) for(int i = 0; i < n; i++)
#define yss cout<<"YES"<<endl
#define noo cout<<"NO"<<endl
const int INF = 1e18;
long long binpow(long long a, long long b, long long m)
 {a %= m;long long res = 1;while (b > 0) {if (b & 1) res = res * a % m;a = a * a % m;b >>= 1;}return res;}
/*----------------------------------------------------------------------------------------*/
// For calculating nCr's just calculate factorials till n and then use
// appropriate modular inverses to get nCr's modulo M.
void solve(int tc){
    int n; cin >> n;
    vector<int> v(n);
    for(auto &x : v) cin >> x;
    vector<pair<int, int>> ans;
    vector<int> done(n + 1, 0);
    for(int i = 0; i < n; i++){
      int curr = v[i];
      for(int j = curr + 1; j <= n; j++){
         if(done[j]) continue;
         ans.pb({j, curr});
      }
      for(int j = n; j > curr; j--){
         if(done[j]) continue;
         ans.pb({curr, j});
      }
      for(int j = curr - 1; j >= 1; j--){
         if(done[j]) continue;
         ans.pb({curr, j});
      }
      done[curr] = 1;
    }
    cout << ans.size() << endl;
    for(auto x : ans) cout << x.first << " " << x.second << endl;
    // cout << fixed << setprecision(10) << ans << endl;
    // Always use this format for printing any double value else you 
    // get wrong answers differing greatly with the actual double 
    // variable while you print the answer.
}
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL); 
 int tt=1;
 // cin>>tt;
 for(int i = 1; i <= tt; i++){
    //cout << "Case #" << i << ": ";
    solve(i);       
 }
}