#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <map>

#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)
#define EPS 1e-11

#define pii pair<int,int>
#define FFF freopen("test","r",stdin)
#define all(a) a.begin(),a.end()

using namespace std;

void output(i64 x)
{
    if(x<0) putchar('-'),x=-x;
    if(x==0)
    {
        putchar('0');
        return;
    }
    int a[20],num=0;
    while(x) a[++num]=x%10,x/=10;
    while(num>0) putchar('0'+a[num--]);
}

inline i64 myInt()
{
    char c=getchar();
    while(!isdigit(c)&&c!='-') c=getchar();
    int flag=1;
    if(c=='-') flag=-1,c=getchar();
    i64 x=0;
    while(isdigit(c))
    {
        x=(x*10)+(c-'0');
        c=getchar();
    }
    if(flag==-1) return -x;
    return x;
}

const int INF=1e9;
const int N=400005;

int n,m;
int K;

int ans;

int f[N];

int ok(int t)
{
    int a=0,b=0;
    int cur1=0,cur2=0;
    for(int i=1;i<=K;i++)
    {
        if(f[i]==1) cur1++;
        else cur2++;

        if(max(cur1,cur2)<t) continue;
        if(cur1==t) a++;
        else b++;
        cur1=0;
        cur2=0;
    }
    if(cur1!=0||cur2!=0) return 0;
    if(a==b) return 0;
    ans=max(a,b);
    return 1;
}

int main()
{
    K=myInt();
    for(int i=1;i<=K;i++)
    {
        int x=myInt();
        f[i]=x;
        if(x==1) n++;
        else m++;
    }
    vector<pair<int,int> > p;
    if(n<m) n=m;
    for(int i=1;i<=n;i++)
    if(n%i==0&&ok(i))
    {
        p.pb(MP(ans,i));
    }
    sort(p.begin(),p.end());
    printf("%d\n",(int)SZ(p));
    for(int i=0;i<SZ(p);i++)
    {
        printf("%d %d\n",p[i].first,p[i].second);
    }
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <map>

#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)
#define EPS 1e-11

#define pii pair<int,int>
#define FFF freopen("test","r",stdin)
#define all(a) a.begin(),a.end()

using namespace std;

void output(i64 x)
{
    if(x<0) putchar('-'),x=-x;
    if(x==0)
    {
        putchar('0');
        return;
    }
    int a[20],num=0;
    while(x) a[++num]=x%10,x/=10;
    while(num>0) putchar('0'+a[num--]);
}

inline i64 myInt()
{
    char c=getchar();
    while(!isdigit(c)&&c!='-') c=getchar();
    int flag=1;
    if(c=='-') flag=-1,c=getchar();
    i64 x=0;
    while(isdigit(c))
    {
        x=(x*10)+(c-'0');
        c=getchar();
    }
    if(flag==-1) return -x;
    return x;
}

const int INF=1e9;
const int N=400005;

int K;

int ans;

int f[N];

int ok(int t)
{
    int curMax=0;
    int a=0,b=0;
    int cur1=0,cur2=0;

    for(int i=1;i<=K;i++)
    {
        if(f[i]==1) cur1++;
        else cur2++;

        if(max(cur1,cur2)<t) continue;

        if(cur1==t) a++;
        else b++;

        cur1=0;
        cur2=0;
        if(i!=K) curMax=max(curMax,max(a,b));
    }
    if(cur1!=0||cur2!=0) return 0;
    if(a==b) return 0;
    ans=max(a,b);
    if(curMax==ans) return 0;

    return 1;
}

int n,m;

int main()
{
    K=myInt();
    for(int i=1;i<=K;i++)
    {
        int x=myInt();
        f[i]=x;
        if(x==1) n++;
        else m++;
    }
    set<pair<int,int> > p;

    for(int i=1;i<=n;i++) if(n%i==0&&ok(i))
    {
        p.insert(MP(ans,i));
    }
    for(int i=1;i<=m;i++) if(m%i==0&&ok(i))
    {
        p.insert(MP(ans,i));
    }
    for(int i=1;i<=K;i++) if(K%i==0&&ok(i))
    {
        p.insert(MP(ans,i));
    }

    printf("%d\n",(int)SZ(p));
    set<pair<int,int> >::iterator it;
    for(it=p.begin();it!=p.end();it++)
    {
        printf("%d %d\n",(*it).first,(*it).second);
    }
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <map>

#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)
#define EPS 1e-11

#define pii pair<int,int>
#define FFF freopen("test","r",stdin)
#define all(a) a.begin(),a.end()

using namespace std;

void output(i64 x)
{
    if(x<0) putchar('-'),x=-x;
    if(x==0)
    {
        putchar('0');
        return;
    }
    int a[20],num=0;
    while(x) a[++num]=x%10,x/=10;
    while(num>0) putchar('0'+a[num--]);
}

inline i64 myInt()
{
    char c=getchar();
    while(!isdigit(c)&&c!='-') c=getchar();
    int flag=1;
    if(c=='-') flag=-1,c=getchar();
    i64 x=0;
    while(isdigit(c))
    {
        x=(x*10)+(c-'0');
        c=getchar();
    }
    if(flag==-1) return -x;
    return x;
}

const int INF=1e9;
const int N=400005;

int n,m;
int K;

int ans;

int f[N];

int ok(int t)
{
    int a=0,b=0;
    int cur1=0,cur2=0;
    for(int i=1;i<=K;i++)
    {
        if(f[i]==1) cur1++;
        else cur2++;

        if(max(cur1,cur2)<t) continue;
        if(cur1==t) a++;
        else b++;
        cur1=0;
        cur2=0;
    }
    if(cur1!=0||cur2!=0) return 0;
    if(a==b) return 0;
    ans=max(a,b);
    return 1;
}

int main()
{
    K=myInt();
    for(int i=1;i<=K;i++)
    {
        int x=myInt();
        f[i]=x;
        if(x==1) n++;
        else m++;
    }
    set<pair<int,int> > p;
    if(n<m) n=m;
    for(int i=1;i<=n;i++)
    if(n%i==0&&ok(i))
    {
        p.insert(MP(ans,i));
    }
    for(int i=1;i<=m;i++)
    if(m%i==0&&ok(i))
    {
        p.insert(MP(ans,i));
    }

    printf("%d\n",(int)SZ(p));
    set<pair<int,int> >::iterator it;
    for(it=p.begin();it!=p.end();it++)
    {

        printf("%d %d\n",(*it).first,(*it).second);
    }
}


#include <iostream>
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <string>
#include <map>

#define abs(x) ((x)>=0?(x):-(x))
#define i64 long long
#define u32 unsigned int
#define u64 unsigned long long
#define clr(x,y) memset(x,y,sizeof(x))
#define CLR(x) x.clear()
#define ph(x) push(x)
#define pb(x) push_back(x)
#define SZ(x) x.size()
#define PI acos(-1.0)
#define sqr(x) ((x)*(x))
#define MP(x,y) make_pair(x,y)
#define EPS 1e-11

#define pii pair<int,int>
#define FFF freopen("test","r",stdin)
#define all(a) a.begin(),a.end()

using namespace std;

void output(i64 x)
{
    if(x<0) putchar('-'),x=-x;
    if(x==0)
    {
        putchar('0');
        return;
    }
    int a[20],num=0;
    while(x) a[++num]=x%10,x/=10;
    while(num>0) putchar('0'+a[num--]);
}

inline i64 myInt()
{
    char c=getchar();
    while(!isdigit(c)&&c!='-') c=getchar();
    int flag=1;
    if(c=='-') flag=-1,c=getchar();
    i64 x=0;
    while(isdigit(c))
    {
        x=(x*10)+(c-'0');
        c=getchar();
    }
    if(flag==-1) return -x;
    return x;
}

const int INF=1e9;
const int N=400005;

int K;

int ans;

int f[N];

int ok(int t)
{
    int curMax=0;
    int a=0,b=0;
    int cur1=0,cur2=0;
    for(int i=1;i<=K;i++)
    {
        if(f[i]==1) cur1++;
        else cur2++;

        if(max(cur1,cur2)<t) continue;
        if(cur1==t) a++;
        else b++;
        cur1=0;
        cur2=0;
        if(i!=K) curMax=max(a,b);
    }
    if(cur1!=0||cur2!=0) return 0;
    if(a==b) return 0;
    ans=max(a,b);
    if(curMax==ans) return 0;
    return 1;
}

int n,m;

int main()
{
    K=myInt();
    for(int i=1;i<=K;i++)
    {
        int x=myInt();
        f[i]=x;
        if(x==1) n++;
        else m++;
    }
    set<pair<int,int> > p;

    for(int i=1;i<=n;i++) if(n%i==0&&ok(i))
    {
        p.insert(MP(ans,i));
    }
    for(int i=1;i<=m;i++) if(m%i==0&&ok(i))
    {
        p.insert(MP(ans,i));
    }

    printf("%d\n",(int)SZ(p));
    set<pair<int,int> >::iterator it;
    for(it=p.begin();it!=p.end();it++)
    {
        printf("%d %d\n",(*it).first,(*it).second);
    }
}


#define filer() freopen("far","r",stdin)
#define filew() freopen("out.txt","w",stdout)

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include <map>
#include<ctime>
#define SET(a, x) memset((a), (x), sizeof(a))
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define i64 ll
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define MAX
using namespace std;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
const int inf=0x20202020;
const ll mod=1000000007;
const double eps=1e-9;
const double pi=3.1415926535897932384626;

const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

template<class X>void debug(vector<X>&v){for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}

int C[100009];
vector<PII> V;
int bs(int lo,int hi,int lst, int strt)
{
    int mid,ans=-1,won,lost;
    while(lo<=hi)
    {
        mid=(lo+hi)/2;
        won=C[mid]-C[strt];
        lost=(mid-strt)-won;
        int m=max(won,lost);
        if(m==lst)
        {
            ans=mid;
            hi=mid-1;
        }
        else if(m<lst)
        {
            lo=mid+1;
        }
        else
        {
            hi=mid-1;
        }
    }
    return ans;
}

int main()
{

    int i,j,k ,T,cas=0;
    //scanf("%d",&T);
    int n,a;
    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>a;
        C[i]=C[i-1] + (a%2);
    }
    int won,lost,lst=0,ans=0;
    for(i=1;i<=n;i++)
    {
        won=C[i];
        lost=i-C[i];
        if(lst<max(won,lost))
        {
            lst=max(won,lost);
            int strt=0;
            int s=0,w=0;
            bool t=1;
            while(1)
            {
                if(strt==-1)
                {
                    t=0;
                    break;
                }
                if(strt==n)
                {
                    if(w!=(s-w)){
                        ans++;
                        V.pb(mp(max(w,s-w),lst));
                    }
                    break;
                }
                int ed=bs(strt+lst,strt+2*lst,lst,strt);
                s++;
                if((ed-strt)-(C[ed]-C[strt])<(C[ed]-C[strt]))w++;
                strt=ed;
            }
        }
    }
    sort(all(V));
    cout<<ans<<endl;
    for(i=0;i<ans;i++)
    {
        cout<<V[i].first<<" "<<V[i].second<<endl;
    }
    return 0;
}
/*Test Cases

*/


#define filer() freopen("far","r",stdin)
#define filew() freopen("out.txt","w",stdout)

#include<iostream>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include <map>
#include<ctime>
#define SET(a, x) memset((a), (x), sizeof(a))
#define ll long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define i64 ll
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))
#define MAX
using namespace std;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<double> VD;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
const int inf=0x20202020;
const ll mod=1000000007;
const double eps=1e-9;
const double pi=3.1415926535897932384626;

const int DX[]={1,0,-1,0},DY[]={0,1,0,-1};
ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

template<class X>void debug(vector<X>&v){for(int i=0;i<v.size();i++)cout<<v[i]<<" ";cout<<endl;}

int C[100009];
vector<PII> V;
int bs(int lo,int hi,int lst, int strt)
{
    int mid,ans=-1,won,lost;
    while(lo<=hi)
    {
        mid=(lo+hi)/2;
        won=C[mid]-C[strt];
        lost=(mid-strt)-won;
        int m=max(won,lost);
        if(m==lst)
        {
            ans=mid;
            hi=mid-1;
        }
        else if(m<lst)
        {
            lo=mid+1;
        }
        else
        {
            hi=mid-1;
        }
    }
    return ans;
}

