#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (a == 0) return b;
  return gcd(b % a, a);
}
template <typename T>
T pow(T a, T b, long long m) {
  T ans = 1;
  while (b > 0) {
    if (b % 2 == 1) ans = ((ans % m) * (a % m)) % m;
    b /= 2;
    a = ((a % m) * (a % m)) % m;
  }
  return ans % m;
}
int n;
int a[1005];
int dp[1005][1005];
int solve(int f, int s) {
  if (f > n) return 0;
  if (s == n) {
    return max(a[f], a[s]);
  }
  if (s > n) {
    return a[f];
  }
  if (dp[f][s] != -1) return dp[f][s];
  int ans = (long long)1e9 + 2;
  ans = min(ans, max(a[f], a[s]) + solve(s + 1, s + 2));
  ans = min(ans, max(a[f], a[s + 1]) + solve(s, s + 2));
  ans = min(ans, max(a[s], a[s + 1]) + solve(f, s + 2));
  return dp[f][s] = ans;
}
void print(int f, int s) {
  if (f > n) return;
  if (s == n) {
    cout << f << " " << s << "\n";
    return;
  }
  if (s > n) {
    cout << f;
    return;
  }
  if (dp[f][s] == max(a[f], a[s]) + solve(s + 1, s + 2)) {
    cout << f << " " << s << "\n";
    print(s + 1, s + 2);
  } else if (dp[f][s] == max(a[f], a[s + 1]) + solve(s, s + 2)) {
    cout << f << " " << s + 1 << "\n";
    print(s, s + 2);
  } else if (dp[f][s] == max(a[s], a[s + 1]) + solve(f, s + 2)) {
    cout << s << " " << s + 1 << "\n";
    print(f, s + 2);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  memset(dp, -1, sizeof dp);
  cout << solve(1, 2) << "\n";
  print(1, 2);
}
