#include <bits/stdc++.h>
using namespace std;
int main() {
  char c, b[1000];
  int a = 0, ans = 0;
  while (cin >> c) {
    if (c == '+') {
      a++;
    }
    if (c == '-') {
      a--;
    }
    if (c == ':') {
      gets(b);
      ans += strlen(b) * a;
    }
  }
  cout << ans << endl;
}
