#include <bits/stdc++.h>
using namespace std;
const int N = 1E3 + 5;
int n, a[N], f[N][N];
struct node {
  int u, v, w;
} road[N][N];
void print(int x, int y) {
  if (x != 1) {
    print(x - 1, road[x][y].w);
  }
  if (road[x][y].u > n + 1) {
    cout << road[x][y].v << endl;
    return;
  }
  if (road[x][y].v > n + 1) {
    cout << road[x][y].u << endl;
  }
  cout << road[x][y].u << " " << road[x][y].v << endl;
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  memset(f, 0x3f, sizeof f);
  f[0][1] = 0;
  for (int i = 1; i <= (n + 1) / 2; i++) {
    int x = i * 2;
    int y = i * 2 + 1;
    for (int j = 1; j < x; j++) {
      if (f[i - 1][j] + max(a[x], a[y]) < f[i][j]) {
        f[i][j] = f[i - 1][j] + max(a[x], a[y]);
        road[i][j] = {x, y, j};
      }
      if (f[i - 1][j] + max(a[j], a[y]) < f[i][x]) {
        f[i][x] = f[i - 1][j] + max(a[j], a[y]);
        road[i][x] = {y, j, j};
      }
      if (f[i - 1][j] + max(a[j], a[x]) < f[i][y]) {
        f[i][y] = f[i - 1][j] + max(a[j], a[x]);
        road[i][y] = {x, j, j};
      }
    }
  }
  cout << f[(n + 1) / 2][(n + 1)] << endl;
  print((n + 1) / 2, n + 1);
  return 0;
}
