#include <bits/stdc++.h>
using namespace std;
int n, a[1010], f[1010][1010];
struct dsa {
  int x, y;
} g[1010][1010], h[1010][1010];
void outt(int x, int y) {
  if (!x || !y) return;
  outt(g[x][y].x, g[x][y].y);
  if (h[x][y].x) printf("%d %d\n", h[x][y].x, h[x][y].y);
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 0; i <= n + 2; i++)
    for (int j = 0; j <= n + 2; j++) f[i][j] = 1e9;
  f[1][2] = 0;
  for (int i = 1; i < n - 1; i++)
    for (int j = i + 1; j < n; j++) {
      if (f[i][j] + max(a[i], a[j]) < f[j + 1][j + 2]) {
        f[j + 1][j + 2] = f[i][j] + max(a[i], a[j]);
        g[j + 1][j + 2] = {i, j};
        h[j + 1][j + 2] = {i, j};
      }
      if (f[i][j] + max(a[i], a[j + 1]) < f[j][j + 2]) {
        f[j][j + 2] = f[i][j] + max(a[i], a[j + 1]);
        g[j][j + 2] = {i, j};
        h[j][j + 2] = {i, j + 1};
      }
      if (f[i][j] + max(a[j], a[j + 1]) < f[i][j + 2]) {
        f[i][j + 2] = f[i][j] + max(a[j], a[j + 1]);
        g[i][j + 2] = {i, j};
        h[i][j + 2] = {j, j + 1};
      }
    }
  int Min = 1e9;
  dsa ans;
  if (n & 1) {
    for (int i = 1; i <= n; i++)
      if (f[i][n + 1] + a[i] < Min) {
        Min = f[i][n + 1] + a[i];
        ans = {i, n + 1};
      }
  } else {
    for (int i = 1; i < n; i++)
      if (f[i][n] + max(a[i], a[n]) < Min) {
        Min = f[i][n] + max(a[i], a[n]);
        ans = {i, n};
      }
  }
  cout << Min << endl;
  outt(ans.x, ans.y);
  if (ans.y <= n)
    printf("%d %d\n", ans.x, ans.y);
  else
    printf("%d", ans.x);
}
