#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const long long mod1 = 998244353;
const long long N = 2e5 + 5;
const long long inf = 1e18;
const long long MAX = 1e3 + 1;
long long n, a[N], dp[MAX][MAX];
pair<long long, long long> state[MAX][MAX];
long long rec(long long pos, long long left) {
  if (pos == n && n % 2 != 0) {
    state[pos][left].first = left;
    return a[left];
  }
  if (pos == n - 1 && n % 2 == 0) {
    state[pos][left] = make_pair(pos, left);
    return max(a[pos], a[left]);
  }
  if (dp[pos][left] != -1) return dp[pos][left];
  long long ans = inf;
  long long ans1 = rec(pos + 2, pos + 1) + max(a[left], a[pos]);
  long long ans2 = rec(pos + 2, left) + max(a[pos], a[pos + 1]);
  long long ans3 = rec(pos + 2, pos) + max(a[pos + 1], a[left]);
  ans = min(ans1, min(ans2, ans3));
  if (ans == ans1) {
    state[pos][left] = make_pair(pos, left);
  } else if (ans == ans2) {
    state[pos][left] = make_pair(pos, pos + 1);
  } else
    state[pos][left] = make_pair(pos + 1, left);
  return dp[pos][left] = ans;
}
void solve() {
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  long long ans = rec(1, 0);
  cout << ans << "\n";
  long long left = 0;
  for (long long pos = 1; pos < n; pos += 2) {
    long long x = state[pos][left].first;
    long long y = state[pos][left].second;
    cout << x + 1 << " " << y + 1 << "\n";
    left = left + pos + pos + 1 - x - y;
  }
  if (n % 2 != 0) {
    cout << left + 1 << "\n";
  }
}
int32_t main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  for (long long tt = 1; tt <= t; tt++) {
    solve();
  }
}
