#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:60777216")
using namespace std;
long long gcd(long long a, long long b) { return a == 0 ? b : gcd(b % a, a); }
string filename = "test";
int n;
int a[10001];
int mem[10001][2];
vector<pair<int, int> > vres;
int go(int pos, int next_alive) {
  if (pos == n) {
    return 0;
  }
  if (mem[pos][next_alive] != -1) {
    return mem[pos][next_alive];
  }
  if (pos == n - 1) {
    return mem[pos][next_alive] = a[pos];
  }
  if (pos == n - 2 && next_alive == 0) {
    return mem[pos][next_alive] = a[pos];
  }
  if (pos == n - 2 && next_alive == 1) {
    return mem[pos][next_alive] =
               (((a[pos]) > (a[pos + 1])) ? (a[pos]) : (a[pos + 1]));
  }
  int& ret = mem[pos][next_alive];
  int first_av = next_alive == 1 ? pos + 1 : pos + 2;
  int sum_other = 0;
  for (int i = first_av, j = 0; i < n; ++i, ++j) {
    int r_now = (((a[pos]) > (a[i])) ? (a[pos]) : (a[i])) + sum_other;
    int r_other = 0;
    if (j % 2 == 0) {
      r_other = go(i + 1, 1);
    } else {
      r_other = go(i - 1, 0);
    }
    if (j % 2 == 1) {
      sum_other += (((a[i]) > (a[i - 1])) ? (a[i]) : (a[i - 1]));
    }
    r_now += r_other;
    if (ret == -1 || r_now < ret) {
      ret = r_now;
    }
  }
  int sum_last = 0;
  for (int i = first_av; i < n; i += 2) {
    if (i + 1 < n) {
      sum_last += (((a[i]) > (a[i + 1])) ? (a[i]) : (a[i + 1]));
    } else {
      sum_last = -1;
    }
  }
  if (sum_last != -1) {
    sum_last += a[pos];
    if (sum_last < ret) {
      ret = sum_last;
    }
  }
  return ret;
}
void build(int pos, int next_alive, int sum) {
  if (pos == n) {
    return;
  }
  if (pos == n - 1) {
    vres.push_back(pair<int, int>(pos, -1));
    return;
  }
  if (pos == n - 2 && next_alive == 0) {
    vres.push_back(pair<int, int>(pos, -1));
    return;
  }
  if (pos == n - 2 && next_alive == 1) {
    vres.push_back(pair<int, int>(pos, pos + 1));
    return;
  }
  int first_av = next_alive == 1 ? pos + 1 : pos + 2;
  int sum_other = 0;
  for (int i = first_av, j = 0; i < n; ++i, ++j) {
    int r_now = (((a[pos]) > (a[i])) ? (a[pos]) : (a[i])) + sum_other;
    int r_other = 0;
    if (j % 2 == 0) {
      r_other = go(i + 1, 1);
    } else {
      r_other = go(i - 1, 0);
    }
    if (j % 2 == 1) {
      sum_other += (((a[i]) > (a[i - 1])) ? (a[i]) : (a[i - 1]));
    }
    if (r_now + r_other == sum) {
      for (int k = first_av; k + 1 < i; k += 2) {
        vres.push_back(pair<int, int>(k, k + 1));
      }
      vres.push_back(pair<int, int>(pos, i));
      if (j % 2 == 0) {
        build(i + 1, 1, sum - r_now);
      } else {
        build(i - 1, 0, sum - r_now);
      }
      return;
    }
  }
  for (int i = first_av; i < n; i += 2) {
    vres.push_back(pair<int, int>(i, i + 1));
  }
  vres.push_back(pair<int, int>(pos, -1));
}
int main() {
  scanf("%d", &n);
  for (int _n(n), i(0); i < _n; i++) {
    scanf("%d", &a[i]);
  }
  memset(mem, -1, sizeof(mem));
  int res = go(0, 1);
  build(0, 1, res);
  printf("%d\n", res);
  for (int _n(vres.size()), i(0); i < _n; i++) {
    if (vres[i].second == -1) {
      printf("%d\n", vres[i].first + 1);
    } else {
      printf("%d %d\n", vres[i].first + 1, vres[i].second + 1);
    }
  }
  return 0;
}
