#include <bits/stdc++.h>
using namespace std;
string s[101];
int main() {
  int i = 0, sum = 0, ans = 0;
  while (getline(cin, s[i])) {
    if (s[i][0] == '+')
      sum++;
    else if (s[i][0] == '-')
      sum--;
    else {
      int j = 0;
      int cnt = 0;
      while (1) {
        j++;
        if (s[i][j] == ':') break;
      }
      cnt = s[i].length() - j - 1;
      ans += cnt * sum;
    }
    i++;
  }
  cout << ans << endl;
}
