#include <bits/stdc++.h>
using namespace std;
const int N = 1002;
int dp[N][N];
bool vis[N][N];
struct data {
  int x, y, z;
} tr[N][N];
int n;
int a[N];
int backtrack(int, int);
void minimum(int& ans, data& Q, int m, int p, int q, int pos) {
  data P = {m, p, q};
  int neo = max(a[m], a[p]) + backtrack(pos + 1, q);
  if (neo < ans) {
    ans = neo;
    Q = P;
  }
}
int backtrack(int pos, int piv) {
  if (pos == (n + 1) / 2) return a[piv];
  if (vis[pos][piv]) return dp[pos][piv];
  int ans = INT_MAX;
  data nxt;
  int it = 2 * pos + 1;
  minimum(ans, nxt, it, it + 1, piv, pos);
  minimum(ans, nxt, it, piv, it + 1, pos);
  minimum(ans, nxt, it + 1, piv, it, pos);
  vis[pos][piv] = 1;
  tr[pos][piv] = nxt;
  return dp[pos][piv] = ans;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  int ans = backtrack(0, 0);
  printf("%d\n", ans);
  int pi = 0;
  for (int i = 0; i < (n + 1) / 2; ++i) {
    data q = tr[i][pi];
    if (q.x > q.y) swap(q.x, q.y);
    if (0 <= q.x and q.x < n) printf("%d ", q.x + 1);
    if (0 <= q.y and q.y < n) printf("%d ", q.y + 1);
    if (i + 1 == (n + 1) / 2 and q.z >= 0 and q.z < n) printf("%d ", q.z + 1);
    puts("");
    pi = q.z;
  }
  return 0;
}
