You are given a function $f$ written in some basic language. The function accepts an integer value, which is immediately written into some variable $x$. $x$ is an integer variable and can be assigned values from $0$ to $2^{32}-1$. The function contains three types of commands:

  for $n$ — for loop;  end — every command between "for $n$" and corresponding "end" is executed $n$ times;  add — adds 1 to $x$. 

After the execution of these commands, value of $x$ is returned.

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

Notice that "add" commands might overflow the value of $x$! It means that the value of $x$ becomes greater than $2^{32}-1$ after some "add" command. 

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

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


-----Input-----

The first line contains a single integer $l$ ($1 \le l \le 10^5$) — the number of lines in the function.

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

  for $n$ ($1 \le n \le 100$) — for loop;  end — every command between "for $n$" and corresponding "end" is executed $n$ times;  add — adds 1 to $x$. 


-----Output-----

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


-----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 $n$" 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 $x$ to go over $2^{32}-1$.

Difficulty: interview

Starter code:

Solutions:
l = int(input())
a = [0] * (l+1)
b = [1] * (l+1)
st = 0
en = 1
cur = 0
for i in range(l):
    x = input()
    if x == 'add':
        a[en-1] += 1
    elif x[0] == 'f':
        d = x.split()
        v = int(d[1])
        a[en] = 0
        b[en] = v
        en += 1
    else:
        en -= 1
        a[en-1] += a[en] * b[en]
        if a[en-1] >= 2 ** 32:
            cur = 1
            break
if cur == 1 or a[0] >= 2 ** 32:
    print('OVERFLOW!!!')
else:
    print(a[0])



n = int(input())
x = 0
loops = []
for _ in range(n):
    if x >= 2**32:
        break
    l = input()
    if l.startswith('for '):
        mul = int(l[4:])
        loops.append((x, mul))
    elif l.startswith('end'):
        old_x, mul = loops.pop()
        x = old_x + mul * (x - old_x)
    else:
        x += 1
if x >= 2**32:
    print('OVERFLOW!!!')
else:
    print(x)


l = int(input())
ans = 0
nest = 0
F = []
m = 1
for _ in range(l):
    com = input()
    if com == "add":
        ans += m
        if ans >= 2**32:
            ans = "OVERFLOW!!!"
            break
    elif com == "end":
        m //= F.pop()
    else:
        if m > 2**40:
            a = 1
        else:
            a = int(com.split()[1])
        F.append(a)
        m *= a

print(ans)



def main():
    buf = input()
    n = int(buf)
    command = []
    for i in range(n):
        buf = input()
        buflist = buf.split()
        if len(buflist) == 2:
            buflist[1] = int(buflist[1])
        command.append(buflist)
    x = []
    for i in range(n):
        x.append(0)
    stack = []
    nest = 0
    for c in command:
        if c[0] == 'for':
            stack.append(c[1])
            nest += 1
        elif c[0] == 'add':
            x[nest] += 1
        else: # c[0] == 'end'
            x[nest-1] += x[nest] * stack.pop()
            x[nest] = 0
            nest -= 1
        if x[nest] >= int(2 ** 32):
            print('OVERFLOW!!!')
            return
    print(x[0])


def __starting_point():
    main()

__starting_point()

n = int(input())
pr = 0
mn = [1]
prib = [0]
b = 1
for _ in range(n):
	s = input().split()
	if s[0] == 'add':
		prib[-1] += 1
	elif s[0] == 'for':
		mn.append(int(s[1]))
		prib.append(0)
	else:
		e = prib.pop() * mn.pop()
		prib[-1] += e
		if prib[-1] > 2**32-1:
			b = 0
			break
if b:
	if prib[0] <= 2**32-1:
		print(prib[0])
	else:
		print('OVERFLOW!!!')
else:
	print('OVERFLOW!!!')

import sys
from collections import deque
input = sys.stdin.readline

l=int(input())

QUE=deque()

for q in range(l):
    QUE.append(input().split())

    while len(QUE)>=2 and QUE[-1][0]=="end" and QUE[-2][0]=="for":
        QUE.pop()
        QUE.pop()


