#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
char mp[N][N];
int s[N], t[N], top;
int main()
{
    FILE *fp;
    fp = fopen("prog.txt", "r"); ///文件读操作
    char ch;
    int tot = 0;
    int i = 0;
    while ((ch = fgetc(fp)) != EOF) ///一个字符一个字符的读入
    {

        if (ch == '\n')
        {
            mp[tot][i] = '\0';
            tot++;
            i = 0;
            continue;
        }
        mp[tot][i++] = ch;
    }
    /*
    for(int i=0;i<tot;i++)
        printf("%s\n",mp[i]);*/
    ///将txt中的数据已经全部保存在了mp数组中
    top = 0;
    int p, w = 1, sum = 0;
    s[top] = -1, t[top] = -1; ///防止栈空的时候进行出栈操作
    for (int i = 0; i < tot; i++)
    {
        int len = strlen(mp[i]);
        p = 0;
        while (mp[i][p] == ' ') ///统计缩进
            p++;
        while (s[top] >= p) ///开始新的循环,上一层的循环不包括
            w /= t[top--];
        if (mp[i][len - 1] == ':') ///当前是循环语句
        {
            int num = mp[i][len - 2] - '0';
            top++;
            w *= num;                 ///累计循环了几次
            s[top] = p, t[top] = num; ///第top层循环语句的缩进量和循环次数
        }
        else
        {
            int num = mp[i][len - 1] - '0';
            sum += w * num;
        }
    }
    printf("%d\n", sum);

    return 0;
}
