#include <bits/stdc++.h>
using namespace std;
int t;
int main() {
  ios_base::sync_with_stdio(0);
  int s = 0;
  string a;
  while (getline(cin, a)) {
    if (a[0] == '+') {
      s++;
    } else if (a[0] == '-') {
      s--;
    } else {
      int u = 0;
      for (int i = a.size() - 1; i >= 0; i--) {
        if (a[i] == ':') {
          break;
        } else {
          u++;
        }
      }
      t += u * s;
    }
  }
  cout << t;
}
