//
// Created by gs on 2026/3/5.
//


// HJ70 矩阵乘法计算量估算

#include <stdio.h>
#include <string.h>

int main() {
    int n = 0, i = 0, j = 0;
    long long num = 0;
    int aa[2][15] = {0};
    char command[105] = {0};
    scanf("%d", &n);
    for (i = 0; i < n; i++) {
        scanf("%d %d", &aa[0][i], &aa[1][i]);
    }
    scanf("%s", command);

    while (n > 1) {
        int index = 0;
        for (i = 0 ; i < strlen(command); i++) {
            if (command[i] >= 'A' && command[i] <= 'Z') {
                index++;
            } else if (command[i] == ')') {
                index--;
                break;
            }
        }

        num += aa[0][index - 1] * aa[1][index - 1] * aa[1][index];

        aa[1][index - 1] = aa[1][index];
        for (i = index; i < n; i++) {
            aa[0][i] = aa[0][i + 1];
            aa[1][i] = aa[1][i + 1];
        }

        j = 0;
        for (i = 0 ; i < strlen(command); i++) {
            if (command[i] == '(') {
                j = i;
            } else if (command[i] == ')') {
                break;
            }
        }

        command[j] = 'A';
        int len = strlen(command);
        for (i = j + 1 ; i < len; i++) {
            command[i] = command[i + 3];
        }

        n--;
    }

    printf("%d\n", num);

    return 0;
}