#include <bits/stdc++.h>
using namespace std;
int n, i, j, p;
int A[1001], M[1001][1001], P[1001][1001];
int solve(int i, int j) {
  int &res = M[i][j];
  if (res == -1)
    if (j >= n - 1)
      res = max(A[i], A[j]);
    else {
      res = solve(i, j + 2) + max(A[j], A[j + 1]);
      P[i][j] = i;
      if (solve(j, j + 2) + max(A[i], A[j + 1]) < res) {
        res = solve(j, j + 2) + max(A[i], A[j + 1]);
        P[i][j] = j;
      }
      if (solve(j + 1, j + 2) + max(A[i], A[j]) < res) {
        res = solve(j + 1, j + 2) + max(A[i], A[j]);
        P[i][j] = j + 1;
      }
    }
  return res;
}
int main() {
  scanf("%d", &n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]);
  if (n <= 2) {
    printf("%d\n", max(A[0], A[1]));
    for (i = 1; i <= n; i++) printf("%d ", i);
    return 0;
  }
  memset(M, -1, sizeof M);
  printf("%d\n", solve(0, 1));
  for (i = 0, j = 1; j < n - 1; j += 2) {
    p = P[i][j];
    if (i != p) printf("%d ", i + 1);
    if (j != p) printf("%d ", j + 1);
    if (j + 1 != p) printf("%d ", j + 2);
    printf("\n");
    i = p;
  }
  printf("%d ", i + 1);
  if (j < n) printf("%d", j + 1);
  return 0;
}
