#include <bits/stdc++.h>
using namespace std;
const int N = 1000;
int t[N];
int phases;
int n;
map<pair<int, pair<int, int> >, int> dp;
map<pair<int, pair<int, int> >, pair<int, int> > picks;
int go(int idx, int c, int a, int b) {
  if (idx == phases) return 0;
  pair<int, pair<int, int> > key = make_pair(c, make_pair(a, b));
  map<pair<int, pair<int, int> >, int>::iterator it = dp.find(key);
  if (it != dp.end()) return it->second;
  pair<int, int> pick;
  int best;
  int d = c + 1;
  pick = make_pair(a, b);
  best = max(t[a], t[b]) + go(idx + 1, c + 2, c, d);
  int test = max(t[a], t[c]) + go(idx + 1, c + 2, b, d);
  if (idx + 1 < phases) {
    if (test < best) {
      best = test;
      pick = make_pair(a, c);
    }
    test = max(t[b], t[c]) + go(idx + 1, c + 2, a, d);
    if (test < best) {
      best = test;
      pick = make_pair(b, c);
    }
  }
  dp[key] = best;
  picks[key] = pick;
  return best;
}
inline pair<int, int> getPick(int curr, int a, int b) {
  pair<int, pair<int, int> > key = make_pair(curr, make_pair(a, b));
  return picks[key];
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> t[i];
  if (n & 1) t[n] = 0;
  phases = (n / 2) + (n & 1);
  int res = go(0, 2, 0, 1);
  cout << res << endl;
  int a = 0, b = 1;
  int curr = 2;
  for (int i = 0; i < phases; i++, curr += 2) {
    pair<int, int> p = getPick(curr, a, b);
    cout << (p.first + 1);
    if (p.second < n) cout << " " << (p.second + 1);
    cout << endl;
    int c = curr, d = curr + 1;
    if (p.first == a && p.second == b)
      a = c, b = d;
    else if (p.first == a && p.second == c)
      a = b, b = d;
    else if (p.first == b && p.second == c)
      b = d;
  }
  return 0;
}
