#include <bits/stdc++.h>
using namespace std;
long long n, d[1007], t[1007][1007], x, y;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> d[i];
  }
  for (int i = 1; i < n; i++) {
    t[i][n] = max(d[i], d[n]);
    t[i][n + 1] = d[i];
  }
  t[n][n + 1] = d[n];
  for (int i = n - 2; i >= 1; i--) {
    for (int j = n - 1; j > i; j--) {
      t[i][j] = min(min(max(d[i], d[j]) + t[j + 1][j + 2],
                        max(d[i], d[j + 1]) + t[j][j + 2]),
                    max(d[j], d[j + 1]) + t[i][j + 2]);
    }
  }
  cout << t[1][2] << endl;
  x = 1;
  y = 2;
  while (y <= n) {
    if (t[x][y] == max(d[x], d[y]) + t[y + 1][y + 2]) {
      cout << x << " " << y << endl;
      x = y + 1;
      y += 2;
    } else if (t[x][y] == max(d[x], d[y + 1]) + t[y][y + 2]) {
      cout << x << " " << y + 1 << endl;
      x = y;
      y += 2;
    } else {
      cout << y << " " << y + 1 << endl;
      y += 2;
    }
  }
  if (x <= n) {
    cout << x << endl;
  }
  return 0;
}
