#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e3 + 5;
int dp[maxn][maxn];
int a[maxn], n;
vector<int> path;
int f(int pos, int ant) {
  if (pos > n) return a[ant];
  if (dp[pos][ant] != -1) return dp[pos][ant];
  int ans = INT_MAX;
  vector<int> posi;
  set<int> st;
  if (ant != 0) st.insert(ant);
  for (int i = 0; i < 3; ++i)
    if (pos + i <= n) st.insert(pos + i);
  int cc = 0;
  for (int x : st) {
    if (posi.size() == 3) break;
    posi.push_back(x);
  }
  if (posi.size() == 1)
    ans = min(ans, a[posi[0]] + f(posi[0] + 1, 0));
  else {
    for (int i = 0; i < posi.size(); ++i) {
      for (int j = i + 1; j < posi.size(); ++j) {
        int val = max(a[posi[i]], a[posi[j]]);
        int ignorado = 0;
        for (int k = 0; k < posi.size(); ++k)
          if (posi[k] != posi[i] and posi[k] != posi[j]) ignorado = posi[k];
        ans = min(ans, val + f(posi[j] + 1, ignorado));
      }
    }
  }
  return dp[pos][ant] = ans;
}
void rec(int pos, int ant) {
  if (pos > n) {
    if (ant != 0) path.push_back(ant);
    return;
  }
  int ans = INT_MAX;
  vector<int> posi;
  set<int> st;
  if (ant != 0) st.insert(ant);
  for (int i = 0; i < 3; ++i)
    if (pos + i <= n) st.insert(pos + i);
  int cc = 0;
  for (int x : st) {
    if (posi.size() == 3) break;
    posi.push_back(x);
  }
  if (posi.size() == 1) {
    path.push_back(posi[0]);
    rec(posi[0] + 1, 0);
  } else {
    pair<int, int> pp;
    int ig = 0;
    for (int i = 0; i < posi.size(); ++i) {
      for (int j = i + 1; j < posi.size(); ++j) {
        int val = max(a[posi[i]], a[posi[j]]);
        int ignorado = 0;
        for (int k = 0; k < posi.size(); ++k)
          if (posi[k] != posi[i] and posi[k] != posi[j]) ignorado = posi[k];
        val = val + f(posi[j] + 1, ignorado);
        if (val < ans) {
          ans = val;
          pp = {posi[i], posi[j]};
          ig = ignorado;
        }
      }
    }
    path.push_back(pp.first);
    path.push_back(pp.second);
    rec(pp.second + 1, ig);
  }
}
int main() {
  cin >> n;
  a[0] = 0;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  memset(dp, -1, sizeof(dp));
  cout << f(1, 0) << endl;
  rec(1, 0);
  for (int i = 0; i < n; i += 2) {
    cout << path[i];
    if (i + 1 < path.size()) cout << " " << path[i + 1];
    cout << endl;
  }
  return 0;
}
