#include <bits/stdc++.h>
using namespace std;
int const N = 1000;
int n, v[N + 10];
unsigned long long mem[N + 1][N + 1];
pair<int, int> best[N + 1][N + 1];
unsigned long long solve(int i, int pr) {
  if (i == n)
    return v[pr];
  else if (i + 1 == n)
    return max(v[pr], v[i]);
  unsigned long long& rv = mem[i][pr];
  if (rv != -1) return rv;
  typeof(best[i][pr])& b = (best[i][pr]);
  rv = solve(i + 2, pr) + max(v[i], v[i + 1]);
  b = make_pair(i, i + 1);
  unsigned long long r = solve(i + 2, i) + max(v[i + 1], v[pr]);
  if (r < rv) {
    rv = r;
    b = make_pair(i + 1, pr);
  }
  r = solve(i + 2, i + 1) + max(v[i], v[pr]);
  if (r < rv) {
    rv = r;
    b = make_pair(i, pr);
  }
  return rv;
}
ostream& operator<<(ostream& out, pair<int, int> p) {
  if (p.first > p.second) swap(p.first, p.second);
  if (p.second == n)
    out << (1 + p.first);
  else
    out << (1 + p.first) << ' ' << (1 + p.second);
  return out;
}
void print(int i, int pr) {
  if (i == n)
    cout << (1 + pr) << '\n';
  else if (i + 1 == n)
    cout << make_pair(pr, i) << '\n';
  else {
    pair<int, int> const& b = best[i][pr];
    cout << b << '\n';
    print(i + 2, i + i + 1 + pr - b.first - b.second);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i != n; ++i) scanf("%d", &v[i]);
  if (n == 1)
    cout << v[0] << ' ' << endl << "1\n";
  else if (n == 2)
    cout << max(v[0], v[1]) << endl << "1 2\n";
  else {
    memset(mem, -1, sizeof(mem));
    pair<int, int> best(1, 2);
    unsigned long long rv = solve(3, 0) + max(v[1], v[2]);
    unsigned long long r = solve(3, 1) + max(v[0], v[2]);
    if (r < rv) {
      rv = r;
      best = make_pair(0, 2);
    }
    r = solve(3, 2) + max(v[0], v[1]);
    if (r < rv) {
      rv = r;
      best = make_pair(0, 1);
    }
    cout << rv << endl;
    cout << best << '\n';
    print(3, 3 - best.first - best.second);
  }
  return 0;
}