ANS=0
Q=deque()
Q.append(1)
SUM=1

for s in QUE:
    
    if s[0]=="add":
        ANS+=SUM
    elif s[0]=="for":
        Q.append(int(s[1]))
        SUM=min(SUM*int(s[1]),1<<40)

    else:
        x=Q.pop()
        SUM//=x

    if ANS>2**32-1:
        print("OVERFLOW!!!")
        break

else:
    print(ANS)
    
    


l = int(input())
tmp = [0]
stack = [1]
for i in range(l):
	line = input().split()
	if line[0] == 'add':
		tmp[-1] += 1
		if tmp[-1] >= 2 ** 32:
			print('OVERFLOW!!!')
			return
	elif line[0] == 'for':
		stack.append(int(line[1]))
		tmp.append(0)
	else:
		t = stack.pop()
		tt = tmp.pop()
		tmp[-1] += t * tt
		if tmp[-1] >= 2 ** 32:
			print('OVERFLOW!!!')
			return

print(tmp[-1])


a = int(input())
cur = 1
last = 1
ans = 0
prev = []
while (a > 0):
    a-=1
    st = input();
    if (st[2]=='r'):
        b = st.split(' ')
        b = int(b[1])
        if (cur>=2**64):
            b = 1
        cur*=b
        prev.append(b)
    if (st[2] == 'd' and st[1] == 'd'):
        ans+=cur
    if (st[2] == 'd' and st[1] == 'n'):
        val = prev[len(prev) - 1]
        prev.pop()
        cur/=val
    if (ans >= 2**32):
        break
if (ans >= 2**32):
    print("OVERFLOW!!!")
else:
    print(int(ans))

# tzuyu <3

N = pow(2, 32)

l = int(input())
n = 0
s = []
t = []
for _ in range(l):
    i = input()
    if i == 'add':
        if t:
            t[-1] += 1
        else:
            n += 1
            if n >= N:
                import sys
                print('OVERFLOW!!!')
                return
    if i.startswith('for'):
        i = i.split(' ')
        c = int(i[1])
        s.append(c)
        t.append(0)
    if i == 'end':
        c = s.pop()
        x = t.pop()
        x *= c
        if t:
            t[-1] += x
            if t[-1] >= N:
                import sys
                print('OVERFLOW!!!')
                return
        else:
            n += x
            if n >= N:
                import sys
                print('OVERFLOW!!!')
                return

if n >= N:
    import sys
    print('OVERFLOW!!!')
    return
print(n)


temp=[0]
temp2=[1]
ju=int(pow(2,32)-1)
n=int(input())
ans=0
for i in range(n):
	t=input()
	if t=='add':
		ans+=temp2[-1]
		if temp2[-1]==-1:
			print('OVERFLOW!!!')
			return
	elif t=='end':
		temp.pop()
		temp2.pop()
	else:
		tt=t.split()
		temp.append(int(tt[-1]))
		if temp2[-1]<0:
			temp2.append(-1)
		else:
			ttt=temp2[-1]*int(tt[-1])
			if ttt>ju:
				temp2.append(-1)
			else:
				temp2.append(temp2[-1]*int(tt[-1]))
		
if ans>ju:
	print('OVERFLOW!!!')
else:
	print(ans)

n = int(input())
L = []

for _ in range(n):
    s = input()
    L.append(s)

S = [(0, 1)]
k = 0

zeta = 2**32-1
fine = True

for i in range(n):
    if 'add' in L[i]:
        if (S[-1][0] == 1):
            fine = False
            break
        k += S[-1][1]
    elif 'end' in L[i]:
        S.pop()
    elif 'for' in L[i]:
        if S[-1][0] == 1:
            S.append(S[-1])
            continue
        x = int(L[i].split()[1])*S[-1][1]
        if x > zeta:
            S.append((1, 0))
        else:
            S.append((0, x))
    if k > zeta:
        fine = False
        break
if fine:
    print(k)
else:
    print('OVERFLOW!!!')




