#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 30;
const int N = 1005;
int dp[N][N], a[N], n;
pair<int, int> nxt[N][N], way[N][N];
int dfs(int x, int y) {
  int &ret = dp[x][y], tmp;
  if (~ret) {
    return ret;
  }
  if (y >= n) return ret = INF;
  if (y == n - 1) {
    way[x][y] = make_pair(x, y);
    return ret = max(a[x], a[y]);
  }
  ret = INF;
  tmp = dfs(y + 1, y + 2) + max(a[x], a[y]);
  if (tmp < ret) {
    ret = tmp;
    way[x][y] = make_pair(x, y);
    nxt[x][y] = make_pair(y + 1, y + 2);
  }
  tmp = dfs(y, y + 2) + max(a[x], a[y + 1]);
  if (tmp < ret) {
    ret = tmp;
    way[x][y] = make_pair(x, y + 1);
    nxt[x][y] = make_pair(y, y + 2);
  }
  tmp = dfs(x, y + 2) + max(a[y], a[y + 1]);
  if (tmp < ret) {
    ret = tmp;
    way[x][y] = make_pair(y, y + 1);
    nxt[x][y] = make_pair(x, y + 2);
  }
  return ret;
}
void trace(int x, int y) {
  if (x == 0 && y == 0) return;
  if (a[y] == 0) {
    printf("%d\n", way[x][y].first + 1);
  } else {
    printf("%d %d\n", way[x][y].first + 1, way[x][y].second + 1);
  }
  trace(nxt[x][y].first, nxt[x][y].second);
}
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  if (n & 1) n++;
  memset(dp, -1, sizeof(dp));
  cout << dfs(0, 1) << endl;
  trace(0, 1);
  return 0;
}
