#include <bits/stdc++.h>
using namespace std;
int n, a[1003], dp[1003][1003], ans = 1e9 + 10, fr[1003][1003], now;
vector<pair<int, int> > res;
void dfs(int x, int wants) {
  if (x == 1) return;
  if (x == wants) {
    res.push_back(make_pair(x - 1, fr[x][wants]));
    dfs(x - 2, fr[x][wants]);
  }
  if (wants + 1 == x) {
    res.push_back(make_pair(x, fr[x][wants]));
    dfs(x - 2, fr[x][wants]);
  }
  if (x != wants && x != wants + 1) {
    res.push_back(make_pair(x, x - 1));
    dfs(x - 2, fr[x][wants]);
  }
}
int main() {
  for (int i = 0; i < 1003; i++)
    for (int j = 0; j < 1003; j++) dp[i][j] = 1e9 + 10;
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  if (n == 1) {
    cout << a[1];
    cout << "\n1";
    return 0;
  }
  if (n == 2) {
    cout << max(a[1], a[2]);
    cout << "\n1 2";
    return 0;
  }
  dp[1][1] = 0;
  for (int i = 3; i <= n; i += 2)
    for (int j = 1; j < i - 1; j++) {
      if (dp[i][j] > dp[i - 2][j] + max(a[i], a[i - 1]))
        dp[i][j] = dp[i - 2][j] + max(a[i], a[i - 1]), fr[i][j] = j;
      if (dp[i][i - 1] > dp[i - 2][j] + max(a[i], a[j]))
        dp[i][i - 1] = dp[i - 2][j] + max(a[i], a[j]), fr[i][i - 1] = j;
      if (dp[i][i] > dp[i - 2][j] + max(a[i - 1], a[j]))
        dp[i][i] = dp[i - 2][j] + max(a[i - 1], a[j]), fr[i][i] = j;
    }
  if (n % 2 == 1) {
    for (int i = 1; i <= n; i++)
      if (ans > dp[n][i] + a[i]) ans = dp[n][i] + a[i], now = i;
  } else {
    for (int i = 1; i < n; i++)
      if (ans > dp[n - 1][i] + max(a[i], a[n]))
        ans = dp[n - 1][i] + max(a[i], a[n]), now = i;
  }
  cout << ans << "\n";
  if (n % 2 == 1) {
    dfs(n, now);
    reverse(res.begin(), res.end());
    for (int i = 0; i < res.size(); i++)
      cout << res[i].first << " " << res[i].second << "\n";
    cout << now << "\n";
  } else {
    dfs(n - 1, now);
    reverse(res.begin(), res.end());
    for (int i = 0; i < res.size(); i++)
      cout << res[i].first << " " << res[i].second << "\n";
    cout << now << " " << n << "\n";
  }
}
