#include using namespace std; int main() { ios::sync_with_stdio(0); cin.tie(0); map> order; string line; while (getline(cin, line) && !line.empty()) { istringstream l(line); int a, b; l >> a; l.ignore(); l >> b; order[a].insert(b); } int ret = 0; while (getline(cin, line) && !line.empty()) { istringstream l(line); int x; vector elems; while (l >> x) { elems.push_back(x); l.ignore(); } for (int i = 0; i < elems.size(); i++) { if (order.contains(elems[i])) { for (int j = 0; j < i; j++) { if (order[elems[i]].contains(elems[j])) { goto next; } } } } ret += elems[elems.size() / 2]; next:; } cout << ret << '\n'; }