#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline bool chkmax(T &x, const T2 &y) {
  return x < y ? x = y, 1 : 0;
}
template <class T, class T2>
inline bool chkmin(T &x, const T2 &y) {
  return x > y ? x = y, 1 : 0;
}
const long long mod = 1e9 + 7;
template <class T>
inline void fix(T &x) {
  if (x >= mod | x <= -mod) {
    x %= mod;
  }
  if (x < 0) {
    x += mod;
  }
}
const long long MAX_N = 2010;
long long arr[MAX_N], got[MAX_N];
signed main() {
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    got[i] = false;
  }
  long long l = 0, r = n - 1;
  long long ret = 0;
  for (long long k = 0; k < n; k++) {
    long long mx = 0, ind = 0, pos = -1;
    for (long long i = 0; i < n; i++) {
      if (got[i]) {
        continue;
      }
      if (chkmax(mx, arr[i] * abs(i - l))) {
        pos = 0;
        ind = i;
      }
      if (chkmax(mx, arr[i] * abs(i - r))) {
        pos = 1;
        ind = i;
      }
    }
    ret += mx;
    got[ind] = true;
    if (pos == 0) {
      l++;
    } else {
      r--;
    }
    cout << ind << " " << l << " " << r << "\n";
  }
  cout << ret;
  return 0;
}
