#include <bits/stdc++.h>
using namespace std;
template <class T>
void pr(T x) {
  cerr << x;
}
template <class T>
void pr(vector<T> v) {
  pr('[');
  for (__typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
    pr(it == v.begin() ? "" : ","), pr(*it);
  pr(']');
  ;
}
template <class T1, class T2>
void pr(pair<T1, T2> x) {
  pr(x.first);
  pr(':');
  pr(x.second);
}
template <class T>
void pr(set<T> v) {
  pr('{');
  for (__typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
    pr(it == v.begin() ? "" : ","), pr(*it);
  pr('}');
  ;
}
template <class T1, class T2>
void pr(map<T1, T2> v) {
  pr('{');
  for (__typeof(v.begin()) it = v.begin(); it != v.end(); ++it)
    pr(it == v.begin() ? "" : ","), pr(*it);
  pr('}');
  ;
}
int A[2000], N;
int dp[1111][1111];
int rec(int h, int n) {
  if (n == N + 1) return A[h];
  if (n == N) return max(A[h], A[N]);
  if (dp[h][n] != -1) return dp[h][n];
  int t1 = max(A[h], A[n]) + rec(n + 1, n + 2);
  int t2 = max(A[h], A[n + 1]) + rec(n, n + 2);
  int t3 = max(A[n], A[n + 1]) + rec(h, n + 2);
  int r = min(t1, min(t2, t3));
  return dp[h][n] = r;
}
void build(int h, int n) {
  if (n == N + 1) {
    cout << h << endl;
    return;
  }
  if (n == N) {
    cout << h << " " << N << endl;
    return;
  }
  int t1 = max(A[h], A[n]) + rec(n + 1, n + 2);
  int t2 = max(A[h], A[n + 1]) + rec(n, n + 2);
  int t3 = max(A[n], A[n + 1]) + rec(h, n + 2);
  int r = min(t1, min(t2, t3));
  if (r == t1) {
    cout << h << " " << n << endl;
    build(n + 1, n + 2);
  } else if (r == t2) {
    cout << h << " " << n + 1 << endl;
    build(n, n + 2);
  } else {
    cout << n << " " << n + 1 << endl;
    build(h, n + 2);
  }
}
int main() {
  cin >> N;
  for (int i = 1; i <= N; ++i) cin >> A[i];
  memset(dp, -1, sizeof(dp));
  cout << rec(1, 2) << endl;
  build(1, 2);
  return 0;
}
