fork download
  1. #include <bits/stdc++.h>
  2. #include <string>
  3. using namespace std;
  4. #define ll long long
  5. #define dd double
  6. #define ld long double
  7. #define pi 3.14159265359
  8. #define ull unsigned long long
  9. #define yes cout<<"YES\n"
  10. #define no cout<<"NO\n"
  11. #define el "\n"
  12. #define Arwa ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
  13. #define fix(x) cout<<fixed<<setprecision(x)
  14. ll gcd(ll a,ll b) {return b==0?a:gcd(b,a%b);}
  15. ll lcm(int a,int b) {return a/gcd(a,b)*b;}
  16. bool prime(ll n)
  17. {
  18. if(n==2) return true;
  19. if(n%2==0||n==1) return false;
  20. else { for(ll i=3; i*i<=n; i+=2) {if(n%i==0) return false;}}return true;
  21. }
  22. //4294967295
  23. //here we go again
  24. int main()
  25. {
  26. Arwa
  27. int t=1;
  28. ll x=0,max=1;
  29. stack<ll>st;
  30. cin>>t;
  31. while(t--)
  32. {
  33. string s;
  34. cin>>s;
  35. if(s=="add"&&st.empty()) x+=1;
  36. else if(s=="add"&&!st.empty()) x+=max;
  37. else if (s=="for")
  38. {
  39. int x;
  40. cin>>x;
  41. st.push(x);
  42. max*=x;
  43. }
  44. else if (s=="end")
  45. {
  46. max/=st.top();
  47. st.pop();
  48. }
  49. if(x+max>4294967295)
  50. {
  51. cout<<"OVERFLOW!!!";
  52. return 0;
  53. }
  54. } cout<<x<<el;
  55. return 0;
  56. }
  57.  
  58.  
  59.  
  60.  
  61.  
Success #stdin #stdout 0.01s 5264KB
stdin
Standard input is empty
stdout
0