#include <bits/stdc++.h>
using namespace std;
int arr[1005];
int dp[1005][1005];
pair<int, int> states[1005][1005];
int n;
int compute(int s, int p) {
  if (p == n) return dp[s][p] = arr[s];
  if (p == n - 1) return dp[s][p] = max(arr[s], arr[p]);
  if (dp[s][p] != -1) return dp[s][p];
  int ans = max(arr[s], arr[p]) + compute(p + 1, p + 2);
  states[s][p] = pair<int, int>(p + 1, p + 2);
  if (ans > max(arr[s], arr[p + 1]) + compute(p, p + 2)) {
    ans = max(arr[s], arr[p + 1]) + compute(p, p + 2);
    states[s][p] = pair<int, int>(p, p + 2);
  }
  if (ans > max(arr[p], arr[p + 1]) + compute(s, p + 2)) {
    ans = max(arr[p], arr[p + 1]) + compute(s, p + 2);
    states[s][p] = pair<int, int>(s, p + 2);
  }
  return dp[s][p] = ans;
}
void print(int s, int p) {
  if (p == n) {
    printf("%d\n", s + 1);
    return;
  }
  if (p == n - 1) {
    printf("%d %d\n", s + 1, p + 1);
    return;
  }
  if (states[s][p] == pair<int, int>(p + 1, p + 2))
    printf("%d %d\n", s + 1, p + 1);
  else if (states[s][p] == pair<int, int>(p, p + 2))
    printf("%d %d\n", s + 1, p + 2);
  else if (states[s][p] == pair<int, int>(s, p + 2))
    printf("%d %d\n", p + 1, p + 2);
  print(states[s][p].first, states[s][p].second);
}
int main() {
  memset(dp, -1, sizeof dp);
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &arr[i]);
  compute(0, 1);
  printf("%d\n", dp[0][1]);
  print(0, 1);
  return 0;
}
