/*
1. 状态定义: f[i][j] 为合并[i~j]的最大值,g[i][j]为合并[i~j]的最小值,结果为f[1][n]
2. 状态计算:以合并的左边界k 划分为 [i~k] 和 [k+1~j] 2个结果合并
当k~k+1 边权为“+”:f[i][j] = MAX(f[i][k] + f[k+1][j])
g[i][j] = MIN(g[i][k] + g[k+1][j])
当k~K+1 边权为“*”:f[i][j] = MAX(f[i][k] * f[k+1][j], f[i][k] * g[k+1][j], g[i][k] * f[k+1][j], g[i][k] * g[k+1][j])
g[i][j] = MIN(f[i][k] * f[k+1][j], f[i][k] * g[k+1][j], g[i][k] * f[k+1][j], g[i][k] * g[k+1][j])
3. 边界:f[i][j] = -INF , f[i][i] = a[i]
g[i][j] = INF , g[i][i] = a[i]
4. 拆环成链, 直接聚合1~2n的结果,中间所有结果的子集也都知道了
*/
import java.util.*;
import java.util.stream.*;
public class Main{
void run(){
int n = jin.nextInt();
for (int i = 1 ; i <= n ; i++){
sign[i] = jin.next().charAt(0);
list[i] = jin.nextInt();
sign[i+n] = sign[i];
list[i+n] = list[i];
}
dp(n);
}
void dp(int n){
for (int i = 0 ; i <= 2*n ; i ++){
for (int j = 0 ; j <= 2*n ; j++){
f[i][j] = i == j ? list[i] : Integer.MIN_VALUE;
g[i][j] = i == j ? list[i] : Integer.MAX_VALUE;
}
}
for (int len = 2 ; len <= n ;len++){
for (int i = 1 ; i + len -1 <=2 * n ;i++){
int j = i + len - 1 ;
for (int k = i ; k < j ; k ++){
int maxValue = Integer.MIN_VALUE;
int minValue = Integer.MAX_VALUE;
if (sign[k+1] == 't'){
maxValue = f[i][k] + f[k+1][j];
minValue = g[i][k] + g[k+1][j];
} else {
int[] candidate = {f[i][k] * f[k+1][j], f[i][k] * g[k+1][j], g[i][k] * f[k+1][j], g[i][k] * g[k+1][j]};
maxValue = Arrays.stream(candidate).max().getAsInt();
minValue = Arrays.stream(candidate).min().getAsInt();
}
f[i][j] = Math.max(f[i][j], maxValue);
g[i][j] = Math.min(g[i][j], minValue);
}
}
}
int r = Integer.MIN_VALUE;
for (int s = 1 ; s <= n ; s++){
r = Math.max(r, f[s][s+n-1]);
}
System.out.println(r);
for (int s = 1 ; s <= n ; s++){
if (r == f[s][s+n-1]) path.add(s);
}
path.sort((a,b)->(a-b));
System.out.println(String.join(" ", path.stream().map(x->String.valueOf(x)).collect(Collectors.toList())));
}
void dp2(int n){ // 当初的做法,留个错误记录,后面再追下问题
List<Integer> res = new ArrayList<>();
List<Integer> index = new ArrayList<>();
for (int s = 1 ; s <= n ; s++){
for (int i = 0 ; i <= 2*n ; i ++){
for (int j = 0 ; j <= 2*n ; j++){
f[i][j] = i == j ? list[i] : Integer.MIN_VALUE;
g[i][j] = i == j ? list[i] : Integer.MAX_VALUE;
}
}
for (int len = 2 ; len <= n ;len++){
for (int i = s ; i + len -1 <= n ;i++){
int j = i + len - 1 ;
for (int k = i ; k < j ; k ++){
int maxValue = Integer.MIN_VALUE;
int minValue = Integer.MAX_VALUE;
if (sign[k+1] == 't'){
maxValue = f[i][k] + f[k+1][j];
minValue = g[i][k] + g[k+1][j];
} else {
int[] candidate = {f[i][k] * f[k+1][j], f[i][k] * g[k+1][j], g[i][k] * f[k+1][j], g[i][k] * g[k+1][j]};
maxValue = Arrays.stream(candidate).max().getAsInt();
minValue = Arrays.stream(candidate).min().getAsInt();
}
f[i][j] = Math.max(f[i][j], maxValue);
g[i][j] = Math.min(g[i][j], minValue);
}
}
}
res.add(f[s][s+n-1]);
index.add(s);
}
int r = res.stream().max((a,b)->(a-b)).get();
System.out.println(r);
for (int i = 0 ; i < res.size(); i++){
if (res.get(i) == r){
path.add(index.get(i));
}
}
path.sort((a,b)->(a-b));
System.out.println(String.join(" ", path.stream().map(x->String.valueOf(x)).collect(Collectors.toList())));
}
int maxN = 102;
int[][] f = new int[maxN][maxN];
int[][] g = new int[maxN][maxN];
int[] list = new int[maxN];
int[] sign = new int[maxN];
List<Integer> path = new ArrayList<>();
Scanner jin = new Scanner(System.in);
public static void main(String[] args) {new Main().run();}
}