import java.io.*;
public class Main {
static BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
static int N = 35;
static int[] a = new int[N];
static int[][] dp = new int[N][N];
static int[][] g = new int[N][N];
public static void main(String[] args) throws Exception{
int n = Integer.valueOf(read.readLine());
String[] ss = read.readLine().split(" ");
for(int i = 1; i <= n; i++) a[i] = Integer.valueOf(ss[i - 1]);
for(int len = 1; len <= n; len++ ){
for(int i = 1; i + len - 1 <= n; i++){
int j = i + len - 1;
if(len == 1) {
dp[i][j] = a[i];
g[i][j] = i;
}
else {
for(int k = i; k <= j; k++){
int left = k == i ? 1: dp[i][k - 1];
int right = k == j ? 1: dp[k + 1][j];
int mul = left * right + a[k];
if(dp[i][j] < mul){
dp[i][j] = mul;
g[i][j] = k;
}
}
}
}
}
System.out.println(dp[1][n]);
print(1, n);
}
public static void print(int left, int right){
if(left > right) return;
int root = g[left][right];
System.out.print(root + " ");
print(left, root - 1);
print(root + 1, right);
}
}