#include <bits/stdc++.h>
using namespace std;
long long dp[1005][1005], ch[1005][1005];
long n;
void print(int i, int j) {
  if (j == n)
    cout << i << " " << j << endl;
  else if (j == n + 1)
    cout << i << endl;
  else {
    if (ch[i][j] == i) {
      cout << j << ' ' << j + 1 << endl;
      print(i, j + 2);
    } else if (ch[i][j] == j) {
      cout << i << ' ' << j + 1 << endl;
      print(j, j + 2);
    } else {
      cout << i << ' ' << j << endl;
      print(j + 1, j + 2);
    }
  }
}
int main() {
  long i, j, t[1005], k;
  cin >> n;
  for (i = 1; i <= n; i++) cin >> t[i];
  dp[n][n + 1] = t[n];
  for (i = n - 1; i >= 1; i--) {
    dp[i][n] = max(t[i], t[n]);
    dp[i][n + 1] = t[i];
  }
  for (i = n - 1; i >= 1; i--) {
    for (j = i - 1; j >= 1; j--) {
      dp[j][i] = max(t[j], t[i]) + dp[i + 1][i + 2];
      ch[j][i] = i + 1;
      if (max(t[j], t[i + 1]) + dp[i][i + 2] < dp[j][i]) {
        dp[j][i] = max(t[j], t[i + 1]) + dp[i][i + 2];
        ch[j][i] = i;
      }
      if (max(t[i], t[i + 1]) + dp[j][i + 2] < dp[j][i]) {
        dp[j][i] = max(t[i], t[i + 1]) + dp[j][i + 2];
        ch[j][i] = j;
      }
    }
  }
  cout << dp[1][2] << endl;
  print(1, 2);
  return 0;
}
