#include <bits/stdc++.h>
using namespace std;
int n;
int cust[1010];
int dp[1010][1010];
pair<int, int> nxt[1010][1010];
int nxtLast[1010][1010];
int total = 0;
int rec(int pos, int last) {
  if (dp[pos][last] != -1) return dp[pos][last];
  int &res = dp[pos][last];
  if (pos == n) return res = cust[last];
  if (pos == n - 1) return res = max(cust[last], cust[pos]);
  res = 2000000000;
  int val1 = max(cust[pos], cust[pos + 1]) + rec(pos + 2, last);
  int val2 = max(cust[last], cust[pos + 1]) + rec(pos + 2, pos);
  int val3 = max(cust[last], cust[pos]) + rec(pos + 2, pos + 1);
  if (val1 < res) {
    nxt[pos][last] = make_pair(pos, pos + 1);
    nxtLast[pos][last] = last;
    res = val1;
  }
  if (val2 < res) {
    nxt[pos][last] = make_pair(last, pos + 1);
    nxtLast[pos][last] = pos;
    res = val2;
  }
  if (val3 < res) {
    nxt[pos][last] = make_pair(last, pos);
    nxtLast[pos][last] = pos + 1;
    res = val3;
  }
  return res;
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> cust[i];
  memset(dp, -1, sizeof dp);
  cout << rec(1, 0) << endl;
  int curPos = 1, curLast = 0;
  for (int i = 0; i < (n + 1) / 2; i++) {
    if (curPos == n)
      printf("%d\n", curLast + 1);
    else if (curPos == n - 1)
      printf("%d %d\n", curLast + 1, n);
    else {
      printf("%d %d\n", nxt[curPos][curLast].first + 1,
             nxt[curPos][curLast].second + 1);
      curLast = nxtLast[curPos][curLast];
      curPos += 2;
    }
  }
  return 0;
}
