fork download
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include<bits/stdc++.h>
  3. typedef long long ll;
  4. using namespace std;
  5. const int N = 1e4 + 5;
  6. void FASTCODE() {
  7. std::ios_base::sync_with_stdio(0);
  8. cin.tie(NULL);
  9. cout.tie(NULL);
  10. }
  11. void File() {
  12. //freopen("input.txt", "r", stdin);
  13. //freopen("output.txt", "w", stdout);
  14. }
  15. void solution() {
  16. int l;
  17. cin >> l;
  18. ll sum = 0, ans = 1;
  19. ll x;
  20. ll v = 0;
  21. ll c = pow(2, 32) - 1;
  22. stack<ll>st;
  23. bool b = 1;
  24. st.push(1);
  25. while (l--) {
  26. string s;
  27. cin >> s;
  28. if (s == "for") {
  29. cin >> x;
  30. ans *= x;
  31. //cout << ans << "\n";
  32. st.push(ans);
  33. }
  34. else if (s == "add") {
  35. // cout << ans << "\n";
  36. if (ans<0 && ans>c) {
  37. b = 0;
  38. }
  39. sum += ans;
  40. if (sum<0 && sum>c) {
  41. b = 0;
  42. }
  43. }
  44. else if (s == "end" && ans > 1) {
  45. if (!st.empty()) {
  46. st.pop();
  47. ans = st.top();
  48. }
  49. }
  50. // cout << "ans: "<<ans << " "<< "sum: "<< sum << "\n";
  51. }
  52. if (sum >= 0 && sum <= c && ans == 1 && b) {
  53. cout << sum;
  54. }
  55. else {
  56. cout << "OVERFLOW!!!";
  57. }
  58. }
  59. int main() {
  60. FASTCODE();
  61. File();
  62. solution();
  63. return 0;
  64. }
Success #stdin #stdout 0.01s 5464KB
stdin
Standard input is empty
stdout
Standard output is empty