#include <bits/stdc++.h>
using namespace std;
int main() {
  string line;
  int persons = 0;
  int data = 0;
  while (getline(cin, line)) {
    if (line[0] == '+')
      ++persons;
    else if (line[0] == '-')
      --persons;
    else
      data += (line.size() - line.find(':') - 1) * persons;
  }
  cout << data << endl;
}
