#include <bits/stdc++.h>
using namespace std;
const long double pi = acos(-1);
const long long int inf = 1e18, M = 1e9 + 7;
const long long int N = 1e3 + 5;
long long int dp[N][N], nxt[N][N];
vector<long long int> v;
long long int n;
long long int rec(long long int ind, long long int last) {
  if (ind == n) {
    nxt[ind][last] = -1;
    return v[last];
  }
  if (ind == n - 1) {
    nxt[ind][last] = -1;
    return max(v[ind], v[last]);
  }
  long long int& res = dp[ind][last];
  if (res != -1) return res;
  long long int tmp;
  tmp = max(v[last], v[ind]) + rec(ind + 2, ind + 1);
  res = tmp;
  nxt[ind][last] = ind + 1;
  tmp = max(v[last], v[ind + 1]) + rec(ind + 2, ind);
  if (res > tmp) {
    res = tmp;
    nxt[ind][last] = ind;
  }
  tmp = max(v[ind], v[ind + 1]) + rec(ind + 2, last);
  if (res > tmp) {
    res = tmp;
    nxt[ind][last] = last;
  }
  return res;
}
void solve() {
  memset(dp, -1, sizeof(dp));
  memset(nxt, -1, sizeof(nxt));
  cin >> n;
  v.resize(n);
  for (long long int i = 0; i < n; ++i) cin >> v[i];
  long long int res = rec(1, 0);
  cout << res << "\n";
  vector<pair<long long int, long long int> > ans;
  long long int x = 1, y = 0;
  while (nxt[x][y] != -1) {
    if (nxt[x][y] == x) {
      ans.push_back({y, x + 1});
    } else if (nxt[x][y] == x + 1) {
      ans.push_back({y, x});
    } else {
      ans.push_back({x, x + 1});
    }
    y = nxt[x][y];
    x += 2;
  }
  if (x == n - 1)
    ans.push_back({y, x});
  else
    ans.push_back({y, -1});
  for (auto c : ans) {
    cout << c.first + 1 << " ";
    if (c.second != -1) cout << c.second + 1;
    cout << "\n";
  }
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
