#include <bits/stdc++.h>
using namespace std;
long long int dp[1005][1005];
long long int chi[1005][1005];
int arr[1000005];
int n;
long long int solve(int l, int r) {
  if (dp[l][r] != -1)
    return dp[l][r];
  else {
    if (r < n - 1) {
      long long int k1 = solve(r + 1, r + 2) + max(arr[l], arr[r]);
      long long int k2 = solve(r, r + 2) + max(arr[l], arr[r + 1]);
      long long int k3 = solve(l, r + 2) + max(arr[r], arr[r + 1]);
      dp[l][r] = min(k1, min(k2, k3));
      if (dp[l][r] == k1)
        chi[l][r] = r + 1;
      else if (dp[l][r] == k2)
        chi[l][r] = r;
      else if (dp[l][r] == k3)
        chi[l][r] = l;
      return dp[l][r];
    } else {
      if (r == n - 1) {
        long long int k1 = max(arr[l], arr[r]) + arr[r + 1];
        long long int k2 = max(arr[l], arr[r + 1]) + arr[r];
        long long int k3 = max(arr[r], arr[r + 1]) + arr[l];
        dp[l][r] = min(max(arr[l], arr[r]) + arr[r + 1],
                       min(max(arr[l], arr[r + 1]) + arr[r],
                           max(arr[r], arr[r + 1]) + arr[l]));
        if (dp[l][r] == k1)
          chi[l][r] = r + 1;
        else if (dp[l][r] == k2)
          chi[l][r] = r;
        else
          chi[l][r] = l;
        return dp[l][r];
      } else {
        dp[l][r] = max(arr[l], arr[r]);
        return dp[l][r];
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i < n + 1; ++i) cin >> arr[i];
  for (int i = 0; i < 1005; ++i)
    for (int j = 0; j < 1005; ++j) dp[i][j] = -1;
  long long int ans = solve(1, 2);
  vector<int> q;
  for (int i = 0; i < min(3, n); ++i) q.push_back(i + 1);
  cout << ans << endl;
  int i = 0, l = 1, r = 2, e = 3;
  while (i < (n / 2 + (n % 2))) {
    int t1 = 0;
    if (n % 2 == 1 && i == n / 2) {
      cout << q[0] << endl;
      return 0;
    }
    if (q.size() == 2) {
      cout << min(q[0], q[1]) << " " << max(q[0], q[1]) << endl;
      return 0;
    }
    for (int j = 0; j < 3; ++j) {
      if (chi[l][r] == q[j]) {
        t1 = j;
        break;
      }
    }
    swap(q[0], q[t1]);
    cout << min(q[1], q[2]) << " " << max(q[2], q[1]) << endl;
    q.pop_back();
    q.pop_back();
    if (e + 1 <= n) q.push_back(e + 1);
    if (e + 2 <= n) q.push_back(e + 2);
    e += 2;
    l = q[0];
    r = q[1];
    i++;
  }
  return 0;
}
