#include <bits/stdc++.h>
using namespace std;
string c;
long long i, l, a, s1;
int main() {
  while (getline(cin, c)) {
    if (c[0] == 43) s1++;
    if (c[0] == 45) s1--;
    l = c.size();
    if (c[0] != 43 && c[0] != 45) {
      for (i = 1; i <= l; i++) {
        if (c[i] == 58) a += (l - i - 1) * s1;
      }
    }
  }
  cout << a;
  return 0;
}
