#include <bits/stdc++.h>
using namespace std;
const long long N = 1e3 + 5;
long long a[N], dp[N][N], n;
long long solve(long long excluded, long long idx) {
  long long &ans = dp[excluded][idx];
  if (ans != -1) return ans;
  if (idx > n) {
    return a[excluded];
  }
  ans = 1e18;
  if (idx <= n and idx + 1 <= n) {
    long long cost = max(a[idx], a[idx + 1]);
    ans = min(ans, cost + solve(excluded, idx + 2));
  }
  if (excluded <= n and idx + 1 <= n) {
    long long cost = max(a[excluded], a[idx + 1]);
    ans = min(ans, cost + solve(idx, idx + 2));
  }
  if (excluded <= n and idx <= n) {
    long long cost = max(a[excluded], a[idx]);
    ans = min(ans, cost + solve(idx + 1, idx + 2));
  }
  return ans;
}
void print(long long excluded, long long idx) {
  if (idx > n) {
    if (n & 1) cout << excluded;
    return;
  }
  long long cost0 = max(a[idx], a[idx + 1]) + solve(excluded, idx + 2);
  long long cost1 = max(a[excluded], a[idx + 1]) + solve(idx, idx + 2);
  long long cost2 = max(a[excluded], a[idx]) + solve(idx + 1, idx + 2);
  if (cost0 <= cost1 && cost0 <= cost2) {
    cout << idx << ' ' << idx + 1 << '\n';
    print(excluded, idx + 2);
  } else if (cost1 <= cost0 && cost1 <= cost2) {
    cout << excluded << ' ' << idx + 1 << '\n';
    print(idx, idx + 2);
  } else {
    cout << excluded << ' ' << idx << '\n';
    print(idx + 1, idx + 2);
  }
}
signed main() {
  std ::ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (long long i = 0; i < N; i++)
    for (long long j = 0; j < N; j++) dp[i][j] = -1;
  long long ans = solve(1, 2);
  cout << ans << '\n';
  print(1, 2);
}
