#include <bits/stdc++.h>
using namespace std;
struct data {
  int x, y;
} bap[1005][1005];
int ara[1009], n;
int dp[1005][1005];
int go(int i, int j) {
  int mx = INT_MAX;
  if (i == n - 1) return dp[i][j] = ara[i];
  if (j == n - 1) return dp[i][j] = max(ara[i], ara[j]);
  if (j >= n) return dp[i][j] = ara[i];
  if (dp[i][j] != -1) return dp[i][j];
  if (mx > (max(ara[i], ara[j]) + go(j + 1, j + 2))) {
    mx = max(ara[i], ara[j]) + go(j + 1, j + 2);
    bap[i][j].x = j + 1;
    bap[i][j].y = j + 2;
  }
  if (mx > (max(ara[i], ara[j + 1]) + go(j, j + 2))) {
    mx = max(ara[i], ara[j + 1]) + go(j, j + 2);
    bap[i][j].x = j, bap[i][j].y = j + 2;
  }
  if (mx > (max(ara[j], ara[j + 1]) + go(i, j + 2))) {
    mx = max(ara[j], ara[j + 1]) + go(i, j + 2);
    bap[i][j].x = i;
    bap[i][j].y = j + 2;
  }
  return dp[i][j] = mx;
}
int main() {
  scanf("%d", &n);
  memset(dp, -1, sizeof(dp));
  memset(bap, -1, sizeof(bap));
  for (int i = 0; i < n; i++) scanf("%d", &ara[i]);
  if (n == 1) {
    printf("%d\n", ara[0]);
    printf("%d\n", 1);
    return 0;
  }
  int ans = go(0, 1);
  printf("%d\n", ans);
  int odd = -1, bhag = (n % 2) + (n / 2);
  int k = 0, s1 = 0, s2 = 1, coder1 = 100000, coder2 = 100000;
  while (bap[s1][s2].x != -1) {
    int coder1 = bap[s1][s2].x, coder2 = bap[s1][s2].y;
    if (coder1 == s2 + 1 && coder2 == s2 + 2)
      printf("%d %d\n", s1 + 1, s2 + 1);
    else if (coder1 == s2 && coder2 == s2 + 2 && s2 + 1 < n)
      printf("%d %d\n", s1 + 1, s2 + 2);
    else if (coder1 == s1 && coder2 == s2 + 2 && s2 + 1 < n)
      printf("%d %d\n", s2 + 1, s2 + 2);
    s1 = coder1, s2 = coder2;
  }
  if (s2 < n) {
    printf("%d %d\n", s1 + 1, s2 + 1);
  } else
    printf("%d\n", s1 + 1);
  return 0;
}
