#include <bits/stdc++.h>
using namespace std;
inline int in() {
  int32_t x;
  scanf("%d", &x);
  return x;
}
inline long long lin() {
  long long x;
  scanf("%lld", &x);
  return x;
}
inline string get() {
  char ch[2000010];
  scanf("%s", ch);
  return ch;
}
const int MAX_LG = 21;
const long long maxn = 1e3 + 10;
const long long base = 29;
const long long mod = 1e9 + 7;
const long long INF = 1e18 + 100;
long long n, a[maxn], dp[maxn][maxn];
bool mark[maxn][maxn];
pair<long long, long long> nxt[maxn][maxn];
pair<long long, long long> pick[maxn][maxn];
inline long long calc(long long pos, long long pre) {
  if (pos == 6 && pre == 1) {
  }
  if (pos > n) return a[pre];
  if (mark[pos][pre]) return dp[pos][pre];
  mark[pos][pre] = true;
  if (pre == 0) {
    long long A = calc(pos + 2, 0) + max(a[pos], a[pos + 1]);
    long long B = calc(pos + 3, pos + 1) + max(a[pos], a[pos + 2]);
    long long C = calc(pos + 3, pos) + max(a[pos + 1], a[pos + 2]);
    if (A <= min(B, C)) {
      nxt[pos][0] = {pos + 2, 0};
      pick[pos][0] = {pos, pos + 1};
    } else if (B <= min(A, C)) {
      nxt[pos][0] = {pos + 3, pos + 1};
      pick[pos][0] = {pos, pos + 2};
    } else {
      pick[pos][0] = {pos + 1, pos + 2};
      nxt[pos][0] = {pos + 3, pos};
    }
    return dp[pos][0] = min(min(A, B), C);
  } else {
    long long A = calc(pos + 2, pre) + max(a[pos], a[pos + 1]);
    long long B = calc(pos + 1, 0) + max(a[pos], a[pre]);
    long long C = calc(pos + 2, pos) + max(a[pos + 1], a[pre]);
    dp[pos][pre] = min(min(A, B), C);
    long long val = dp[pos][pre];
    if (val == A) {
      nxt[pos][pre] = {pos + 2, pre};
      pick[pos][pre] = {pos, pos + 1};
    } else if (val == B) {
      nxt[pos][pre] = {pos + 1, 0};
      pick[pos][pre] = {pos, pre};
    } else if (val == C) {
      nxt[pos][pre] = {pos + 2, pos};
      pick[pos][pre] = {pos + 1, pre};
    }
    return dp[pos][pre];
  }
}
int32_t main() {
  memset(dp, 63, sizeof dp);
  for (long long i = 0; i < maxn; i++)
    for (long long j = 0; j < maxn; j++) nxt[i][j] = {INF, INF};
  n = in();
  for (long long i = 1; i <= n; i++) a[i] = in();
  cout << calc(1, 0) << "\n";
  pair<long long, long long> cur = {1, 0};
  while ((cur.first <= n || cur.second <= n)) {
    if (cur.first > n && cur.second) {
      cout << cur.second << "\n";
      break;
    }
    pair<long long, long long> pk = pick[cur.first][cur.second];
    if (pk.first <= n && pk.first) cout << pk.first << " ";
    if (pk.second <= n && pk.second) cout << pk.second;
    cout << "\n";
    cur = nxt[cur.first][cur.second];
  }
}
