#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;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8ZnN0cmVhbT4KI2luY2x1ZGUgPGNzdGRpbz4KI2luY2x1ZGUgPGNzdHJpbmc+CiNpbmNsdWRlIDxjc3RkbGliPgojaW5jbHVkZSA8bWF0aC5oPgojaW5jbHVkZSA8Y21hdGg+CiNpbmNsdWRlIDxhbGdvcml0aG0+CiNkZWZpbmUgcmVwKGksIG4pIGZvcihMTCBpID0gMDsgaSA8IG47I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