#include <bits/stdc++.h>
using namespace std;
long long n, dp[1004][1004], a[1002], mn = 1e9, an = -1, kh[505], sk = 0;
int dfs(int x, int mar) {
  kh[mar / 2] = x;
  if (mar == 0) return 0;
  if (x >= mar) {
    for (long long i = 1; i < mar; i++) {
      if ((dp[mar - 2][i] + max(a[i], a[x + (x == mar) - (x != mar)])) ==
          dp[mar][x]) {
        dfs(i, mar - 2);
        return 0;
      }
    }
  } else {
    dfs(x, mar - 2);
  }
  return 0;
}
int main() {
  cin >> n;
  for (long long i = 1; i < n + 1; i++) cin >> a[i];
  for (long long i = 2; i < n; i += 2) {
    for (long long j = 1; j < i + 2; j++) dp[i][j] = 1e9;
  }
  dp[0][1] = 0;
  for (long long i = 2; i < n; i += 2) {
    for (long long j = 1; j < i + 2; j++) {
      if (j < i)
        dp[i][j] = dp[i - 2][j] + max(a[i], a[i + 1]);
      else {
        for (long long k = 1; k < i; k++) {
          dp[i][j] = min(dp[i][j],
                         dp[i - 2][k] + max(a[k], a[j + (j == i) - (j != i)]));
        }
      }
    }
  }
  if (n % 2 == 1) {
    for (long long i = 1; i < n + 1; i++) {
      if (dp[n / 2 * 2][i] + a[i] < mn) {
        mn = dp[n / 2 * 2][i] + a[i];
        an = i;
      }
    }
    cout << mn << endl;
    dfs(an, n - 1);
    int gh = 1;
    for (long long i = 1; i < n / 2 + 1; i++) {
      if (kh[i] == gh) {
        cout << i * 2 << " " << i * 2 + 1 << endl;
      } else if (kh[i] == i * 2) {
        cout << gh << " " << i * 2 + 1 << endl;
      } else
        cout << gh << " " << i * 2 << endl;
      gh = kh[i];
    }
    cout << an;
  } else {
    mn = 1e9;
    for (long long i = 1; i < n; i++) {
      if (dp[n - 2][i] + max(a[i], a[n]) < mn) {
        mn = dp[n - 2][i] + max(a[i], a[n]);
        an = i;
      }
    }
    cout << mn << endl;
    dfs(an, n - 2);
    int gh = 1;
    for (long long i = 1; i < n / 2; i++) {
      if (kh[i] == gh) {
        cout << i * 2 << " " << i * 2 + 1 << endl;
      } else if (kh[i] == i * 2) {
        cout << gh << " " << i * 2 + 1 << endl;
      } else
        cout << gh << " " << i * 2 << endl;
      gh = kh[i];
    }
    cout << an << " " << n;
  }
}
