#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <math.h>
#include <cmath>
#include <algorithm>
#define rep(i, n) for(LL i = 0; i < n; i++)
typedef long long LL;
using namespace std;

const LL N=1010;
LL a[N], dp[N][N], lchap;
LL n;
vector <LL> out1, out2;

LL solve(LL pos, LL saf, LL chap)
{
    if (dp[pos][saf] && chap != 1) return dp[pos][saf];
    if (pos == -1) {
        if (chap) lchap = saf + 1;
        return a[saf];
    }
    if (pos == 0) {
        if (chap) cout << saf + 1 << ' ' << 0 + 1 << endl;
        return max(a[0], a[saf]);
    }
    LL p1 = solve(pos - 2, saf, 0) + max(a[pos], a[pos - 1]);
    LL p2 = solve(pos - 2, pos - 1, 0) + max(a[pos], a[saf]);
    LL p3 = solve(pos - 2, pos, 0) + max(a[pos - 1], a[saf]);
    
    LL mx = min(p1, min(p2, p3));
    p1 *= (p1 == mx); p2 *= (p2 == mx); p3 *= (p3 == mx);
    
    if (p1 && chap) solve(pos - 2, saf, 1), cout << pos + 1 << ' ' << pos - 1 + 1 << endl;
    else if (p2 && chap) solve(pos - 2, pos - 1, 1), cout << pos + 1 << ' ' << saf + 1 << endl;
    else if (p3 && chap) solve(pos - 2, pos, 1), cout << pos - 1 + 1 << ' ' << saf + 1 << endl;
    return dp[pos][saf] = mx;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n;
    rep(i, n)
        cin >> a[i];
    reverse(a, a + n);
    cout << solve(n - 2, n - 1, 0) << endl;
    solve(n - 2, n - 1, 1);
    if (lchap) cout << lchap << endl;
    return 0;
}