#include <bits/stdc++.h>
using namespace std;
const int MAXN = (int)1e3 + 5;
const long long INF = (long long)1e18;
array<int, 4> par[MAXN][MAXN];
long long dp[MAXN][MAXN];
int arr[MAXN];
int n;
void solve() {
  cin >> n;
  for (int i = (1); i < (n + 1); ++i) {
    cin >> arr[i];
  }
  for (int i = (1); i < (n + 3); ++i) {
    for (int j = (1); j < (n + 3); ++j) {
      dp[i][j] = INF;
    }
  }
  dp[1][2] = 0;
  for (int i = (1); i < (n + 1); ++i) {
    for (int j = (1); j < (n + 2); ++j) {
      if (j <= n && dp[j + 1][j + 2] > dp[i][j] + max(arr[i], arr[j])) {
        dp[j + 1][j + 2] = dp[i][j] + max(arr[i], arr[j]);
        par[j + 1][j + 2] = {i, j, i, j};
      }
      if (j + 1 <= n && dp[j][j + 2] > dp[i][j] + max(arr[i], arr[j + 1])) {
        dp[j][j + 2] = dp[i][j] + max(arr[i], arr[j + 1]);
        par[j][j + 2] = {i, j, i, j + 1};
      }
      if (j + 1 <= n && dp[i][j + 2] > dp[i][j] + max(arr[j], arr[j + 1])) {
        dp[i][j + 2] = dp[i][j] + max(arr[j], arr[j + 1]);
        par[i][j + 2] = {i, j, j, j + 1};
      }
      if (j == n + 1 && dp[j][j + 1] > dp[i][j] + arr[i]) {
        dp[j][j + 1] = dp[i][j] + arr[i];
        par[j][j + 1] = {i, j, i, -1};
      }
    }
  }
  cout << dp[n + 1][n + 2] << endl;
  int i = n + 1, j = n + 2;
  vector<pair<int, int> > ans;
  while (make_pair(i, j) != make_pair(1, 2)) {
    array<int, 4> tmp = par[i][j];
    ans.emplace_back(tmp[2], tmp[3]);
    i = tmp[0];
    j = tmp[1];
  }
  reverse((ans).begin(), (ans).end());
  for (auto it : ans) {
    if (it.second == -1) {
      cout << it.first << endl;
    } else {
      cout << it.first << ' ' << it.second << endl;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt = 1;
  while (tt--) {
    solve();
  }
  return 0;
}
