#include <iostream>
#include <vector>
#include <stack>
using namespace std;
void compute(stack<int>& x, stack<int>& y, int& sum) {
int a = x.top();
x.pop();
int b = y.top();
y.pop();
int c = x.top();
y.pop();
sum += a * b * c;
y.push(b);
}
int main() {
int n, x, y, sum = 0, t, ans = 0;
cin >> n;
string s;
vector<vector<int>> v(n, vector<int>(2, 0));
for (int i = 0; i < n; i++) {
cin >> x >> y;
v[i][0] = x;
v[i][1] = y;
}
cin >> s;
stack<int> xx;
stack<int> yy;
stack<int> kuohao;
for (int i = 0; i < s.size(); i++) {
if (s[i] == '(') {
t++;
} else if (s[i] == ')') {
int q = kuohao.top();
kuohao.pop();
if (q == 1 && xx.size() != 1) {
compute(xx, yy, sum);
}
else{
q--;
kuohao.push(q);
}
} else {
if (t != 0) {
xx.push(v[ans][0]);
yy.push(v[ans][1]);
ans++;
kuohao.push(t);
t = 0;
} else {
xx.push(v[ans][0]);
yy.push(v[ans][1]);
compute(xx, yy, sum);
ans++;
}
}
}
cout << sum;
}
// 64 位输出请用 printf("%lld")