#include <bits/stdc++.h>
using namespace std;
int n;
int a[1010], dp[1010][1010];
pair<int, int> nxt[1010][1010], take[1010][1010];
bool calc[1010][1010];
int solve(int ft, int bk) {
  if (calc[ft][bk]) return dp[ft][bk];
  if (bk > n) {
    if (ft <= n) {
      nxt[ft][bk] = pair<int, int>(bk, bk + 1);
      take[ft][bk] = pair<int, int>(ft, -1);
      calc[ft][bk] = true;
      return dp[ft][bk] = a[ft] + solve(bk, bk + 1);
    } else {
      nxt[ft][bk] = pair<int, int>(-1, -1);
      take[ft][bk] = pair<int, int>(-1, -1);
      calc[ft][bk] = true;
      return dp[ft][bk] = 0;
    }
  }
  dp[ft][bk] = 0x3f3f3f3f;
  int q = solve(bk + 1, bk + 2);
  if (dp[ft][bk] > max(a[ft], a[bk]) + q) {
    dp[ft][bk] = max(a[ft], a[bk]) + q;
    nxt[ft][bk] = pair<int, int>(bk + 1, bk + 2);
    take[ft][bk] = pair<int, int>(ft, bk);
  }
  if (bk + 1 <= n) {
    q = solve(bk, bk + 2);
    if (dp[ft][bk] > max(a[ft], a[bk + 1]) + q) {
      dp[ft][bk] = max(a[ft], a[bk + 1]) + q;
      nxt[ft][bk] = pair<int, int>(bk, bk + 2);
      take[ft][bk] = pair<int, int>(ft, bk + 1);
    }
  }
  q = solve(ft, bk + 2);
  if (dp[ft][bk] > max(a[bk], a[bk + 1]) + q) {
    dp[ft][bk] = max(a[bk], a[bk + 1]) + q;
    nxt[ft][bk] = pair<int, int>(ft, bk + 2);
    take[ft][bk] = pair<int, int>(bk, bk + 1 <= n ? bk + 1 : -1);
  }
  calc[ft][bk] = true;
  return dp[ft][bk];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  printf("%d\n", solve(1, 2));
  int ft = 1, bk = 2;
  while (nxt[ft][bk] != pair<int, int>(-1, -1)) {
    if (take[ft][bk].second == -1)
      printf("%d\n", take[ft][bk].first);
    else
      printf("%d %d\n", take[ft][bk].first, take[ft][bk].second);
    pair<int, int> nt = nxt[ft][bk];
    ft = nt.first;
    bk = nt.second;
  }
  return 0;
}
