#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60777216")
using namespace std;
int n;
int a[1000 | 1];
int dp[1000 | 1][1000 | 1];
int solve(int first, int second) {
  int &it = dp[first][second];
  if (it != -1) {
    return it;
  }
  if (second == n - 1) {
    return max(a[first], a[second]);
  }
  if (second >= n) {
    return a[first];
  }
  it = 1000000000;
  it = min(it, solve(second + 1, second + 2) + max(a[second], a[first]));
  it = min(it, solve(first, second + 2) + max(a[second], a[second + 1]));
  it = min(it, solve(second, second + 2) + max(a[first], a[second + 1]));
  return it;
}
void print(int first, int second) {
  if (second == n - 1) {
    printf("%d %d\n", first + 1, second + 1);
    return;
  }
  if (second == n) {
    printf("%d\n", first + 1);
    return;
  }
  int res = solve(first, second);
  if (res == solve(second + 1, second + 2) + max(a[second], a[first])) {
    printf("%d %d\n", first + 1, second + 1);
    print(second + 1, second + 2);
    return;
  }
  if (res == solve(first, second + 2) + max(a[second], a[second + 1])) {
    printf("%d %d\n", second + 1, second + 2);
    print(first, second + 2);
    return;
  }
  if (res == solve(second, second + 2) + max(a[first], a[second + 1])) {
    printf("%d %d\n", first + 1, second + 2);
    print(second, second + 2);
    return;
  }
  return;
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  memset(dp, -1, sizeof(dp));
  printf("%d\n", solve(0, 1));
  print(0, 1);
  return 0;
}
