#include <bits/stdc++.h>
using namespace std;
vector<long long> a;
long long dp[1005][1005];
int n;
long long cal(int x, int y) {
  if (dp[x][y] == LLONG_MAX) {
    if (x == n - 1) return dp[x][y] = max(a[x], a[y]);
    if (x == n) return dp[x][y] = a[y];
    dp[x][y] = max(a[y], a[x]) + cal(x + 2, x + 1);
    dp[x][y] = min(dp[x][y], max(a[y], a[x + 1]) + cal(x + 2, x));
    dp[x][y] = min(dp[x][y], max(a[x], a[x + 1]) + cal(x + 2, y));
  }
  return dp[x][y];
}
void pri(int x, int y) {
  if (x == n - 1)
    cout << x + 1 << " " << y + 1 << "\n";
  else if (x == n)
    cout << y + 1 << "\n";
  else {
    if (dp[x][y] == max(a[x], a[y]) + cal(x + 2, x + 1)) {
      cout << x + 1 << " " << y + 1 << "\n";
      pri(x + 2, x + 1);
    } else if (dp[x][y] == max(a[y], a[x + 1]) + cal(x + 2, x)) {
      cout << x + 2 << " " << y + 1 << "\n";
      pri(x + 2, x);
    } else {
      cout << x + 1 << " " << x + 2 << "\n";
      pri(x + 2, y);
    }
  }
}
void fun() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  if (n == 1) {
    cout << a[0] << "\n";
    cout << "1";
    return;
  }
  if (n == 2) {
    cout << max(a[0], a[1]) << "\n";
    cout << "1 2";
    return;
  }
  for (int i = 0; i <= n; i++)
    for (int j = 0; j < n + 3; j++) dp[i][j] = LLONG_MAX;
  long long ans = LLONG_MAX, s = a[0] + a[1] + a[2];
  ans = min(ans, max(a[0], a[1]) + cal(3, 2));
  ans = min(ans, max(a[0], a[2]) + cal(3, 1));
  ans = min(ans, max(a[2], a[1]) + cal(3, 0));
  cout << ans << "\n";
  if (ans == (max(a[0], a[1]) + cal(3, 2))) {
    cout << "1 2\n";
    s = 2;
  } else if (ans == (max(a[0], a[2]) + cal(3, 1))) {
    cout << "1 3\n";
    s = 1;
  } else {
    cout << "2 3\n";
    s = 0;
  }
  pri(3, s);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  srand(time(0));
  ;
  int t = 1;
  while (t--) {
    fun();
  }
}
