#include <bits/stdc++.h>
using namespace std;
int n, ans;
int a[1010];
int f[1010][1010];
int dp[1010][1010];
int solve(int i, int j) {
  int mn, cur, kj, ret;
  if (j > n)
    ret = a[i];
  else if (j == n)
    ret = max(a[i], a[j]);
  else if (f[i][j] > 0)
    ret = f[i][j];
  else {
    mn = solve(i, j + 2) + max(a[j], a[j + 1]);
    kj = 1;
    cur = solve(j, j + 2) + max(a[i], a[j + 1]);
    if (cur < mn) mn = cur, kj = 2;
    cur = solve(j + 1, j + 2) + max(a[i], a[j]);
    if (cur < mn) mn = cur, kj = 3;
    f[i][j] = mn;
    dp[i][j] = kj;
    ret = mn;
  }
  return ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  ans = solve(1, 2);
  cout << ans << endl;
  int i = 1, j = 2;
  while (j < n) {
    if (dp[i][j] == 1)
      cout << j << ' ' << j + 1 << endl;
    else if (dp[i][j] == 2) {
      cout << i << ' ' << j + 1 << endl;
      i = j;
    } else {
      cout << i << ' ' << j << endl;
      i = j + 1;
    }
    j += 2;
  }
  if (j == n)
    cout << i << ' ' << j << endl;
  else
    cout << i << endl;
  return 0;
}
