Problem: 2052A - Adrenaline Rush
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 4):
#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
// #include <atcoder/all>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
using namespace std;

// using namespace __gnu_pbds;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};



// https://docs.google.com/document/d/1VuLkJfkaBBFdcV-BPtT2JdTDrD2lC3POFj6NPTl_Pzo/edit?addon_store&tab=t.0
// typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
//find by order-> element at ith idx(starting from 0)//gives iterator to that index//if not present *it gives 0
//order of key-> number of element less than a number

// erase function for ordered multiset
// void myerase(pbds &t, int v){
//     int rank = t.order_of_key(v);//Number of elements that are less than v in t
//     pbds::iterator it = t.find_by_order(rank); //Iterator that points to the (rank+1)th element in t
//     t.erase(it);
// }



#define int long long int 
// #define ll long long int
#define loop(var, s, e) for(int var = s; var < e; var++)
#define rloop(var, e, s) for(int var = e; var>= s; var--)
#define v vector<int>
// #define vll vector<long long int>
#define printyes cout<<"YES\n"
#define printno cout<<"NO\n"
//COMMENT THIS FOR INTERACTIVE PROBLEMS...............
// #define endl '\n'
#define mod (int)(1e9 + 7)
#define inf 1e18
#define dbg(x) cerr<<"value of "<<#x<<" is => "<<x<<endl;
#define all(x) x.begin(), x.end()
#define vpii vector<pair<int, int>>
#define pii pair<int,int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define vpll vector<pll>
#define here(i) cerr<<"here "<<i<<" "<<endl;
#define rt return;
#define mx max_element
#define mn min_element
#define asum accumulate
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.ff << ", " << a.ss << ")";
}
 
template <class A> ostream& operator << (ostream& out, const vector<A> &ve) {
	out << "[";
	loop(i, 0, ve.size()) {
		if(i) out << ", ";
		out << ve[i];
	}
	return out << "]";
}

                //U R D L
int delrow[4] = {-1,0,1,0};
int delcol[4] = {0,1,0,-1};
// unordered_map<char, int> mpp = {{'U', 0}, {'R', 1}, {'D', 2}, {'L', 3}};

namespace bit {
  int setBit(int n, int bitNo) {
    n = (n|(1LL<<bitNo));
    return n;
  }

  int currBit(int n, int bitNo) {
    return ((n&(1ll<<bitNo)) == 0)?0:1;
  }

  int unSetBit(int n, int bitNo) {
    n = (n&(~(1ll<<bitNo)));
    return n;
  }
  /*
  __lg() returns the highest set bit index in a number i.e for 100 it will be 2 and for 000 will be -1

  __builtin_ctz() give number of trailing zeros -> 1000-> 3

  n&(n - 1) clears the first set bit

  n&(-n) give the first set bit => 101100 -> 000100

  n&(n + 1) clear all trailing ones

  n|(n + 1) set the first unset bit
  */
}
//*************************************************CHECK THE CONSTRAINTS**********************************************************//
int extendedEuclidean(int a, int b, int&x, int& y) {
  if(b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  int x1, y1;
  int d = extendedEuclidean(b, a%b, x1, y1);
  x = y1;
  y = x1 - y1*(a/b);
  return d;
}


int f(int a, int b) {
  if(b == 0)return 1;
  int res = f(a, b/2);
  if(b%2 != 0) {
    return (((res)%mod* (res)%mod)%mod * a)%mod;
  }
  else {
    return ((res)%mod * (res)%mod)%mod;
  }
}


int _f(int a, int b) {
  if(b == 0)return 1;
  int res = f(a, b/2);
  if(b%2 != 0) {
    return (((res)* (res))* a);
  }
  else {
    return ((res) * (res));
  }
}


int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}


