#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
const long long int mod = 1e8;
const long long int inf = 1e9 + 5;
const long long int inf64 = 1e18 + 5;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> a(n);
  for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
       i += 1 - 2 * ((0) > (n)))
    cin >> a[i];
  if (n == 1) {
    cout << a[0] << '\n' << 1 << '\n';
    return;
  }
  if (n == 2) {
    cout << max(a[0], a[1]) << '\n';
    cout << 1 << " " << 2 << '\n';
    return;
  }
  vector<vector<long long int>> dp(n, vector<long long int>(n, inf));
  vector<vector<pair<long long int, long long int>>> parent(
      n + 1, vector<pair<long long int, long long int>>(n + 1, {-1, -1}));
  vector<vector<pair<long long int, long long int>>> chose(
      n + 1, vector<pair<long long int, long long int>>(n + 1));
  dp[2][0] = max(a[1], a[2]);
  dp[2][1] = max(a[2], a[0]);
  dp[2][2] = max(a[1], a[0]);
  chose[2][0] = {1, 2};
  chose[2][1] = {2, 0};
  chose[2][2] = {1, 0};
  long long int ma = inf;
  pair<long long int, long long int> ans;
  for (long long int i = 4; i < n; i += 2) {
    for (long long int j = 0; j < i - 1; j++) {
      dp[i][j] = dp[i - 2][j] + max(a[i], a[i - 1]);
      parent[i][j] = {i - 2, j};
      chose[i][j] = {i, i - 1};
      if (dp[i - 2][j] + max(a[i - 1], a[j]) < dp[i][i]) {
        dp[i][i] = dp[i - 2][j] + max(a[i - 1], a[j]);
        parent[i][i] = {i - 2, j};
        chose[i][i] = {i - 1, j};
      }
      if (dp[i - 2][j] + max(a[i], a[j]) < dp[i][i - 1]) {
        dp[i][i - 1] = dp[i - 2][j] + max(a[i], a[j]);
        parent[i][i - 1] = {i - 2, j};
        chose[i][i - 1] = {i, j};
      }
    }
  }
  vector<pair<long long int, long long int>> res;
  if (n % 2 == 0) {
    for (long long int i = 0; i < n - 1; i++) {
      if (ma > dp[n - 2][i] + max(a[i], a[n - 1])) {
        ma = dp[n - 2][i] + max(a[i], a[n - 1]);
        ans = {n, 0};
        chose[n][0] = {i, n - 1};
        parent[n][0] = {n - 2, i};
      }
    }
  } else {
    for (long long int i = 0; i < n; i++) {
      if (ma > dp[n - 1][i] + a[i]) {
        ma = dp[n - 1][i] + a[i];
        ans = {n - 1, i};
        if (res.size() == 1) {
          res.pop_back();
        }
        res.push_back({i, -1});
      }
    }
  }
  cout << ma << '\n';
  while (ans.first != -1 && ans.second != -1) {
    res.push_back(chose[ans.first][ans.second]);
    ans = parent[ans.first][ans.second];
  }
  reverse(res.begin(), res.end());
  for (auto p : res) {
    if (p.second == -1) {
      cout << p.first + 1 << '\n';
    } else {
      cout << p.first + 1 << " " << p.second + 1 << '\n';
    }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int test;
  test = 1;
  while (test--) {
    solve();
    cout << '\n';
  }
  cerr << "Time : "
       << 1000 * ((long double)clock()) / (long double)CLOCKS_PER_SEC << "ms\n";
  return 0;
}
