import java.util.*;
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 a = in.nextInt();
        //     int b = in.nextInt();
        //     System.out.println(a + b);
        // }
        int n = in.nextInt();
        int[][] arr = new int[n][2];
        for (int i = 0; i < n; i++) {
            arr[i][0] = in.nextInt();
            arr[i][1] = in.nextInt();
        }
        String rule = in.next();
        char[] cs = rule.toCharArray();

        int sum = 0;
        int index = 0;
        for (int i = 0; i < cs.length; i++) {
            char c = cs[i];
            if (c == '(') {
                continue;
            }
            if (c >= 'A' && c <= 'Z') {
                index++;
            }
            if (c == ')') {
                int temp = index - 2;
                while (temp >= 0) {
                    if (arr[temp][0] == 0) {
                        temp--;
                        continue;
                    } else {
                        sum += arr[temp][0] * arr[temp][1] * arr[index - 1][1];
                        arr[index - 1][0] = arr[temp][0];
                        arr[temp][0] = 0;
                        arr[temp][1] = 0;
                        break;
                    }
                }
            }
        }
        System.out.print(sum);
    }
}