#include <bits/stdc++.h>
using namespace std;
int n;
int a[1010], d[1010][1010], dp[1010][1010];
int ans;
int go(int x, int y) {
  int minn;
  if (y > n)
    return a[x];
  else if (y == n)
    return max(a[x], a[y]);
  else if (dp[x][y] > 0)
    return dp[x][y];
  else {
    minn = go(x, y + 2) + max(a[y], a[y + 1]);
    int k = 1;
    int tmp = go(y, y + 2) + max(a[x], a[y + 1]);
    if (tmp < minn) {
      minn = tmp;
      k = 2;
    }
    tmp = go(y + 1, y + 2) + max(a[x], a[y]);
    if (tmp < minn) {
      minn = tmp;
      k = 3;
    }
    dp[x][y] = minn;
    d[x][y] = k;
    return minn;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  ans = go(1, 2);
  printf("%d\n", ans);
  int i, j;
  for (i = 1, j = 2; j < n; j += 2) {
    if (d[i][j] == 1)
      printf("%d %d\n", j, j + 1);
    else if (d[i][j] == 2) {
      printf("%d %d\n", i, j + 1);
      i = j;
    } else {
      printf("%d %d\n", i, j);
      i = j + 1;
    }
  }
  if (j == n)
    printf("%d %d\n", i, j);
  else
    printf("%d\n", i);
  return 0;
}
