#include <bits/stdc++.h>
using namespace std;
int N;
int Data[1024];
int Vs[1024][1024];
int Dp[1024][1024];
int solve(int i, int j) {
  if (i >= N) return 0;
  if (j >= N) return Data[i];
  if (j + 1 >= N) return max(Data[i], Data[j]);
  if (Vs[i][j])
    return Dp[i][j];
  else
    Vs[i][j] = 1;
  int &ret = Dp[i][j];
  ret = solve(i, j + 2) + max(Data[j], Data[j + 1]);
  ret = min(ret, solve(j + 1, j + 2) + max(Data[i], Data[j]));
  ret = min(ret, solve(j, j + 2) + max(Data[i], Data[j + 1]));
  return ret;
}
void track(int i, int j) {
  if (i >= N) return;
  if (j >= N) {
    printf("%d\n", i + 1);
    return;
  }
  if (j + 1 >= N) {
    printf("%d %d\n", i + 1, j + 1);
    return;
  }
  if (solve(i, j + 2) + max(Data[j], Data[j + 1]) == Dp[i][j]) {
    printf("%d %d\n", j + 1, j + 2);
    track(i, j + 2);
  } else if (solve(j + 1, j + 2) + max(Data[i], Data[j]) == Dp[i][j]) {
    printf("%d %d\n", i + 1, j + 1);
    track(j + 1, j + 2);
  } else {
    printf("%d %d\n", i + 1, j + 2);
    track(j, j + 2);
  }
}
int main() {
  scanf("%d", &N);
  for (int q = 0; q < N; ++q) scanf("%d", Data + q);
  printf("%d\n", solve(0, 1));
  track(0, 1);
  return 0;
}