vector<bool> sieve(int n) {
  vector<bool> is_prime(n+1, 1);
  // v prime;
  // v dp(n + 1, 0);
  is_prime[0] = 0;
  is_prime[1] = 0;
  for(int i = 2; i <= n; i++) {
    if(is_prime[i] == 1) {
      // prime.pb(i);
      for(int j = i*i; j <= n; j+=i) {
        is_prime[j] = 0;
      }
    }
  }
  return is_prime;
}
// void *memcpy(void *dest, const void *src, size_t n);
// make the hard time of your life as your strength
// first write complete pseudo code on paper then code dont care about the time!!!!!!


void pikachu(int tt, int tc) {
  int n;
  cin>>n;
  v arr(n);
  loop(i, 0, n)cin>>arr[i];
  vpii ans;
  loop(i, 0, n) {
    loop(j, i + 1, n) {
      if(arr[i] < arr[j]) {
        ans.pb({arr[j], arr[i]});
        ans.pb({arr[i], arr[j]});
      }
      else ans.pb({arr[i], arr[j]});
    }
  }
  cout<<ans.size()<<endl;
  for(auto &[x, y]: ans)cout<<x<<' '<<y<<endl;
}         



int32_t main() {
  auto begin = std::chrono::high_resolution_clock::now();
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  int gsBall = 1;
//   cin>>gsBall;
  int tt = gsBall;
  int tc = 1; 
  cout<<setprecision(20);
  while(gsBall--) {
    pikachu(tt, tc);
    tc++;
  }
  auto end = std::chrono::high_resolution_clock::now();
  auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
  cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
  return 0;
}

Submission (verdict: Wrong answer on test 4):
#pragma GCC optimize("O3,unroll-loops")
#include<bits/stdc++.h>
// #include <atcoder/all>
// #include<ext/pb_ds/assoc_container.hpp>
// #include<ext/pb_ds/tree_policy.hpp>
using namespace std;

// using namespace __gnu_pbds;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};



// https://docs.google.com/document/d/1VuLkJfkaBBFdcV-BPtT2JdTDrD2lC3POFj6NPTl_Pzo/edit?addon_store&tab=t.0
// typedef tree<int, null_type, greater<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
//find by order-> element at ith idx(starting from 0)//gives iterator to that index//if not present *it gives 0
//order of key-> number of element less than a number

// erase function for ordered multiset
// void myerase(pbds &t, int v){
//     int rank = t.order_of_key(v);//Number of elements that are less than v in t
//     pbds::iterator it = t.find_by_order(rank); //Iterator that points to the (rank+1)th element in t
//     t.erase(it);
// }



#define int long long int 
// #define ll long long int
#define loop(var, s, e) for(int var = s; var < e; var++)
#define rloop(var, e, s) for(int var = e; var>= s; var--)
#define v vector<int>
// #define vll vector<long long int>
#define printyes cout<<"YES\n"
#define printno cout<<"NO\n"
//COMMENT THIS FOR INTERACTIVE PROBLEMS...............
// #define endl '\n'
#define mod (int)(1e9 + 7)
#define inf 1e18
#define dbg(x) cerr<<"value of "<<#x<<" is => "<<x<<endl;
#define all(x) x.begin(), x.end()
#define vpii vector<pair<int, int>>
#define pii pair<int,int>
#define pll pair<ll, ll>
#define ff first
#define ss second
#define pb push_back
#define vpll vector<pll>
#define here(i) cerr<<"here "<<i<<" "<<endl;
#define rt return;
#define mx max_element
#define mn min_element
#define asum accumulate
mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());
template <class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out << "(" << a.ff << ", " << a.ss << ")";
}
 
template <class A> ostream& operator << (ostream& out, const vector<A> &ve) {
	out << "[";
	loop(i, 0, ve.size()) {
		if(i) out << ", ";
		out << ve[i];
	}
	return out << "]";
}

                //U R D L
int delrow[4] = {-1,0,1,0};
int delcol[4] = {0,1,0,-1};
// unordered_map<char, int> mpp = {{'U', 0}, {'R', 1}, {'D', 2}, {'L', 3}};

