#include <bits/stdc++.h>
using namespace std;
int n;
long long a[1005];
long long dp[1005][1005];
int ch[1005][1005];
void print() {
  int i = 0, j = 0;
  while (i < n) {
    if (ch[i][j] == -1) {
      cout << j + 1 << "\n";
      break;
    } else if (ch[i][j] == 0) {
      cout << j + 1 << " " << i + 2 << "\n";
      break;
    } else if (ch[i][j] == 1) {
      cout << i + 2 << " " << i + 3 << "\n";
      i += 2;
    } else if (ch[i][j] == 2) {
      cout << j + 1 << " " << i + 2 << "\n";
      i += 2;
      j = i;
    } else {
      cout << j + 1 << " " << i + 3 << "\n";
      i += 2;
      j = i - 1;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = n - 1; i >= 0; i--) {
    for (int j = i; j >= 0; j--) {
      if (i + 1 < n && i + 2 >= n) {
        ch[i][j] = 0;
        dp[i][j] = max(a[j], a[i + 1]);
      } else if (i + 1 >= n) {
        ch[i][j] = -1;
        dp[i][j] = a[j];
      } else {
        long long ans1 = max(a[i + 1], a[i + 2]) + dp[i + 2][j];
        long long ans2 = max(a[j], a[i + 1]) + dp[i + 2][i + 2];
        long long ans3 = max(a[j], a[i + 2]) + dp[i + 2][i + 1];
        dp[i][j] = min(min(ans1, ans2), ans3);
        if (dp[i][j] == ans1)
          ch[i][j] = 1;
        else if (dp[i][j] == ans2)
          ch[i][j] = 2;
        else
          ch[i][j] = 3;
      }
    }
  }
  cout << dp[0][0] << endl;
  print();
  return 0;
}
