#include <bits/stdc++.h>
using namespace std;
long long int p = 1000000007;
vector<pair<int, int>> pai;
long long int inversions(pair<int, int> *arr, int l, int r) {
  if (l == r) return 0;
  long long int inv = 0;
  int mi = (l + r) / 2;
  inv = inversions(arr, l, mi) + inversions(arr, mi + 1, r);
  int i = l;
  int j = mi + 1;
  vector<pair<int, int>> temp;
  while ((j <= r) && (i <= mi)) {
    if (arr[j].first >= arr[i].first) {
      temp.push_back(arr[i]);
      i++;
    } else {
      temp.push_back(arr[j]);
      for (int ct = mi; ct >= i; ct--) {
        pai.push_back(make_pair(arr[ct].second + 1, arr[j].second + 1));
      }
      j++;
      inv = inv + mi - i + 1;
    }
  }
  while (i <= mi) {
    temp.push_back(arr[i]);
    i++;
  }
  while (j <= r) {
    temp.push_back(arr[j]);
    j++;
  }
  for (int g = l; g <= r; g++) {
    arr[g] = temp[g - l];
  }
  return inv;
}
int main() {
  int n;
  cin >> n;
  pair<int, int> arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i].first;
    arr[i].second = i;
  }
  cout << inversions(arr, 0, n - 1) << "\n";
  for (int i = pai.size() - 1; i >= 0; i--) {
    cout << pai[i].first << " " << pai[i].second << "\n";
  }
}
