#include <bits/stdc++.h>
using namespace std;
const int maxn = 1010;
const int infi = 1000000000;
int n, v[maxn], dp[maxn][maxn], path[maxn][maxn];
int cal(int i, int j) {
  if (j > n) {
    return v[i];
  }
  if (j == n) {
    return max(v[i], v[j]);
  }
  int &ret = dp[i][j];
  if (ret != -1) return ret;
  int k = j + 1;
  ret = infi;
  ret = min(ret, max(v[i], v[j]) + cal(k, j + 2));
  ret = min(ret, max(v[j], v[k]) + cal(i, j + 2));
  ret = min(ret, max(v[k], v[i]) + cal(j, j + 2));
  return ret;
}
void output(int i, int j) {
  if (j > n) {
    printf("%d\n", i);
    return;
  }
  if (j == n) {
    printf("%d %d\n", i, j);
    return;
  }
  int ret = cal(i, j), k = j + 1;
  if (ret == max(v[i], v[j]) + cal(k, j + 2)) {
    printf("%d %d\n", i, j);
    output(k, j + 2);
  } else if (ret == max(v[j], v[k]) + cal(i, j + 2)) {
    printf("%d %d\n", j, k);
    output(i, j + 2);
  } else {
    printf("%d %d\n", k, i);
    output(j, j + 2);
  }
}
int main() {
  while (cin >> n) {
    for (int i = 1; i <= n; ++i) cin >> v[i];
    memset(dp, -1, sizeof(dp));
    cout << cal(1, 2) << endl;
    output(1, 2);
  }
  return 0;
}
