#include <bits/stdc++.h>
using namespace std;
int n, a[1001], dp[1001][1001];
int sol(int i, int last) {
  if (i >= n) return a[last];
  int &ret = dp[i][last];
  if (ret != -1) return ret;
  return ret = min(sol(i + 2, last) + max(a[i], a[i + 1]),
                   min(sol(i + 2, i) + max(a[last], a[i + 1]),
                       sol(i + 2, i + 1) + max(a[last], a[i])));
}
void track(int i, int last) {
  if (i >= n) {
    if (a[last]) cout << last + 1 << endl;
    return;
  }
  if (sol(i, last) == sol(i + 2, last) + max(a[i], a[i + 1]))
    cout << i + 1 << " " << i + 2 << endl, track(i + 2, last);
  else if (sol(i, last) == sol(i + 2, i) + max(a[last], a[i + 1]))
    cout << last + 1 << " " << i + 2 << endl, track(i + 2, i);
  else if (sol(i, last) == sol(i + 2, i + 1) + max(a[last], a[i]))
    cout << last + 1 << " " << i + 1 << endl, track(i + 2, i + 1);
}
int main() {
  ios_base::sync_with_stdio(NULL);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  cin >> n;
  memset(dp, -1, sizeof dp);
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << sol(1, 0) << endl;
  track(1, 0);
}
