#include <bits/stdc++.h>
using namespace std;
int a[1001];
int dp[1010][1010];
int from[1010][1010][2];
int del[1010][1010][2];
int main() {
  int i, j, n;
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  if (n % 2) n++;
  for (i = 0; i <= n + 2; i++)
    for (j = 0; j <= n + 2; j++) dp[i][j] = 2000000000;
  dp[0][1] = 0;
  for (i = 0; i < n; i++)
    for (j = i + 1; j < n; j++) {
      if (dp[i][j + 2] > dp[i][j] + max(a[j], a[j + 1])) {
        dp[i][j + 2] = dp[i][j] + max(a[j], a[j + 1]);
        from[i][j + 2][0] = i, from[i][j + 2][1] = j;
        del[i][j + 2][0] = j, del[i][j + 2][1] = j + 1;
      }
      if (dp[j + 1][j + 2] > dp[i][j] + max(a[i], a[j])) {
        dp[j + 1][j + 2] = dp[i][j] + max(a[i], a[j]);
        from[j + 1][j + 2][0] = i, from[j + 1][j + 2][1] = j;
        del[j + 1][j + 2][0] = i, del[j + 1][j + 2][1] = j;
      }
      if (dp[j][j + 2] > dp[i][j] + max(a[i], a[j + 1])) {
        dp[j][j + 2] = dp[i][j] + max(a[i], a[j + 1]);
        from[j][j + 2][0] = i, from[j][j + 2][1] = j;
        del[j][j + 2][0] = i, del[j][j + 2][1] = j + 1;
      }
    }
  i = n, j = n + 1;
  cout << dp[i][j] << endl;
  vector<int> res;
  while (i || j) {
    int p1 = from[i][j][0], p2 = from[i][j][1];
    res.push_back(del[i][j][0] + 1), res.push_back(del[i][j][1] + 1);
    i = p1, j = p2;
  }
  for (i = n - 1; i >= 0; i -= 2) {
    cout << res[i - 1];
    if (a[res[i] - 1]) cout << " " << res[i];
    cout << endl;
  }
  return 0;
}
