#include <bits/stdc++.h>
using namespace std;
const int N = 5010;
const int INF = 0x3f3f3f3f;
inline int read() {
  int x = 0;
  bool f = true;
  char c = getchar();
  while (!isdigit(c)) {
    if (c == '-') f = false;
    c = getchar();
  }
  while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
  return f ? x : -x;
}
int n, a[N], f[N][N];
int pre[N][N];
inline void out(int x) {
  if (a[x]) printf("%d ", x);
}
inline void Output(int i, int j) {
  if (!i) return;
  int pos = pre[i][j];
  Output(i - 1, pos);
  if (j < (i << 1))
    out(i << 1), out(i << 1 | 1), puts("");
  else if (j == i << 1)
    out(pos), out(i << 1 | 1), puts("");
  else
    out(pos), out(i << 1), puts("");
}
int main() {
  n = read();
  for (register int i = 1; i <= n; ++i) a[i] = read();
  for (register int i = 1; i <= n; ++i) {
    for (register int j = 1; j <= n + 2; ++j) f[i][j] = INF;
  }
  for (register int i = 1; i <= (n + 1) >> 1; ++i) {
    for (register int j = 1; j <= 2 * i - 1; ++j) {
      if (f[i - 1][j] + max(a[i << 1], a[i << 1 | 1]) < f[i][j])
        f[i][j] = f[i - 1][j] + max(a[i << 1], a[i << 1 | 1]), pre[i][j] = j;
      if (f[i][i << 1], f[i - 1][j] + max(a[j], a[i << 1 | 1]) < f[i][i << 1])
        f[i][i << 1] = f[i - 1][j] + max(a[j], a[i << 1 | 1]),
                  pre[i][i << 1] = j;
      if (f[i - 1][j] + max(a[j], a[i << 1]) < f[i][i << 1 | 1])
        f[i][i << 1 | 1] = f[i - 1][j] + max(a[j], a[i << 1]),
                      pre[i][i << 1 | 1] = j;
    }
  }
  printf("%d\n", f[(n + 1) >> 1][n + 1]);
  Output((n + 1) >> 1, n + 1);
  return 0;
}
