#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
set<string> names;
char command[110];
int n;
int ans = 0;
void processAdd() { names.insert(command + 1); }
void processRemove() { names.erase(names.find(command + 1)); }
void processSend() {
  int lenMsg = n;
  for (int(i) = 0; (i) < (int)(n); ++(i)) {
    lenMsg--;
    if (command[i] == ':') break;
  }
  ans += lenMsg * names.size();
}
void processCommand() {
  if (command[0] == '+')
    processAdd();
  else if (command[0] == '-')
    processRemove();
  else
    processSend();
}
int main() {
  while (gets(command)) {
    n = strlen(command);
    processCommand();
  }
  printf("%d\n", ans);
}
