#include <bits/stdc++.h>
using namespace std;
template <class T>
T abs(T x) {
  return x > 0 ? x : -x;
}
int n;
int m;
int x[1000];
int was[1001][1001];
int res[1001][1001];
int go(int i, int j) {
  int a = j, b = i, c = i + 1;
  if (i == j) {
    b++;
    c++;
  }
  if (a >= n)
    return 0;
  else if (b >= n)
    return x[a];
  else if (c >= n)
    return max(x[a], x[b]);
  else if (was[i][j])
    return res[i][j];
  was[i][j] = 1;
  int cur = 2e9;
  cur = min(cur, max(x[a], x[b]) + go(c, c));
  cur = min(cur, max(x[a], x[c]) + go(c + 1, b));
  cur = min(cur, max(x[b], x[c]) + go(c + 1, a));
  return res[i][j] = cur;
}
int out(int i, int j) {
  int a = j, b = i, c = i + 1;
  if (i == j) {
    b++;
    c++;
  }
  if (a >= n) return 0;
  if (b >= n) {
    printf("%d\n", a + 1);
    return 0;
  }
  if (c >= n) {
    printf("%d %d\n", a + 1, b + 1);
    return 0;
  }
  int cur = res[i][j];
  if (cur == max(x[a], x[b]) + go(c, c)) {
    printf("%d %d\n", a + 1, b + 1);
    out(c, c);
    return 0;
  }
  if (cur == max(x[a], x[c]) + go(c + 1, b)) {
    printf("%d %d\n", a + 1, c + 1);
    out(c + 1, b);
    return 0;
  }
  if (cur == max(x[b], x[c]) + go(c + 1, a)) {
    printf("%d %d\n", b + 1, c + 1);
    out(c + 1, a);
    return 0;
  }
  return 0;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &x[i]);
  memset(was, 0, sizeof(was));
  printf("%d\n", go(0, 0));
  out(0, 0);
  return 0;
}
