#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
int n;
long long a[1001], dp[1001][1001];
pair<int, int> nxt[1001][1001], res[1001][1001];
long long go(int idx, int last) {
  if (idx >= n) {
    nxt[idx][last] = {-1, -1};
    if (n & 1) {
      res[idx][last] = {last + 1, -1};
      return a[last];
    } else {
      res[idx][last] = {-1, -1};
    }
    return 0;
  }
  if (dp[idx][last] != -1) return dp[idx][last];
  long long ans = inf, tmp;
  tmp = go(idx + 2, idx + 1) + max(a[last], a[idx]);
  if (tmp < ans) {
    ans = tmp;
    res[idx][last] = {last + 1, idx + 1};
    nxt[idx][last] = {idx + 2, idx + 1};
  }
  tmp = go(idx + 2, last) + max(a[idx], a[idx + 1]);
  if (tmp < ans) {
    ans = tmp;
    res[idx][last] = {idx + 1, idx + 2};
    nxt[idx][last] = {idx + 2, last};
  }
  tmp = go(idx + 2, idx) + max(a[last], a[idx + 1]);
  if (tmp < ans) {
    ans = tmp;
    res[idx][last] = {last + 1, idx + 2};
    nxt[idx][last] = {idx + 2, idx};
  }
  return dp[idx][last] = ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (n % 2 == 0) a[n] = inf;
  memset(dp, -1, sizeof dp);
  cout << go(1, 0) << '\n';
  int st1 = 1, st2 = 0;
  do {
    int x = res[st1][st2].first, y = res[st1][st2].second;
    if (x != -1) {
      cout << x;
    }
    if (y != -1) {
      cout << ' ' << y << '\n';
    }
    x = st1, y = st2;
    st1 = nxt[x][y].first, st2 = nxt[x][y].second;
  } while (st1 != -1 && st2 != -1);
  if (n & 1) cout << '\n';
  return 0;
}
