#include <bits/stdc++.h>
using namespace std;
struct liu {
std::string a;
int b;
} c[100000];
int main() {
int sum = 0;
int n, num = 0;
std::cin >> n;
for (int i = 1; i <= n; i++) {
std::string line, lion;
bool flag = false;
int aa = 0;
std::cin >> line >> lion;
int open = lion.find_first_of('(');
int close = lion.find_last_of(')');
std::string a, b;
a = lion.substr(0, open);
if (lion[open + 1] == '"')
b = lion.substr(open + 2, lion.size() - a.size() - 5);
else
b = lion.substr(open + 1, lion.size() - a.size() - 3);
for (int j = 1; j <= num; j++) {
if (c[j].a == b) {
flag = true;
aa = j;
break;
}
}
if (flag)
c[++num].a = a, c[num].b = c[aa].b;
else
c[++num].a = a, c[num].b = b.size();
if (line == "string")
sum += c[num].b;
}
std::cout << sum << std::endl;
return 0;
}