#include <bits/stdc++.h>
using namespace std;
int a[10000];
int res1[1000];
int res2[1000];
int d[1010][1010];
int l1[1010][1010];
int l2[1010][1010];
int gi[1010][1010];
int gj[1010][1010];
const int inf = (int)1e9;
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  if (n == 1) {
    cout << a[0] << endl << 1;
    return 0;
  }
  if (n == 2) {
    cout << max(a[0], a[1]) << endl << "1 2";
    return 0;
  }
  for (int i = n; i >= 0; i--) {
    for (int j = 0; j < i; j++) {
      int h = inf;
      if (i <= n - 2) h = min(h, d[j][i + 2] + max(a[i], a[i + 1]));
      if (i <= n - 2) h = min(h, d[i][i + 2] + max(a[j], a[i + 1]));
      if (i <= n - 1) h = min(h, d[i + 1][i + 2] + max(a[j], a[i]));
      if (i == n) {
        l1[j][i] = j;
        l2[j][i] = j;
        gi[j][i] = i + 1;
        gj[j][i] = i + 2;
        d[j][i] = a[j];
        continue;
      } else if (i <= n - 2 && h == d[j][i + 2] + max(a[i], a[i + 1])) {
        l1[j][i] = i;
        l2[j][i] = i + 1;
        gi[j][i] = j;
        gj[j][i] = i + 2;
      } else if (i <= n - 2 && h == d[i][i + 2] + max(a[j], a[i + 1])) {
        l1[j][i] = j;
        l2[j][i] = i + 1;
        gi[j][i] = i;
        gj[j][i] = i + 2;
      } else {
        l1[j][i] = j;
        l2[j][i] = i;
        gi[j][i] = i + 1;
        gj[j][i] = i + 2;
      }
      d[j][i] = h;
    }
  }
  int li = 0, lj = 1, nli = li, nlj = lj;
  int res = 0;
  int resc = 0;
  while (res < n) {
    res1[resc] = l1[li][lj];
    res2[resc] = l2[li][lj];
    resc++;
    res += 2;
    nli = gi[li][lj];
    nlj = gj[li][lj];
    li = nli;
    lj = nlj;
  }
  cout << d[0][1] << endl;
  for (int i = 0; i < resc; i++) {
    cout << res1[i] + 1 << " ";
    if (res1[i] != res2[i]) cout << res2[i] + 1;
    cout << endl;
  }
  return 0;
}
