#include <bits/stdc++.h>
using namespace std;
int arr[1001];
int fmem[1001], gmem[1001][1001];
int n;
int min(int a, int b, int c) { return min(min(a, b), c); }
int g(int, int);
void gtrace(int, int);
int f(int s) {
  if (s == n - 1) return arr[s];
  if (s == n - 2) return max(arr[s], arr[s + 1]);
  if (fmem[s] != -1) return fmem[s];
  return fmem[s] = min(f(s + 2) + max(arr[s], arr[s + 1]),
                       g(s + 3, s + 1) + max(arr[s], arr[s + 2]),
                       g(s + 3, s) + max(arr[s + 1], arr[s + 2]));
}
int g(int s, int l) {
  if (s == n) return arr[l];
  if (s == n - 1) return max(arr[l], arr[s]);
  if (gmem[s][l] != -1) return gmem[s][l];
  return gmem[s][l] = min(f(s + 1) + max(arr[l], arr[s]),
                          g(s + 2, s) + max(arr[l], arr[s + 1]),
                          g(s + 2, l) + max(arr[s], arr[s + 1]));
}
void ftrace(int s) {
  if (s == n - 1) {
    cout << s + 1 << endl;
    return;
  }
  if (s == n - 2) {
    cout << s + 1 << " " << s + 2 << endl;
    return;
  }
  int a = f(s + 2) + max(arr[s], arr[s + 1]);
  int b = g(s + 3, s + 1) + max(arr[s], arr[s + 2]);
  int c = g(s + 3, s) + max(arr[s + 1], arr[s + 2]);
  if (a <= b && a <= c) {
    cout << s + 1 << " " << s + 2 << endl;
    ftrace(s + 2);
    return;
  }
  if (b <= a && b <= c) {
    cout << s + 1 << " " << s + 3 << endl;
    gtrace(s + 3, s + 1);
    return;
  }
  if (c <= a && c <= b) {
    cout << s + 2 << " " << s + 3 << endl;
    gtrace(s + 3, s);
    return;
  }
}
void gtrace(int s, int l) {
  if (s == n) {
    cout << l + 1 << endl;
    return;
  }
  if (s == n - 1) {
    cout << l + 1 << " " << s + 1 << endl;
    return;
  }
  int a = f(s + 1) + max(arr[l], arr[s]);
  int b = g(s + 2, s) + max(arr[l], arr[s + 1]);
  int c = g(s + 2, l) + max(arr[s], arr[s + 1]);
  if (a <= b && a <= c) {
    cout << l + 1 << " " << s + 1 << endl;
    ftrace(s + 1);
    return;
  }
  if (b <= a && b <= c) {
    cout << l + 1 << " " << s + 2 << endl;
    gtrace(s + 2, s);
    return;
  }
  if (c <= a && c <= b) {
    cout << s + 1 << " " << s + 2 << endl;
    gtrace(s + 2, l);
    return;
  }
}
int main() {
  memset(fmem, -1, sizeof fmem);
  memset(gmem, -1, sizeof gmem);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  cout << f(0) << endl;
  ftrace(0);
  return 0;
}
