#include <bits/stdc++.h>
using namespace std;
using LL = long long;
constexpr int N = 1005;
int in[N];
int cache[N][N], order[N][N];
int n;
int dp(int a, int b) {
  int &rv = cache[a][b];
  if (~rv) return rv;
  rv = 2e9;
  if (b + 1 < n) {
    if (rv > max(in[a], in[b]) + dp(b + 1, b + 2)) {
      rv = max(in[a], in[b]) + dp(b + 1, b + 2);
      order[a][b] = b + 1;
    }
    if (rv > max(in[a], in[b + 1]) + dp(b, b + 2)) {
      rv = max(in[a], in[b + 1]) + dp(b, b + 2);
      order[a][b] = b;
    }
    if (rv > max(in[b], in[b + 1]) + dp(a, b + 2)) {
      rv = max(in[b], in[b + 1]) + dp(a, b + 2);
      order[a][b] = a;
    }
  } else if (b < n) {
    rv = max(in[a], in[b]);
  } else {
    rv = in[a];
  }
  return rv;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> in[i];
  memset(cache, -1, sizeof cache);
  int result = dp(0, 1);
  cout << result << "\n";
  int a = 0, b = 1;
  for (int i = 1; i <= (n + 1) / 2; i++) {
    if (b + 1 < n) {
      int k = order[a][b];
      if (k != a) cout << a + 1 << ' ';
      if (k != b) cout << b + 1 << ' ';
      if (k != b + 1) cout << b + 2 << ' ';
      a = k, b += 2;
      cout << "\n";
    } else if (b < n) {
      cout << a + 1 << ' ' << b + 1 << "\n";
    } else {
      cout << a + 1 << endl;
    }
  }
}
