#include <bits/stdc++.h>
using namespace std;
long long int a[1005], n;
long long int dp[1005][1005];
long long int best[1005][1005];
long long int recur(long long int rem, long long int pos) {
  long long int &res = dp[rem][pos];
  if (res != -1) return res;
  if (n <= pos + 1) {
    if (n == pos + 1) return res = max(a[rem], a[pos]);
    if (n == pos) return res = a[rem];
  }
  best[rem][pos] = 0;
  res = (1ll << (long long int)(60));
  res = min(res, recur(rem, pos + 2) + max(a[pos], a[pos + 1]));
  res = min(res, recur(pos, pos + 2) + max(a[rem], a[pos + 1]));
  res = min(res, recur(pos + 1, pos + 2) + max(a[rem], a[pos]));
  if (res == recur(rem, pos + 2) + max(a[pos], a[pos + 1]))
    best[rem][pos] = rem;
  if (res == recur(pos, pos + 2) + max(a[rem], a[pos + 1]))
    best[rem][pos] = pos;
  if (res == recur(pos + 1, pos + 2) + max(a[rem], a[pos]))
    best[rem][pos] = pos + 1;
  return res;
}
int main() {
  cin >> n;
  for (long long int i = 0; i < ((long long int)(n)); ++i) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  memset(best, -1, sizeof(best));
  cout << recur(0, 1) << endl;
  long long int rem = 0, pos = 1;
  while (pos + 1 < n) {
    vector<long long int> vec;
    if (best[rem][pos] != rem) vec.push_back(rem);
    if (best[rem][pos] != pos) vec.push_back(pos);
    if (best[rem][pos + 1] != pos + 1) vec.push_back(pos + 1);
    cout << vec[0] + 1 << " " << vec[1] + 1 << endl;
    rem = best[rem][pos];
    pos += 2;
  }
  if (n % 2)
    cout << rem + 1 << endl;
  else
    cout << rem + 1 << " " << n << endl;
}
