#include <bits/stdc++.h>
using namespace std;
long long n, a[1003], mem[1003][1003];
pair<int, int> path[1003][1003];
long long Try(long long i, long long j) {
  if (i == n + 1) return max(a[n], a[j]);
  if (i == n + 2) return a[j];
  if (mem[i][j] != -1) return mem[i][j];
  long long res1, res2, res3;
  res1 = Try(i + 2, j) + max(a[i], a[i - 1]);
  res2 = Try(i + 2, i - 1) + max(a[i], a[j]);
  res3 = Try(i + 2, i) + max(a[i - 1], a[j]);
  long long mn = min(res1, min(res2, res3));
  mem[i][j] = mn;
  if (res1 == mn) path[i][j] = make_pair(i + 2, j);
  if (res2 == mn) path[i][j] = make_pair(i + 2, i - 1);
  if (res3 == mn) path[i][j] = make_pair(i + 2, i);
  return mn;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  memset(mem, -1, sizeof mem);
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cout << Try(3, 1) << endl;
  int i = 3, j = 1;
  while (1) {
    if (i == n + 1) {
      cout << j << ' ' << n;
      break;
    }
    if (i == n + 2) {
      cout << j;
      break;
    }
    if (path[i][j] == make_pair(i + 2, j)) {
      cout << i - 1 << ' ' << i << endl;
      i = i + 2;
      continue;
    }
    if (path[i][j] == make_pair(i + 2, i - 1)) {
      cout << j << ' ' << i << endl;
      j = i - 1;
      i = i + 2;
      continue;
    }
    if (path[i][j] == make_pair(i + 2, i)) {
      cout << j << ' ' << i - 1 << endl;
      j = i;
      i = i + 2;
      continue;
    }
  }
}
