#include <bits/stdc++.h>
using namespace std;
const long long N = 1010;
long long n, a[N], dp[N][N];
vector<pair<long long, long long> > ans;
inline long long DP(long long i, long long j) {
  if (j >= n - 1 or i >= n - 2) dp[i][j] = max(a[i], a[j]);
  if (dp[i][j]) return dp[i][j];
  dp[i][j] = min({max(a[i], a[j]) + DP(j + 1, j + 2),
                  max(a[i], a[j + 1]) + DP(j, j + 2),
                  max(a[j], a[j + 1]) + DP(i, j + 2)});
  return dp[i][j];
}
inline void find_match(long long i, long long j) {
  if (i == n - 1 or j >= n) {
    ans.push_back({i, -1});
    return;
  }
  if (i == n - 2 or j == n - 1) {
    ans.push_back({i, j});
    return;
  }
  long long x = max(a[i], a[j]) + dp[j + 1][j + 2];
  long long y = max(a[i], a[j + 1]) + dp[j][j + 2];
  long long z = max(a[j], a[j + 1]) + dp[i][j + 2];
  if (x <= y and x <= z) {
    ans.push_back({i, j});
    find_match(j + 1, j + 2);
    return;
  }
  if (y <= x and y <= z) {
    ans.push_back({i, j + 1});
    find_match(j, j + 2);
    return;
  }
  if (z <= x and z <= y) {
    ans.push_back({j, j + 1});
    find_match(i, j + 2);
    return;
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  cout << DP(0, 1) << '\n';
  find_match(0, 1);
  for (auto x : ans) {
    x.first++;
    x.second++;
    if (x.second)
      cout << x.first << " " << x.second << '\n';
    else
      cout << x.first;
  }
}
