#include <bits/stdc++.h>
using namespace std;
int n;
int dp[1000][501];
int fans;
deque<pair<int, int> > q;
int cS(int steps) {
  if (q.size() <= 2) {
    if (q.size() == 2) {
      pair<int, int> t1 = q.front();
      q.pop_front();
      pair<int, int> t2 = q.front();
      int ans = max(t1.first, t2.first);
      q.push_front(t1);
      return dp[t1.second][steps] = ans;
    }
    if (q.size() == 1) {
      return dp[q.front().second][steps] = q.front().first;
    }
    return 0;
  }
  if (dp[q.front().second][steps] != -1) {
    return dp[q.front().second][steps];
  }
  int ans = INT_MAX;
  pair<int, int> a[3];
  for (int i = 0; i < 3; i++) {
    a[i] = q.front();
    q.pop_front();
  }
  for (int i = 0; i < 3; i++) {
    q.push_front(a[i]);
    ans = min(max(a[(i + 1) % 3].first, a[(i + 2) % 3].first) + cS(steps + 1),
              ans);
    q.pop_front();
  }
  for (int i = 2; i >= 0; --i) {
    q.push_front(a[i]);
  }
  return dp[q.front().second][steps] = ans;
}
void print(int steps) {
  if (q.size() <= 2) {
    if (q.size() == 2) {
      int t1 = q.front().second + 1;
      q.pop_front();
      cout << t1 << " " << q.front().second + 1 << "\n";
      return;
    }
    if (q.size() == 1) {
      cout << q.front().second + 1 << "\n";
      return;
    }
    return;
  }
  pair<int, int> a[3];
  for (int i = 0; i < 3; i++) {
    a[i] = q.front();
    q.pop_front();
  }
  for (int i = 0; i < 3; i++) {
    if (max(a[(i + 1) % 3].first, a[(i + 2) % 3].first) +
            dp[a[i].second][steps + 1] ==
        fans) {
      fans -= max(a[(i + 1) % 3].first, a[(i + 2) % 3].first);
      cout << a[(i + 1) % 3].second + 1 << " " << a[(i + 2) % 3].second + 1
           << "\n";
      q.push_front(a[i]);
      print(steps + 1);
      break;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  memset(dp, -1, sizeof(dp));
  int temp;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    q.push_back({temp, i});
  }
  fans = cS(0);
  cout << fans << "\n";
  print(0);
  return 0;
}
