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


//录入矩阵

//右括号与计算次数相匹配
int main(){

int n;
while(scanf("%d",&n)!=EOF){
int edge[n][2];
for(int i=0;i<n;i++){
    scanf("%d %d",&edge[i][0],&edge[i][1]);
}
char str[100];
scanf("%s",str);
int count=0;
int top=-1;
int compute[n][2];
int pos = 0;    
for(int i=0;i<strlen(str);i++){
if(str[i]>='A' && str[i]<='Z'){
    ++top;
compute[top][0]= edge[pos][0],compute[top][1]= edge[pos][1];
    pos++;
}
if(str[i]==')'){
//弹出两个计算 top top-1
count += compute[top-1][0]*compute[top-1][1]*compute[top][1];
compute[top-1][0]= compute[top-1][0];
    compute[top-1][1]= compute[top][1];
top--;
}
}


printf("%d\n",count);
}
return 0;
}