#include <bits/stdc++.h>
using namespace std;
int n;
int cnt[1001][1001];
int process[1001][1001];
void printProc(int i, int j) {
  if (j == n + 1) {
    cout << i << "\n";
    return;
  }
  if (process[i][j] == 10) {
    cout << j << " " << j + 1 << "\n";
    printProc(i, j + 2);
  } else if (process[i][j] == 20) {
    cout << i << " " << j + 1 << "\n";
    printProc(j, j + 2);
  } else if (process[i][j] == 30) {
    cout << i << " " << j << "\n";
    printProc(j + 1, j + 2);
  } else if (process[i][j] == 40) {
    cout << i << " " << j << "\n";
  }
}
int main() {
  cin >> n;
  int a[1001];
  memset(process, 0, sizeof(process));
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    cnt[i][n] = max(a[i], a[n]);
    process[i][n] = 40;
    cnt[i][n + 1] = a[i];
  }
  cnt[n][n + 1] = a[n];
  for (int i = n - 2; i > 0; i--) {
    for (int j = n - 1; j > i; j--) {
      int leavei = cnt[i][j + 2] + max(a[j], a[j + 1]);
      int leavejplus1 = cnt[j + 1][j + 2] + max(a[i], a[j]);
      int leavej = cnt[j][j + 2] + max(a[j + 1], a[i]);
      cnt[i][j] = min(leavei, min(leavej, leavejplus1));
      if (cnt[i][j] == leavei)
        process[i][j] = 10;
      else if (cnt[i][j] == leavej)
        process[i][j] = 20;
      else if (cnt[i][j] == leavejplus1)
        process[i][j] = 30;
    }
  }
  cout << cnt[1][2] << "\n";
  printProc(1, 2);
}
