#include <bits/stdc++.h>
using namespace std;
int n, arr[1007], dp[1007][1007], where[1007][1007];
bool vis[1007][1007];
vector<int> ans;
int rec(int left, int start) {
  if (left == 0 && start > n) return 0;
  if (left != 0 && start > n) return arr[left];
  if (vis[left][start]) return dp[left][start];
  vis[left][start] = 1;
  int a, b, c;
  if (left == 0) {
    a = max(arr[start + 1], arr[start]) + rec(0, start + 2);
    b = max(arr[start], arr[start + 2]) + rec(start + 1, start + 3);
    c = max(arr[start + 1], arr[start + 2]) + rec(start, start + 3);
  } else {
    a = max(arr[left], arr[start]) + rec(0, start + 1);
    b = max(arr[left], arr[start + 1]) + rec(start, start + 2);
    c = max(arr[start + 1], arr[start]) + rec(left, start + 2);
  }
  if (a <= min(b, c)) {
    where[left][start] = 0;
  } else if (b <= c) {
    where[left][start] = 1;
  } else
    where[left][start] = 2;
  return dp[left][start] = min(min(a, b), c);
}
void make(int left, int start) {
  if (start > n) {
    if (left != 0) ans.push_back(left);
    return;
  }
  if (left == 0) {
    switch (where[left][start]) {
      case 0:
        ans.push_back(start), ans.push_back(start + 1);
        make(0, start + 2);
        break;
      case 1:
        ans.push_back(start), ans.push_back(start + 2);
        make(start + 1, start + 3);
        break;
      case 2:
        ans.push_back(start + 1), ans.push_back(start + 2);
        make(start, start + 3);
    }
  } else {
    switch (where[left][start]) {
      case 0:
        ans.push_back(left), ans.push_back(start);
        make(0, start + 1);
        break;
      case 1:
        ans.push_back(left), ans.push_back(start + 1);
        make(start, start + 2);
        break;
      case 2:
        ans.push_back(start), ans.push_back(start + 1);
        make(left, start + 2);
    }
  }
}
int main() {
  int i, j, t;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  if (n == 1) {
    cin >> j;
    cout << j << "\n" << 1;
    return 0;
  }
  for (i = 1; i < n + 1; i++) cin >> arr[i];
  rec(0, 1);
  cout << dp[0][1] << '\n';
  make(0, 1);
  vector<int> aans;
  for (auto z : ans)
    if (z <= n) aans.push_back(z);
  for (i = 1; i < (int)((aans).size()); i += 2) {
    cout << aans[i - 1] << ' ' << aans[i] << '\n';
  }
  if ((int)((aans).size()) % 2) cout << aans.back();
  return 0;
}
