#include <bits/stdc++.h>
struct triple {
  int a;
  int b;
  int c;
};
int a[2000];
int N;
triple DP[2000][2000];
triple dp(int i, int j) {
  if (i == 0) return {j, -1, a[j]};
  if (i == 1) return {i, j, std::max(a[i], a[j])};
  if (DP[i][j].c != -1) return DP[i][j];
  triple ret = {i, j, dp(i - 2, i - 1).c + std::max(a[i], a[j])};
  if (ret.c > dp(i - 2, i).c + std::max(a[j], a[i - 1]))
    ret = {i - 1, j, dp(i - 2, i).c + std::max(a[j], a[i - 1])};
  if (ret.c > dp(i - 2, j).c + std::max(a[i], a[i - 1]))
    ret = {i - 1, i, dp(i - 2, j).c + std::max(a[i], a[i - 1])};
  return (DP[i][j] = ret);
}
signed main() {
  long long t = 1;
  while (t--) {
    std::cin >> N;
    for (long long i = 1; i <= N; i++) std::cin >> a[N + 1 - i];
    for (long long i = 1; i <= N; i++)
      for (long long j = 1; j <= N; j++) DP[i][j] = {0, 0, -1};
    std::cout << dp(N - 1, N).c << std::endl;
    long long i = N - 1;
    long long j = N;
    while (i >= 0) {
      long long a = dp(i, j).a;
      long long b = dp(i, j).b;
      std::cout << N + 1 - a << " ";
      if (b != -1) std::cout << N + 1 - b;
      std::cout << std::endl;
      long long newi, newj;
      if (b == j) {
        newi = i - 2;
        newj = i ^ (i - 1) ^ a;
      } else {
        newi = i - 2;
        newj = j;
      }
      i = newi;
      j = newj;
    }
  }
  return 0;
}
