#include <bits/stdc++.h>
using namespace std;
int F[1005][1005], a[1005], n;
int call(int i, int j) {
  int &ret = F[i][j];
  if (ret != -1) return ret;
  if (j == n)
    return ret = a[i];
  else if (j == n - 1)
    return ret = max(a[i], a[j]);
  return ret = min(max(a[j], a[j + 1]) + call(i, j + 2),
                   min(max(a[i], a[j]) + call(j + 1, j + 2),
                       max(a[i], a[j + 1]) + call(j, j + 2)));
}
void backtrack(int i, int j) {
  if (j == n) {
    cout << i + 1 << "\n";
  } else if (j == n - 1) {
    cout << i + 1 << " " << j + 1 << "\n";
  } else {
    if (F[i][j] == max(a[j], a[j + 1]) + F[i][j + 2]) {
      cout << j + 1 << " " << j + 2 << "\n";
      backtrack(i, j + 2);
    } else if (F[i][j] == max(a[i], a[j]) + F[j + 1][j + 2]) {
      cout << i + 1 << " " << j + 1 << "\n";
      backtrack(j + 1, j + 2);
    } else {
      cout << i + 1 << " " << j + 2 << "\n";
      backtrack(j, j + 2);
    }
  }
  return;
}
int main() {
  cin >> n;
  memset(F, -1, sizeof(F));
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << call(0, 1) << "\n";
  backtrack(0, 1);
}
