#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<int> a(n + 10, 0);
  for (int i = 1; i <= n; i++) cin >> a[i];
  ++n;
  constexpr long long inf = 1e16;
  vector<vector<long long>> dp(n + 10, vector<long long>(n + 10, inf));
  struct P {
    int x, y, i;
  };
  vector<vector<P>> lst(n + 10, vector<P>(n + 10));
  dp[0][1] = 0;
  for (int i = 1; i <= (n >> 1); i++) {
    int x = i << 1, y = i << 1 | 1;
    for (int j = 1; j < i * 2; j++) {
      if (dp[i - 1][j] + max(a[x], a[y]) < dp[i][j]) {
        dp[i][j] = dp[i - 1][j] + max(a[x], a[y]);
        lst[i][j] = {x, y, j};
      }
      if (dp[i - 1][j] + max(a[x], a[j]) < dp[i][y]) {
        dp[i][y] = dp[i - 1][j] + max(a[x], a[j]);
        lst[i][y] = {j, x, j};
      }
      if (dp[i - 1][j] + max(a[y], a[j]) < dp[i][x]) {
        dp[i][x] = dp[i - 1][j] + max(a[y], a[j]);
        lst[i][x] = {j, y, j};
      }
    }
  }
  function<void(int, int)> dfs = [&](int i, int j) {
    if (i != 1) dfs(i - 1, lst[i][j].i);
    if (lst[i][j].x > n) {
      cout << lst[i][j].y << '\n';
      return;
    }
    if (lst[i][j].y > n) {
      cout << lst[i][j].x << '\n';
      return;
    }
    cout << lst[i][j].x << ' ' << lst[i][j].y << '\n';
  };
  cout << dp[n >> 1][n] << '\n';
  dfs(n >> 1, n);
  return 0;
}
