#include <bits/stdc++.h>
using namespace std;
const int N = 1000 + 123;
int dp[N][N];
int pre[N][N];
int i, j;
int n;
int a[N];
void output(int i, int j) {
  if (i == 2) {
    if (j == 0)
      puts("2 3");
    else if (j == 1)
      puts("1 3");
    else if (j == 2)
      puts("1 2");
    return;
  }
  output(i - 2, pre[i][j]);
  if (j <= i - 2)
    printf("%d %d\n", i, i + 1);
  else {
    if (j == i)
      printf("%d %d\n", pre[i][j] + 1, i);
    else
      printf("%d %d\n", pre[i][j] + 1, i + 1);
  }
}
int main() {
  while (scanf("%d", &n) != EOF) {
    for (i = 0; i < n; ++i) scanf("%d", a + i);
    if (n == 1) {
      printf("%d\n1\n", a[0]);
      continue;
    }
    if (n == 2) {
      printf("%d\n1 2\n", (((a[0]) > (a[1])) ? (a[0]) : (a[1])));
      continue;
    }
    dp[2][0] = (((a[1]) > (a[2])) ? (a[1]) : (a[2]));
    dp[2][1] = (((a[0]) > (a[2])) ? (a[0]) : (a[2]));
    dp[2][2] = (((a[0]) > (a[1])) ? (a[0]) : (a[1]));
    for (i = 4; i < n; i += 2) {
      int ma = (((a[i]) > (a[i - 1])) ? (a[i]) : (a[i - 1]));
      for (j = 0; j <= i - 2; ++j) {
        dp[i][j] = dp[i - 2][j] + ma;
        pre[i][j] = j;
      }
      dp[i][i - 1] = 1110000000;
      for (j = 0; j <= i - 2; ++j) {
        int ma = (((a[j]) > (a[i])) ? (a[j]) : (a[i]));
        if (ma + dp[i - 2][j] < dp[i][i - 1]) {
          dp[i][i - 1] = ma + dp[i - 2][j];
          pre[i][i - 1] = j;
        }
      }
      dp[i][i] = 1110000000;
      for (j = 0; j <= i - 2; ++j) {
        int ma = (((a[j]) > (a[i - 1])) ? (a[j]) : (a[i - 1]));
        if (ma + dp[i - 2][j] < dp[i][i]) {
          dp[i][i] = ma + dp[i - 2][j];
          pre[i][i] = j;
        }
      }
    }
    int ans = 1110000000;
    int p = -1;
    if (n & 1) {
      for (i = 0; i < n; ++i)
        if (dp[n - 1][i] + a[i] < ans) {
          ans = dp[n - 1][i] + a[i];
          p = i;
        }
      printf("%d\n", ans);
      output(n - 1, p);
      printf("%d\n", p + 1);
    } else {
      for (i = 0; i < n - 1; ++i) {
        int ma = (((a[n - 1]) > (a[i])) ? (a[n - 1]) : (a[i]));
        if (dp[n - 2][i] + ma < ans) {
          ans = dp[n - 2][i] + ma;
          p = i;
        }
      }
      printf("%d\n", ans);
      output(n - 2, p);
      printf("%d %d\n", p + 1, n);
    }
  }
  return 0;
}
