#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e3 + 5;
const int INF = 2147483647;
int n, flag;
int a[MAXN];
int f[MAXN][MAXN];
int from[MAXN][MAXN], way[MAXN][MAXN][2];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) (ch == '-') && (f = -f), ch = getchar();
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  return x * f;
}
void print(int dep, int res) {
  if (!dep) return;
  print(dep - 1, from[dep][res]);
  if (dep != n / 2 || (dep == n / 2 && !flag))
    printf("%d %d\n", way[dep][res][0], way[dep][res][1]);
  else
    printf("%d\n", way[dep][res][0]);
}
int main() {
  register int i, j;
  n = read();
  for (i = 1; i <= n; ++i) a[i] = read();
  if (n & 1) flag = 1, ++n;
  memset(f, 0x7f, sizeof f);
  f[0][1] = 0;
  from[0][1] = 0;
  for (i = 1; i <= n / 2; ++i) {
    int x = i + i, y = x + 1;
    for (j = 1; j < x; ++j)
      if (f[i][j] > f[i - 1][j] + max(a[x], a[y])) {
        f[i][j] = f[i - 1][j] + max(a[x], a[y]);
        from[i][j] = j;
        way[i][j][0] = x;
        way[i][j][1] = y;
      }
    for (j = 1; j < x; ++j)
      if (f[i][x] > f[i - 1][j] + max(a[j], a[y])) {
        f[i][x] = f[i - 1][j] + max(a[j], a[y]);
        from[i][x] = j;
        way[i][x][0] = j;
        way[i][x][1] = y;
      }
    for (j = 1; j < x; ++j)
      if (f[i][y] > f[i - 1][j] + max(a[j], a[x])) {
        f[i][y] = f[i - 1][j] + max(a[j], a[x]);
        from[i][y] = j;
        way[i][y][0] = j;
        way[i][y][1] = x;
      }
  }
  printf("%d\n", f[n / 2][n + 1]);
  print(n / 2, n + 1);
  return 0;
}
