You are given a function ff written in some basic language. The function accepts an integer value, which is immediately written into some variable xx. xx is an integer variable and can be assigned values from 00 to 232−1232−1. The function contains three types of commands:

  • for nn — for loop;
  • end — every command between "for nn" and corresponding "end" is executed nntimes;
  • add — adds 1 to xx.

After the execution of these commands, value of xx is returned.

Every "for nn" is matched with "end", thus the function is guaranteed to be valid. "for nn" can be immediately followed by "end"."add" command can be outside of any for loops.

Notice that "add" commands might overflow the value of xx! It means that the value of xx becomes greater than 232−1232−1 after some "add" command.

Now you run f(0)f(0) and wonder if the resulting value of xx is correct or some overflow made it incorrect.

If overflow happened then output "OVERFLOW!!!", otherwise print the resulting value of xx.

Input

The first line contains a single integer ll (1≤l≤1051≤l≤105) — the number of lines in the function.

Each of the next ll lines contains a single command of one of three types:

  • for nn (1≤n≤1001≤n≤100) — for loop;
  • end — every command between "for nn" and corresponding "end" is executed nntimes;
  • add — adds 1 to xx.

Output

If overflow happened during execution of f(0)f(0), then output "OVERFLOW!!!", otherwise print the resulting value of xx.

Examples

Input
9
add
for 43
end
for 10
for 15
add
end
add
end
Output
161
Input
2
for 62
end
Output
0
Input
11
for 100
for 100
for 100
for 100
for 100
add
end
end
end
end
end
Output
OVERFLOW!!!

Note

In the first example the first "add" is executed 1 time, the second "add" is executed 150 times and the last "add" is executed 10 times. Note that "for nn" can be immediately followed by "end" and that "add" can be outside of any for loops.

In the second example there are no commands "add", thus the returning value is 0.

In the third example "add" command is executed too many times, which causes xx to go over 232−1232−1.

题意:

给出for循环伪代码,计算执行add的次数(加了几次)。

思路:

很新颖的一道题,不难想到使用栈模拟。

因为栈底的值会影响栈顶的结果,因此放入累乘值来表示当前的状态,每次add只需加入栈顶的值即可。

具体实现见代码,注意判断越界。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll; string s;
stack<ll> st; int main()
{
int t,i;
ll x=,y=;
scanf("%d",&t);
st.push();
int f=;
while(t--){
scanf(" ");
cin>>s;
if(s[]=='f'){
scanf("%I64d",&x);
st.push(min(4294967296ll,x*st.top()));
}
else if(s[]=='a'){
y+=st.top();
if(y>=){
f=;
break;
}
}
else if(s[]=='e'){
st.pop();
}
}
if(f==) printf("OVERFLOW!!!\n");
else printf("%I64d\n",y);
return ;
}

最新文章

  1. [LeetCode] Department Top Three Salaries 系里前三高薪水
  2. 关于python装饰器
  3. 【转载】VS2012的打包方法
  4. WPF Freezable&ndash;How to improve your application's performances
  5. javaScript 查询字符串参数 获取
  6. LoadRunner参数数组
  7. careercup-递归和动态规划 9.9
  8. Activity(二)
  9. C++ 子类继承父类纯虚函数、虚函数和普通函数的区别
  10. arcengine导出复本
  11. Java 平时作业五
  12. invalid location of tag 解决办法
  13. Java中的equals和==的差别 以及Java中等价性和同一性的讨论
  14. 【bzoj1758】 Wc2010—重建计划
  15. 《跟老男孩学Linux运维:Web集群实战》读书笔记
  16. Unity性能优化之Draw Call(转)
  17. go omitempty 忽略类型
  18. iOS开发-UITableView常用方法
  19. k8s的Ingress
  20. WAF攻防实战

热门文章

  1. 【亲测有效】vs2017无法断点
  2. [LeetCode] 137. 只出现一次的数字,其余三次 II ☆☆☆
  3. IDEA配置maven报错解决方案
  4. scikit-learn中的机器学习算法封装——kNN
  5. windows10下安装tensorflow2.0-GPU和Cupy(不用搞CUDA+cudnn)
  6. Redis未授权访问漏洞复现及修复方案
  7. 遍历SQL SERVER中所有存储过程和触发器
  8. 0013SpringBoot处理国际化问题
  9. 《3+1团队》第七次作业:团队项目设计完善&amp;编码
  10. 【Mac】打开配置文件,添加/修改环境变量