#include <bits/stdc++.h>
using namespace std;
int dp[1200][1200], ara[1200], n, st[1200];
vector<int> vc;
int dp_func(int pos, int take) {
  if (pos > n) return dp[pos][take] = ara[take];
  int a, b, c;
  if (dp[pos][take] != -1) return dp[pos][take];
  int ret = 2147483647;
  if (pos == take) {
    a = ara[pos];
    b = ara[pos + 1];
    c = ara[pos + 2];
    ret = min(ret, dp_func(pos + 3, pos) + max(b, c));
    ret = min(ret, dp_func(pos + 3, pos + 1) + max(a, c));
    ret = min(ret, dp_func(pos + 2, pos + 2) + max(a, b));
    return dp[pos][take] = ret;
  }
  a = ara[take];
  b = ara[pos];
  c = ara[pos + 1];
  ret = min(ret, dp_func(pos + 2, take) + max(b, c));
  ret = min(ret, dp_func(pos + 1, pos + 1) + max(a, b));
  ret = min(ret, dp_func(pos + 2, pos) + max(a, c));
  return dp[pos][take] = ret;
}
void print(int pos, int take) {
  if (pos > n) {
    if (!st[take]) return;
    vc.push_back(take);
    return;
  }
  int a, b, c;
  int ret = dp[pos][take];
  if (pos == take) {
    a = ara[pos];
    b = ara[pos + 1];
    c = ara[pos + 2];
    if (ret == dp_func(pos + 3, pos) + max(b, c)) {
      if (st[pos + 1]) {
        vc.push_back(pos + 1);
      }
      if (st[pos + 2]) {
        vc.push_back(pos + 2);
      }
      print(pos + 3, pos);
      return;
    }
    if (ret == dp_func(pos + 3, pos + 1) + max(a, c)) {
      if (st[pos]) {
        vc.push_back(pos);
      }
      if (st[pos + 2]) {
        vc.push_back(pos + 2);
      }
      print(pos + 3, pos + 1);
      return;
    }
    if (ret == dp_func(pos + 2, pos + 2) + max(a, b)) {
      if (st[pos]) vc.push_back(pos);
      if (st[pos + 1]) vc.push_back(pos + 1);
      print(pos + 2, pos + 2);
      return;
    }
  }
  a = ara[take];
  b = ara[pos];
  c = ara[pos + 1];
  if (ret == dp_func(pos + 2, take) + max(b, c)) {
    if (st[pos]) vc.push_back(pos);
    if (st[pos + 1]) vc.push_back(pos + 1);
    print(pos + 2, take);
    return;
  }
  if (ret == dp_func(pos + 1, pos + 1) + max(a, b)) {
    if (st[take]) vc.push_back(take);
    if (st[pos]) vc.push_back(pos);
    print(pos + 1, pos + 1);
    return;
  }
  if (ret == dp_func(pos + 2, pos) + max(a, c)) {
    if (st[take]) vc.push_back(take);
    if (st[pos + 1]) vc.push_back(pos + 1);
    print(pos + 2, pos);
  }
}
int main() {
  int i, j, k, l, m, base;
  memset(st, 0, sizeof st);
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> ara[i];
    st[i] = 1;
  }
  memset(dp, -1, sizeof dp);
  l = dp_func(1, 1);
  cout << l << endl;
  print(1, 1);
  if (n % 2 == 0) {
    for (i = 0; i < vc.size(); i += 2) {
      cout << vc[i] << " " << vc[i + 1] << endl;
    }
    return 0;
  }
  for (i = 0; i < vc.size() - 1; i += 2) {
    cout << vc[i] << " " << vc[i + 1] << endl;
  }
  cout << vc[vc.size() - 1] << endl;
}
