#include <bits/stdc++.h>
const long long int maxn = 2e7 + 5;
const long long mod = 1e9 + 7;
using namespace std;
long long int power(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b % 2 == 1) res = res * a;
    a = a * a;
    b = b / 2;
  }
  return res;
}
long long po(long long x, long long y) {
  long long res = 1;
  x = x % mod;
  while (y > 0) {
    if (y & 1) res = ((res % mod) * (x % mod)) % mod;
    y = y >> 1;
    x = ((x % mod) * (x % mod)) % mod;
  }
  return res;
}
int n;
vector<long long> a(1001);
long long int dp[1001][1001];
vector<int> ans;
long long int fun(int i, int j) {
  if (j == n - 1) {
    return dp[i][j] = max(a[i], a[j]);
  }
  if (j >= n) {
    return dp[i][j] = a[i];
  }
  if (dp[i][j] != -1) return dp[i][j];
  long long int x = max(a[i], a[j]) + fun(j + 1, j + 2);
  long long int y = max(a[i], a[j + 1]) + fun(j, j + 2);
  long long int z = max(a[j], a[j + 1]) + fun(i, j + 2);
  return dp[i][j] = min(x, min(y, z));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t = 1;
  while (t--) {
    memset(dp, -1, sizeof(dp));
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    long long int an = fun(0, 1), count = 0;
    cout << an << '\n';
    int i = 0, j = 1;
    while (j < n - 1) {
      if (count + max(a[i], a[j]) + dp[j + 1][j + 2] == an) {
        count += max(a[i], a[j]);
        ans.push_back(i + 1);
        ans.push_back(j + 1);
        i = j + 1;
        j = j + 2;
      } else if (count + max(a[i], a[j + 1]) + dp[j][j + 2] == an) {
        count += max(a[i], a[j + 1]);
        ans.push_back(i + 1);
        ans.push_back(j + 2);
        i = j;
        j = j + 2;
      } else if (count + max(a[j], a[j + 1]) + dp[i][j + 2] == an) {
        count += max(a[j], a[j + 1]);
        ans.push_back(j + 1);
        ans.push_back(j + 2);
        j = j + 2;
      }
    }
    ans.push_back(i + 1);
    if (j == n - 1) ans.push_back(j + 1);
    int c = 0;
    for (int i = 0; i < ans.size(); i++) {
      if (c == 2) {
        cout << '\n';
        c = 0;
      }
      cout << ans[i] << " ";
      c++;
    }
  }
}
