#include <bits/stdc++.h>
using namespace std;
const int INF = 1000 * 1000 * 1000 + 100;
const int N = 1001;
int dp[N][N];
int n;
int a[N];
pair<int, int> parent1[N][N], parent2[N][N];
int solve(int first, int second) {
  if (first >= n) return 0;
  if (second >= n) return a[first];
  if (dp[first][second] != -1) return dp[first][second];
  dp[first][second] = solve(second + 1, second + 2) + max(a[first], a[second]);
  parent1[first][second].first = first;
  parent1[first][second].second = second;
  parent2[first][second].first = second + 1;
  parent2[first][second].second = second + 2;
  int cur = (second + 1 < n)
                ? solve(first, second + 2) + max(a[second], a[second + 1])
                : INF;
  if (dp[first][second] > cur) {
    dp[first][second] = cur;
    parent1[first][second].first = second;
    parent1[first][second].second = second + 1;
    parent2[first][second].first = first;
    parent2[first][second].second = second + 2;
  }
  cur = (second + 1 < n)
            ? (solve(second, second + 2) + max(a[first], a[second + 1]))
            : INF;
  if (dp[first][second] > cur) {
    dp[first][second] = cur;
    parent1[first][second].first = first;
    parent1[first][second].second = second + 1;
    parent2[first][second].first = second;
    parent2[first][second].second = second + 2;
  }
  return dp[first][second];
}
int main() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  memset(dp, -1, sizeof(dp));
  dp[0][1] = solve(0, 1);
  printf("%d\n", dp[0][1]);
  pair<int, int> cur(0, 1);
  while (true) {
    if (cur.first >= n) break;
    if (cur.second == n) {
      printf("%d\n", cur.first + 1);
      break;
    }
    printf("%d %d\n", parent1[cur.first][cur.second].first + 1,
           parent1[cur.first][cur.second].second + 1);
    cur = parent2[cur.first][cur.second];
  }
  return 0;
}