import math
n=int(input())
l=1
l1=[]
ans=0
d=math.pow(2,32)-1
f=False
for i in range(n) :
    s=input().split()
    if s[0]=="add" :
        if f :
            print("OVERFLOW!!!")
            return
        ans+=l
    if s[0]=="for" :
        w=int(s[1])
        if d<l*w :
            f=True
            l1.append([w,0])
        else:
            l*=w
            l1.append([w,1])
        
    if s[0]=="end" :
        if l1[-1][1]==1 :
            l/=l1[-1][0]
        else :
            if l1[-2][1]==1 :
                f=False
        l1.pop()
        
    if ans>d :
        print("OVERFLOW!!!")
        return
print(int(ans))
        
        
    


n = int(input())
inf = 2**32 - 1
x = 0
mult = [1]
uk = 0
amount = 1
for i in range(n):
    l = list(input().split())
    if l[0] == "for":
        mult.append(int(l[1]))
    if l[0] == "end":
        if (uk + 1 == len(mult)):
            amount //= mult[-1]
        mult.pop()
        if (uk == len(mult)): uk -= 1
    if l[0] == "add":
        while uk < len(mult) - 1:
            uk += 1
            amount *= mult[uk]
            if amount > inf:
                print('OVERFLOW!!!')
                return
        x += amount
        if (x > inf):
            print('OVERFLOW!!!')
            return
print(x)

t = int(input())
st = [1]
x = 0
OVER = (1 << 32) - 1
for _ in range(t):
    command = input().split(" ")
    if command[0] == "add":
        x += st[-1]
        if x > OVER:
            print("OVERFLOW!!!")
            return
    elif command[0] == "for":
        number = int(command[1])
        st.append(min(OVER + 1, st[-1] * number))
    elif command[0] == "end":
        st.pop(-1)
print(x)
    


lim = 2 ** 32 - 1
n = int( input() )
ans = 0
f = [ 1 ]
a = [ 0 ]
ov = False
for l in range(n):
    i = input()
    if i == 'add':
        if a[ -1 ] < lim:
            a[ -1 ] += 1
        else:
            ov = True
            break
    elif i[ :3 ] == 'for':
        f.append( int(i[ 4: ]) )
        a.append( 0 )
    else:
        if a[ -1 ] == 0:
            f.pop()
            a.pop()
            continue
        if lim / f[ -1 ] < a[ -1 ]:
            ov = True
            break
        sm = f.pop() * a.pop()
        if lim - sm < a[ -1 ]:
            ov = True
            break
        a[ -1 ] += sm

if not ov:
    print( a[ -1 ] )
else:
    print( "OVERFLOW!!!")


l = int(input())

com = []
for i in range(l):
	s = input()
	com += [s]

def parse(commands):
	stack = []
	adder = 0
	for s in commands:
		if s.startswith("for"):
			x = int(s.split()[1])
			stack.append((x, adder))
			adder = 0
		elif s=="end":
			old_x, old_adder = stack.pop()
			adder = old_adder + adder * old_x
			if adder > 2**32-1:
				break
		else:
			adder += 1
	return adder
adder = parse(com)

if adder > 2**32-1:
	print("OVERFLOW!!!")
else:
	print(adder)

l=int(input())
a=[]
ans=0
b=[]
for i in range(l+5):
	a.append(0)
	b.append(0)
temp=1
ii=1
a[0]=1
b[0]=1
g=2**32-1
over=0
for i in range(l):
	x=list(input().split())
	if(x[0]=='add'):
		ans+=b[ii-1]*1
	elif(x[0]=='for'):
		b[ii]=int(x[1])*b[ii-1]
		a[ii]=int(x[1])
		if(b[ii]>g):
			b[ii]=g+2
		ii+=1
	elif(x[0]=='end'):
		temp=b[ii-1]//a[ii-1]
		ii-=1
	if(ans>g):
		over=1
		break
if(over==1):
	print("OVERFLOW!!!")
else:
	print(ans)

