#include <bits/stdc++.h>
int IntMaxVal = (int)1e20;
long long LongMaxVal = (long long)1e20;
using namespace std;
int n;
vector<int> a;
int **cache;
int getCost(int op, int carried) {
  if (cache[op][carried] != -1) return cache[op][carried];
  int i1 = 2 * op - 1;
  int i2 = i1 + 1;
  int ac = a[carried];
  if (i1 >= n) return ac;
  int a1 = a[i1];
  if (i2 >= n) return max(a1, ac);
  int a2 = a[i2];
  auto opt = make_pair(max(a1, a2) + getCost(op + 1, carried), carried);
  { opt = min(opt, make_pair(max(ac, a2) + getCost(op + 1, i1), i1)); };
  { opt = min(opt, make_pair(max(ac, a1) + getCost(op + 1, i2), i2)); };
  cache[op][carried] = opt.first;
  return opt.first;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  a.resize(n);
  for (int i = 0; i < n - 1 + 1; ++i) cin >> a[i];
  int nOps = (n + 1) / 2;
  int carryCost[nOps + 1][n];
  cache = new int *[nOps + 1];
  for (int i = 1; i < nOps + 1; ++i) {
    cache[i] = new int[n];
    memset(cache[i], -1, n * sizeof(int));
  }
  if (n == 1) {
    cout << a[0] << endl;
    cout << 1;
  } else if (n == 2) {
    cout << max(a[0], a[1]) << endl;
    cout << 1 << ' ' << 2;
  } else {
    vector<int> q;
    q.push_back(0);
    for (int op = 1; op < nOps + 1; ++op) {
      int i1 = op * 2 - 1;
      int i2 = i1 + 1;
      if (i1 < n) q.push_back(i1);
      if (i2 < n) q.push_back(i2);
      if (q.size() == 1) {
        cout << q[0] + 1;
      } else if (q.size() == 2) {
        cout << q[0] + 1 << ' ' << q[1] + 1;
      } else {
        int i1 = q[0];
        int i2 = q[1];
        int i3 = q[2];
        int a1 = a[q[0]];
        int a2 = a[q[1]];
        int a3 = a[q[2]];
        auto opt = make_pair(max(a1, a2) + getCost(op + 1, i3),
                             make_pair(i3, make_pair(i1, i2)));
        {
          opt = min(opt, make_pair(max(a1, a3) + getCost(op + 1, i2),
                                   make_pair(i2, make_pair(i1, i3))));
        };
        {
          opt = min(opt, make_pair(max(a2, a3) + getCost(op + 1, i1),
                                   make_pair(i1, make_pair(i2, i3))));
        };
        if (op == 1) cout << opt.first << endl;
        cout << opt.second.second.first + 1 << ' '
             << opt.second.second.second + 1 << endl;
        q.clear();
        q.push_back(opt.second.first);
      }
    }
  }
}
