#include <bits/stdc++.h>
using namespace std;
inline int max(int x, int y) { return x > y ? x : y; }
inline int min(int x, int y) { return x < y ? x : y; }
const int N = 1000 + 50;
const int mod = 1e9 + 7;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  return x * f;
}
int n, a[N], dp[N][N], out[N][N][3];
inline void ass(int i, int j, int x, int y, int z) {
  out[i][j][0] = x;
  out[i][j][1] = y;
  out[i][j][2] = z;
}
inline void print(int x, int y) {
  if (y == 0) return;
  print(x - 1, out[x][y][2]);
  if (out[x][y][0] <= n) cout << out[x][y][0] << " ";
  if (out[x][y][1] <= n) cout << out[x][y][1] << " ";
  cout << endl;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  memset(dp, 63, sizeof(dp));
  dp[1][1] = max(a[2], a[3]);
  dp[1][2] = max(a[1], a[3]);
  dp[1][3] = max(a[2], a[1]);
  ass(1, 1, 2, 3, 0);
  ass(1, 2, 1, 3, 0);
  ass(1, 3, 1, 2, 0);
  int m = (n & 1) ? n / 2 + 1 : n / 2;
  for (int i = 2; i <= m; i++) {
    int x = i << 1, y = i << 1 | 1;
    for (int j = 1; j < x; j++) {
      if (dp[i][x] > dp[i - 1][j] + max(a[j], a[y])) {
        dp[i][x] = dp[i - 1][j] + max(a[j], a[y]);
        ass(i, x, j, y, j);
      }
      if (dp[i][y] > dp[i - 1][j] + max(a[j], a[x])) {
        dp[i][y] = dp[i - 1][j] + max(a[j], a[x]);
        ass(i, y, j, x, j);
      }
      if (dp[i][j] > dp[i - 1][j] + max(a[y], a[x])) {
        dp[i][j] = dp[i - 1][j] + max(a[y], a[x]);
        ass(i, j, x, y, j);
      }
    }
  }
  cout << dp[m][n + 1] << endl;
  print(m, n + 1);
}