n= int(input())
a=[0]*(n//2+1)
k=[0]*(n//2+1)
j=0
df=False
for i in range (n):
    str=input().split()
    if str[0]=='add':
        a[j]+=1
    if str[0]=='for':
        j+=1
        k[j]=int(str[1])
    if str[0]=='end':
        j-=1
        a[j]+=a[j+1]*k[j+1]
        a[j+1]=0
    if a[j]>=4294967296:
        df=True
        
        break
if df==True:
    print('OVERFLOW!!!')
else:
    print(a[0])


k=0
ad=[]
res=0
for _ in range(int(input())):
	s=input()
	if res>2**32-1 :
		break
	if len(ad)>0:
		if (res+ ad[-1][0]*ad[-1][1])>2**32-1 :
			res =res+ (ad[-1][0]*ad[-1][1])
			break

	if s[:3]=='add':
		if len(ad)>0:
			ad[-1][0]+=1
		else:
			res+=1
	elif s[:3]=='end':
		k=ad[-1][0]*ad[-1][1]
		ad.pop()
		if len(ad)>0:
			ad[-1][0]+=k
		else:
			res+=k
		k=0
	else:
		p=int(s[4:])
		ad.append([0,p])
	# print(ad,res,k)
if res>2**32-1:
	print('OVERFLOW!!!')
else:
	print(res)

t = int(input())
r = 0
s = [0] * 10**5
ss = 0
for _ in range(t):
    x = input().split()
    if x[0] == 'add':
        r += 1
    elif x[0] == 'for':
        s[ss] = (r, int(x[1]))
        ss += 1
        r = 0
    elif x[0] == 'end':
        ss -= 1
        r_old, k = s[ss]
        r = r_old + r * k
        if r >= 2**32:
            print("OVERFLOW!!!")
            break
else:
    print(r if r < 2**32 else "OVERFLOW!!!")

ov = 2**32-1
cnt = 1
x = 0
t = int(input())
st = []
for i in range(t):
	s = input().split()
	if s[0] == "for":
		if len(st) == 0:
			st.append(int(s[1]))
		else:
			if st[len(st) - 1] != -1 and st[len(st) - 1] * int(s[1]) < ov:
				st.append(st[len(st) - 1] * int(s[1]))
			else:
				st.append(-1)
	elif s[0] == "end":
		st.pop()
	else:
		if len(st) != 0 and st[len(st) - 1] == -1:
			x = 2**33
			break
		elif len(st) == 0:
			x += 1
		else:
			x += st[len(st) - 1]

if (x > ov):
	print("OVERFLOW!!!")
else:
	print(x)


from collections import defaultdict as dd
import math
import sys
def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return list(map(int, input().split()))

def lm():
	return list(map(int, input().split()))



q=nn()


x=0
forstack=[]
forproduct=1
badfors=0
willoverflow=False
bad=0
for _ in range(q):


	l=input().split(' ')
	#print(l)
	
	if len(l)==2:
		if willoverflow: 		
			forstack.append(int(l[1]))
			badfors+=1
		else:
			forstack.append(int(l[1]))
			forproduct*= int(l[1])
			if x+forproduct>2**32-1:
				willoverflow=True
				badfors=1

	elif l[0]=='add':
		if willoverflow:
			print("OVERFLOW!!!")
			bad=1			
			break
			#return
		x+=forproduct
		if x>2**32-1:
			print("OVERFLOW!!!")
			bad=1			
			break
			#return

		
	elif l[0]=='end':
		p=forstack.pop()
		if willoverflow:
			badfors-=1

			if badfors==0:
				forproduct//=p
				willoverflow=False
		else:
			forproduct//=p

if bad==0:
	print(x)
	







T = int(input())
ans = 0
top = -1
stack = []
times = 1
j = 0
bj = 0
while T>0:
    T = T - 1
    s = input().strip().split()
    if len(s)==1:
        if s[0]=="add":
            ans+=times
        else:
            if j==0:
                times//=stack[top]
                top-=1
            else:
                j-=1
    else:
        x=int(s[1])
        
        if times<=4294967295:
            times*=x
            top+=1
            if top>=len(stack):
                stack.append(x)
            else:
                stack[top]=x
        else:
            j+=1
        
    if ans>4294967295:
        bj=1
        break
if bj==0:
    print(ans)
else:
    print("OVERFLOW!!!")