#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int n, a[1010];
pair<int, pair<int, int> > dp[1010][1010];
pair<int, int> use[1010][1010];
vector<pair<int, int> > ans;
bool iso = false;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  if (n % 2 == 1) n++, iso = true;
  for (int i = 0; i < 1005; i++)
    for (int j = 0; j < 1005; j++) dp[i][j].first = 1e9 + 1;
  dp[1][0].first = 0;
  dp[1][0].second = {-1, -1};
  for (int i = 1; i < n - 2; i += 2) {
    for (int j = 0; j < i; j++) {
      if (dp[i][j].first == 1e9 + 1) continue;
      if (dp[i + 2][j].first > dp[i][j].first + max(a[i], a[i + 1])) {
        dp[i + 2][j].first = dp[i][j].first + max(a[i], a[i + 1]);
        dp[i + 2][j].second = {i, j};
        use[i + 2][j] = {i + 1, i + 2};
      }
      if (dp[i + 2][i].first > dp[i][j].first + max(a[i + 1], a[j])) {
        dp[i + 2][i].first = dp[i][j].first + max(a[i + 1], a[j]);
        dp[i + 2][i].second = {i, j};
        use[i + 2][i] = {j + 1, i + 2};
      }
      if (dp[i + 2][i + 1].first > dp[i][j].first + max(a[i], a[j])) {
        dp[i + 2][i + 1].first = dp[i][j].first + max(a[i], a[j]);
        dp[i + 2][i + 1].second = {i, j};
        use[i + 2][i + 1] = {j + 1, i + 1};
      }
    }
  }
  int fpos = n - 1, spos, ansn = 1e9, p, s1, s2;
  for (int i = 0; i < n - 1; i++) {
    if (dp[n - 1][i].first + (iso ? a[i] : max(a[i], a[n - 1])) < ansn) {
      ansn = dp[n - 1][i].first + (iso ? a[i] : max(a[i], a[n - 1]));
      spos = i;
    }
  }
  cout << ansn << endl;
  if (iso)
    ans.push_back({spos + 1, 0});
  else
    ans.push_back({spos + 1, n});
  while (fpos != -1) {
    ans.push_back({use[fpos][spos]});
    p = fpos;
    fpos = dp[fpos][spos].second.first;
    spos = dp[p][spos].second.second;
  }
  for (int i = ans.size() - 2; i >= 0; i--) {
    cout << ans[i].first << ' ';
    if (ans[i].second != 0)
      cout << ans[i].second << endl;
    else
      cout << endl;
  }
  return 0;
}
