#include <bits/stdc++.h>
using namespace std;
int dp[1001][1001];
vector<int> v;
int f(int last, int ind) {
  if (ind == v.size() - 1) return max(v[last], v[ind]);
  if (ind == v.size()) return v[last];
  if (dp[last][ind] != -1) return dp[last][ind];
  int c1 = f(last, ind + 2) + max(v[ind], v[ind + 1]);
  int c2 = f(ind + 1, ind + 2) + max(v[last], v[ind]);
  int c3 = f(ind, ind + 2) + max(v[last], v[ind + 1]);
  return dp[last][ind] = min(min(c1, c2), c3);
}
void build(int last, int ind) {
  if (ind == v.size() - 1) {
    cout << last + 1 << " " << ind + 1 << endl;
    return;
  }
  if (ind == v.size()) {
    cout << last + 1 << endl;
    return;
  }
  int c1 = f(last, ind + 2) + max(v[ind], v[ind + 1]);
  int c2 = f(ind + 1, ind + 2) + max(v[last], v[ind]);
  int c3 = f(ind, ind + 2) + max(v[last], v[ind + 1]);
  int c = f(last, ind);
  if (c == c1) {
    cout << ind + 1 << " " << ind + 1 + 1 << endl;
    build(last, ind + 2);
  } else if (c == c2) {
    cout << last + 1 << " " << ind + 1 << endl;
    build(ind + 1, ind + 2);
  } else {
    cout << last + 1 << " " << ind + 1 + 1 << endl;
    build(ind, ind + 2);
  }
}
int main() {
  int n;
  cin >> n;
  if (cin.fail()) return 0;
  v = vector<int>(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  memset(dp, -1, sizeof(dp));
  cout << f(0, 1) << endl;
  build(0, 1);
  return 0;
}
