import java.util.Scanner;
import java.util.Stack;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNextInt()) { // 注意 while 处理多个 case
            int n = in.nextInt();
            int[][] ints = new int[n][2];
            for (int i = 0; i < n; i++) {
                // 行数
                ints[i][0] = in.nextInt();
                // 列数
                ints[i][1] = in.nextInt();
            }
            String s = in.next();
            Stack<Integer> stack = new Stack<>();

            int count = 0;
            // 倒着遍历
            for (int i = s.length() - 1,j = n - 1; i >=0; i--) {
                char c = s.charAt(i);
                if (c >= 'A' && c <= 'Z'){
                    // 列
                    int y = ints[j][1];
                    // 行
                    int x = ints[j][0];
                    stack.push(y);
                    stack.push(x);
                    j--;
                    continue;
                }
                if (c == '('){
                    Integer x1 = stack.pop();
                    Integer y = stack.pop();
                    Integer x2 = stack.pop();
                    Integer z = stack.pop();
                    // 计算本次乘的数量
                    count += x1 * y * z;
                    // 添加计算后的列和行
                    stack.push(z);
                    stack.push(x1);
                }
            }
            System.out.println(count);
        }
    }
}