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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        while(in.hasNext()){
            solution1(in);
            // solution2(in);
        }
    }

    /**
     * stack
     * @param in
     */
    private static void solution1(Scanner in){
        int num = in.nextInt();

        int[][] matrixRC = new int[num][2];
        for(int i=0; i<num; i++){
            matrixRC[i][0] = in.nextInt();
            matrixRC[i][1] = in.nextInt();
            in.nextLine();
        }

        String rule = in.nextLine();

        int result = 0;
        Stack<Integer> rcStack = new Stack<>();
        for(int i=0; i<rule.length(); i++){
            char ch = rule.charAt(i);
            if(ch == '('){
                continue;
            }else if(ch == ')'){
                // 右矩阵列数
                int RC = rcStack.pop();
                // 右矩阵行数
                int RR = rcStack.pop();
                // 左矩阵列数
                int LC = rcStack.pop();
                // 左矩阵行数
                int LR = rcStack.pop();

                result += LR * LC * RC;

                rcStack.push(LR);
                rcStack.push(RC);
            }else{
                rcStack.push(matrixRC[ch-'A'][0]);
                rcStack.push(matrixRC[ch-'A'][1]);
            }
        }

        System.out.println(result);
    }


    /**
     * stack + map
     */
    private static void solution2(Scanner in){
        int num = Integer.parseInt(in.nextLine());

        // 矩阵名->矩阵行列数
        HashMap<String, String> matrixMap = new HashMap<>();
        for(int i=0; i<num; i++){
            matrixMap.put(String.valueOf((char) ('A'+i)), in.nextLine());
        }

        String rule = in.nextLine();

        int result = 0;
        Stack<String> operate = new Stack<>();
        for(int i=0; i<rule.length(); i++){
            char ch = rule.charAt(i);
            if(ch == '('){
                continue;
            }else if(ch == ')'){
                // 右矩阵
                String matrixR = operate.pop();
                // 左矩阵
                String matrixL = operate.pop();
                // 右矩阵行列数
                String[] matrixRRC = matrixMap.get(matrixR).split(" ");
                // 左矩阵行列数
                String[] matrixLRC = matrixMap.get(matrixL).split(" ");
                
                result += Integer.parseInt(matrixLRC[0]) * Integer.parseInt(matrixLRC[1]) * Integer.parseInt(matrixRRC[1]);
                
                matrixMap.put(matrixL+matrixR, matrixLRC[0]+" "+matrixRRC[1]);
                operate.push(matrixL+matrixR);
            }else{
                operate.push(String.valueOf(ch));
            }
        }

        System.out.println(result);
    }
}