#include <bits/stdc++.h>
using namespace std;
int dp[1007][1007];
struct pp {
  int i, j;
};
pp p[1007][1007];
int n;
int a[1007];
pp ans[1007];
bool flag[1007];
int main() {
  scanf("%d", &n);
  int i, j;
  for (i = 0; i < n; i++) scanf("%d", &a[i]);
  bool ok = false;
  if (n & 1) {
    ok = true;
    n++;
  }
  for (i = 0; i <= n + 1; i++)
    for (j = 0; j <= n + 1; j++) dp[i][j] = 2000000000;
  dp[0][1] = 0;
  for (i = 0; i < n; i++)
    for (j = i + 1; j < n; j++) {
      if (dp[i][j + 2] > dp[i][j] + max(a[j + 1], a[j])) {
        dp[i][j + 2] = dp[i][j] + max(a[j + 1], a[j]);
        p[i][j + 2].i = i;
        p[i][j + 2].j = j;
      }
      if (dp[j + 1][j + 2] > dp[i][j] + max(a[i], a[j])) {
        dp[j + 1][j + 2] = dp[i][j] + max(a[i], a[j]);
        p[j + 1][j + 2].i = i;
        p[j + 1][j + 2].j = j;
      }
      if (dp[j][j + 2] > dp[i][j] + max(a[i], a[j + 1])) {
        dp[j][j + 2] = dp[i][j] + max(a[i], a[j + 1]);
        p[j][j + 2].i = i;
        p[j][j + 2].j = j;
      }
    }
  printf("%d\n", dp[n][n + 1]);
  int x, y;
  y = n;
  x = n + 1;
  int coun = 0;
  int tem[7];
  int coun2;
  while (x != 0 || y != 0) {
    coun2 = 0;
    int predx, predy;
    predx = p[y][x].j;
    predy = p[y][x].i;
    if (!flag[predy]) {
      flag[predy] = true;
      tem[coun2++] = predy;
    }
    for (i = predx; i < min(i + 4, n); i++)
      if (!flag[i]) {
        flag[i] = true;
        tem[coun2++] = i;
      }
    if (coun2 == 2) {
      ans[coun].i = tem[0];
      ans[coun++].j = tem[1];
    }
    if (coun2 == 1) {
      ans[coun].i = tem[0];
      ans[coun++].j = n + 2;
    }
    x = predx;
    y = predy;
  }
  if (ok) n--;
  for (i = coun - 1; i > -1 && ans[i].i < n; i--) {
    printf("%d", ans[i].i + 1);
    if (ans[i].j < n) printf(" %d", ans[i].j + 1);
    printf("\n");
  }
  return 0;
}
