#include <bits/stdc++.h>
using namespace std;
template <class T>
T power(T a, T b) {
  T x;
  if (b == 0)
    x = 1;
  else
    x = a;
  for (size_t i = 1; i < b; i++) x *= a;
  return x;
}
long long int gcd(long long int a, long long int b) {
  return b == 0 ? a : gcd(b, a % b);
}
long long int n, m, a, b, c, ab, ba, x, y, z, avg, sum;
int arr3[1000001], arr4[200001], arr5[100001];
bool f, f1, f2;
string str, s1, s2, s3, s4;
set<int> seto;
double d, d1;
long long int x1, x2, y11, y2;
int mini = 1 << 30, maxi = 0;
vector<int> v;
stack<int> s;
string arr[1001];
int main() {
  while (getline(cin, str)) {
    if (str[0] == '+')
      sum++;
    else if (str[0] == '-')
      sum--;
    else
      x += str.substr(str.find(':') + 1).size() * sum;
  }
  cout << x;
}
