#include <bits/stdc++.h>
using namespace std;
int n;
int d[1005][1005], a[1005], inf = 1000500000;
int calc(int cur, int left) {
  int &ret = d[cur][left];
  if (ret < inf) return ret;
  ret = ((((((a[cur]) > (a[left]) ? (a[cur]) : (a[left])) +
            calc(cur + 2, cur + 1)) <
                   (((a[cur]) > (a[cur + 1]) ? (a[cur]) : (a[cur + 1])) +
                    calc(cur + 2, left))
               ? (((a[cur]) > (a[left]) ? (a[cur]) : (a[left])) +
                  calc(cur + 2, cur + 1))
               : (((a[cur]) > (a[cur + 1]) ? (a[cur]) : (a[cur + 1])) +
                  calc(cur + 2, left)))) <
                 (((a[cur + 1]) > (a[left]) ? (a[cur + 1]) : (a[left])) +
                  calc(cur + 2, cur))
             ? (((((a[cur]) > (a[left]) ? (a[cur]) : (a[left])) +
                  calc(cur + 2, cur + 1)) <
                         (((a[cur]) > (a[cur + 1]) ? (a[cur]) : (a[cur + 1])) +
                          calc(cur + 2, left))
                     ? (((a[cur]) > (a[left]) ? (a[cur]) : (a[left])) +
                        calc(cur + 2, cur + 1))
                     : (((a[cur]) > (a[cur + 1]) ? (a[cur]) : (a[cur + 1])) +
                        calc(cur + 2, left))))
             : (((a[cur + 1]) > (a[left]) ? (a[cur + 1]) : (a[left])) +
                calc(cur + 2, cur)));
  return ret;
}
int main() {
  for (int i = 0; i < 1005; i++)
    for (int j = 0; j < 1005; j++) d[i][j] = inf;
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n % 2 == 0)
    for (int i = 0; i < n - 1; i++)
      d[n - 1][i] = ((a[n - 1]) > (a[i]) ? (a[n - 1]) : (a[i]));
  else
    for (int i = 0; i < n; i++) d[n][i] = a[i];
  cout << calc(1, 0) << endl;
  int cur = 1, left = 0;
  for (int i = 0; i < (n + 1) / 2; i++) {
    if (n % 2 == 0 && cur == n - 1) {
      cout << (left + 1) << " " << (cur + 1) << endl;
    } else if (n % 2 == 1 && cur == n) {
      cout << (left + 1) << endl;
    } else if (d[cur][left] == (((a[cur]) > (a[left]) ? (a[cur]) : (a[left])) +
                                calc(cur + 2, cur + 1))) {
      cout << (left + 1) << " " << (cur + 1) << endl;
      left = cur + 1;
    } else if (d[cur][left] ==
               (((a[cur]) > (a[cur + 1]) ? (a[cur]) : (a[cur + 1])) +
                calc(cur + 2, left))) {
      cout << (cur + 1) << " " << (cur + 1 + 1) << endl;
      left = left;
    } else {
      cout << (left + 1) << " " << (cur + 1 + 1) << endl;
      left = cur;
    }
    cur += 2;
  }
  cin >> n;
  return 0;
}