int main()
{

    int i,j,k ,T,cas=0;
    //scanf("%d",&T);
    int n,a;
    cin>>n;

    for(i=1;i<=n;i++)
    {
        cin>>a;
        C[i]=C[i-1] + (a%2);
    }
    int won,lost,lst=0,ans=0;
    for(i=1;i<=n;i++)
    {
        won=C[i];
        lost=i-C[i];
        if(lst<max(won,lost) && won != lost)
        {
            lst=max(won,lost);
            int strt=0;
            int s=0,w=0;
            bool t=1;
            while(1)
            {
                if(strt==-1)
                {
                    t=0;
                    break;
                }
                if(strt==n)
                {
                    if((w<(s-w) && C[n]-C[n-1]==0)||(w>(s-w) && C[n]-C[n-1]==1)){
                        ans++;
                        V.pb(mp(max(w,s-w),lst));
                    }
                    break;
                }
                int ed=bs(min(strt+lst,N),min(strt+2*lst,N),lst,strt);
                s++;
                if((ed-strt)-(C[ed]-C[strt])<(C[ed]-C[strt]))w++;
                strt=ed;
            }
        }
    }
    sort(all(V));
    cout<<ans<<endl;
    for(i=0;i<ans;i++)
    {
        cout<<V[i].first<<" "<<V[i].second<<endl;
    }
    return 0;
}
/*Test Cases

*/


/* ...I want to live forever... */

#pragma comment(linker, "/stack:4294967296")

#include <algorithm>
#include <cmath>
#include <ctime>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <vector>

#define all(v) v.begin(), v.end()
#define ft first
#define len(s) s.length()
#define mp(a, b) make_pair((a), (b))
#define pop() pop_back()
#define push(s) push_back(s)
#define sc second

#define maxV(type) numeric_limits<type>::max()
#define minV(type) numeric_limits<type>::min()

#define ford(i, r, l) for(register int (i)=(r); (i)>=(l); (i)--)
#define foru(i, l, r) for(register int (i)=(l); (i)<=(r); (i)++)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

typedef pair <ll, ll> pll;
typedef pair <int, int> pi;
typedef pair <double, double> pd;

typedef vector <pi> vec_pi;
typedef vector <int> vec_i;
typedef vector <bool> vec_b;
typedef vector <char> vec_c;
typedef vector <double> vec_d;
typedef vector <long long> vec_ll;

struct pnt {
    pnt() {}
    ~pnt() {}
    pnt(double&& _x, double&& _y) { x = _x; y = _y; }
    double x, y; };
const double eps = 0.000001;
const long double PI = 3.1415926535897932384626433832795L;
inline bool eq(double&& x, double&& y)   { return fabs((x) - (y)) < eps; }
inline bool less(double&& x, double&& y) { return (x) < (y) - eps; }
inline bool more(double&& x, double&& y) { return (x) > (y) + eps; }

