#include <bits/stdc++.h>
using namespace std;
int PD[1010][1010];
bool mark[1010][1010];
int as[1010], n;
int pros[1010][1010][2];
int es[1010][1010][2];
int maxi(int a, int b) {
  if (a > b) return a;
  return b;
}
int rec(int p1, int p2) {
  if (p1 > n) return 0;
  if (p2 > n) {
    es[p1][p2][0] = p1;
    return as[p1];
  }
  if (mark[p1][p2]) return PD[p1][p2];
  mark[p1][p2] = true;
  int p3 = p2 + 1;
  PD[p1][p2] = maxi(as[p1], as[p2]) + rec(p3, p3 + 1);
  pros[p1][p2][0] = p3;
  pros[p1][p2][1] = p3 + 1;
  es[p1][p2][0] = p1;
  es[p1][p2][1] = p2;
  int aux = maxi(as[p1], as[p3]) + rec(p2, p3 + 1);
  if (aux < PD[p1][p2]) {
    PD[p1][p2] = aux;
    pros[p1][p2][0] = p2;
    pros[p1][p2][1] = p3 + 1;
    es[p1][p2][0] = p1;
    es[p1][p2][1] = p3;
  }
  aux = maxi(as[p2], as[p3]) + rec(p1, p3 + 1);
  if (aux < PD[p1][p2]) {
    PD[p1][p2] = aux;
    pros[p1][p2][0] = p1;
    pros[p1][p2][1] = p3 + 1;
    es[p1][p2][0] = p2;
    es[p1][p2][1] = p3;
  }
  return PD[p1][p2];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i) scanf("%d", &as[i]);
  printf("%d\n", rec(1, 2));
  int at1 = 1, at2 = 2;
  int ate = n / 2, t1;
  for (int i = 0; i < ate; ++i) {
    printf("%d %d\n", es[at1][at2][0], es[at1][at2][1]);
    t1 = at1;
    at1 = pros[t1][at2][0];
    at2 = pros[t1][at2][1];
  }
  if (n & 1) {
    printf("%d\n", es[at1][at2][0]);
  }
  return 0;
}
