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

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

#define int long long
#define fi first
#define se second

const int N = 1000 + 5;
const int K = 1e2 + 5;
const int mod = 1e9 + 7;
const int inf = 1e18 + 7;

#define all(v) (v).begin(), (v).end()
#define pii pair<int, int> 

using namespace std;

mt19937 rd(chrono::steady_clock::now().time_since_epoch().count());

int n, a[N], fin[N];
vector<pii> ovt;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    if(ifstream("file.inp")){
    	freopen("file.inp", "r", stdin);
    	freopen("file.out", "w", stdout);
    }
    
    cin >> n;
    for(int i = 1; i <= n; i++) {
    	cin >> a[i];
    	for(int j = a[i] + 1; j <= n; j++) {
    		if(!fin[j]) {
    			ovt.push_back({j, a[i]});
    		}
    	}
    	for(int j = n; j >= a[i] + 1; j--) {
    		if(!fin[j]) {
    			ovt.push_back({a[i], j});
    		}
    	}
    	for(int j = a[i] - 1; j >= 1; j--) {
    		if(!fin[j]) {
    			ovt.push_back({a[i], j});
    		}
    	}
    	fin[a[i]] = 1;
    }
    cout << ovt.size() << '\n';
    for(auto &g : ovt) cout << g.fi << ' ' << g.se << '\n';
    
    return 0;
}

// tuntun


Solution 2 (runtime: 1015 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fi first
#define se second
#define so(v) sort(v.begin(),v.end())
#define fo(i,n) for(int i=0;i<n;i++)
#define co(x)   cout<<x
#define coe(x)   cout<<x<<endl
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vii;
typedef vector<pair<ll,ll>> vpl;
typedef pair<ll,ll> pll;
#define pb push_back
vector<ll> fact, inv_fact;
const int mod=1000000007;
long long int mmi(long long int a ,long long int m ){
long long int res=1;
ll b=mod-2;
while(b>0){
if(b&1){
res=(res*a)%m;
}
a=(a*a)%m;
b>>=1;
}
return res;
}
long long power(long long a, long long b, int mod) {
long long result = 1;
a = a % mod;  
while (b > 0) {
 if (b % 2 == 1) {
 result = (result * a) % mod;
}
 b = b >> 1; 
a = (a * a) % mod; 
}
return result;
}
void precompute(int n) {
fact.resize(n + 1);
inv_fact.resize(n + 1);
fact[0] = 1;
for (int i = 1; i <= n; i++) {
 fact[i] = (fact[i - 1] * i) % mod;
}
 inv_fact[n] = mmi(fact[n], mod); 
for (int i = n - 1; i >= 0; i--) {
inv_fact[i] = (inv_fact[i + 1] * (i + 1)) % mod;
 }
}
 ll bc(int n, int k) {
 if (k > n || k < 0) return 0;
return (fact[n] * inv_fact[k] % mod) * inv_fact[n - k] % mod;
}
ll ad(ll a,ll b){
    return ((a%mod) + (b%mod)+mod)%mod;
}
ll mul(ll a,ll b){
    return ((a%mod) *(b%mod))%mod;
}
ll ceil(ll n,ll k){
if(n%k==0){
 return n/k;
}
 else{
return (n/k)+1;
}
}
bool comp (pair<ll,ll>a,pair<ll,ll>b){
if(max(a.first,a.second)>max(b.first,b.second)){
 return false;
}
else if(max(a.first,a.second)==max(b.first,b.second)){
if(min(a.first,a.second)>=min(b.first,b.second)){
return false;
}
else{
return true;
}
}
else{
return true;
}
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
cout.precision(10); cout.setf(ios::fixed);

ll n;
cin >> n;
vector<ll>v(n);
for(int i = 0;i < n;i++){
cin >> v[i];
}
   vector<pair<int,int>>ans;
   for(int i=n-1;i>=0;i--){
    
        vector<int>g;
        for(int j=0;j<i;j++){
            g.pb(v[j]);
        }
        so(g);
        reverse(g.begin(),g.end());
        for(int j=0;j<i;j++){
          if(v[i]>g[j]){
            ans.pb({v[i],g[j]});
          }
        }
         for(int j=i-1;j>=0;j--){
            ans.pb({g[j],v[i]});
        
   }
   
}
cout<<ans.size()<<endl;
for(int i=0;i<ans.size();i++){
cout<<ans[i].fi<<" "<<ans[i].se<<endl;
}

return 0;
}