#include <bits/stdc++.h>
using namespace std;
const long long maxn = 1e3 + 5;
const long long mod = 1e9 + 7;
long long a[maxn], dp[maxn][maxn];
long long n, m, k, pre[maxn][maxn];
vector<pair<long long, long long> > ans;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> m;
  memset(dp, 0x3f, sizeof(dp));
  dp[1][1] = 0;
  for (long long i = 1; i <= m; i++) {
    cin >> a[i];
  }
  if (m % 2) {
    n = m + 2;
    a[m + 1] = a[m + 2] = 0;
  } else {
    n = m + 1;
    a[n] = 0;
  }
  for (long long i = 1; i <= n; i += 2) {
    for (long long j = 1; j <= i; j++) {
      long long x = i + 1, y = i + 2;
      long long vj = a[j], vx = a[x], vy = a[y];
      if (dp[i + 2][j] > dp[i][j] + max(vx, vy)) {
        pre[i + 2][j] = j;
        dp[i + 2][j] = dp[i][j] + max(vx, vy);
      }
      if (dp[i + 2][x] > dp[i][j] + max(vj, vy)) {
        pre[i + 2][x] = j;
        dp[i + 2][x] = dp[i][j] + max(vj, vy);
      }
      if (dp[i + 2][y] > dp[i][j] + max(vj, vx)) {
        pre[i + 2][y] = j;
        dp[i + 2][y] = dp[i][j] + max(vj, vx);
      }
    }
  }
  cout << dp[n][n] << "\n";
  long long i = n, j = n;
  while (i > 1) {
    long long prej = pre[i][j];
    if (prej == j) {
      ans.push_back(make_pair(i - 1, i));
    } else {
      long long res = (j == i) ? i - 1 : i;
      ans.push_back(make_pair(prej, res));
    }
    i -= 2;
    j = prej;
  }
  long long tot = (long long)ans.size() - 1;
  for (long long i = tot; i >= 0; i--) {
    long long x = ans[i].first, y = ans[i].second;
    if (x <= m) {
      cout << x << " ";
    }
    if (y <= m) {
      cout << y << " ";
    }
    cout << "\n";
  }
  return 0;
}
