#include <bits/stdc++.h>
using namespace std;
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&...args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
struct cell {
  int two;
  int five;
  int zero;
};
int helper(int i, int j, vector<vector<int> > &dp, vector<int> &arr, int n) {
  int sza = arr.size();
  if (i >= sza) return 0;
  if (dp[i][j] != -1) return dp[i][j];
  if (i != 0 && j > n)
    return dp[i][j] = arr[i];
  else if (i == 0 && j == (n - 1)) {
    dp[i][j + 2] = 0;
    return dp[i][j] = max(arr[j + 1], arr[j]);
  } else if (i != 0 && j == (n)) {
    dp[0][j + 1] = 0;
    return dp[i][j] = max(arr[i], arr[j]);
  } else if (i == 0 && j > n) {
    return dp[i][j] = 0;
  } else if (i == 0 && j == n)
    return dp[i][j] = arr[j];
  if (i == 0) {
    int op1 = max(arr[j], arr[j + 1]) + helper(0, j + 2, dp, arr, n);
    int op2 = max(arr[j], arr[j + 2]) + helper(j + 1, j + 3, dp, arr, n);
    int op3 = max(arr[j + 1], arr[j + 2]) + helper(j, j + 3, dp, arr, n);
    dp[i][j] = min(op1, min(op2, op3));
  } else {
    int op1 = max(arr[i], arr[j]) + helper(0, j + 1, dp, arr, n);
    int op2 = max(arr[i], arr[j + 1]) + helper(j, j + 2, dp, arr, n);
    int op3 = max(arr[j], arr[j + 1]) + helper(i, j + 2, dp, arr, n);
    dp[i][j] = min(op1, min(op2, op3));
  }
  return dp[i][j];
}
int main() {
  int T = 1;
  for (int tc = 1; tc <= T; tc++) {
    int n;
    cin >> n;
    int ans = 0;
    vector<int> arr(n + 1);
    for (int i = 1; i <= n; i++) cin >> arr[i];
    vector<vector<int> > dp(n + 5, vector<int>(n + 5, -1));
    if (n == 1)
      cout << arr[1] << "\n1\n";
    else if (n == 2)
      cout << max(arr[2], arr[1]) << "\n1 2\n";
    else {
      int ans = helper(0, 1, dp, arr, n);
      cout << ans << "\n";
      int i = 0, j = 1;
      int cnt = 0;
      while (cnt != n) {
        if (cnt == (n - 1)) {
          if (i == 0)
            cout << j << "\n";
          else
            cout << i << "\n";
          break;
        }
        if (i == 0) {
          if (dp[i][j] == max(arr[j], arr[j + 1]) + dp[i][j + 2]) {
            cout << j << " " << (j + 1) << "\n";
            cnt += 2;
            j += 2;
          } else if (dp[i][j] == max(arr[j], arr[j + 2]) + dp[j + 1][j + 3]) {
            cout << j << " " << (j + 2) << "\n";
            cnt += 2;
            i = j + 1;
            j += 3;
          } else if (dp[i][j] == max(arr[j + 1], arr[j + 2]) + dp[j][j + 3]) {
            cout << (j + 1) << " " << (j + 2) << "\n";
            cnt += 2;
            i = j;
            j += 3;
          }
        } else {
          if (dp[i][j] == max(arr[j], arr[j + 1]) + dp[i][j + 2]) {
            cout << j << " " << (j + 1) << "\n";
            cnt += 2;
            j += 2;
          } else if (dp[i][j] == max(arr[i], arr[j + 1]) + dp[j][j + 2]) {
            cout << i << " " << (j + 1) << "\n";
            cnt += 2;
            i = j;
            j += 2;
          } else if (dp[i][j] == max(arr[i], arr[j]) + dp[0][j + 1]) {
            cout << i << " " << (j) << "\n";
            cnt += 2;
            i = 0;
            j += 1;
          }
        }
      }
    }
  }
  return 0;
}
