#include <bits/stdc++.h>
using namespace std;
int dp[1005][1005], a[1005], n;
int dfs(int i, int j) {
  if (dp[i][j] != -1) return dp[i][j];
  if (j > n) return dp[i][j] = a[i];
  if (j == n) return dp[i][j] = max(a[i], a[j]);
  dp[i][j] = max(a[i], a[j]) + dfs(j + 1, j + 2);
  dp[i][j] = min(dp[i][j], max(a[i], a[j + 1]) + dfs(j, j + 2));
  dp[i][j] = min(dp[i][j], max(a[j], a[j + 1]) + dfs(i, j + 2));
  return dp[i][j];
}
void output(int i, int j) {
  if (j > n) {
    printf("%d\n", i);
  } else if (j == n) {
    printf("%d %d\n", i, j);
  } else if (dp[i][j] == max(a[i], a[j]) + dp[j + 1][j + 2]) {
    printf("%d %d\n", i, j);
    output(j + 1, j + 2);
  } else if (dp[i][j] == max(a[i], a[j + 1]) + dp[j][j + 2]) {
    printf("%d %d\n", i, j + 1);
    output(j, j + 2);
  } else if (dp[i][j] == max(a[j], a[j + 1]) + dp[i][j + 2]) {
    printf("%d %d\n", j, j + 1);
    output(i, j + 2);
  }
}
int main() {
  scanf("%d", &n);
  memset(dp, -1, sizeof dp);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  printf("%d\n", dfs(1, 2));
  output(1, 2);
  return 0;
}
