//语言解析,模拟法,顺序表实现简单栈结构
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
/*
typedef struct Node {
int data;
Node* next;
}Node,*linklist;
*/
string str;
const int N = 100;
int space_stack[N];//存储当前层语言前空白数
int loop_stack[N];//当前层的循环数
int top = 0;//栈顶元素
int main() {
int space = 0;//每行前空格数
int lnum = 1;//总循环次数
int ans = 0;
space_stack[0] = -1;
loop_stack[0] = 1;
freopen("C:\\Users\\xutianci\\OneDrive\\Desktop\\prog.txt","r",stdin);
//从文本中获取输入
//首行字符A = 0
while(getline(cin,str)){//读取行数据
int len = str.size();
space = 0;//每次读取space重新计数
while (str[space] == ' ') {
space++;
}
while(space<=space_stack[top]) {
lnum /= loop_stack[top--];//当出现空格数小于或等于上一repeat行时,退出一层循环
}
if (str[len-1] == ':') {
int k = str[len - 2] - '0';//当前循环次数
lnum *= k;
top++;
space_stack[top] = space;
loop_stack[top] = k;
}
else {
int k = str[len - 1] - '0';
ans += lnum * k;
}
}
std::cout << ans << endl;
return 0;
}