namespace bit {
  int setBit(int n, int bitNo) {
    n = (n|(1LL<<bitNo));
    return n;
  }

  int currBit(int n, int bitNo) {
    return ((n&(1ll<<bitNo)) == 0)?0:1;
  }

  int unSetBit(int n, int bitNo) {
    n = (n&(~(1ll<<bitNo)));
    return n;
  }
  /*
  __lg() returns the highest set bit index in a number i.e for 100 it will be 2 and for 000 will be -1

  __builtin_ctz() give number of trailing zeros -> 1000-> 3

  n&(n - 1) clears the first set bit

  n&(-n) give the first set bit => 101100 -> 000100

  n&(n + 1) clear all trailing ones

  n|(n + 1) set the first unset bit
  */
}
//*************************************************CHECK THE CONSTRAINTS**********************************************************//
int extendedEuclidean(int a, int b, int&x, int& y) {
  if(b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  int x1, y1;
  int d = extendedEuclidean(b, a%b, x1, y1);
  x = y1;
  y = x1 - y1*(a/b);
  return d;
}


int f(int a, int b) {
  if(b == 0)return 1;
  int res = f(a, b/2);
  if(b%2 != 0) {
    return (((res)%mod* (res)%mod)%mod * a)%mod;
  }
  else {
    return ((res)%mod * (res)%mod)%mod;
  }
}


int _f(int a, int b) {
  if(b == 0)return 1;
  int res = f(a, b/2);
  if(b%2 != 0) {
    return (((res)* (res))* a);
  }
  else {
    return ((res) * (res));
  }
}


int inv(int a, int b){
 return 1<a ? b - inv(b%a,a)*b/a : 1;
}


vector<bool> sieve(int n) {
  vector<bool> is_prime(n+1, 1);
  // v prime;
  // v dp(n + 1, 0);
  is_prime[0] = 0;
  is_prime[1] = 0;
  for(int i = 2; i <= n; i++) {
    if(is_prime[i] == 1) {
      // prime.pb(i);
      for(int j = i*i; j <= n; j+=i) {
        is_prime[j] = 0;
      }
    }
  }
  return is_prime;
}
// void *memcpy(void *dest, const void *src, size_t n);
// make the hard time of your life as your strength
// first write complete pseudo code on paper then code dont care about the time!!!!!!


void pikachu(int tt, int tc) {
  int n;
  cin>>n;
  v arr(n);
  map<int, int> pos;
  loop(i, 0, n) {
    cin>>arr[i];
    pos[arr[i]] = i;
  }
  v ans(n, inf);
  vpii swap;
  loop(i, 1, n + 1) {
    ans[pos[i]] = i;
    loop(j, pos[i] + 1, n) {
      if(ans[pos[i]] > ans[j])swap.pb({i, ans[j]});
    }
  }
  rloop(i, n - 1, 0) {
    loop(j, i + 1, n) {
      if(arr[j] > arr[i]) {
        swap.pb({arr[j], arr[i]});
      }
    }
  }
  loop(i, 0, n - 1) {
    loop(j, i + 1, n) {
      if(arr[j] > arr[i]) {
        swap.pb({arr[i], arr[j]});
      }
    }
  }
//   cerr<<ans<<endl;
//   cerr<<swap<<endl;
  cout<<swap.size()<<endl;
  for(auto &[x, y]: swap)cout<<x<<' '<<y<<endl;
}         



int32_t main() {
  auto begin = std::chrono::high_resolution_clock::now();
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #ifndef ONLINE_JUDGE
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  int gsBall = 1;
//   cin>>gsBall;
  int tt = gsBall;
  int tc = 1; 
  cout<<setprecision(20);
  while(gsBall--) {
    pikachu(tt, tc);
    tc++;
  }
  auto end = std::chrono::high_resolution_clock::now();
  auto elapsed = std::chrono::duration_cast<std::chrono::nanoseconds>(end - begin);
  cerr << "Time measured: " << elapsed.count() * 1e-9 << " seconds.\n"; 
  return 0;
}