#include <bits/stdc++.h>
using namespace std;
unsigned long long a[1005];
unsigned long long dp[1005][1005];
int n;
void go() {
  for (int j = n; j >= 0; --j) {
    for (int i = j - 1; i >= 0; --i) {
      if (j == n)
        dp[i][n] = a[i];
      else if (j == n - 1)
        dp[i][j] = max(a[i], a[j]);
      else {
        dp[i][j] = dp[i][j + 2] + max(a[j], a[j + 1]);
        dp[i][j] = min(dp[i][j], dp[j][j + 2] + max(a[i], a[j + 1]));
        dp[i][j] = min(dp[i][j], dp[j + 1][j + 2] + max(a[i], a[j]));
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> a[i];
  go();
  cout << dp[0][1] << endl;
  int i = 0, j = 1;
  while (j <= n - 2) {
    if (dp[i][j] == dp[i][j + 2] + max(a[j], a[j + 1])) {
      cout << j + 1 << " " << j + 2 << endl;
      j += 2;
      continue;
    }
    if (dp[i][j] == dp[j][j + 2] + max(a[i], a[j + 1])) {
      cout << i + 1 << " " << j + 2 << endl;
      i = j;
      j += 2;
      continue;
    }
    if (dp[i][j] == dp[j + 1][j + 2] + max(a[i], a[j])) {
      cout << i + 1 << " " << j + 1 << endl;
      i = j + 1;
      j += 2;
      continue;
    }
  }
  if (j == n - 1)
    cout << i + 1 << " " << n << endl;
  else
    cout << i + 1 << endl;
  return 0;
}
