#include <bits/stdc++.h>
using namespace std;
int n, pr[1010];
int dp[1010][1010];
bool calc[1010][1010];
int solve(int from, int idx) {
  if (from > n) return pr[idx];
  if (from == n) return max(pr[idx], pr[from]);
  if (calc[from][idx]) return dp[from][idx];
  calc[from][idx] = true;
  int a = idx, b = from, c = from + 1, best = 1E9;
  best = min(min(solve(c + 1, a) + max(pr[b], pr[c]),
                 solve(c + 1, b) + max(pr[a], pr[c])),
             solve(c + 1, c) + max(pr[a], pr[b]));
  return (dp[from][idx] = best);
}
void output(int from, int idx) {
  if (from > n) {
    cout << idx << '\n';
    return;
  }
  if (from == n) {
    cout << idx << ' ' << from << '\n';
    return;
  }
  int a = idx, b = from, c = from + 1, best = dp[from][idx];
  if (best == solve(c + 1, a) + max(pr[b], pr[c])) {
    cout << b << ' ' << c << '\n';
    output(c + 1, a);
  } else if (best == solve(c + 1, b) + max(pr[a], pr[c])) {
    cout << a << ' ' << c << '\n';
    output(c + 1, b);
  } else if (best == solve(c + 1, c) + max(pr[a], pr[b])) {
    cout << a << ' ' << b << '\n';
    output(c + 1, c);
  }
}
int main() {
  int i, j, k, l;
  cin >> n;
  for (i = 1; i <= n; ++i) cin >> pr[i];
  cout << solve(2, 1) << '\n';
  output(2, 1);
  return 0;
}
