#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10, MN = 1010;
int n, arr[MN];
int dp[MN][MN];
pair<int, int> par[MN][MN];
int main() {
  ios_base ::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> arr[i];
  for (int i = 0; i < MN; ++i) fill(dp[i], dp[i] + MN, INF);
  for (int i = 0; i < MN; ++i)
    for (int j = i + 1; j < MN; ++j)
      if (min(i, j) >= n) dp[i][j] = 0;
  for (int j = n; ~j; --j)
    for (int i = j - 1; ~i; --i) {
      int v1 = max(arr[i], arr[j]) + dp[j + 1][j + 2];
      if (dp[i][j] > v1) {
        par[i][j] = {i, j};
        dp[i][j] = v1;
      }
      int v2 = max(arr[i], arr[j + 1]) + dp[j][j + 2];
      if (dp[i][j] > v2) {
        par[i][j] = {i, j + 1};
        dp[i][j] = v2;
      }
      int v3 = max(arr[j], arr[j + 1]) + dp[i][j + 2];
      if (dp[i][j] > v3) {
        par[i][j] = {j, j + 1};
        dp[i][j] = v3;
      }
    }
  cout << dp[0][1] << '\n';
  int R = 0, C = 1;
  while (R < n) {
    int a = par[R][C].first, b = par[R][C].second;
    if (a < n) cout << a + 1 << ' ';
    if (b < n) cout << b + 1 << ' ';
    cout << '\n';
    if (a == R && b == C)
      R = b + 1, C = b + 2;
    else if (a == R && b == C + 1)
      R = b - 1, C = b + 1;
    else
      C = b + 1;
  }
  return 0;
}