int main()
{
   //freopen("qsort.in", "r", stdin);
   //freopen("qsort.out", "w", stdout);
   cin.tie(0);
   cin.sync_with_stdio(0);
   cout.sync_with_stdio(0);
   int cnt = 0, tr = 0;
   string cmd;
   while(getline(cin, cmd)) {
       if(cmd[0] == '+') cnt++;
       if(cmd[0] == '-') cnt--;
       if(cmd[0] != '+' && cmd[0] != '-') {
           int pos = cmd.find(":");
           tr += cnt * (cmd.length() - pos - 1);
       }
   }
   cout << tr << endl;
   return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define INF_MAX 	2147483647
#define INF_MIN 	-2147483648
#define INF 		(1 << 30)
#define SORT(a,n)   sort(a,a+n)
#define EPS			1e-9
#define PI 			acos(-1.0)
#define N 		    2 + 100
#define MOD			10000000007
#define sz(x) 		(int)(x).size()
#define all(x) 		(x).begin(), (x).end()
#define pb 			push_back
#define mp			make_pair
#define ms(x, a) 	memset((x), (a), sizeof(x))
#define ff           first
#define ss           second
#define rep(i,a,b)  for(int i=(a); i<(b); i++)
#define repC(i,x) 	for(size_t i=0; i<x.size(); i++)
#define repIT(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define nn          '\n'
#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)
#define i64 __int64
#define isValid(x, y) ( x >= 0 And x < row And y >= 0 And y < col )
#define dump cin.ignore()

typedef long long 		LL;
typedef pair<int,int> 	pii;
typedef vector<int> 	vi;
typedef vector<string> 	vs;
typedef vector<char>	vc;
typedef vector<bool>    vb;
typedef vector< pii >   vii;
typedef map<string,int> msi;
typedef map<int,int>	mii;
typedef map<char,int>   mci;
typedef map<int,string>	mis;

template<class T> T Abs(T x) {return x>0 ? x : -x;}
template<class T> T Max(T a, T b) {return a>b ? a : b;}
template<class T> T Min(T a, T b) {return a<b ? a : b;}
template<class T> T gcd(T a, T b) {return (b ? gcd(b,a%b) : a);}
template< class T > T sq(T x){ return x * x;}
template< class T > T lcm(T a, T b){ return (a / gcd<T>(a, b) * b); }
template< class T > T deb(T cmd) {cout << "debugger:" << endl; cout << cmd << endl;}
template< class T > T deb(T cmd1, T cmd2) {cout << "debugger:" << endl; cout << cmd1 << "\t" << cmd2 << endl;}
template< class T > T deb(T cmd1, T cmd2, T cmd3) {cout << "debugger:" << endl; cout << cmd1 << "\t" << cmd2 << "\t" << cmd3 << endl;}
template< class T > T deb(T cmd1, T cmd2, T cmd3, T cmd4) {cout << "debugger:" << endl; cout << cmd1 << "\t" << cmd2 << "\t" << cmd3 <<"\t" << cmd4 << endl;}
bool isVowel(char ch){ch=tolower(ch);return(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u');}

//int dx[4] = {-1, 0, 0, 1};
//int dy[4] = {0, -1, 1, 0};
//int dx[8] = {-1, -1, -1, 0, 0, 1, 1, 1};
//int dy[8] = {-1, 0, 1, -1, 1, -1, 0, 1};

#define MAX 10000

int main()
{
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
	#endif

	string line;
	int online = 0, byte = 0, len = 0;

	while(getline(cin, line))
    {
        if(line[0] == '+')
            online++;
        else if(line[0] == '-')
            online--;

        else
        {
            repC(i, line)
            {
                if(line[i] == ':')
                    break;
                len++;
            }

            len++;
            byte += online * (sz(line) - len);
            len = 0;
        }
    }

    cout << byte << nn;

    return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<bitset>
#include<iomanip>
#include<iostream>
#include<cmath>
using namespace std;
#define rep(i,x,y) for(i=x;i<=y;i++)
#define _rep(i,x,y) for(i=x;i>=y;i--)
#define REP(i,x,y) for(int i=(x);i<=(y);i++)
#define _REP(i,x,y) for(int i=(x);i>=(y);i--)
#define CL(S,x) memset(S,x,sizeof(S))
#define CP(S1,S2) memcpy(S1,S2,sizeof(S2))
#define ALL(x,S) for(x=S.begin();x!=S.end();x++)
#define pb push_back
#define IN insert
#define ER erase
#define BE begin()
#define ED end()
#define LB lower_bound
#define UB upper_bound
#define mp make_pair
#define fi first
#define se second
#define upmin(x,y) x=min(x,y)
#define upmax(x,y) x=max(x,y)
#define COUT(S,x) cout<<fixed<<setprecision(x)<<S<<endl
template<class T> inline void read(T&x){bool fu=0;char c;for(c=getchar();c<=32;c=getchar());if(c=='-')fu=1,c=getchar();for(x=0;c>32;c=getchar())x=x*10+c-'0';if(fu)x=-x;};
template<class T> inline void read(T&x,T&y){read(x);read(y);}
template<class T> inline void read(T&x,T&y,T&z){read(x);read(y);read(z);}
inline char getc(){char c;for(c=getchar();c<=32;c=getchar());return c;}

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;

int ans,tot;
char ss[1111];
int main()
{
   // freopen("1.in","r",stdin);freopen("1.out","w",stdout);
	while(gets(ss+1)>0)
	{
		if(ss[1]=='+')tot++;
		else if(ss[1]=='-')tot--;
		else
		{
			int l=strlen(ss+1);
			int i;
			rep(i,1,l)if(ss[i]==':')break;
			ans+=tot*(l-i);
		}
	}
	printf("%d\n",ans);
    return 0;
}


#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <fstream>

#define fs first
#define sc second
#define sz size()
#define pb push_back
#define mp make_pair
#define For(i,n) for(i=0;i<n;i++)

using namespace std;
ifstream fin("a.in");

/*
 *
 */

string s;
int l,Ut;

int main()
{
    int i;
    while(getline(cin,s)){
        if(s[0]=='+')Ut++;
        else if(s[0]=='-')Ut--;
        else {
            For(i,s.sz){
                if(s[i]==':'){
                    l+=(s.sz-i-1)*Ut;
                    break;
                }
            }
        }

    }
    cout<<l;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int k, r;
string s;
main()
{
    while (getline(cin, s))
        if (s[0] > 45)
            r += k * (s.size() - s.find(':') - 1);
        else
            k -= s[0] - 44;
    cout << r;
}


#include <iostream>
#include <string>
using namespace std;

int main(void)
{
    string str;
    int k = 0, res = 0;
    while (getline(cin, str))
    {
        if (str[0] == '+')
            ++k;
        else if (str[0] == '-')
            --k;
        else
            res += k * (str.size() - str.find(':') - 1);
    }
    cout << res;
    return 0;
}


#include <iostream>
#include <string>
using namespace std;
int k, r;
string str;
main()
{
    while (getline(cin, str))
        if (str[0] > 45)
            r += k * (str.size() - str.find(':') - 1);
        else
            k -= str[0] - 44;
    cout << r;
}


#include <iostream>
#include <string>
#include <cstdio>
#include <unordered_set>
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    string s;
    unordered_set<string> all;
    long long ans=0;
    while(getline(cin,s)){
        if(s[0]=='+')
            all.insert(s.substr(1));
        else if(s[0]=='-')
            all.erase(s.substr(1));
        else{
            int i=0;
            while(s[i]!=':')
                i++;
            ans+=(s.size()-i-1)*all.size();
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    int n=0,ans;
    while(getline(cin,s))
    {
        if(s[0]=='+') n++;
            else if(s[0]=='-') n--;
            else
            {
                ans=n*(s.length()-s.find(':')-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<string>
using namespace std;
int main()
{
    string s;
    int n=0,ans;
    while(getline(cin,s))
    {
        if(s[0]=='+') n++;
            else if(s[0]=='-') n--;
            else
            {
                ans+=n*(s.length()-s.find(':')-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include<iostream>
#include<string>
#include<cstdio>
using namespace std;
int main()
{
    string s;
    int n=0,ans=0;
    while(getline(cin,s))
    {
        if(s[0]=='+') n++;
            else if(s[0]=='-') n--;
            else
            {
            //  printf("n=%d\n",n);
                ans+=n*(s.length()-s.find(':')-1);
        }
    }
    cout<<ans<<endl;
    return 0;
}


#include <bits/stdc++.h>
#define sc scanf
#define pf printf
typedef long long ll;

using namespace std;

int main()
{

    map<string,int>mp;
    map<string,int>::iterator it;
    string str;
    ll sum=0;
    while(getline(cin,str))
    {
       // if(mp.size()>100) break;
        if(str[0]=='+')
        {
            string ss=str.substr(1,str.size());
            if(mp[ss]==0) mp[ss]++;

        }
        else  if(str[0]=='-')
        {
            string ss=str.substr(1,str.size());
            if(mp[ss]>0) mp[ss]--;

        }
        else
        {
            int index;
            for(int i=0; i<str.size(); i++) if(str[i]==':') index=i;
            string g=str.substr(index+1,str.size());
            int len=g.size();
            for(it=mp.begin(); it!=mp.end(); it++)
            {
                if(it->second==1) sum+=len;

            }

        }

    }
    cout<<sum<<endl;

    return 0;
}


#include <bits/stdc++.h>
#define sc scanf
#define pf printf
typedef long long ll;

using namespace std;

int main()
{

    map<string,int>mp;
    map<string,int>::iterator it;
    string str;
    ll sum=0;
    while(getline(cin,str))
    {
        if(mp.size()>100) break;
        if(str[0]=='+')
        {
            string ss=str.substr(1,str.size());
            if(mp[ss]==0) mp[ss]++;

        }
        else  if(str[0]=='-')
        {
            string ss=str.substr(1,str.size());
            if(mp[ss]>0) mp[ss]--;

        }
        else
        {
            int index;
            for(int i=0; i<str.size(); i++) if(str[i]==':') index=i;
            string g=str.substr(index+1,str.size());
            int len=g.size();
            for(it=mp.begin(); it!=mp.end(); it++)
            {
                if(it->second==1) sum+=len;

            }

        }

    }
    cout<<sum<<endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define sz(x) (int)(x).size()
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define for_each(it, c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); ++it)
typedef long long ll;
typedef long double ld;
int main() {

    string x;
    int counter = 0;
    int ans = 0;
    while (getline(cin , x)) {
        if (x[0] == '+') {
            counter++;
        } else if (x[0] == '-') {
            counter--;
        } else {
            x = x.substr(x.find(':')+1);
            ans += (sz(x) * counter);

        }
    }
    cout << ans << endl;

}


#include<iostream>
#include<string>

int main() {
    int counter = 0;
    int sum = 0;
    std::string s;
    while (getline(std::cin, s)) {
        if (s[0] == '+') {
            counter++;
        }
        else {
            if (s[0] == '-') {
                counter--;
            }
            else {
                int i = 0;
                for (i; i < s.size(); ++i) {
                    if (s[i] == ':') { break; }
                }
                int cur_sum = s.size() - (i + 1);
                sum += cur_sum * counter;
            }
        }
    }
    std::cout << sum << std::endl;
    return 0;
}


#include <iostream>
#include <string>

using namespace std;

int main()
{
    int party = 0;
    int answer = 0;

    string s;

    for (; getline(cin, s); ) {
        party += s[0] == '+' ? 1 : (s[0] == '-' ? -1 : 0);

        for (size_t i = 0; i < s.size(); i++)
            if (s[i] == ':') {
                answer += party * (s.size() - 1 - i);
                break;
            }

    }

    cout << answer << endl;

    return 0;
}


#include <iostream>
#include <string>
#include <unordered_set>

using namespace std;

unordered_set<string> p;
string s;

int main() {
    int ans = 0;
    while(getline(cin, s)) {
        if (s[0] == '+')
            p.insert(s.substr(1, s.size()-1));
        else if (s[0] == '-')
            p.erase(s.substr(1, s.size()-1));
        else
            ans += p.size() * (s.size()-s.find(':')-1);
    }
    cout << ans << endl;
}


#include <cstdio>
#include <cstring>
#include <utility>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main(){
    int ans=0;
    char s[200];
    set<string> user;
    while(gets(s)){
        if(*s=='+') user.insert(s+1);
        if(*s=='-') user.erase(s+1);
        if(*s!='+' && *s!='-'){
            strtok(s,":");
            ans+=strlen(strtok(0,":"))*user.size();
        }
    }
    printf("%d\n",ans);
}


#include <cstdio>
#include <cstring>
#include <utility>
#include <vector>
#include <string>
#include <set>
#include <algorithm>
using namespace std;

int main(){
    int ans=0;
    char s[200];
    set<string> user;
    while(gets(s)){
        if(*s=='+') user.insert(s+1);
        if(*s=='-') user.erase(s+1);
        if(*s!='+' && *s!='-'){
            strtok(s,":");
            char* t=strtok(0,":");
            if(t) ans+=strlen(t)*user.size();
        }
    }
    printf("%d\n",ans);
}


/*****************************************************************************
 * codeforces:   knst
 * topcoder:     knstqq
 * projecteuler: knstqq
 * **************************************************************************/

#include <algorithm>
#include <iostream>
#include <limits>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <vector>

using namespace std;
//test speed
/*
namespace std {
    template <class T1, class T2>
    class hash<pair<T1, T2>> {
    public:
        size_t operator()(const pair<T1, T2>& p) const {
            return hash<T1>()(p.first) & hash<T2>()(p.second);
        }
    };
}; */
namespace std {
    template <>
    class hash<pair<long long,long long>> {
    public:
        size_t operator()(const pair<long long, long long>& p) const {
            return hash<long long>()(p.first) ^ (hash<long long>()(p.second) << 32);
        }
    };
};

constexpr long double const_pi() { return std::atan(static_cast<long double>(1))*4; }

int main() {
    std::ios_base::sync_with_stdio(false);

    string s;
    int count = 0;
    int result = 0;
    while (getline(cin, s)) {
        cerr << "test: " << s << endl;
        if (s[0] == '+')
            ++count;
        else if (s[0] == '-')
            --count;
        else if (s.size() > 1) {
            int index = 0;
            while (s[index] != ':')
                ++index;
            cerr << "result: " << result << endl;
            result += (s.size() - index - 1) * count;
        }

    }
    cout << result << endl;

    return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
	string a;
	int ans=0,n=0;
	while (true) {
		getline(cin,a);
		if (a=="") break;
		n+=a[0]=='+';
		n-=a[0]=='-';
		if (a[0]!='+' && a[0]!='-')
			ans+=n*(a.size() - a.find(':') - 1);
	}
	cout<<ans<<endl;
}


#include <iostream>
#include <cstdio>
#include <math.h>
#include <vector>
#include <map>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <sstream>
using namespace std;
long long INF=1000*1000*1000;
long long p=31;

int main()
{
    string s;
    int res=0;
    int c=0;
    while(getline(cin,s))
    {
        if(s[0]=='+')
            c++;
        else if(s[0]=='-')
            c--;
        else
        {
            int i;
            for(i=0;s[i]!=':';++i);
            //cout<<s<<"--"<<i<<" "<<s.length()<<endl;
            res+=(s.length()-i-1)*c;
        }
    }
    cout<<res;
    return 0;
}


#include <iostream>
using namespace std;

int main() {
    string current;
    unsigned int number = 0, traffic = 0;
    while (getline(cin, current)) {
        if (current[0] == '+') {
            number++;
        }
        else
            if (current[0] == '-') {
                number--;
            }
            else {
                traffic += number;
            }
    }
    cout << traffic;
    return 0;
}


#include <iostream>
using namespace std;

int main() {
    string current;
    unsigned int number = 0, traffic = 0;
    while (getline(cin, current)) {
        if (current[0] == '+') {
            number++;
        }
        else
            if (current[0] == '-') {
                number--;
            }
            else {
                traffic += number * (current.size() - current.find_first_of(':') - 1);
            }
    }
    cout << traffic;
    return 0;
}


#include <cstdio>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

char s[200];
set<string> clients;

int main() {
	clients.clear();
	int traffic = 0;
	while (gets(s)) {
		if (*s == '+') {
			clients.insert(string{s + 1});
		}
		else if (*s == '-') {
			clients.erase(string{s + 1});
		}
		else {
			int i = strchr(s, ':') - s;
			traffic += clients.size() * (strlen(s) - i - 1);
		}
	}
	printf("%d\n", traffic);
}


#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <set>

using namespace std;

char s[200];
set<string> clients;

int main() {
	clients.clear();
	int traffic = 0;
	while (gets(s)) {
		if (*s == '+') {
			clients.insert(string{s + 1});
		}
		else if (*s == '-') {
			clients.erase(string{s + 1});
		}
		else {
			int i = strchr(s, ':') - s;
			traffic += clients.size() * (strlen(s) - i - 1);
		}
	}
	printf("%d\n", traffic);
}


#include <iostream>

int main(){

    std::string line;
    int users(0), total(0);
    while(getline(std::cin, line)){
        if(line[0] == '+'){++users;}
        else if(line[0] == '-'){--users;}
        else{total += users * (line.size() - line.find(':') - 1);}
    }

    printf("%d\n", total);
    return 0;
}


#include <iostream>

int main(){

    std::string line;
    int users(0), total(0);
    while(getline(std::cin, line)){
        if(line[0] == '+'){++users;}
        else if(line[0] == '-'){--users;}
        else{total += users * (line.size() - line.find(':') - 1);}
    }

    std::cout <<  total << std::endl;
    return 0;
}


# include <iostream>
# include <cstdio>
# include <cstdlib>
# include <vector>
# include <string>
# include <cmath>
# include <algorithm>
# include <iomanip>
# include <deque>
# include <queue>
# include <stack>
# include <numeric>
# include <ios>
# include <set>
# include <map>
# include <sstream>
# include <iterator>
# include <limits>
# include <cstring>
# include <string.h>
# include <list>
# include <bitset>
# include <climits>
# include <cassert>

# define INF numeric_limits<long double>::infinity()
# define Fi 1.6180339887
# define eps 1e-6
# define quadro __float128
# define abc() printf("\nUnexpected in \"%s\" at line %d\n", __func__, __LINE__)

# define startt clock_t start,end; start = clock()
# define endt end = clock(); printf("\nFunction \"%s\" executed in %.2f seconds\n", __func__, (float)(end-start)/CLOCKS_PER_SEC)
# define checktime() startt; init(); endt

using namespace std;

template <typename T> class Point { public: T x,y,pos;  Point<T>(const T& a, const T& b){x = a; y = b;} Point<T>(){ Point<T>(0,0);} };

template <typename T> void read(T& val) { cin >> val; }
template <typename T> void read(vector<T>& vec) { for(int i=0; i<vec.size(); ++i) read(vec[i]); }
template <typename T> void print(const T& val) { cout << val << " " ; }
template <typename T> void print(const vector<T>& vec) { for(int i=0; i<vec.size(); ++i) { print(vec[i]); } cout << endl; }
template <typename T> string toString(const T& val) { ostringstream ostr; ostr << val; return ostr.str(); }
long double fromString(const string& str) { long double res; istringstream(str) >> res; return res; }

inline bool isDigit(const char& ch) { return (ch >= '0' && ch <='9'); }
inline bool isAlpha(const char& ch) { return (ch >= 'a' && ch <='z' || ch >='A' && ch <= 'Z'); }
inline string trimString(string& str){ while(*str.begin()==' ') { str.erase(str.begin()); } while(*str.rbegin()==' ') {str.erase(str.end()-1); } return str;}
void skip() { while (cin.peek() == ' ' || cin.peek() == '\n' || cin.peek() == '\r' || cin.peek() == '\t') cin.get(); }

int messageSize(string& str)
{
    return ( str.size() - str.find(":") -1);
}

void init()
{
    map<string, bool> chat;
    long long num = 0, traffic = 0;
    string name;

    while( getline(cin, name) )
    {
        trimString(name);

        if ( isAlpha(name[0]) || isDigit(name[0])) traffic += num*messageSize(name);
        else if (name[0] == '+')
        {
            chat[name] = true;
            ++num;
        }
        else if (name[0] == '-')
        {
            chat[name] = false;
            --num;
        }
        else throw("error");
    }

    cout << traffic;
}

void test()
{

}

int main()
{
    //freopen ("/home/idainet/code/in.txt", "r", stdin);
//    freopen ("/home/idainet/code/out.txt", "w", stdout);

    //checktime();
    init();

    //test();

    fflush(stdout);
    return 0;
}


# include <iostream>
# include <cstdio>
# include <cstdlib>
# include <vector>
# include <string>
# include <cmath>
# include <algorithm>
# include <iomanip>
# include <deque>
# include <queue>
# include <stack>
# include <numeric>
# include <ios>
# include <set>
# include <map>
# include <sstream>
# include <iterator>
# include <limits>
# include <cstring>
# include <string.h>
# include <list>
# include <bitset>
# include <climits>
# include <cassert>

# define INF numeric_limits<long double>::infinity()
# define Fi 1.6180339887
# define eps 1e-6
# define quadro __float128
# define abc() printf("\nUnexpected in \"%s\" at line %d\n", __func__, __LINE__)

# define startt clock_t start,end; start = clock()
# define endt end = clock(); printf("\nFunction \"%s\" executed in %.2f seconds\n", __func__, (float)(end-start)/CLOCKS_PER_SEC)
# define checktime() startt; init(); endt

using namespace std;

template <typename T> class Point { public: T x,y,pos;  Point<T>(const T& a, const T& b){x = a; y = b;} Point<T>(){ Point<T>(0,0);} };

template <typename T> void read(T& val) { cin >> val; }
template <typename T> void read(vector<T>& vec) { for(int i=0; i<vec.size(); ++i) read(vec[i]); }
template <typename T> void print(const T& val) { cout << val << " " ; }
template <typename T> void print(const vector<T>& vec) { for(int i=0; i<vec.size(); ++i) { print(vec[i]); } cout << endl; }
template <typename T> string toString(const T& val) { ostringstream ostr; ostr << val; return ostr.str(); }
long double fromString(const string& str) { long double res; istringstream(str) >> res; return res; }

inline bool isDigit(const char& ch) { return (ch >= '0' && ch <='9'); }
inline bool isAlpha(const char& ch) { return (ch >= 'a' && ch <='z' || ch >='A' && ch <= 'Z'); }
inline string trimString(string& str){ while(*str.begin()==' ') { str.erase(str.begin()); } while(*str.rbegin()==' ') {str.erase(str.end()-1); } return str;}
void skip() { while (cin.peek() == ' ' || cin.peek() == '\n' || cin.peek() == '\r' || cin.peek() == '\t') cin.get(); }

int messageSize(string& str)
{
    return ( str.size() - str.find(":") -1);
}

void init()
{
    map<string, bool> chat;
    long long num = 0, traffic = 0;
    string name;

    while( getline(cin, name) )
    {
        trimString(name);

        if ( isAlpha(name[0]) ) traffic += num*messageSize(name);
        else if (name[0] == '+')
        {
            chat[name] = true;
            ++num;
        }
        else if (name[0] == '-')
        {
            chat[name] = false;
            --num;
        }
        else throw("error");
    }

    cout << traffic;
}

void test()
{

}

int main()
{
    //freopen ("/home/idainet/code/in.txt", "r", stdin);
//    freopen ("/home/idainet/code/out.txt", "w", stdout);

    //checktime();
    init();

    //test();

    fflush(stdout);
    return 0;
}


#include <functional>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <memory.h>
#include <limits.h>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <vector>
#include <cctype>
#include <math.h>
#include <time.h>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define Rep(i, a, b) for (int (i) = (a); (i) <= (b); ++(i))
#define Repd(i, a, b) for (int (i) = (a); (i) >= (b); --(i))
#define For(i, n) for (int (i) = (0); i < (n); ++(i))
#define Ford(i, n) for (int (i) = (n) - (1); (i) > (-1); --(i))
#define all(p) (p).begin(), (p).end()
#define odd(x) ((x)&(1))
#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sz size
#define fi first
#define se second

#define TASKNAME ""
//#define DEBUG

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vpii;

const int N = 111111;
const int INF = int(1e9), mod = (int)1e9 + 7;

int main() {
    #ifdef DEBUG
        freopen (TASKNAME".in", "r", stdin);
       	freopen (TASKNAME".out", "w", stdout);
    #else
         //freopen ("input.txt", "r", stdin);
         //freopen ("output.txt", "w", stdout);
    #endif

    string q;
    set <string> users;

    int res = 0;
    while(getline(cin, q)) {

        if (isalpha(q[0])) {

            res += users.size() * (q.length() - q.find(':') - 1);

        } else {

            char query = q[0];
            q = q.substr(1, q.length() - 1);

            if (query == '+') users.insert(q);
            else users.erase(users.lower_bound(q));
        }
    }

    cout << res;

    return 0;
}


#include <functional>
#include <algorithm>
#include <iterator>
#include <iostream>
#include <memory.h>
#include <limits.h>
#include <numeric>
#include <iomanip>
#include <stdio.h>
#include <string>
#include <vector>
#include <cctype>
#include <math.h>
#include <time.h>
#include <queue>
#include <stack>
#include <set>
#include <map>

using namespace std;

#define Rep(i, a, b) for (int (i) = (a); (i) <= (b); ++(i))
#define Repd(i, a, b) for (int (i) = (a); (i) >= (b); --(i))
#define For(i, n) for (int (i) = (0); i < (n); ++(i))
#define Ford(i, n) for (int (i) = (n) - (1); (i) > (-1); --(i))
#define all(p) (p).begin(), (p).end()
#define odd(x) ((x)&(1))
#define sqr(x) ((x)*(x))
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sz size
#define fi first
#define se second

#define TASKNAME ""
//#define DEBUG

typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> vi;
typedef vector <pii> vpii;

const int N = 111111;
const int INF = int(1e9), mod = (int)1e9 + 7;

int main() {
    #ifdef DEBUG
        freopen (TASKNAME".in", "r", stdin);
       	freopen (TASKNAME".out", "w", stdout);
    #else
         //freopen ("input.txt", "r", stdin);
         //freopen ("output.txt", "w", stdout);
    #endif

    string q;
    set <string> users;

    int res = 0;
    while(getline(cin, q)) {

        if (isalpha(q[0]) || isdigit(q[0])) {

            res += users.size() * (q.length() - q.find(':') - 1);

        } else {

            char query = q[0];
            q = q.substr(1, q.length() - 1);

            if (query == '+') users.insert(q);
            else users.erase(users.lower_bound(q));
        }
    }

    cout << res;

    return 0;
}


/* <<< Marek Sommer >>> */

/* ====== HEADERS ====== */

#include <bits/stdc++.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>

#ifdef ONLINE_JUDGE
	#define MINIMAL
#endif

#ifdef MINIMAL
	#define err(a) ;
	#define ASSERT(a) ;
#else
	void err(const char *format, ...)
	{
		va_list valist;
		va_start(valist, format);
		int ret = vfprintf(stderr, format, valist);
		va_end(valist);
	}
	#define ASSERT(a) a
#endif

using namespace std;

typedef long long int ll;
typedef long double ld;

char *_buffer = nullptr;
inline void make_buf(int a) { _buffer = new char[a]; }

#define TOSTRING_INNER(x) #x
#define TOSTRING(x) TOSTRING_INNER(x)

#ifndef PRECISION
	#define PRECISION 15
#endif
#define FLOAT_PRECISION "%." TOSTRING(PRECISION) "f"
#define DOUBLE_PRECISION "%." TOSTRING(PRECISION) "f"

inline void make(int &a) { if(scanf("%d", &a)); }
inline void make(float &a) { if(scanf("%f", &a)); }
inline void make(double &a) { if(scanf("%lf", &a)); }
inline void make(char *a) { if(scanf("%s", a)); }
inline void make(string &a) { ASSERT( if(_buffer == nullptr) err("Use make_buf(int buffer_size); at the beginning\n"); ) if(scanf("%s", _buffer)); a = _buffer; }
inline void make(char &a) { if(scanf(" %c", &a)); }
inline void makec(char &a) { if(scanf("%c", &a)); }
template<typename A>
inline void maketab(A *tab, int size) { for(int i = 0; i < size; i++) make(tab[i]); }
template<typename A>
inline void maketab(vector<A> &v, int size) { typedef typename vector<A>::iterator iter; v.resize(size); for(iter i = v.begin(); i != v.end(); i++) make(*i); }

template<typename A, typename B>
inline void make(A &a, B &b) { make(a); make(b); }
template<typename A, typename B, typename C>
inline void make(A &a, B &b, C &c) { make(a); make(b); make(c); }
template<typename A, typename B, typename C, typename D>
inline void make(A &a, B &b, C &c, D &d) { make(a); make(b); make(c); make(d); }
template<typename A, typename B, typename C, typename D, typename E>
inline void make(A &a, B &b, C &c, D &d, E &e) { make(a); make(b); make(c); make(d); make(e); }

// ====== OUTPUT ======

#define MAKE_OUT(arg_type, format, args...) \
inline void out(arg_type) { printf(format, args); }\
inline void outn(arg_type) { printf(format "\n", args); }\
inline void outs(arg_type) { printf(format " ", args); }

inline void outn() { printf("\n"); }
inline void outs() { printf(" "); }

MAKE_OUT(int a, "%d", a);
MAKE_OUT(float a, FLOAT_PRECISION, a);
MAKE_OUT(double a, DOUBLE_PRECISION, a);
MAKE_OUT(long double a, DOUBLE_PRECISION, (double) a);
MAKE_OUT(const char *a, "%s", a);
MAKE_OUT(const string &a, "%s", a.c_str());
MAKE_OUT(char c, "%c", c);
typedef pair<int, int> pair_int_int;
MAKE_OUT(const pair_int_int &p, "%d %d", p.first, p.second);

template<typename T, typename A> inline void out(const vector<T, A> &v)
{
	auto i = v.begin();
	if(i == v.end())
	{
		outn();
		return;
	}
	for(; i + 1 != v.end(); i++)
		outs(*i);
	outn(*i);
}
template<typename T, typename A> inline void outs(const vector<T, A> &v)
{
	auto i = v.begin();
	if(i == v.end())
	{
		outn();
		return;
	}
	for(; i + 1 != v.end(); i++)
		out(*i), out(", ");
	outn(*i);
}
template<typename T, typename A> inline void outn(const vector<T, A> &v)
{
	for(auto i = v.begin(); i != v.end(); i++)
		outn(*i);
}

#ifdef ONLINE_JUDGE
	inline void make(ll &a) { scanf("%I64d", &a); }
	inline void make(long double &a) { double _a; if(scanf("%lf", &_a)); a = _a; }
	MAKE_OUT(ll a, "%I64d", a);
	#define M_PI (3.14159265358979323846l)
#else // NOT ONLINE_JUDGE
	inline void make(ll &a) { scanf("%lld", &a); }
	inline void make(long double &a) { if(scanf("%Lf", &a)); }
	MAKE_OUT(ll a, "%lld", a);
#endif

#define ter(a) { out(a); exit(0); }
#define tern(a) { outn(a); exit(0); }
#define ters(a) { outs(a); exit(0); }

/* ====== CODE ====== */

char nap[105];

int main()
{
	int ile = 0;
	int wyn = 0;
	while(scanf(" %[^\n]", nap) != EOF)
	{
		if(nap[0] == '+')
			ile++;
		else if(nap[0] == '-')
			ile--;
		else
		{
			int i;
			for(i = 0; nap[i] != ':'; i++)
				;
			int l = 0;
			for(i++; nap[i]; i++)
				l++;
			wyn += l * ile;
		}
	}
	outn(wyn);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    int res  = 0;
    string s;
    vector<string>list;
    while(getline(cin, s))
    {
        if(s[0] != '+' && s[0] != '-')
        {
            int i;
            for(i = 0;i < s.size() && s[i] != ':';i++);
            res += list.size() * (s.size() - i - 1);
        }
        else if(s[0] == '+')
            list.push_back(s.substr(1, s.size() - 1));
        else
        {
            string t = s.substr(1, s.size() - 1);
            list.erase(find(list.begin(), list.end(), t));
        }
    }
    cout << res;
    return 0;
}


#include <iostream>
#include <cassert>

void run(std::istream& in, std::ostream& out) {
    int64_t answer = 0;
    int users = 0;
    while (true) {
        std::string line;
        std::getline(in, line);
        if (in.fail()) break;
        assert(line.length() > 0);
        if (line[0] == '+') {
            users++;
        } else if (line[0] == '-') {
            users--;
        } else {
            size_t index = line.find(':');
            assert(index != line.npos);
            answer += users * (line.length() - index - 1);
        }
    }
    out << answer << std::endl;
}

int main() {
    run(std::cin, std::cout);
    return 0;
}


#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;

ifstream Cin("input.txt");
ofstream Cout("output.txt");

set < string > f ;

main()
{
      char s[128];
      long long i, p, ans = 0 ;
      string x ;
      while( Cin.getline( s, 127 ) )
      {
             x.clear() ;
             if( s[0] == '+' )
             {
               for( i = 1 ; i < strlen( s ) ; i++ )
                 x.push_back( s[i] ) ;
               f.insert( x );
             }
             else if( s[0] == '-' )
             {
               for( i = 1 ; i < strlen( s ) ; i++ )
                 x.push_back( s[i] ) ;
               f.erase( x );
             }
             else
             {
                 for( i = 0 ; i < strlen( s ) ; i++ )
                   if( s[i] == ':' )
                     p = i ;
                 ans += ( strlen( s ) - p - 1 ) * (int)f.size() ;
             }
      }
      Cout << ans << endl ;
}


#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <stdio.h>
#include <algorithm>
#include <bitset>
#include <set>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
using namespace std;

//ifstream Cin("input.txt");
//ofstream Cout("output.txt");

set < string > f ;

main()
{
      char s[128];
      long long i, p, ans = 0 ;
      string x ;
      while( cin.getline( s, 127 ) )
      {
             x.clear() ;
             if( s[0] == '+' )
             {
               for( i = 1 ; i < strlen( s ) ; i++ )
                 x.push_back( s[i] ) ;
               f.insert( x );
             }
             else if( s[0] == '-' )
             {
               for( i = 1 ; i < strlen( s ) ; i++ )
                 x.push_back( s[i] ) ;
               f.erase( x );
             }
             else
             {
                 for( i = 0 ; i < strlen( s ) ; i++ )
                   if( s[i] == ':' )
                     p = i ;
                 ans += ( strlen( s ) - p - 1 ) * (int)f.size() ;
             }
      }
      cout << ans << endl ;
}


#include <iostream>

using namespace std;

int main() {
	string s;
	int num = 0, ret = 0;
	while (getline(cin, s)) {
		if (s[0] == '+') {
			++num;
		}
		else if (s[0] == '-') {
			--num;
		}
		else {
			int pos = s.find(':');
			ret += num * (s.length() - pos - 1);
		}
	}
	cout << ret << endl;
	return 0;
}


#include <iostream>
#include <string>
using namespace std;
main(){
    int k, r;
    string s;
    while (getline(cin, s))
        if (s[0] > 45)
            r += k * (s.size() - s.find(':') - 1);
        else
            k -= s[0] - 44;
    cout << r;
}


#include <iostream>
using namespace std;
int main(){
    string l;
    int u=0, t=0;
    while(getline(cin, l)){
        if(l[0] == '+')
            ++u;
        else if(l[0] == '-')
            --u;
        else{
            t += u * (l.size() - l.find(':') - 1);
        }
    }
    cout << t <<endl;
}


// template by is_prime
#undef NDEBUG
#ifdef tty
#define _GLIBCXX_DEBUG
#endif

#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cassert>
#include <cstring>
#include <ctime>
#include <bitset>
#include <numeric>
#include <iterator>
#include <utility>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>

using namespace std;

#define elif else if
#define gcd __gcd
#define lg __lg
#define ln log
#define bitcount __builtin_popcount
#define fabsl __builtin_fabsl
#define sqrtl __builtin_sqrtl
#define atan2l __builtin_atan2l
#define cosl __builtin_cosl
#define sinl __builtin_sinl
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
#define len(a) (a).size()
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define iter(a,b) for (int a=0;a<(int)b;++a)
#define reti(a,b) for (int a=(int)b-1;a>=0;--a)
#define foreach(a,b) for (auto&a:(b))

typedef string str;
typedef pair<int, int> pii;
typedef vector<int> vi;

/* initiate variables */
int n, tot;
str line;
map<string, bool> names;

void algo() {
    /* solves problem */
    n = 0;
    tot = 0;
    while (getline(cin, line)) {
        // printf("%s\n", line.c_str());
        if (line[0] == '+') {
            names[line.substr(1, len(line) - 1)];
            n++;
        } elif (line[0] == '-') {
            names.erase(names.find(line.substr(1, len(line) - 1)));
            n--;
        } else {
            tot += n * (len(line.substr(line.find(':'))) - 1);
        }
    }
    printf("%d\n", tot);
}

int main(int agrc, char **argv) {
#ifdef tty
    assert(freopen(argv[1], "rt", stdin));
#endif

    algo();

#ifdef tty
    printf("%lfs\n", double(clock()) / CLOCKS_PER_SEC);
#endif
    return 0;
}


#include <algorithm>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <climits>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <unordered_map>
#include <unordered_set>

using namespace std;

#define clr(x) memset((x), 0, sizeof(x))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
#define sz size()
#define For(i, st, en) for(int i=(st); i<=(int)(en); i++)
#define Ford(i, st, en) for(int i=(st); i>=(int)(en); i--)
#define forn(i, n) for(int i=0; i<(int)(n); i++)
#define ford(i, n) for(int i=(n)-1; i>=0; i--)
#define fori(it, x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define in(x) int (x); input((x));
typedef long double ld;
template <class _T> inline _T sqr(const _T& x) { return x * x; }
template <class _T> inline string tostr(const _T& a) { ostringstream os(""); os << a; return os.str(); }
const ld PI = 3.1415926535897932384626433832795L;
const ld EPS = 1e-8;
char TEMPORARY_CHAR;
typedef long long ll;
typedef unsigned long long ull;
typedef set < int > SI;
typedef vector < int > VI;
typedef vector < vector < int > > VVI;
typedef map < string, int > MSI;
typedef pair < int, int > PII;
const int INF = 2e9;
#define x first
#define y second
#define less(a,b) ((a) < (b) - EPS)
#define more(a,b) ((a) > (b) + EPS)
#define eq(a,b) (fabs((a) - (b)) < EPS)
#define remax(a, b) ((a) = (b) > (a) ? (b) : (a))
#define remin(a, b) ((a) = (b) < (a) ? (b) : (a))
typedef complex<double> cbase;
inline void fft (vector<cbase> &a, bool invert) {
    int n = (int)a.size();
    for (int i = 1, j = 0; i < n; ++i)
    {
        int bit = n >> 1;
        for (; j >= bit; bit >>= 1)
            j -= bit;
        j += bit;
        if (i < j)
            swap(a[i], a[j]);
    }
    for (int len = 2; len <= n; len <<= 1)
    {
        double ang = 2 * (double)PI / len * (invert ? -1 : 1);
        cbase wlen(cos(ang), sin(ang));
        for (int i = 0; i < n; i += len)
        {
            cbase w(1);
            for (int j=0; j < len / 2; ++j)
            {
                cbase u = a[i + j],  v = a[i + j + len / 2] * w;
                a[i + j] = u + v;
                a[i + j + len / 2] = u - v;
                w *= wlen;
            }
        }
    }
    if (invert)
        for (int i = 0; i < n; ++i)
            a[i] /= n;
}

inline void input(int &a)
{
    a = 0;
    while (((TEMPORARY_CHAR = getchar()) > '9' || TEMPORARY_CHAR < '0') && (TEMPORARY_CHAR != '-')){}
    char neg = 0;
    if (TEMPORARY_CHAR == '-')
    {
        neg = 1;
        TEMPORARY_CHAR = getchar();
    }
    while (TEMPORARY_CHAR <= '9' && TEMPORARY_CHAR >= '0')
    {
        a = (a << 3) + (a << 1) + TEMPORARY_CHAR - '0';
        TEMPORARY_CHAR = getchar();
    }
    if (neg)
        a = -a;
}
inline void out(int a)
{
    if (!a) putchar('0');
    if (a < 0)
    {
        putchar('-');
        a = -a;
    }
    char s[10];
    int i;
    for(i = 0; a; ++i)
    {
        s[i] = '0' + a % 10;
        a /= 10;
    }
    ford(j, i) putchar(s[j]);
}
inline int nxt()
{
    in(ret);
    return ret;
}

struct lnum
{
    vector <int> a;
    int base;
    lnum(int num = 0, int base = 1000000000):base(base)
    {
        if (!num)
            a.resize(1);
        while(num)
        {
            a.pb(num % base);
            num /= base;
        }
    }
    inline int len() const
    {
        return a.size();
    }
    lnum & operator=(const lnum &l)
    {
        if (this != &l)
        {
            a = l.a;
            base = l.base;
        }
        return *this;
    }
    inline friend lnum operator+(const lnum &l, const lnum &r)
    {
        lnum ret(0, l.base);
        int base = l.base;
        int ln = l.len(), rn = r.len();
        int n = max(ln, rn);
        ret.a.resize(n);
        int o = 0;
        for(int i = 0; i < n; ++i)
        {
            int s = o;
            if (i < ln)
                s += l.a[i];
            if (i < rn)
                s += r.a[i];
            o = s >= base;
            if (o)
                s -= base;
            ret.a[i] = s;
        }
        if (o)
            ret.a.push_back(1);
        return ret;
    }
    inline friend lnum operator-(const lnum &l, const lnum &r)
    {
        lnum ret(0, l.base);
        int base = l.base;
        int n = l.len();
        int rn = r.len();
        ret.a.resize(n);
        int o = 0;
        for(int i = 0; i < n; ++i)
        {
            int s = l.a[i] - o;
            if (i < rn)
                s -= r.a[i];
            o = s < 0;
            if (o)
                s += base;
            ret.a[i] = s;
        }
        if (ret.len() > 1 && !ret.a.back())
            ret.a.pop_back();
        return ret;
    }

    inline friend lnum operator*(const lnum &l, const lnum &r)
    {
        lnum ret(0, l.base);
        int base = l.base;
        if (l.len() * r.len() > 1000000)
        {
            vector<cbase> fa (l.a.begin(), l.a.end()),  fb (r.a.begin(), r.a.end());
            int  n = 1;
            while (n < max (l.len(), r.len()))
                n <<= 1;
            n <<= 1;
            fa.resize (n),  fb.resize (n);
            fft (fa, false),  fft (fb, false);
            for (int i = 0; i < n; ++i)
                fa[i] *= fb[i];
            fft (fa, true);
            ret.a.resize(n);
            for (int i = 0; i < n; ++i)
                ret.a[i] = int (fa[i].real() + 0.5);
            int carry = 0;
            for (int i=0; i < n; ++i)
            {
                ret.a[i] += carry;
                carry = ret.a[i] / base;
                ret.a[i] %= base;
            }
        }
        else
        {
            ret.a.resize(l.len() + r.len());
            for (int i = 0; i < l.len(); ++i)
                for (int j = 0, carry = 0; j < r.len() || carry; ++j)
                {
                    long long cur = ret.a[i + j] + (ll)l.a[i] * (j < r.len() ? r.a[j] : 0) + carry;
                    ret.a[i + j] = cur % base;
                    carry = cur / base;
                }
        }
        while (ret.len() > 1 && !ret.a.back())
                ret.a.pop_back();
        return ret;
    }
    inline friend lnum operator/(const lnum &l, const int &r)
    {
        lnum ret(0, l.base);
        ret.a.resize(l.len());
        int carry = 0;
        for(int i = l.len() - 1; i >= 0; --i)
        {
            long long cur = l.a[i] + (ll)carry * l.base;
            ret.a[i] = cur / r;
            carry = cur % r;
        }
        while (ret.len() > 1 && ret.a.back() == 0)
            ret.a.pop_back();
        return ret;
    }

    inline friend bool operator<(const lnum &l, const lnum &r)
    {
        if (l.len() < r.len())
            return true;
        if (l.len() > r.len())
            return false;
        int n = l.len();
        for(int i = n - 1; i; --i)
        {
            if (l.a[i] < r.a[i])
                return true;
            if (l.a[i] > r.a[i])
                return false;
        }
        return false;
    }
    inline friend bool operator>(const lnum &l, const lnum &r)
    {
        return r > l;
    }
    inline friend bool operator==(const lnum &l, const lnum &r)
    {
        if (l.len() != r.len())
            return false;
        int n = l.len();
        for(int i = n - 1; i; --i)
        {
            if (l.a[i] != r.a[i])
                return false;
        }
        return true;
    }
    inline friend bool operator!=(const lnum &l, const lnum &r)
    {
        return !(l == r);
    }
    inline void print()
    {
        if (base == 1000000000)
        {
            printf("%d", a.back());
            for(int i = a.size() - 2; i >=0; --i)
                printf("%09d", a[i]);
        }
        else
        {
            for(int i = a.size() - 1; i >= 0; --i)
                printf("%d", a[i]);
        }
    }
};
int gcd(int a, int b)
{
    if (a > b)
        swap(a, b);
    if (!a)
        return a;
    if (a == b)
        return a;
    if (a == 1)
        return 1;
    if (!(a & 1))
    {
        if (b & 1)
            return gcd(a >> 1, b);
        else
            return gcd(a >> 1, b >> 1) << 1;
    }
    else
    {
        if (b & 1)
            return gcd((b - a) >> 1, a);
        else
            return gcd(a, b >> 1);
    }

}

struct sr
{

};

int main()
{
    int ans = 0;
    set <string> cur;
    while(!cin.eof())
    {
        string s;
        getline(cin, s);
        if (s[0] == '+')
        {
            cur.insert(s.substr(1));
            continue;
        }
        if (s[0] == '-')
        {
            cur.erase(s.substr(1));
            continue;
        }
        int pos = s.find(":");
        ans += (s.length() - pos - 1) * cur.size();
    }
    cout << ans << endl;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;

int main()
{
    string S;
    int us=0,ans=0;
    while(getline(cin,S))
    {
        if(S[0]=='+')
        {
            us++;
        }
        else if(S[0]=='-')
        {
            us--;
        }
        else
        {
            int n=0;
            int k=S.length()-1;
            while(S[k]!=':')
            {
                k--;
                n++;
            }
            ans+=n*us;
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#define s(x) scanf("%d",&(x))
#define print(x) printf("%d ",x)
#define printnl(x) printf("%d\n",x);
#define forI(i,a,b) for(int i=(a);i<=(b);i++)
#define forD(i,a,b) for(int i=(a);i>=(b);--i)
#define MOD 1000000009
#define INF_LONG 8999999999999999999
#define ll long long
#define FOUND 1
#define NOTFOUND 0
#define MAXSIZE 10000
using namespace::std;
/*when handling double use %lf in scanf and %0.6f in printf */
/*inline int read_int()
{
    char c;
    while ((c=getchar_unlocked()) < 48 || c > 57);
    int p = c-48;
    while ((c=getchar_unlocked()) >= 48 && c <= 57) p=p*10+c-48;
    return p;
}*/

ll power(ll base,ll exponent)
/*works for any base and long long power*/
{
    if(base==1 || exponent==0)
        return 1;

    if((exponent&1)==0)
        return ((power(((base%MOD)*(base%MOD))%MOD,exponent>>1)))%MOD;

    return (((base%MOD)*(power(((base%MOD)*(base%MOD))%MOD,(exponent-1)>>1)%MOD)))%MOD;
}

int main()
{
    int group,i,load;
    load=group=0;
    string name;
    while(getline(cin,name))
    {
        if(name[0]=='+')
        {
            ++group;
        }
        else if(name[0]=='-')
        {
            --group;
        }
        else
        {
            for(i=0;name[i]!=':';++i)
                ;
            load+=(group*(name.length()-i-1));
        }
    }
    cout<<load;
    return 0;
}


#include <string>
#include <vector>
//#include <iostream>
#include <algorithm>

#include <cstdlib>
#include <cstdio>

using namespace ::std;

int main () {
//	std::ios::sync_with_stdio(false);

	int c, users = 0, traffic = 0;
	while ((c = getchar()) != EOF) {
		if (c == '+' || c == '-') {
			if (c == '+')
				++users;
			else
				if (users <= 0)
					return EXIT_FAILURE;
				else
					--users;
			while ((c = getchar()) != '\n')
				if (c == EOF)
					return EXIT_FAILURE;
		} else {
			if (users <= 0)
				return EXIT_FAILURE;
			int characters = 0;
			while ((c = getchar()) != ':')
				if (c == EOF)
					return EXIT_FAILURE;
			while ((c = getchar()) != '\n')
				if (c == EOF)
					return EXIT_FAILURE;
				else
					++characters;
			traffic += users * characters;
		}
	}
	printf ("%d\n", traffic);
	return EXIT_SUCCESS;
}


#include <iostream>
#include <string>
using namespace std;

int main() {
    string s;
    int cnt = 0;
    int ans = 0;
    while (getline(cin, s)) {
        if (s[0] == '+') cnt += 1;
        else if (s[0] == '-') cnt -= 1;
        else {
            ans += cnt * (s.length() - s.find(':') - 1);
        }
    }
    cout << ans << endl;
    return 0;
}


#include <sstream>
#include <iomanip>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <deque>
#include <complex>

#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; i--)
#define REP(i,a) for(int i=0,_a=(a); i<_a; i++)
#define ll long long
#define F first
#define S second
#define PB push_back
#define MP make_pair

#define DEBUG(x) cout << #x << " = "; cout << x << endl;
#define PR(a,n) cout << #a << " = "; FOR(_,1,n) cout << a[_] << ' '; cout << endl;
#define PR0(a,n) cout << #a << " = "; REP(_,n) cout << a[_] << ' '; cout << endl;
using namespace std;

const double PI = acos(-1.0);

char s[1011];

int main() {
    int cur = 0;
    long long res = 0;
    while (gets(s)) {
        if (s[0] == '+') ++cur;
        else if (s[0] == '-') --cur;
        else {
            res += cur * (ll) (strlen(s) - (strchr(s, ':') - s) - 1);
        }
    }
    cout << res << endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    int sum=0,sum1=0,pls=0;
    while(getline(cin,s)&&EOF)
    {
        if(s[0]=='+') {
                pls++;
            sum1=0;
        }
        else if(s[0]=='-')
            {
                pls--;sum1=0;
            }
        else
        {
            bool b=true;
            int c=0;
            sum1=0;
            for(int i=0; i<s.size(); i++)
            {
                if(s[i]==':' && b)
                    b=false;
                else if(!b)
                  sum1++;
                  else
                    continue;
            }
           sum+=(pls*sum1);
        }
        s.clear();
    }
      cout<<sum<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{
    string s;
    int sum=0,sum1=0,pls=0;
    while(getline(cin,s)&&EOF)
    {
        if(s[0]=='+') {
                pls++;
            sum1=0;
        }
        else if(s[0]=='-')
            {
                pls--;sum1=0;
            }
        else if(isalpha(s[0]))
        {
            bool b=true;
            int c=0;
            sum1=0;
            for(int i=0; i<s.size(); i++)
            {
                if(!isalpha(s[i]) && b)
                    b=false;
                else if(!b)
                  sum1++;
            }
           sum+=(pls*sum1);
        }
    }
      cout<<sum<<endl;
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:16777216")
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <ctime>
#include <stack>
#include <queue>
#include <string>
#include <iomanip>
#include <sstream>
#include <cassert>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <bitset>
#include <fstream>

using namespace std;

#define forn(i, n) for(int i = 0; i < int(n); ++i)
#define ford(i, n) for(int i = int(n - 1); i >= 0; --i)
#define forn1(i, n) for(int i = 1; i <= int(n); ++i)
#define ford1(i, n) for(int i = int(n); i > 0; --i)
#define foran(i, a, n) for(int i = a; i <= int(n); ++i)

#define all(v) (v).begin(), (v).end()
#define mp make_pair

template <class T> T abs(T a) { return (a) > 0 ? (a) : -(a); }
template <class T> T sqr(T a) { return (a) * (a); }

typedef long double ld;
typedef long long ll;

const ld PI = 3.1415926535897932;
const ld EPS = 1e-9;
const ll INF = 10e12;

int main( )
{
    string s;
    int t = 0;
    int ans = 0;

    while (getline (cin, s)) {
        if (s[0] == '+')
            t++;
        else
        if (s[0] == '-')
            t--;
        else {
            int k = 0;
            for (; k < s.size(); k++)
                if (s[k] == ':')
                    break;
            ans += (s.size() - k - 1) * t;
        }
    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <set>
#include <string>

int main() {
  std::string line;
  std::set<std::string> nicks;
  int traffic = 0;
  while (std::getline(std::cin, line)) {
    if (line[0] == '+') nicks.insert(line.substr(1));
    else if (line[0] == '-') nicks.erase(line.substr(1));
    else {
      int length = line.size() - line.find(':') - 1;
      traffic += length * nicks.size();
    }
  }
  std::cout << traffic << std::endl;
}


#include <string>
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

int toInt(string s) {int res;stringstream ss;ss<<s;ss>>res;return res;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;

typedef long long ll;
typedef unsigned long long ull;

typedef tuple<int,int> int2;
typedef tuple<int,int,int> int3;
typedef tuple<int,int,int,int> int4;

#define all(v) (v).begin(), (v).end()
#define est(v,e) (find(all(v), (e)) != (v).end())
#define eb emplace_back
#define SZ(a) (int((a).size()))
#define For(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) For(i,0,n)
#define tag(i,v) rep(i,SZ(v))
#define trace(x)  cerr << #x << " = " << (x) << endl
#define tracev(x) cerr << #x << " = "; tag(__i, x) { cerr << x[__i] << ","; } cerr << endl

const int inf = 1 << 27;

int main(void) {

  string s;
  int n = 0, res = 0;

  while(getline(cin,s)){
    if(s[0] == '+'){
      n++;
      continue;
    }
    if(s[0] == '-'){
      n--;
      continue;
    }
    res += n*(s.size()-s.find_first_of(':')-1);
  }
  cout << res << endl;
  return 0;

}


#include <iostream>
using namespace std;

int main() {
	int people = 0, ans = 0;

	string cmd;
	while(getline(cin, cmd)) {
		switch(cmd[0]) {
			case '+':
				people++;
				break;
			case '-':
				people--;
				break;
			default:
				ans += (cmd.length()-cmd.find(":")-1)*people;
		}
	}

	cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
typedef double D;
typedef long long ll;
typedef int TYPE;
typedef pair<int,int> PII;
#define mod9 1000000009ll
#define mod7 1000000007ll
#define INF 1023456789
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
int getint(){
    int x=0,tmp=1; char tc=getchar();
    while( (tc<'0'||tc>'9')&&tc!='-' ) tc=getchar();
    if( tc == '-' ) tc=getchar() , tmp = -1;
    while(tc>='0'&&tc<='9') x*=10,x+=(tc-'0'),tc=getchar();
    return x*tmp;
}
int __ = 1;
/*********default*********/
#define N 1010
char c[ N ] , c2[ N ] , c3[ N ];
set<string> S;
void build(){

}
void init(){
    int ans = 0;
    while( gets( c ) ){
        if( sscanf( c , "+%s" , c2 ) == 1 ){
            string stmp;
            for( int i = 0 ; c2[ i ] ; i ++ ) stmp += c2[ i ];
            S.insert( stmp );
        }else if( sscanf( c , "-%s" , c2 ) == 1 ){
            string stmp;
            for( int i = 0 ; c2[ i ] ; i ++ ) stmp += c2[ i ];
            S.erase( stmp );
        }else{
            int len = strlen( c );
            for( int i = 0 ; i < len ; i ++ )
                if( c[ i ] == ':' ){
                    len -= ( i + 1 );
                    break;
                }
            ans += (int)S.size() * len;
        }
    }
    printf( "%d\n" , ans );
}
void solve(){

}
int main(){
    build();
//    __ = getint();
    while( __ -- ){
        init();
        solve();
    }
}


#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <valarray>
#include <vector>
#include <unordered_set>
using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define MP make_pair
#define SZ(x) ((int) (x).size())
#define maxit(x,y) ((x) = max((x),(y)))
#define minit(x,y) ((x) = min((x),(y)))
typedef long long LL;

int main()
{
	unordered_set<string> parts;
	char buf[2048];
	int result = 0;
	while (fgets(buf, 2048, stdin) != NULL) {
		if (buf[0] == '+') {
			parts.insert(buf+1);
		} else if (buf[0] == '-') {
			parts.erase(buf+1);
		} else {
			char *colon = strchr(buf, ':');
			if (colon == NULL) continue;
			int len = strlen(colon+2);
			result += len * SZ(parts);
		}
	}
	printf("%d\n", result);

	return 0;
}


#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
#include <list>
#include <fstream>
#include <time.h>
#include <iomanip>
#include <queue>
#include <stack>
#include <complex>
//#include <assert.h>

using namespace std;

#define For(i,a,b,d) for (int i = (a); i != (b); i += d)
#define FORD(i,a,b) for (int i = (a); i >= b; i--)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define REPD(i,n) for (int i = (n - 1); i >= 0; i--)
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define CLR(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << "=" << x << endl;
#define pb push_back
#define mp make_pair

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int mx[4] = {1, -1, 0, 0};
const int my[4] = {0, 0, 1, -1};

const int Inf = 1000000000;
const int Mi = 1000000009;
const int N = 1005;
const int K = 105;
const ld eps = 10e-6;
const ld PI = 2 * acos(0.0);
const ll InfLL = ll(Inf) * ll(Inf);;

set<string> M;

int main () {
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    int ans = 0;
    for (;;) {
        string s = "";
        getline(cin, s);
        if (s == "") break;
        if (s[0] == '+') {
            s.erase(0, 1);
            M.insert(s);
        } else if (s[0] == '-') {
            s.erase(0, 1);
            M.erase(s);
        } else {
            s.erase(0, s.find(':') + 1);
            ans += M.size() * s.length();
        }
    }
    cout << ans << endl;
    return 0;
}


#include <stdio.h>
#include <cstdlib>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <string>
#include <memory.h>
#include <map>
#define _USE_MATH_DEFINES
#include <math.h>
#include <list>
#include <fstream>
#include <time.h>
#include <iomanip>
#include <queue>
#include <stack>
#include <complex>
//#include <assert.h>

using namespace std;

#define For(i,a,b,d) for (int i = (a); i != (b); i += d)
#define FORD(i,a,b) for (int i = (a); i >= b; i--)
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define REPD(i,n) for (int i = (n - 1); i >= 0; i--)
#define REP(i,n) for (int i = 0; i < (n); i++)
#define ALL(a) (a).begin(), (a).end()
#define CLR(a,x) memset(a,x,sizeof(a))
#define debug(x) cout << #x << "=" << x << endl;
#define pb push_back
#define mp make_pair

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

const int mx[4] = {1, -1, 0, 0};
const int my[4] = {0, 0, 1, -1};

const int Inf = 1000000000;
const int Mi = 1000000009;
const int N = 1005;
const int K = 105;
const ld eps = 10e-6;
const ld PI = 2 * acos(0.0);
const ll InfLL = ll(Inf) * ll(Inf);;

set<string> M;

//#define ONLINE_JUDGE
int main () {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    int ans = 0;
    for (;;) {
        string s = "";
        getline(cin, s);
        if (s == "") break;
        if (s[0] == '+') {
            s.erase(0, 1);
            M.insert(s);
        } else if (s[0] == '-') {
            s.erase(0, 1);
            M.erase(s);
        } else {
            s.erase(0, s.find(':') + 1);
            ans += M.size() * s.length();
        }
    }
    cout << ans << endl;
    return 0;
}


#include<iostream>

#include<cstdio>

using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);

    string s;

    int d = 0, res = 0;

    while(getline(cin, s))
    {
        if(s[0] == '+') d++;
        else if(s[0] == '-') d--;
        else
        {
            int i = s.length() - 1;

            while(s[i] != ':') i--;

            int tmp = s.length() - 1 - i;

            res += d * tmp;
        }
    }

    cout << res;
}


#include<iostream>

#include<cstdio>

using namespace std;

int main()
{
    //freopen("in.txt", "r", stdin);

    string s;

    int d = 0, res = 0;

    while(getline(cin, s))
    {
        cout << s << endl;

        if(s[0] == '+') d++;
        else if(s[0] == '-') d--;
        else
        {
            int i = s.length() - 1;

            while(s[i] != ':') i--;

            int tmp = s.length() - 1 - i;

            res += d * tmp;
        }
    }

    cout << res;
}


#include <cstdio>
#include <cstdlib>

int msglen(char *);

int main()
{
	char s[120];
	int count = 0;
	int res = 0;

	while (gets(s)) {
		if (feof(stdin))
			break;
		if (s[0] == '+')
			count++;
		else if (s[0] == '-')
			count--;
		else
			res += msglen(s) * count;
	}

	printf("%d\n", res);

	return 0;
}

int msglen(char *s)
{
	int res = 0;
	int i = 0;
	while (s[i++] != ':')
		;
	for (; s[i]; i++, res++)
		;
	return res;
}


#include <cstdio>
#include <cstdlib>

int msglen(char *);

int main()
{
	char s[120];
	int count = 0;
	int res = 0;

	while (gets_s(s)) {
		if (feof(stdin))
			break;
		if (s[0] == '+')
			count++;
		else if (s[0] == '-')
			count--;
		else
			res += msglen(s) * count;
	}

	printf("%d\n", res);

	return 0;
}

int msglen(char *s)
{
	int res = 0;
	int i = 0;
	while (s[i++] != ':')
		;
	for (; s[i]; i++, res++)
		;
	return res;
}


#include <stdio.h>
#include<string.h>
int main() {
  int i=0,c=0,s=0;
char a[102];
while(gets(a)!=NULL)
{
if(a[0]=='+')c++;
else if(a[0]=='-') c--;
else
{i=0;
while(a[i]!=':'){i++;}
s+=(strlen(a)-i-1)*c;
}
}
printf("%d",s);
return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main()
{
    char name[1000],count=0;
    int i,j,result=0;
    while(gets(name)!='\0')
    {
        if(name[0]=='+')count++;
        else if (name[0]=='-')count--;
        else
        {
            for(i=0;name[i]!=':';i++);i++;
            for(j=0;name[i]!='\0';j++,i++);
            result+=count*j;
        }
    }
    printf("%d\n",result);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int i,l=0,p=0,sum=0,f=0;
    char s;
    while(scanf("%c",&s)!=EOF){
    	 if(s=='\n'){
            f=0;
            sum+=p*l;
            l=0;
        }
        else if(s==':'){
            f=1;
        }
        else if(f==1){
            l++;
        }
        else if(s=='+'){
            p++;
            f=0;
        }
        else if(s=='-'){
            p--;
            f=0;
        }
    }
    printf("%d",sum);
    return 0;
}


#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    int i,l=0,p=0,sum=0;
    char *s;
    s=(char *)malloc(105);
    while(scanf("%s",s)!=EOF){
        if(s[0]=='+')p++;
        else if(s[0]=='-')p--;
        else{
            for(i=0;s[i]!=':';i++){
            }
            l=strlen(s)-i-1;
        }
        sum+=p*l;
    }
    printf("%d",sum);
    return 0;
}


#include <stdio.h>

int len(char *s);

int main()
{
  int n = 0, i, j ,k, sum = 0;
  char str[1000];

  while(gets(str))
  {
    if(str[0] == '+')
      n++;
    else if(str[0] == '-')
      n--;
    else
    {
      k = len(str);
      sum += n * k;

    }
  }

  printf("%d\n",sum);

  return 0;
}

int len(char *s)
{
  int i = 0, l = 0;

  while(s[i] != ':')
   i++;

  i++;
  while(s[i])
  {
    i++;
    l++;
  }

  return l;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long result(long long n,long long m)
{
     if(n<m)
     return 0;
     int i,t=1,ans=1;
     for(i=n;i>m;i--)/*Computation of the combination aCb*/
     {
          ans*=i;
          ans/=t++;
     }
     return ans;
}
char* bitchange(char* ch)
{
     int i,t=0,cnt=0,j,k=0;
     t=strlen(ch);
     for(i=t-1;i>=0;i--)
     {
          if(ch[i]=='1')
          cnt++;
          else
          {
               k=i;
               break;
          }
     }
   //  printf("%d %s\n",cnt,ch);
     if(cnt==t)
     {
          ch[0]='1';
          ch[t]='0';
          ch[t+1]='\0';
          k=1;
     }
     for(i=k;i<t;i++)
     {
          if(ch[i]=='1')
          ch[i]='0';
          else if(ch[i]=='0')
          ch[i]='1';
        //  printf("c== %d",ch[i]);
     }
     if(cnt!=t)
     ch[t]='\0';
     //printf("\n%d %s\n\n",t,ch);
     return ch;
}
int cmpfunc(const void*a,const void*b)
{
    return (*(int*)a - *(int*)b);
}
int main()
{
    int n,m,i,j,sum=0,chk=0,z=0,k=0,c=':',t=0,s=0,max=0,min=0,d=0;
    int a[2000005]={0},b[5000]={0};
    char ch[1000001],st[1000000];
    while(gets(ch))
    {
        // getchar();
       // printf("%d\n",strlen(ch));
        if(ch[0]=='+')
        k++;
        else if(ch[0]=='-')
        k--;
        else
         {
             //printf("%d\n",strlen(ch));
              i=0;
              while(ch[i]!=58)
              {
                   i++;
                  // printf("%c ",ch[i]);
              }
              t=strlen(ch);
              chk+=k*(t-(i+1));
              //printf("\ni = %d %d\n",i,chk);
         }
        // printf("%d\n",chk);
        // memset(ch,NULL,sizeof(int));
       // getchar();
    }
    printf("%d",chk);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long result(long long n,long long m)
{
     if(n<m)
     return 0;
     int i,t=1,ans=1;
     for(i=n;i>m;i--)/*Computation of the combination aCb*/
     {
          ans*=i;
          ans/=t++;
     }
     return ans;
}
char* bitchange(char* ch)
{
     int i,t=0,cnt=0,j,k=0;
     t=strlen(ch);
     for(i=t-1;i>=0;i--)
     {
          if(ch[i]=='1')
          cnt++;
          else
          {
               k=i;
               break;
          }
     }
   //  printf("%d %s\n",cnt,ch);
     if(cnt==t)
     {
          ch[0]='1';
          ch[t]='0';
          ch[t+1]='\0';
          k=1;
     }
     for(i=k;i<t;i++)
     {
          if(ch[i]=='1')
          ch[i]='0';
          else if(ch[i]=='0')
          ch[i]='1';
        //  printf("c== %d",ch[i]);
     }
     if(cnt!=t)
     ch[t]='\0';
     //printf("\n%d %s\n\n",t,ch);
     return ch;
}
int cmpfunc(const void*a,const void*b)
{
    return (*(int*)a - *(int*)b);
}
int main()
{
    int n,m,i,j,sum=0,chk=0,z=0,k=0,c=0,t=0,s=0,max=0,min=0,d=0;
    int a[2000005]={0},b[5000]={0};
    char ch[1000001],st[1000000];
    while(scanf("%s",ch)!=EOF)
    {
         getchar();
         if(ch[0]=='+'||ch[0]=='-')
         continue;
         else
         {
              i=0;
              while(ch[i]!=':')
              {
                   i++;
              }
              chk+=strlen(ch);
              chk-=i;
         }
         //printf("%d\n",chk);
    }
    printf("%d",chk);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long result(long long n,long long m)
{
     if(n<m)
     return 0;
     int i,t=1,ans=1;
     for(i=n;i>m;i--)/*Computation of the combination aCb*/
     {
          ans*=i;
          ans/=t++;
     }
     return ans;
}
char* bitchange(char* ch)
{
     int i,t=0,cnt=0,j,k=0;
     t=strlen(ch);
     for(i=t-1;i>=0;i--)
     {
          if(ch[i]=='1')
          cnt++;
          else
          {
               k=i;
               break;
          }
     }
   //  printf("%d %s\n",cnt,ch);
     if(cnt==t)
     {
          ch[0]='1';
          ch[t]='0';
          ch[t+1]='\0';
          k=1;
     }
     for(i=k;i<t;i++)
     {
          if(ch[i]=='1')
          ch[i]='0';
          else if(ch[i]=='0')
          ch[i]='1';
        //  printf("c== %d",ch[i]);
     }
     if(cnt!=t)
     ch[t]='\0';
     //printf("\n%d %s\n\n",t,ch);
     return ch;
}
int cmpfunc(const void*a,const void*b)
{
    return (*(int*)a - *(int*)b);
}
int main()
{
    int n,m,i,j,sum=0,chk=0,z=0,k=0,c=':',t=0,s=0,max=0,min=0,d=0;
    int a[2000005]={0},b[5000]={0};
    char ch[1000001],st[1000000];
    while(gets(ch))
    {
        // getchar();
         if(ch[0]!='+'&&ch[0]!='-')
         {
             // printf("%d\n",strlen(ch));
              i=0;
              while(ch[i]!=58)
              {
                   i++;
                  // printf("%c ",ch[i]);
              }
              chk+=strlen(ch);
              chk-=i+1;
            //  printf("\ni = %d %d\n",i,chk);
         }
        // printf("%d\n",chk);
        // memset(ch,NULL,sizeof(int));
    }
    printf("%d",chk);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long result(long long n,long long m)
{
     if(n<m)
     return 0;
     int i,t=1,ans=1;
     for(i=n;i>m;i--)/*Computation of the combination aCb*/
     {
          ans*=i;
          ans/=t++;
     }
     return ans;
}
char* bitchange(char* ch)
{
     int i,t=0,cnt=0,j,k=0;
     t=strlen(ch);
     for(i=t-1;i>=0;i--)
     {
          if(ch[i]=='1')
          cnt++;
          else
          {
               k=i;
               break;
          }
     }
   //  printf("%d %s\n",cnt,ch);
     if(cnt==t)
     {
          ch[0]='1';
          ch[t]='0';
          ch[t+1]='\0';
          k=1;
     }
     for(i=k;i<t;i++)
     {
          if(ch[i]=='1')
          ch[i]='0';
          else if(ch[i]=='0')
          ch[i]='1';
        //  printf("c== %d",ch[i]);
     }
     if(cnt!=t)
     ch[t]='\0';
     //printf("\n%d %s\n\n",t,ch);
     return ch;
}
int cmpfunc(const void*a,const void*b)
{
    return (*(int*)a - *(int*)b);
}
int main()
{
    int n,m,i,j,sum=0,chk=0,z=0,k=0,c=':',t=0,s=0,max=0,min=0,d=0;
    int a[2000005]={0},b[5000]={0};
    char ch[1000001],st[1000000];
    while(gets(ch))
    {
        // getchar();
         if(ch[0]!='+'&&ch[0]!='-')
         {
             // printf("%d\n",strlen(ch));
              i=0;
              while(ch[i]!=58)
              {
                   i++;
                  // printf("%c ",ch[i]);
              }
              chk+=strlen(ch);
              chk-=(i);
              //printf("\ni = %d %d\n",i,chk);
         }
        // printf("%d\n",chk);
        // memset(ch,NULL,sizeof(int));
       // getchar();
    }
    printf("%d",chk);
    return 0;
}


#include<stdio.h>
#include<stdlib.h>
#include<string.h>
long long result(long long n,long long m)
{
     if(n<m)
     return 0;
     int i,t=1,ans=1;
     for(i=n;i>m;i--)/*Computation of the combination aCb*/
     {
          ans*=i;
          ans/=t++;
     }
     return ans;
}
char* bitchange(char* ch)
{
     int i,t=0,cnt=0,j,k=0;
     t=strlen(ch);
     for(i=t-1;i>=0;i--)
     {
          if(ch[i]=='1')
          cnt++;
          else
          {
               k=i;
               break;
          }
     }
   //  printf("%d %s\n",cnt,ch);
     if(cnt==t)
     {
          ch[0]='1';
          ch[t]='0';
          ch[t+1]='\0';
          k=1;
     }
     for(i=k;i<t;i++)
     {
          if(ch[i]=='1')
          ch[i]='0';
          else if(ch[i]=='0')
          ch[i]='1';
        //  printf("c== %d",ch[i]);
     }
     if(cnt!=t)
     ch[t]='\0';
     //printf("\n%d %s\n\n",t,ch);
     return ch;
}
int cmpfunc(const void*a,const void*b)
{
    return (*(int*)a - *(int*)b);
}
int main()
{
    int n,m,i,j,sum=0,chk=0,z=0,k=0,c=':',t=0,s=0,max=0,min=0,d=0;
    int a[2000005]={0},b[5000]={0};
    char ch[1000001],st[1000000];
    while(gets(ch))
    {
        // getchar();
         if(ch[0]!='+'&&ch[0]!='-')
         {
             // printf("%d\n",strlen(ch));
              i=0;
              while(ch[i]!=58)
              {
                   i++;
                  // printf("%c ",ch[i]);
              }
              chk+=strlen(ch);
              chk-=i;
            //  printf("\ni = %d %d\n",i,chk);
         }
        // printf("%d\n",chk);
        // memset(ch,NULL,sizeof(int));
    }
    printf("%d",chk);
    return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{
    int count=0, sum=0, i, len=0;
    char a[10000];

    while(gets(a)!='\0')
    {
        if(a[0]=='+')
        {
            count++;
        }
        else if(a[0]=='-')
        {
            count--;
        }
        else
        {
            for(i=0;;i++)
            {
                if(a[i]==':')
                {
                    break;
                }
            }
            i+=1;
            //printf("%d", i);
            len=len-i;
            sum=sum+len*count;
        }

    }

    printf("%d", sum);
    return 0;
}


#include <stdio.h>
#include <string.h>
int main()
{
    int count=0, sum=0, i=0, len=0;
    char a[10000];

    while(gets(a)!='\0')
    {
        if(a[0]=='+')
        {
            count++;
        }
        else if(a[0]=='-')
        {
            count--;
        }
        else
        {
            i=0;
            while(a[i]!=':')
            {
                i++;
            }
            //printf("%d", i);
            sum=sum+(strlen(a)-i-1)*count;
        }

    }
    printf("%d", sum);
    return 0;
}


#include <stdio.h>
int main()
{
    int count=0, sum=0, i, len=0;
    char a[10000];

    while(gets(a)!=0)
    {
        if(a[0]=='+')
        {
            count++;
        }
        else if(a[0]=='-')
        {
            count--;
        }
        else
        {
            len=strlen(a);
            for(i=0;;i++)
            {
                if(a[i]==':')
                {
                    break;
                }
            }
        }
        i+=1;
        //printf("%d", i);
        len=len-i;
        sum=sum+len*count;
    }

    printf("%d", sum);
}


#include <stdio.h>
#include <string.h>

char buffer[1024];

int main (void)
{
	int ans = 0;
	int num = 0;
	int len;
	int l;

	while (gets(buffer) ) {
		if (buffer[0] == '+') ++num;
		else if (buffer[0] == '-') --num;
		else {
			len = strlen (buffer);
			for (l=0;l<len;l++)
				if (buffer[l] == ':')
					break;
			l = len - l -1;

			ans += num * l;
		}
	}

	printf ("%d",ans);
	return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
	char c[101];
	int n=0,sum=0;
	while(gets(c)!=NULL)
	{
		if(c[0]=='+')n++;
		else if(c[0]=='-')n--;
		else
		{
			sum = sum + ((c+strlen(c)) - strchr(c,':')-1)*n;
		}
	}
printf("%d",sum);
return 0;
}


#include<stdio.h>

#include<string.h>
int main()
{

    char cmd[101] ;
    int byte = 0;
    int online = 0;
    int i;

    while(gets(cmd))
    {
        if(cmd[0]=='+')
            online++;
        else if(cmd[0]=='-')
            online--;
        else
        {

            for(i=0;i<110;i++)
                if(cmd[i]==':')
                break;

            byte +=(strlen(cmd)-1-i)*online;

        }
    }
    printf("%d\n",byte);
    return 0;
}


#include <stdio.h>
int main(void) {
    char ch = 0;
    int no_wait = 0;
    int people = 0;
    int symbols = 0;
    int total = 0;
    while(1) {
        ch = getchar();
        if (ch != -1)
        {
            switch (ch) {
                case '+':
                    {
                        people++;
                        no_wait = 0;
                        break;
                    }
                case '-':
                    {
                        people--;
                        no_wait = 0;
                        break;
                    }
                case ':':
                    {
                        no_wait = 1;
                        break;
                    }
                case '\n':
                    {
                        if (no_wait){
                            total += (symbols - 1) * people;
                            symbols = 0;
                            no_wait = 0;
                            break;
                        }
                    }
            }
        }
        else
            break;
        if (no_wait) {
            symbols++;
        }
    }
    printf("%i", total);
    return 0;
}


#include<stdio.h>

int main(){
	char msg[100];
	char t=4;
	int i;
	int count,sum,users;
	sum=0;
	users=0;
	while (t!=EOF){
		count=0;
		for (i=0;((t=getchar())!=10)&&(t!=EOF);i++){
			msg[i]=t;
			msg[i+1]=EOF;
		}
		if (t==EOF) break;
		if (msg[0]=='+') {
			users++;
			//printf("users:%d\n",users);
		}
		else if (msg[0]=='-') users--;
			else {
				i--;
				while (msg[i]!=':'){
					count++;
					i--;
				}
				//printf("count:%d\n",count);
				sum=sum+count*users;
			}
	}
	printf("%d\n",sum);
	return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char s[100];
    int i,sum=0,res=0,j=0;
    while(gets(s)!=NULL){
        if (s[0]=='+')
            sum++;
            else if (s[0]=='-')
                sum--;
            else{
                j=0;
                while(s[j]!=':')
                    {j++;}
                res=res+(strlen(s)-j-1)*sum;}
    }
    printf("%d",res);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char s[100];
    int i,sum=0,res=0,j=1;
    while(gets(s)!=NULL){
        if (s[0]=='+')
            sum++;
            else if (s[0]=='-')
                sum--;
            else{
                j=1;
                while(s[j]!=':')
                    {j++;}
                res=res+(strlen(s)-j)*sum;}
    }
    printf("%d",res);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>

int main()
{

    char ch;
    int sum=0;
    char ch2;
    int res=0;
    int ress=0;
    FILE *f;
     f=fopen("d","w");
    while((ch=getchar())!=EOF)
            {
             putc(ch,f);
            }
            fclose(f);
            f=fopen("d","r");
            while((ch=getc(f))!=EOF)
            {
                if(ch=='+')
                {
                    sum++;
                }
              else if(ch=='-')
                {
                    sum--;
                }
                else if(ch==':')
               {
                    while(ch=getc(f)!='\n')
                    {
                        res++;
                    }
                    res*=sum;
                    ress+=res;
                    res=0;
               }

            }

printf("%d",ress);

return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char ent[150];
    int res = 0, p = 0;

    while(scanf(" %[^\n]", ent) != EOF)
    {
        if(ent[0] == '+')
            p++;
        else if(ent[0] == '-')
            p--;
        else
        {
            int i;
            for(i = 0; i < strlen(ent); ++i)
                if(ent[i] == ':')
                    break;
            i++;
            res += (strlen(ent)-i)*p;
        }
    }

    printf("%d", res);

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    char ent[150];
    int res = 0, p = 0;

    while(scanf(" %[^\n]", ent) != EOF)
    {
        if(ent[0] == '+')
            p++;
        else if(ent[0] == '-')
            p--;
        else
        {
            char *c;
            c = strtok(ent, ":");
            c = strtok(NULL, ":");

            res += strlen(c)*p;
        }
    }

    printf("%d", res);

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main()
{
    freopen("a.in", "r", stdin);
    char ent[150];
    int res = 0, p = 0;

    while(scanf(" %[^\n]", ent) != EOF)
    {
        if(ent[0] == '+')
            p++;
        else if(ent[0] == '-')
            p--;
        else
        {
            int i;
            for(i = 0; i < strlen(ent); ++i)
                if(ent[i] == ':')
                    break;
            i++;
            res += (strlen(ent)-i)*p;
        }
    }

    printf("%d", res);

    return 0;
}


#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int main(){
    char str[120];
    int count=0,i,tr=0,len;

	while(gets(str)!='\0'){
        if(str[0]=='+') count++;
        else if(str[0]=='-')    count--;
        else{
            len=strlen(str);

            for(i=0; ;i++){
                if(str[i]!=':') len--;
                else {
                    len--;
                    break;
                }
            }

            tr+=len*count;
        }

        //printf("%d\n",tr);
	}
	printf("%d\n",tr);

	return(0);
}


#include<stdio.h>
int main(){
	int i,j,k,l,n,m,our = 0,ans=0;
	char c,s[1000];
	c = getchar();
	while(c!=EOF){
		j = 0;
		s[j] = c;
		while(c!='\n'){
			j++;
			c = getchar();
			s[j] = c;
		}
		if(s[0]=='+')
			our++;
		else if(s[0]=='-')
			our--;
		else{
		l = 0;
			while(s[l]!=':')
				l++;
			ans = ans + (our*(j-l-1));
		}
		c = getchar();
	}
	printf("%d\n",ans);
	return 0;
}


#include <stdio.h>

int main()
{
     int n = 0, l = 0, i;
     char s[105];

     while (fgets(s, 105, stdin) != NULL) {
      if (s[0] == '+') {
           n++;
      } else if (s[0] == '-') {
           n--;
      } else {
           for (i = 0; i < strlen(s); i++) {
            if (s[i] == ':') break;
           }

           l += (strlen(s) - i - 2) * n;
      }
     }

     printf("%d\n", l);

     return 0;
}


#include<stdio.h>
#include<string.h>
int main()
{
    int inchat=0,length,data=0,i;
    char command[110];

    while(gets(command))
    {
        if(command[0] == '+')
        inchat++;
        else if(command[0] == '-')
        inchat--;
        else
        {
            length = strlen(command);
            for(i=0;i<length;i++)
            if(command[i] == ':')
            break;

            length = strlen(command + i +1);
            //printf("length %d inchat %d\n",length,inchat);
            data+= length * inchat;
        }

    }

    printf("%d",data);
return 0;
}