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$.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Data structures

Implementation


Solutions:
(x, s) = (0, [1])
for t in map(input, ' ' * int(input())):
	if 'e' < t[0]:
		s += [min(10000000000.0, s[-1] * int(t[4:]))]
	elif 'b' > t[0]:
		x += s[-1]
	else:
		s.pop()
print(['OVERFLOW!!!', x][x < 2 ** 32])


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
t = int(sys.stdin.readline())
n = 0
f = [1]
m = 2 ** 32
for i in range(t):
	s = sys.stdin.readline()
	if s[0] == 'a':
		n += f[-1]
		if n >= m:
			n = 'OVERFLOW!!!'
			break
	elif s[0] == 'f':
		f.append(min(f[-1], m) * int(s[4:]))
	else:
		f.pop()
print(n)


t = int(input())
com = []
for _ in range(t):
	a = input().split()
	com.append(a)
x = 0
forflag = 0
temp = 0
shit = 0
high = pow(2, 32) - 1
a = [0 for i in range(int(100000.0 + 1))]
le = 0
mul = 1
indi = 0
poo = 0
check = [0 for i in range(int(100000.0 + 1))]
for i in range(t):
	if com[i][0] == 'add':
		if forflag == 0:
			x += 1
		else:
			for j in range(indi, le):
				mul *= a[j]
				check[j] = 1
				if mul > high:
					shit = 1
					break
			if shit == 1:
				break
			x += mul
			indi = le
	elif com[i][0] == 'end':
		forflag -= 1
		if check[le - 1] == 1:
			mul //= a[le - 1]
			check[le - 1] = 0
			if mul == 0:
				mul = 1
			indi -= 1
		le -= 1
	else:
		n = int(com[i][1])
		a[le] = n
		le += 1
		forflag += 1
	if x > high:
		shit = 1
		break
if shit == 1:
	print('OVERFLOW!!!')
else:
	print(x)


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!!!')
			exit()
	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!!!')
			exit()
print(tmp[-1])


l = int(input())
x = [1]
ans = 0
po = 2 ** 32 - 1
for i in range(l):
	p = input()
	if p[0] == 'f':
		t = x[-1] * int(p[4:])
		if t > po:
			t = po + 1
		x.append(t)
	elif p[0] == 'e':
		x.pop()
	elif len(x) == 1:
		ans += 1
	else:
		ans += x[-1]
		if ans > po:
			ans = 'OVERFLOW!!!'
			break
	if ans > po:
		ans = 'OVERFLOW!!!'
		break
print(ans)


ADD_COMMAND = 'add'
END_COMMAND = 'end'
OVERFLOW_ERROR = 'OVERFLOW!!!'
MAX_VALUE = 2 ** 32 - 1
x = 0
n = int(input())
valid_output = True
stack = [1]
temp = 0
for i in range(n):
	command = input()
	if command == ADD_COMMAND:
		x += stack[-1]
	elif command == END_COMMAND:
		stack.pop()
	else:
		loop_count = int(command.split(' ')[1])
		new_value = loop_count * stack[-1]
		stack.append(min(MAX_VALUE + 1, new_value))
	if x > MAX_VALUE:
		valid_output = False
		break
if valid_output:
	print(x)
else:
	print(OVERFLOW_ERROR)


n = int(input())
last = [1]
MAX = 2 ** 32 - 1
ans = 0
for i in range(n):
	s = input()
	if s[0] == 'f':
		last.append(min(last[-1] * int(s[4:]), MAX + 1))
	elif s[0] == 'e':
		last.pop()
	else:
		ans += last[-1]
print('OVERFLOW!!!' if ans > MAX else ans)


stack = [1]
add_tmp = 0
result = 0
tmp = 0
cc = 0
check = True
li = [0 for i in range(100001)]
for _ in range(int(input())):
	comnd = input().split(' ')
	if comnd[0] == 'for':
		num = comnd[1]
		stack.append(num)
		cc += 1
	elif comnd[0] == 'add':
		if cc == 0:
			li[cc] += 1
		else:
			stack.append('add')
	elif comnd[0] == 'end':
		a = stack.pop()
		while a.isalpha():
			li[cc] += 1
			a = stack.pop()
		cc -= 1
		a = int(a)
		li[cc] = li[cc] + li[cc + 1] * a
		li[cc + 1] = 0
		if li[cc] >= 2 ** 32:
			check = False
			break
if li[0] >= 2 ** 32 or check == False:
	print('OVERFLOW!!!')
else:
	print(li[0])


ub = 2 ** 32
r = 0
stack = [1]
overflow = False
for _ in range(int(input())):
	s = input()
	if not overflow and s.startswith('add'):
		new_r = r + stack[len(stack) - 1]
		if new_r >= ub or stack[len(stack) - 1] == 0:
			overflow = True
		else:
			r = new_r
	elif s.startswith('for'):
		inc = int(s.split()[1]) * stack[len(stack) - 1]
		if inc >= ub:
			inc = 0
		stack.append(inc)
	elif s.startswith('end'):
		stack.pop()
print(r if not overflow else 'OVERFLOW!!!')


from collections import defaultdict, OrderedDict, Counter
from sys import stdin, stdout
from bisect import bisect_left, bisect_right
from queue import Queue, PriorityQueue
from heapq import heapify, heappop, heappush
from statistics import median
from math import gcd, sqrt, floor, factorial, ceil, log2, log10
import fractions
import copy
from copy import deepcopy
import sys
import io
sys.setrecursionlimit(10 ** 8)
import math
import os
import bisect
import collections
mod = pow(10, 9) + 7
import random
from random import random, randint, randrange

def ncr(n, r, p=mod):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % p
		den = den * (i + 1) % p
	return num * pow(den, p - 2, p) % p

def normalncr(n, r):
	r = min(r, n - r)
	count = 1
	for i in range(n - r, n + 1):
		count *= i
	for i in range(1, r + 1):
		count //= i
	return count
inf = float('inf')
adj = defaultdict(set)
visited = defaultdict(int)

def addedge(a, b):
	adj[a].add(b)
	adj[b].add(a)

def bfs(v):
	q = Queue()
	q.put(v)
	visited[v] = 1
	while q.qsize() > 0:
		s = q.get_nowait()
		print(s)
		for i in adj[s]:
			if visited[i] == 0:
				q.put(i)
				visited[i] = 1

def dfs(v, visited):
	if visited[v] == 1:
		return
	visited[v] = 1
	print(v)
	for i in adj[v]:
		dfs(i, visited)

def reverse_bisect_right(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x > a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

def reverse_bisect_left(a, x, lo=0, hi=None):
	if lo < 0:
		raise ValueError('lo must be non-negative')
	if hi is None:
		hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if x >= a[mid]:
			hi = mid
		else:
			lo = mid + 1
	return lo

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

def get_str_list_in_int():
	return [int(i) for i in list(input())]

def get_str_list():
	return list(input())

def get_map():
	return map(int, input().split())

def input_int():
	return int(input())

def matrix(a, b):
	return [[0 for i in range(b)] for j in range(a)]

def swap(a, b):
	return (b, a)

def find_gcd(l):
	a = l[0]
	for i in range(len(l)):
		a = gcd(a, l[i])
	return a

def is_prime(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return 0
	return 1

def prime_factors(n):
	sqrta = int(sqrt(n))
	for i in range(2, sqrta + 1):
		if n % i == 0:
			return [i] + prime_factors(n // i)
	return [n]
nc = 'NO'
yc = 'YES'
ns = 'No'
ys = 'Yes'
t = 1

def get_mul():
	pro = 1
	for i in dict:
		pro *= pow(i, dict[i])
		if pro >= pow(2, 32):
			return -1
	return pro

def reduce(a):
	dict[a] -= 1
	if dict[a] == 0:
		dict.pop(a)
for i in range(t):
	add = 0
	count = [1]
	n = int(input())
	dict = defaultdict(int)
	dict[1] = 1
	overflow = 0
	for i in range(n):
		if add >= pow(2, 32):
			overflow = 1
		if overflow:
			input()
			continue
		l = list(input().split())
		if len(l) == 2:
			l[1] = int(l[1])
			count.append(l[1])
			dict[l[1]] += 1
		elif l[0] == 'add':
			addition = get_mul()
			if addition == -1:
				overflow = 1
				continue
			add += addition
		elif l[0] == 'end':
			a = count.pop()
			reduce(a)
	if add >= pow(2, 32):
		overflow = 1
	if overflow:
		print('OVERFLOW!!!')
	else:
		print(add)


import sys
runs = int(sys.stdin.readline().rstrip())
tot = 0
loops = [0] * runs
oneCount = [0] * runs
counter = 0
flag = False
for x in range(runs):
	line = sys.stdin.readline().rstrip()
	if line[:3] == 'for':
		if loops[counter - 1] == 1 and int(line[4:]) == 1:
			oneCount[counter] += 1
		else:
			loops[counter] = int(line[4:])
			counter += 1
	elif line[:3] == 'add':
		num = 1
		for i in range(counter):
			if num > (1 << 32) - 1:
				flag = True
				break
			num *= loops[i]
		if flag:
			break
		tot += num
	elif line[:3] == 'end':
		if loops[counter - 1] == 1 and oneCount[counter - 1] != 0:
			oneCount[counter - 1] -= 1
		else:
			loops[counter - 1] = 0
			counter -= 1
	if tot > (1 << 32) - 1:
		flag = True
		break
if flag:
	print('OVERFLOW!!!')
else:
	print(tot)


import sys
L = int(sys.stdin.readline().strip())
x = 0
i = 1
m = []
v = True
l = 0
y = 0
while l < L:
	w = sys.stdin.readline().strip()
	if v == True and y == 0:
		if w == 'add':
			x = x + i
		elif w == 'end':
			i = i // m.pop()
		else:
			m.append(int(w.split()[1]))
			i = i * m[-1]
		if x > 2 ** 32 - 1:
			v = False
		if i > 2 ** 32 - 1:
			y = y + 1
	elif v == True and y > 0:
		if w == 'add':
			v = False
		elif w == 'end':
			y = y - 1
			if y == 0:
				i = i // m.pop()
		else:
			y = y + 1
	l = l + 1
if v == True:
	print(x)
else:
	print('OVERFLOW!!!')


limit = 2 ** 32
queue = []
stack = [0]
inputs = int(input())
for i in range(inputs):
	commands = list(map(str, input().rstrip().split()))
	if commands[0] == 'for':
		stack.append(0.0)
		queue.append(int(commands[1]))
	elif commands[0] == 'add':
		stack[len(stack) - 1] = stack[len(stack) - 1] + 1
	elif commands[0] == 'end':
		stack[len(stack) - 1] = stack.pop() * queue.pop() + stack[len(stack) - 1]
if stack[0] < limit:
	print(int(stack[0]))
else:
	print('OVERFLOW!!!')


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left, bisect_right
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections as col
import math, string

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7
LIM = 2 ** 32

def solve():
	L = getInt()
	x = 0
	queue = [1]
	for l in range(L):
		com = getStr()
		if com[:3] == 'for':
			y = int(com[4:])
			queue.append(min(LIM, y * queue[-1]))
		elif com[:3] == 'add':
			x += queue[-1]
		else:
			queue.pop()
	return x if x < LIM else 'OVERFLOW!!!'
print(solve())


n = int(input())
f = 1
x = 0
k = 0
ch = pow(2, 32) - 1
po = [1]
for i in range(n):
	s = input()
	if s[0] == 'f':
		if po[-1] != -1 and po[-1] * int(s[4:]) < ch:
			po.append(po[-1] * int(s[4:]))
		else:
			po.append(-1)
	elif s[0] == 'e':
		po.pop()
	elif len(po) == 1 and x + 1 < ch:
		x += 1
	elif po[-1] == -1:
		k = 1
		break
	else:
		x += po[-1]
	if x > ch:
		k = 1
		break
if k == 1:
	print('OVERFLOW!!!')
else:
	print(x)


import sys
t = int(input())
a = []
for i in range(t):
	s = sys.stdin.readline().strip()
	if s[:3] != 'for':
		k = 0
	else:
		k = int(s[4:])
	a.append([s[:3], k])
f = 1
e = 0
p = []
o = 2 ** 32 - 1
q = 0
j = 0
an = 0
while j < t:
	if a[j][0] == 'for' and f * a[j][1] <= o and (e == 0):
		f = f * a[j][1]
		p.append(a[j][1])
	elif a[j][0] == 'for':
		e = e + 1
	elif a[j][0] == 'add' and e > 0:
		q = 1
		break
	elif a[j][0] == 'add' and e <= 0:
		an = an + f
	elif e > 0:
		e = e - 1
	else:
		f = f // p[-1]
		p.pop()
	j = j + 1
	if an > o:
		q = 1
		break
if q == 0:
	print(an)
else:
	print('OVERFLOW!!!')


s = [0]
limit = 2 ** 32
q = []
num_inputs = int(input())
counter = 0
while counter < num_inputs:
	instructions = input().split(' ')
	command = instructions[0]
	if command == 'for':
		s.append(0.0)
		q.append(int(instructions[1]))
	elif command == 'add':
		s[-1] = s[-1] + 1
	elif command == 'end':
		s[-1] = s.pop() * q.pop() + s[-1]
	counter += 1
if s[0] < limit:
	print(int(s[0]))
else:
	print('OVERFLOW!!!')


import sys
input = sys.stdin.readline
from math import *
n = int(input())
pro = [1 for i in range(n + 5)]
j = 0
c = 0
for i in range(n):
	a = [x for x in input().split()]
	if a[0][0] == 'f':
		if j == 0:
			pro[j] = int(a[1])
			j += 1
		else:
			if pro[j - 1] == -1:
				pro[j] = -1
			else:
				pro[j] = pro[j - 1] * int(a[1])
			if pro[j] >= 2 ** 32:
				pro[j] = -1
			j += 1
	elif a[0][0] == 'a':
		if j == 0:
			c += 1
		else:
			if pro[j - 1] < 0:
				print('OVERFLOW!!!')
				exit(0)
			c += pro[j - 1]
	else:
		pro[j - 1] = 1
		j -= 1
	if pro[j - 1] >= 2 ** 32 or c >= 2 ** 32:
		print('OVERFLOW!!!')
		exit(0)
print(c)


import sys
data = []
inf = 1 << 32
a = [0]
for j in range(int(input())):
	com = input()
	if com[0] == 'f':
		data.append(int(com[4:]))
		a.append(0)
	elif com[0] == 'e':
		q = a.pop() * data.pop()
		a[-1] += q
	else:
		a[-1] += 1
	if a[-1] >= inf:
		print('OVERFLOW!!!')
		sys.exit()
print(a[0])


n = int(input())
ans = 0
stak = [1]
maxz = 2 ** 32
for i in range(n):
	s = input().split()
	if s[0] == 'add':
		ans += stak[-1]
	elif s[0] == 'for':
		s = int(s[1])
		stak.append(min(s * stak[-1], maxz))
	else:
		stak.pop()
	if ans >= maxz:
		ans = 'OVERFLOW!!!'
		break
print(ans)


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
c = 1
ans = 0
d = [0] * n
t = -1
f = 0
for i in range(n):
	p = input()
	if p == 'add':
		if f != 1:
			ans += c
		if f == 1 or ans > 2 ** 32 - 1:
			print('OVERFLOW!!!')
			sys.exit(0)
	elif p == 'end':
		if d[t] != -1:
			c /= d[t]
		if c <= 2 ** 32 - 1:
			f = 0
		t -= 1
	else:
		(a, b) = map(str, p.split())
		if f != 1:
			d[t + 1] = int(b)
		else:
			d[t + 1] = -1
		t += 1
		if f != 1:
			c *= int(b)
		if c > 2 ** 32 - 1:
			f = 1
if ans > 2 ** 32 - 1:
	print('OVERFLOW!!!')
else:
	print(int(ans))


import sys
input = sys.stdin.readline
l = int(input())
ans = 0
depth = [0 for i in range(l + 1)]
forcount = [0 for i in range(l + 1)]
flag = 1
count = 0
for i in range(l):
	a = list(input().split())
	if a[0] == 'add':
		depth[count] += 1
	elif a[0] == 'end':
		count -= 1
		depth[count] += depth[count + 1] * forcount[count + 1]
		forcount[count + 1] = 0
		depth[count + 1] = 0
	else:
		count += 1
		k = int(a[1])
		forcount[count] = k
	if depth[count] > 2 ** 32 - 1:
		flag = 0
		for j in range(l - 1 - i):
			input()
		break
if flag == 1:
	print(depth[0])
else:
	print('OVERFLOW!!!')


n = int(input())
commands = []
x = 0
forLoops = []
multiplierValue = 1
for i in range(n):
	command = input()
	commands.append(command)
overFlowFlag = False
forOverFlow = False
forOverFlowCount = 0
for command in commands:
	commandType = command[:3]
	if commandType == 'add':
		if forOverFlow:
			overFlowFlag = True
			break
		x += multiplierValue
	elif commandType == 'for':
		if forOverFlow:
			forOverFlowCount += 1
			continue
		newMultiplierValue = int(command[4:])
		if x + newMultiplierValue * multiplierValue > 2 ** 32 - 1:
			forOverFlow = True
			forOverFlowCount += 1
			continue
		forLoops.append(newMultiplierValue)
		multiplierValue = multiplierValue * newMultiplierValue
	else:
		if forOverFlow:
			forOverFlowCount -= 1
			if forOverFlowCount == 0:
				forOverFlow = False
			continue
		multiplierValue = multiplierValue // forLoops[-1]
		forLoops.pop()
	if x > 2 ** 32 - 1:
		overFlowFlag = True
		break
if overFlowFlag:
	print('OVERFLOW!!!')
else:
	print(x)


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]))
		elif 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()
	elif 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)


limit = 4294967295
lines = int(input())
ans = 0
stackWith = []
stackWithout = []
donts = 0
for l in range(lines):
	line = input()
	if line == 'add':
		if not stackWith:
			ans += 1
		else:
			add = 1
			for num in stackWithout:
				add *= num
			ans += add
			if ans > limit:
				break
	elif line == 'end':
		if stackWith:
			if stackWith.pop() != 1:
				stackWithout.pop()
	else:
		addThis = int(line[4:])
		if addThis == 1:
			stackWith.append(addThis)
		else:
			stackWith.append(addThis)
			stackWithout.append(addThis)
if ans > limit:
	print('OVERFLOW!!!')
else:
	print(ans)


import atexit
import io
import sys
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())
T = int(input())
stk = [None] * 100005
stk[0] = 1
top = 0
ans = 0
for turn in range(T):
	inp = input().split()
	if inp[0] == 'add':
		ans += stk[top]
	if inp[0] == 'for':
		stk[top + 1] = stk[top] * int(inp[1])
		if stk[top + 1] > 2 ** 33:
			stk[top + 1] = 2 ** 33
		top += 1
	if inp[0] == 'end':
		top -= 1
if ans > 2 ** 32 - 1:
	print('OVERFLOW!!!')
else:
	print(ans)


n = int(input())
x = 0
a = [1]
incrementer = 1
for i in range(n):
	inp = input()
	command = inp
	if inp.split()[0] == 'for':
		value = int(inp.split()[1])
		a.append(min(4294967296, value * a[-1]))
	elif command == 'add':
		x += a[-1]
		if x >= 4294967296:
			x = 'OVERFLOW!!!'
			break
	elif command == 'end':
		value = a.pop()
print(x)


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)


l = int(input())
m = 2 ** 32
add = [0]
f = []
for i in range(l):
	s = input().split(' ')
	c = s[0]
	if c == 'for':
		add.append(0.0)
		f.append(int(s[1]))
	elif c == 'add':
		add[-1] += 1
	elif c == 'end':
		add[-1] = add.pop() * f.pop() + add[-1]
if add[0] < m:
	print(int(add[0]))
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!!!')
			exit()
		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]
		elif l1[-2][1] == 1:
			f = False
		l1.pop()
	if ans > d:
		print('OVERFLOW!!!')
		exit()
print(int(ans))


n = int(input())
mul = 1
s = 0
x = 0
l2 = []
fl = 0
tag = 0
count = 0
for _ in range(n):
	y = input()
	if fl == 0:
		l1 = y.split(' ')
		if l1[0] == 'for':
			if tag == 0:
				if mul * int(l1[1]) > 2 ** 32 - 1:
					tag = 1
					count += 1
				else:
					mul *= int(l1[1])
					l2 += [int(l1[1])]
			else:
				count += 1
		elif l1[0] == 'end':
			if count > 0:
				count -= 1
				if count == 0:
					tag = 0
			else:
				mul = mul // l2[-1]
				l2.pop()
		elif tag == 1:
			fl = 1
		else:
			x += mul
			if x > 2 ** 32 - 1:
				fl = 1
if fl == 1:
	print('OVERFLOW!!!')
else:
	print(x)


t = int(input())
stack = []
stack.append(1)
ans = 0
mm = 1 << 32
for i in range(t):
	s = list(map(str, input().split()))
	if s[0] == 'add':
		ans += stack[-1]
	elif s[0] == 'for':
		k = int(s[1])
		stack.append(min(mm, k * stack[-1]))
	else:
		stack.pop()
if ans >= mm:
	print('OVERFLOW!!!')
	exit()
print(ans)


n = int(input())
cycles = []
ans = 0
overflow = 2 ** 32
mull = 1
for i in range(n):
	now_cmd = input()
	if now_cmd == 'add':
		if cycles:
			ans += cycles[-1]
		else:
			ans += 1
		if ans > overflow:
			break
	elif now_cmd == 'end':
		cycles.pop()
	else:
		cycle = now_cmd.split()
		if cycles:
			cycles.append(min(cycles[-1] * int(cycle[1]), overflow))
		else:
			cycles.append(int(cycle[1]))
if ans < overflow:
	print(ans)
else:
	print('OVERFLOW!!!')


INF = int((1 << 32) - 1)
e = int(input())
f = [1]
v = [0]
ans = 0
curr = 0
while e:
	e -= 1
	s = input()
	if s[0] == 'f':
		f.append(int(s[4:]))
		v.append(min(curr, INF + 1))
		curr = 0
	elif s[0] == 'a':
		curr += 1
	else:
		curr = v.pop() + curr * f.pop()
	if curr > INF:
		ans = 'OVERFLOW!!!'
		break
	else:
		ans = curr
res = ans
print(res)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
l = int(input())
z = []
val = 0
for i in range(l):
	x = input().strip('\n')
	if x == 'add':
		if z:
			if z[-1][0] == 'add':
				z[-1][1] += 1
			else:
				z.append(['add', 1])
		else:
			z.append(['add', 1])
	elif 'f' in x:
		(f, n) = x.split()
		n = int(n)
		z.append([f, n])
	elif z[-1][0] == 'for':
		z.pop()
	else:
		r = 0
		while True:
			last = z.pop()
			if last[0] == 'for':
				r *= last[1]
				break
			else:
				r += last[1]
		z.append(['add', r])
for i in z:
	val += i[1]
if val <= 2 ** 32 - 1:
	print(val)
else:
	print('OVERFLOW!!!')


x = 0
for s in [[1.0]] * int(input()):
	(t, c) = (input(), s.pop())
	if 'f' < t:
		s += [c, c * int(t[4:])]
	elif 'e' > t:
		x += c
		s += [c]
print(['OVERFLOW!!!', '%.f' % x][x < 2 ** 32])


cnt = 1 << 32
l = int(input().strip())
ans = 0
array = []
multiply = [1]
for i in range(l):
	line = input().strip()
	if line[0] == 'f':
		multiply.append(min(cnt, multiply[-1] * int(line[3:])))
		array.append(int(line[3:]))
	elif line[0] == 'e':
		multiply.pop()
		array.pop()
	elif line[0] == 'a':
		ans += multiply[-1]
if ans >= cnt:
	print('OVERFLOW!!!')
else:
	print(int(ans))


from collections import deque
n = int(input())
p = 1
r = deque()
r.append(1)
m = 0
for i in range(n):
	s = input()
	if s[:3] == 'for':
		(_, q) = s.split()
		q = int(q)
		x = r.pop()
		r.append(x)
		r.append(min(2 ** 32, x * q))
	elif s[:3] == 'end':
		r.pop()
	else:
		x = r.pop()
		m += x
		r.append(x)
if m >= 2 ** 32:
	print('OVERFLOW!!!')
else:
	print(m)


n = int(input())
mx = 2 ** 32
(x, flag) = (0, 0)
buf = []
pr = [1]
for i in range(n):
	inp = input().split()
	if flag == 1:
		continue
	if inp[0] == 'add':
		if x + pr[0] >= mx or len(pr) > 1:
			print('OVERFLOW!!!')
			flag = 1
		x += pr[0]
	elif inp[0] == 'for':
		ch = int(inp[1])
		if pr[-1] * ch >= mx:
			pr.append(1)
		pr[-1] *= ch
		buf.append(ch)
	else:
		pr[-1] /= buf[-1]
		if pr[-1] == 1 and len(pr) > 1:
			pr.pop()
		buf.pop()
if flag == 0:
	print(int(x))


import collections
dq = collections.deque([1])
n = int(input())
k = 0
num_add = 0
time = 1
over = False
for i in range(n):
	cmd = input()
	if cmd == 'add':
		k += dq[-1]
	elif cmd == 'end':
		dq.pop()
	else:
		time = int(cmd[4:])
		time *= dq[-1]
		if time < 2 ** 32:
			dq.append(time)
		else:
			dq.append(2 ** 32)
print(k if k < 2 ** 32 else 'OVERFLOW!!!')


flow = 2 ** 32 - 1
lines = []
n = int(input())
for i in range(n):
	lines.append(input().strip().split())
x = 0
i = 0
stack = []
g = 0
while i < len(lines):
	if x > flow:
		g = 1
		break
	if len(stack) == 1 and stack[0][0] == '$':
		x += stack[0][1]
		stack.pop()
	elif len(stack) >= 1:
		if lines[i][0] == 'end':
			temp = 0
			a = stack.pop()
			while stack and a[0] != 'for':
				if a[0] == 'add':
					temp += 1
				elif a[0] == '$':
					temp += a[1]
				a = stack.pop()
			temp *= int(a[1])
			if temp > flow:
				g = 1
				break
			stack.append(['$', temp])
		else:
			stack.append(lines[i])
	if len(stack) == 0:
		if lines[i][0] == 'add':
			x += 1
		elif lines[i][0] == 'for':
			stack.append(lines[i])
	i += 1
if g:
	print('OVERFLOW!!!')
else:
	for i in stack:
		if i[0] == '$':
			x += i[1]
	print('OVERFLOW!!!' if x > 2 ** 32 - 1 else x)


n = int(input())
temp = []
stack = [1]
for i in range(n):
	op = input()
	xy = op.split('for ')
	if len(xy) == 2:
		xy[0] = 'for'
		xy[1] = int(xy[1])
	temp.append(xy)
i = 0
add = 0
flag = 0
n = len(temp)
inf = pow(2, 32)
while i < n:
	if temp[i][0] == 'for':
		stack.append(min(inf, temp[i][1] * stack[-1]))
		i += 1
	elif temp[i][0] == 'add':
		add = add + stack[-1]
		i += 1
	elif temp[i][0] == 'end':
		stack.pop(-1)
		i += 1
if add < inf:
	print(add)
else:
	print('OVERFLOW!!!')


n = int(input())
stack_for = [1]
overflow = int(4294967295)
ans = 0
for i in range(n):
	c = input()
	if c[0] == 'f':
		f_str = c.split()
		t = int(f_str[1]) * stack_for[len(stack_for) - 1]
		if t > overflow:
			t = overflow + 1
		stack_for.append(t)
	elif c[0] == 'a':
		ans += stack_for[len(stack_for) - 1]
	else:
		stack_for.pop()
if ans > overflow:
	print('OVERFLOW!!!')
else:
	print(ans)


loop = [1]
x = 0
z = 2 ** 32
for _ in range(int(input())):
	inp = input().split(' ')
	if inp[0] == 'for':
		loop.append(min(z, int(inp[1]) * loop[-1]))
	elif inp[0] == 'add':
		x += loop[-1]
	elif inp[0] == 'end':
		loop.pop()
	if x >= z:
		print('OVERFLOW!!!')
		exit()
print(x)


def solution():
	num = int(input())
	result = 0
	stack = []
	for i in range(num):
		str_input = input()
		if str_input == 'add':
			if len(stack) != 0 and '+' in stack[-1]:
				n = int(stack.pop()[1:])
				stack.append('+' + str(n + 1))
			else:
				stack.append('+1')
		elif str_input == 'end':
			if '+' in stack[-1] and 'x' in stack[-2]:
				pop1 = int(stack.pop()[1:])
				pop2 = int(stack.pop()[1:])
				stack.append('+' + str(pop1 * pop2))
				if len(stack) > 1 and '+' in stack[-1] and ('+' in stack[-2]):
					pop1 = int(stack.pop()[1:])
					pop2 = int(stack.pop()[1:])
					stack.append('+' + str(pop1 + pop2))
			else:
				stack.pop()
		else:
			stack.append('x' + str_input.split()[1])
		if len(stack) != 0 and int(stack[-1][1:]) > 2 ** 32 - 1:
			print('OVERFLOW!!!')
			return
	for i in range(len(stack)):
		result += int(stack.pop()[1:])
		if result > 2 ** 32 - 1:
			print('OVERFLOW!!!')
			return
	print(result)
solution()


n = int(input())
x = 0
a = [1]
INF = 2 ** 32
for i in range(n):
	s = input()
	if x > 2 ** 32 - 1:
		continue
	if 'for' in s:
		m = int(s[4:])
		a.append(min(m * a[-1], INF))
	elif 'end' in s:
		a.pop()
	else:
		x += a[-1]
		if x > INF - 1:
			print('OVERFLOW!!!')
			exit(0)
if x > INF - 1:
	print('OVERFLOW!!!')
else:
	print(x)


import sys
mul = 1
m = []
ret = 0
mx = 2 ** 32 - 1
over = 0
request = []
for _ in range(int(input())):
	com = sys.stdin.readline().split()
	if com[0] == 'end' and request[-1][0] == 'for':
		request.pop(-1)
	else:
		request.append(com)
for command in request:
	if not over:
		if len(command) > 1:
			v = int(command[1])
			mul *= v
			m.append(v)
		elif command[0] == 'add':
			ret += max(mul, 1)
		elif command[0] == 'end':
			minus = m.pop(-1)
			mul //= minus
		if ret > mx:
			over = 1
			break
print(ret if not over else 'OVERFLOW!!!')


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])


l = int(input())
st = [1]
ans = 0
for i in range(l):
	s = input()
	if s[0] == 'f':
		st.append(min(st[-1], 2 ** 32) * int(s[4:]))
	elif s[0] == 'e':
		st.pop()
	else:
		ans += st[-1]
		if ans >= 2 ** 32:
			exit(print('OVERFLOW!!!'))
print(ans)


num_lines = int(input())
commands = [None] * 1000000
for_stack = []
fors = 0
k = 0
iters = [1] * 1000000
x = 0
overflow = 2 ** 32 - 1
for i in range(num_lines):
	commands[i] = input()
for i in range(num_lines):
	if commands[i][0:3] == 'for':
		fors += 1
		iters[k] *= int(commands[i][4:])
		if iters[k] > overflow:
			k += 1
		for_stack.append(int(commands[i][4:]))
	elif commands[i][0:3] == 'end':
		fors -= 1
		if iters[k] == 1 and k != 0:
			k -= 1
		iters[k] /= for_stack.pop(-1)
	elif commands[i][0:3] == 'add':
		if k != 0:
			x = overflow + 1
			break
		else:
			x += iters[0]
if x > overflow:
	print('OVERFLOW!!!')
else:
	print(int(x))


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))


import sys, math, queue, bisect
MOD = 10 ** 9 + 7
sys.setrecursionlimit(1000000)
limit = (1 << 32) - 1
a = 0
n = int(input())
m = 1
s = []
p = set()
for i in range(n):
	x = input()
	if len(x) > 3:
		(x, y) = x.split()
		y = int(y)
		if m > limit:
			p.add(len(s))
		else:
			m = m * y
		s.append((i, y))
	elif x == 'add':
		if len(p) > 0:
			print('OVERFLOW!!!')
			exit()
		a += m
		if a > limit:
			print('OVERFLOW!!!')
			exit()
	elif len(s) - 1 in p:
		p.remove(len(s) - 1)
		s.pop()
	else:
		m = m // s.pop()[1]
print(a)


from collections import deque
n = int(input())
cou = 0
mx = 2 ** 32 - 1
i = 0
ll = []
lol = 0
mul = 1
co = 0
d = deque([])
for i in range(n):
	l = list(input().split())
	if l[0] == 'for':
		if mul < mx:
			mul = mul * int(l[1])
			d.append(int(l[1]))
		else:
			co += 1
	elif l[0] == 'end':
		if co > 0:
			co -= 1
		else:
			a = d.pop()
			mul = mul // a
	elif co == 0:
		cou += mul
	else:
		lol = 1
		break
	if cou > mx:
		lol = 1
		break
if lol == 1:
	print('OVERFLOW!!!')
else:
	print(cou)


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!!!')


mx = 2 ** 32 - 1
n = int(input())
v = []
for i in range(n):
	inp = input().split()
	if inp[0] == 'add':
		v.append(0)
	elif inp[0] == 'end':
		v.append(-1)
	else:
		v.append(int(inp[1]))
suck = 1
ch = 0
st = []
b = []
for i in range(n):
	if v[i] > 0:
		st.append(len(b))
		b.append(False)
	elif v[i] == -1:
		if b[st[len(st) - 1]] == True:
			if len(st) > 1:
				b[st[len(st) - 2]] = True
		st.pop()
	elif len(st) > 0:
		b[st[len(st) - 1]] = True
ind = 0
suck = 1
ch = 0
st1 = []
fuck = []
for i in range(n):
	if v[i] > 0:
		fuck.append(ind)
		if b[fuck[len(fuck) - 1]] == True:
			st1.append(v[i])
			suck *= v[i]
			if suck > mx:
				print('OVERFLOW!!!')
				exit()
		ind += 1
	elif v[i] == -1:
		if b[fuck[len(fuck) - 1]]:
			suck /= st1[len(st1) - 1]
			st1.pop()
		fuck.pop()
	else:
		ch += suck
		if ch > mx:
			print('OVERFLOW!!!')
			exit()
print(int(ch))


maxlim = 4294967295
l = int(input())
x = 0
numberoftimes = 1
loops = []
flag = False
unecessary = 0
for i in range(l):
	line = input()
	if flag:
		continue
	cmd = line[:3]
	if cmd == 'for':
		if numberoftimes * int(line.split(' ')[1]) > maxlim or unecessary >= 1:
			unecessary += 1
		else:
			loops.append(int(line.split(' ')[1]))
			numberoftimes *= loops[-1]
	elif cmd == 'end':
		if unecessary >= 1:
			unecessary -= 1
		else:
			numberoftimes = numberoftimes // loops.pop()
	elif unecessary < 1:
		x += numberoftimes
		if x > maxlim:
			print('OVERFLOW!!!')
			flag = True
	else:
		print('OVERFLOW!!!')
		flag = True
if not flag:
	print(x)


x = [0]
y = []
z = 0
for i in range(int(input())):
	k = input().split()
	if len(k) == 1:
		if k[0] == 'add':
			x[-1] += 1
		else:
			x[len(x) - 2] += x.pop() * y.pop()
		if x[-1] > 2 ** 32 - 1 and z == 0:
			print('OVERFLOW!!!')
			exit(0)
	else:
		y.append(int(k[1]))
		x.append(0)
		if y[-1] == 0:
			z += 1
if x[0] <= 2 ** 32 - 1:
	print(x[0])
else:
	print('OVERFLOW!!!')


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)


x = 2 ** 32 - 1
n = int(input())
st = [0]
fs = []
flag = 0
for i in range(n):
	s = [o for o in input().split()]
	if s[0] == 'add':
		k = st.pop()
		k += 1
		st.append(k)
	elif s[0] == 'for':
		st.append('(')
		st.append(0)
		fs.append(int(s[1]))
	else:
		a = 0
		while st[-1] != '(':
			a += st.pop()
		st.pop()
		lol = fs.pop() * a
		if lol > x:
			flag = 1
			break
		st.append(lol)
d = 0
if flag == 0:
	while st:
		d += st.pop()
		if d > x:
			flag = 1
			break
print(d if flag == 0 else 'OVERFLOW!!!')


n = int(input())
MAX = 2 ** 32 - 1
st = []
last = [1]
c = 0
f = False
for i in range(n):
	s = input()
	if s[0] == 'f':
		last.append(min(last[-1] * int(s[4:]), MAX + 1))
	elif s[0] == 'e':
		last.pop()
	else:
		c += last[-1]
		if c > MAX:
			f = True
			break
print('OVERFLOW!!!') if f else print(c)


def cal(a):
	l = 1
	for i in a:
		if a[i] == 0:
			continue
		else:
			l *= i ** a[i]
		if l >= 2 ** 32:
			return -1
	return l
n = int(input())
b = {}
c = []
(p, r) = (0, 0)
for _ in range(n):
	a = input()
	if a[0] == 'f':
		l = int(a[4:])
		c.append(l)
		if l in b:
			b[l] += 1
		else:
			b[l] = 1
	elif a[0] == 'e':
		v = c.pop()
		b[v] -= 1
	elif c == []:
		if p + 1 >= 2 ** 32:
			r = r + 1
			break
		else:
			p = p + 1
	else:
		k = cal(b)
		if k == -1:
			r = r + 1
			break
		elif p + k >= 2 ** 32:
			r = r + 1
			break
		else:
			p = p + k
if r == 0:
	print(p)
else:
	print('OVERFLOW!!!')


l = int(input().strip())
limit = 2 ** 32 - 1
multiplier = 1
stack = []
total = 0
for i in range(l):
	arr = input().strip().split()
	if arr[0] == 'add':
		if len(stack):
			if stack[-1] == -1:
				exit(print('OVERFLOW!!!'))
		total += multiplier
	elif arr[0] == 'for':
		num = int(arr[1])
		if len(stack):
			if stack[-1] == -1:
				stack.append(-1)
				continue
		if multiplier * num > limit:
			stack.append(-1)
		else:
			multiplier *= num
			stack.append(num)
	else:
		multiplier //= abs(stack.pop(-1))
	if total > limit:
		exit(print('OVERFLOW!!!'))
if total > limit:
	print('OVERFLOW!!!')
else:
	print(total)


import atexit
import io
import sys
_I_B = sys.stdin.read().splitlines()
input = iter(_I_B).__next__
_O_B = io.StringIO()
sys.stdout = _O_B

@atexit.register
def write():
	sys.__stdout__.write(_O_B.getvalue())

def main():
	lstack = []
	x = 0
	flag = 1
	for _ in range(int(input())):
		s = input()
		if flag:
			if s[0] == 'f':
				s = s.split()
				count = int(s[1])
				if len(lstack) == 0:
					lstack.append(count)
				elif count * lstack[-1] > 4294967295:
					lstack.append(4294967296)
				else:
					lstack.append(count * lstack[-1])
			elif s[0] == 'e':
				lstack.pop()
			elif s[0] == 'a':
				try:
					x += lstack[-1]
				except IndexError:
					x += 1
				if x > 4294967295:
					print('OVERFLOW!!!')
					flag = 0
	if flag:
		print(x)
main()


n = int(input())
ans = 0
limit = 2 ** 32 - 1
st2 = [1]
m = 1
for _ in range(n):
	inst = input()
	if inst == 'end':
		m //= st2.pop()
	elif inst == 'add':
		ans += m
		if ans > limit:
			ans = 'OVERFLOW!!!'
			break
	else:
		t = int(inst.split(' ')[1])
		if m > limit:
			t = 1
		m *= t
		st2.append(t)
print(ans)


def go():
	n = int(input())
	f = []
	v = [0]
	for _ in range(n):
		s = input()
		if s == 'add':
			v[-1] += 1
		elif s == 'end':
			x = v.pop() * f.pop()
			v[-1] += x
		else:
			f += (int(s.split()[1]),)
			v += (0,)
		if v[-1] >= 1 << 32:
			print('OVERFLOW!!!')
			return
	print(v[0])
go()


l = int(input())
stack = [1]
f = 0
x = 0
overflow = 2 ** 32 - 1
for i in range(l):
	cmd = input()
	if cmd[0] == 'f':
		t = stack[-1] * int(cmd[4:])
		if t > overflow:
			t = overflow + 1
		stack.append(t)
	if cmd[0] == 'e':
		stack.pop()
	if cmd[0] == 'a':
		x += stack[-1]
		if x > overflow:
			f = 1
if f == 1:
	print('OVERFLOW!!!')
else:
	print(x)


(x, m, c, M) = (0, [1], [0], (1 << 32) - 1)
for _ in range(int(input())):
	cmd = input()
	if cmd == 'add':
		c[-1] += 1
	elif cmd == 'end':
		x += c[-1] * m[-1]
		c.pop()
		m.pop()
	else:
		arg = int(cmd.split()[1])
		c.append(0)
		if m[-1] * arg > M:
			m.append(M + 1)
		else:
			m.append(m[-1] * arg)
x += c[0]
print('OVERFLOW!!!' if x > M else x)


n = int(input())
ans = 0
st = [1]
cur = 1
MX = int(1000000000000.0)
for i in range(n):
	s = input()
	if s == 'add':
		ans += cur
		continue
	if s == 'end':
		st.pop()
		cur = st[-1]
		continue
	t = int(s.split()[1])
	g = cur * t
	g = min(MX, g)
	cur = g
	st.append(g)
print(ans if ans <= 2 ** 32 - 1 else 'OVERFLOW!!!')


N = int(input())
Query = [list(map(str, input().split())) for _ in range(N)]
stack = [1]
ok = True
ans = 0
for A in Query:
	if A[0] == 'for':
		num = stack[-1] * int(A[1])
		if num > 2 ** 32 - 1 or stack[-1] == -1:
			stack.append(-1)
		else:
			stack.append(num)
	elif A[0] == 'add':
		if stack[-1] == -1:
			ok = False
			break
		ans += stack[-1]
	else:
		stack.pop()
if ok and ans <= 2 ** 32 - 1:
	print(ans)
else:
	print('OVERFLOW!!!')


n = int(input())
ans = 0
stack = [1]
accum = [0]
MAX = 1 << 32
while n:
	n = n - 1
	cmd = input()
	cmd = cmd.split()
	if len(cmd) == 1:
		if cmd[0] == 'add':
			accum[-1] = min(accum[-1] + 1, MAX)
		else:
			accum[-2] = min(accum[-2] + accum[-1] * stack[-1], MAX)
			stack.pop()
			accum.pop()
	else:
		accum.append(0)
		stack.append(int(cmd[1]))
ans = accum[-1] * stack[-1]
if ans < MAX:
	print(ans)
else:
	print('OVERFLOW!!!')


def solve():
	maxv = 2 ** 32 - 1
	stk = [0]
	n = int(input())
	for i in range(n):
		cmd = input()
		if cmd == 'add':
			stk[-1] += 1
		elif cmd.startswith('for'):
			x = int(cmd.split()[1])
			stk.append(x)
			stk.append(0)
		else:
			x = stk.pop()
			y = stk.pop()
			z = stk.pop()
			a = z + x * y
			if a > maxv:
				return -1
			stk.append(a)
	return -1 if stk[0] > maxv else stk[0]
res = solve()
print('OVERFLOW!!!' if res < 0 else res)


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)


from math import pow
l = int(input())
m = int(pow(2, 32))
ans = 0
stk = [1]
for i in range(l):
	x = input()
	if 'add' in x:
		ans += stk[len(stk) - 1]
	elif 'for' in x:
		(p, v) = x.split()
		v = int(v)
		stk.append(min(m, v * stk[len(stk) - 1]))
	elif 'end' in x:
		stk.pop()
if ans >= m:
	print('OVERFLOW!!!')
	f = False
else:
	print(ans)


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)


from collections import deque
number_of_lines = 0
lines = []
type_of_lines = deque([])
times = deque([])
result = 0
printed = False

def Input(number_of_lines, lines):
	number_of_lines = int(input())
	for index in range(number_of_lines):
		lines.append(list(map(str, input().split())))
	return (number_of_lines, lines)

def Processing(number_of_lines, lines, result, type_of_lines, times, printed):
	for index in range(number_of_lines):
		if len(lines[index]) == 2:
			type_of_lines.append(int(lines[index][1]))
		elif lines[index][0] == 'add':
			type_of_lines.append(-1)
		else:
			type_of_lines.append(0)
	index = 0
	tem = 0
	while type_of_lines:
		type_line = type_of_lines[0]
		if type_line != 0:
			times.append(type_line)
		else:
			count = 0
			while times[-1] < 0:
				count -= times[-1]
				times.pop()
			tem = count * times[-1]
			times.pop()
			if tem != 0:
				times.append(-tem)
			if tem > 2 ** 32 - 1:
				print('OVERFLOW!!!')
				printed = True
				return (number_of_lines, lines, result, type_of_lines, times, printed)
		type_of_lines.popleft()
	return (number_of_lines, lines, result, type_of_lines, times, printed)

def Output(times, printed):
	result = 0
	result = abs(sum(times))
	if printed == False:
		if result <= 2 ** 32 - 1:
			print(result)
		else:
			print('OVERFLOW!!!')
	return (times, printed)
(number_of_lines, lines) = Input(number_of_lines, lines)
(number_of_lines, lines, result, type_of_lines, times, printed) = Processing(number_of_lines, lines, result, type_of_lines, times, printed)
(times, printed) = Output(times, printed)


import sys
sys.setrecursionlimit(10 ** 5 + 1)
inf = int(10 ** 20)
max_val = inf
min_val = -inf
RW = lambda : sys.stdin.readline().strip()
RI = lambda : int(RW())
RMI = lambda : [int(x) for x in sys.stdin.readline().strip().split()]
RWI = lambda : [x for x in sys.stdin.readline().strip().split()]
overflow = 2 ** 32
ans = 0
nb_test = RI()
calc = [1]
for _ in range(nb_test):
	(mods, *vals) = RWI()
	if mods == 'add':
		ans += calc[-1]
	elif mods == 'for':
		val = int(vals[0])
		calc.append(min(calc[-1] * val, overflow))
	else:
		calc.pop()
ans = 'OVERFLOW!!!' if ans >= overflow else ans
print(ans)


from math import pow
over = 4294967295
x = 0
List_For = [1]
for i in range(int(input())):
	s = input()
	if s == 'add':
		x += List_For[1 * -1]
	elif s == 'end':
		y = List_For.pop()
	else:
		List_For.append(min(int(s.split()[1]) * List_For[int(pow(-1, 1))], over + 1))
	if x > over:
		print('OVERFLOW!!!')
		exit()
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 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(' ')
	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
		x += forproduct
		if x > 2 ** 32 - 1:
			print('OVERFLOW!!!')
			bad = 1
			break
	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())
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)


from array import array
n = int(input())
stack = array('Q', list((1 for _ in range(n // 2 + 1))))
stack_top = 1
overflow = 2 ** 32 - 1
s = 0
flag = True
for _ in range(n):
	command = input()
	if command == 'end':
		stack_top -= 1
	elif command == 'add':
		s += stack[stack_top - 1]
		if s > overflow:
			print('OVERFLOW!!!')
			flag = False
			break
	else:
		res = stack[stack_top - 1] * int(command[4:len(command)])
		stack[stack_top] = min(res, overflow + 1)
		stack_top += 1
if flag:
	print(s)


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])


import os
from io import BytesIO, StringIO
b = BytesIO(os.read(0, os.fstat(0).st_size)).readline
input = lambda : b().decode()
DEBUG = False
debug_print = print if DEBUG else lambda *x, **y: None

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

def array_of(f, *dim):
	return [array_of(f, *dim[1:]) for _ in range(dim[0])] if dim else f()

def main():
	l = int(input())
	MAX = 2 ** 32 - 1
	OF = False
	x = 0
	stack = [1]
	cur = 1
	offlag = False
	oflen = None
	for _ in range(l):
		s = input().split()
		debug_print(stack, x, cur, offlag, oflen)
		if s[0][0] == 'a':
			if not offlag:
				x += cur
				if x > MAX:
					OF = True
					break
			if offlag:
				OF = True
				break
		elif s[0][0] == 'f':
			v = int(s[1])
			stack.append(v)
			if not offlag:
				if cur * v > MAX:
					offlag = True
					oflen = len(stack)
				else:
					cur *= v
		elif s[0][0] == 'e':
			v = stack.pop()
			if offlag:
				if len(stack) < oflen:
					offlag = False
			else:
				cur //= v
	print('OVERFLOW!!!' if OF else x)
main()


x = 0
n = int(input())
cur = 1
stack = []
error = 0
flag = 0
for i in range(n):
	s = input().split()
	if s[0] == 'add':
		if error != 0:
			print('OVERFLOW!!!')
			break
		x += cur
		if x >= 2 ** 32:
			print('OVERFLOW!!!')
			break
	elif s[0] == 'for':
		if flag == 1:
			error += 1
		elif cur * int(s[1]) < 2 ** 32:
			cur *= int(s[1])
			stack.append(int(s[1]))
		else:
			flag = 1
			error += 1
	elif error == 0:
		cur //= stack.pop()
	else:
		error -= 1
		if error == 0:
			flag = 0
else:
	print(x)


import sys, math

def read_int():
	return int(sys.stdin.readline().strip())

def read_int_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def read_string():
	return sys.stdin.readline().strip()

def read_string_list(delim=' '):
	return sys.stdin.readline().strip().split(delim)
n = read_int()
stack = [1]
x = 0
limit = 1 << 32
for _ in range(n):
	com_list = read_string_list()
	if com_list[0] == 'add':
		x += stack[-1]
	elif com_list[0] == 'for':
		stack.append(min(limit, int(com_list[1]) * stack[-1]))
	else:
		stack.pop()
if x >= limit:
	print('OVERFLOW!!!')
else:
	print(x)


mx = (1 << 32) - 1
T = int(input())
n = 0
S = []
M = []
for i in range(T):
	s = input()
	if s[0] == 'a':
		if not len(S):
			n += 1
		else:
			M[-1] += 1
	elif s[0] == 'f':
		(s, p) = s.split()
		p = int(p)
		S.append(p)
		M.append(0)
	else:
		r = S.pop(-1) * M.pop(-1)
		if not len(S):
			n += r
			if n > mx:
				print('OVERFLOW!!!')
				exit(0)
		else:
			M[-1] += r
			if M[-1] > mx:
				print('OVERFLOW!!!')
				exit(0)
if n > mx:
	print('OVERFLOW!!!')
	exit(0)
print(n)


class stack:

	def __init__(self, n):
		self.arr = [0 for i in range(n)]
		self.arr2 = [0 for i in range(n)]
		self.top = -1
		self.n = n

	def push(self, x):
		if self.top > self.n - 1:
			return
		self.top += 1
		self.arr[self.top] = x

	def pop(self):
		if self.top == -1:
			return 1
		else:
			self.top -= 1
			return self.arr[self.top + 1]

	def isEmpty(self):
		if self.top == -1:
			return True
		else:
			return False

	def peek(self):
		if self.top == -1:
			return 1
		else:
			return self.arr[self.top]
l = int(input())
commands = []
for i in range(l):
	commands.append(str(input()))
s = stack(l)
count = 0
flag = 0
for i in range(l):
	if commands[i][:3] == 'for':
		s.push(min(2 ** 32, s.peek() * int(commands[i][4:])))
	elif commands[i][:3] == 'end':
		s.pop()
	else:
		count += s.peek()
	if count > 2 ** 32 - 1:
		break
if count > 2 ** 32 - 1 or flag == 1:
	print('OVERFLOW!!!')
else:
	print(count)


x = 0
for s in [[1]] * int(input()):
	t = input()
	if 'f' < t:
		s += [min(5000000000.0, s[-1] * int(t[4:]))]
	elif 'b' > t:
		x += s[-1]
	else:
		s.pop()
print(['OVERFLOW!!!', x][x < 2 ** 32])


l = int(input())
x = 0
cap = 2 ** 32 - 1
forstacc = []
commandstacc = []
skip = 0
while l > 0:
	line = input()
	if line == 'add':
		if len(forstacc) == 0:
			x = x + 1
			if x > cap:
				break
		else:
			temp = 1
			for i in commandstacc:
				temp = temp * i
			x = x + temp
			if x > cap:
				break
	elif line == 'end':
		if len(forstacc) != 0:
			if forstacc.pop() != 1:
				commandstacc.pop()
	elif line[0] == 'f':
		linesplit = line.split()
		do = int(linesplit[1])
		if do != 1:
			commandstacc.append(do)
		forstacc.append(do)
	l = l - 1
if x > cap:
	print('OVERFLOW!!!')
else:
	print(x)


val = 0
x = 1
st = []
g = pow(2, 32) - 1
for _ in range(int(input())):
	inp = input()
	if len(inp.split()) == 1:
		if inp == 'end':
			if st[-1] == 'add':
				st.append(inp)
			elif st[-1] == 'end':
				st.append(inp)
			else:
				st.pop()
		else:
			st.append(inp)
	else:
		st.append(inp)
st2 = []
for i in st:
	inp = i.split()
	if len(inp) == 1:
		if inp[0] == 'end':
			x //= st2[-1]
			st2.pop()
		else:
			val += x
			if val > g:
				print('OVERFLOW!!!')
				exit(0)
	else:
		m = int(inp[1])
		x *= m
		if x > g:
			print('OVERFLOW!!!')
			exit(0)
		st2.append(m)
print(val)


stack = []
ans = 0
LIM = 2 ** 32 - 1
for _ in range(int(input())):
	s = input()
	if s[:3] == 'for':
		(_, val) = s.split()
		val = int(val)
		if stack:
			if stack[-1] == 'INF':
				stack.append('INF')
			elif val * stack[-1] > LIM:
				stack.append('INF')
			else:
				stack.append(val * stack[-1])
		else:
			stack.append(val)
	elif s == 'add':
		if stack:
			if stack[-1] == 'INF':
				print('OVERFLOW!!!')
				break
			else:
				ans += stack[-1]
		else:
			ans += 1
		if ans > LIM:
			print('OVERFLOW!!!')
			break
	elif s == 'end':
		stack.pop(-1)
else:
	print(ans)


n = int(input())
x = 2 ** 32 - 1
stack = []
for i in range(n):
	s = input()
	if len(stack) == 0:
		if s == 'add':
			stack.append('add 1')
		else:
			stack.append(s)
	elif s == 'end':
		if stack[-1][0] != 'f':
			while stack[-2][0] == 'a':
				temp4 = stack.pop()
				num3 = int(temp4.split()[-1])
				temp5 = stack.pop()
				num4 = int(temp5.split()[-1])
				if num3 + num4 > x:
					print('OVERFLOW!!!')
					exit(0)
				stack.append('add ' + str(num3 + num4))
			temp = stack.pop()
			num = int(temp.split()[-1])
			temp2 = stack.pop()
			num2 = int(temp2.split()[-1])
			temp3 = num * num2
			stack.append('add ' + str(temp3))
			if temp3 > x:
				print('OVERFLOW!!!')
				exit(0)
		else:
			stack.pop()
	elif s == 'add':
		if stack[-1][0:3] == 'add':
			temp = stack.pop()
			num = int(temp.split()[-1])
			stack.append('add ' + str(num + 1))
			if num + 1 > x:
				print('OVERFLOW!!!')
				exit(0)
		else:
			stack.append('add 1')
	else:
		stack.append(s)
ans = 0
for i in stack:
	num = i.split()[-1]
	ans += int(num)
	if ans > x:
		print('OVERFLOW!!!')
		exit(0)
print(ans)


import sys
p = 2 ** 32 - 1
seq = 0
num = 0
st = [1]
for _ in range(int(input())):
	command = input().split()
	if command[0] == 'add':
		num += st[-1]
		if num > p:
			print('OVERFLOW!!!')
			sys.exit()
	elif command[0] == 'for':
		if st[-1] > p:
			seq += 1
		else:
			st.append(int(command[1]) * st[-1])
	elif command[0] == 'end':
		if seq > 0:
			seq -= 1
		else:
			st.pop()
print(num) if num <= p else print('OVERFLOW!!!')


import sys
from collections import Counter

def input():
	return sys.stdin.readline().strip()

def dinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def main():
	aleonov = 0
	aleonov1 = 2 ** 32 - 1
	x = []
	z = 0
	c = -1
	d = 1
	for i in range(dinput()):
		s = input()
		if s == 'add':
			if len(x) > z or aleonov + d > aleonov1:
				print('OVERFLOW!!!')
				exit(0)
			aleonov += d
		elif s == 'end':
			g = x.pop()
			if len(x) == z:
				d = c
			elif len(x) < z:
				d //= g
				c = d
				z = len(x)
		else:
			f = int(s.split()[1])
			x.append(f)
			if d < aleonov1:
				d *= f
				c = d
				z = len(x)
	print(aleonov)
main()


from collections import deque
n = int(input())
command = []
for i in range(n):
	command.append(input().split(' '))
d = deque()
adds = []
mult = 1
for i in range(len(command)):
	if command[i][0] == 'add':
		if mult > 2 ** 32 - 1:
			print('OVERFLOW!!!')
			quit()
		adds.append(mult)
	else:
		adds.append(0)
	if command[i][0] == 'for':
		if mult > 2 ** 32 - 1:
			d.append(1)
		else:
			mult = mult * int(command[i][1])
			d.append(int(command[i][1]))
	if command[i][0] == 'end':
		num = d.pop()
		mult = mult / num
sum = 0
for i in range(len(adds)):
	sum += adds[i]
if sum > 2 ** 32 - 1:
	print('OVERFLOW!!!')
else:
	print(int(sum))


numInput = int(input())
a = [0]
b = []
limit = 2 ** 32
c = 0
while c < numInput:
	instruct = input().split(' ')
	cmd = instruct[0]
	if cmd == 'for':
		a.append(0.0)
		b.append(int(instruct[1]))
	elif cmd == 'add':
		a[-1] = a[-1] + 1
	elif cmd == 'end':
		a[-1] = a.pop() * b.pop() + a[-1]
	c += 1
if a[0] < limit:
	print(int(a[0]))
else:
	print('OVERFLOW!!!')


lst = [1]
ans = 0
for i in range(int(input())):
	x = input()
	if x == 'add':
		ans += lst[-1]
		if ans > 2 ** 32 - 1:
			exit(print('OVERFLOW!!!'))
	elif x[0] == 'f':
		lst.append(min(2 ** 32, lst[-1] * int(x[4:])))
	else:
		lst.pop()
print(ans)


import os
import sys
from io import BytesIO, IOBase
from collections import deque
multiplier = 1
(n, queries) = [None] * 2
x = 0
MAXVAL = 2 ** 32 - 1

def getInput() -> None:
	global n, queries
	n = int(input())

def main() -> None:
	global queries, x
	getInput()
	l = deque()
	l.append(1)
	for i in range(n):
		query = input()
		if query == 'add':
			x += l[-1]
		elif query[:3] == 'for':
			l.append(min(MAXVAL + 1, l[-1] * int(query.split()[1])))
		else:
			l.pop()
		if x > MAXVAL:
			print('OVERFLOW!!!')
			exit(0)
	print(x)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


ans = 0
mult = 1
limit = 4294967296
overflow = False
np = False
st = []
l = int(input())
for i in range(l):
	s = input()
	if s[0] == 'f':
		if np:
			st.append(1)
			continue
		(_, n) = s.split()
		n = int(n)
		mult = mult * n
		if ans + mult >= limit:
			np = True
		st.append(n)
	elif s[0] == 'e':
		mult = mult / int(st[-1])
		if np and ans + mult < limit:
			np = False
		st.pop()
	else:
		ans = ans + mult
		if ans >= limit:
			overflow = True
			break
if overflow:
	print('OVERFLOW!!!')
else:
	print(int(ans))


def solve():
	INT_MAX = (1 << 32) - 1
	n = int(input())
	l = []
	p = []
	for i in range(n):
		s = input()
		if s[0] == 'a':
			l.append(1)
			p.append(True)
		elif s[0] == 'f':
			(a, d) = s.split()
			l.append(int(d))
			p.append(False)
		else:
			num = 0
			while p.pop():
				num = num + l.pop()
			num *= l.pop()
			if num != 0:
				l.append(num)
				if num > INT_MAX:
					return 'OVERFLOW!!!'
				p.append(True)
	x = 0
	while len(l) != 0:
		x = x + l[len(l) - 1]
		l.pop()
	if x > INT_MAX:
		return 'OVERFLOW!!!'
	else:
		return str(x)
print(solve())


t = int(input())
x = 0
fin = []
flag = 0
inf = 0
for I in range(t):
	a = [str(i) for i in input().split()]
	if a[0] == 'add' and len(fin) == 0 and (flag == 0):
		x += 1
	elif a[0] == 'for' and len(fin) == 0 and (flag == 0):
		if inf:
			fin.append(-1)
		else:
			fin.append(int(a[1]))
	elif a[0] == 'for' and len(fin) > 0 and (flag == 0):
		if inf:
			fin.append(-1)
		else:
			fin.append(int(a[1]) * fin[-1])
	elif a[0] == 'end' and flag == 0:
		fin.pop()
		if len(fin) > 0 and fin[-1] <= 2 ** 32 - 1:
			inf = 0
	elif a[0] == 'add' and len(fin) > 0 and (flag == 0):
		if fin[-1] == -1:
			flag = 1
		else:
			x += fin[-1]
	if x > 2 ** 32 - 1 or x < 0:
		flag = 1
	if len(fin) > 0 and fin[-1] > 2 ** 32 - 1:
		inf = 1
if x > 2 ** 32 - 1 or flag == 1 or x < 0:
	print('OVERFLOW!!!')
else:
	print(x)


count = int(input())
opts = []
for i in range(count):
	opts.append(input().split())
forNums = []
stack = [1]
res = 0
overflow_v = 2 ** 32 - 1
overflow = False
for i in opts:
	if i[0] == 'for':
		for_v = int(i[1])
		forNums.append(for_v)
		stack.append(min(overflow_v + 1, for_v * stack[-1]))
	if i[0] == 'add':
		res += stack[-1]
	if res > overflow_v:
		print('OVERFLOW!!!')
		overflow = True
		break
	elif i[0] == 'end':
		forNums.pop()
		stack.pop()
if not overflow:
	print(res)


def catchOverflow(operations, N):
	mainStack = [1]
	summ = 0
	i = 0
	comparison = 2 ** 32
	while i < N:
		if operations[i] == 'add':
			summ += mainStack[-1]
		elif operations[i] == 'end':
			mainStack.pop()
		else:
			temp = operations[i].split()
			iterations = int(temp[1])
			mainStack.append(min(iterations * mainStack[-1], comparison))
		i += 1
	if summ >= comparison:
		return 'OVERFLOW!!!'
	else:
		return summ
N = int(input())
i = 0
operations = []
while i < N:
	operations.append(input())
	i += 1
print(catchOverflow(operations, N))


import sys

def main():
	t = int(input())
	mul = 1
	ans = 0
	num = [1]
	for _ in range(t):
		stm = input()
		if stm[0] == 'f':
			(f, n) = stm.split()
			n = int(n)
			prod = num[-1] * n
			if prod > 4294967295:
				num.append(4294967296)
			else:
				num.append(prod)
		elif stm == 'add':
			ans = ans + num[-1]
		else:
			num.pop()
		if ans > 4294967295:
			print('OVERFLOW!!!')
			sys.exit(0)
	print(ans)
main()


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)


count = [0]
bound = 2 ** 32
counter = []
numOfLines = int(input())
for i in range(numOfLines):
	functions = list(map(str, input().rstrip().split()))
	if functions[0] == 'for':
		count.append(0.0)
		counter.append(int(functions[1]))
	elif functions[0] == 'add':
		count[len(count) - 1] = count[len(count) - 1] + 1
	elif functions[0] == 'end':
		count[len(count) - 1] = count.pop() * counter.pop() + count[len(count) - 1]
if count[0] < bound:
	print(int(count[0]))
else:
	print('OVERFLOW!!!')


l = int(input())
stack = [1]
x = 0
mx = 2 ** 32
for i in range(l):
	cmd = input().split()
	if len(cmd) == 2:
		stack.append(min(int(cmd[1]) * stack[-1], mx))
	elif cmd[0] == 'add':
		x += stack[-1]
	else:
		stack.pop()
if x >= mx:
	print('OVERFLOW!!!')
else:
	print(x)


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!!!')


import sys
import re
MAX = pow(2, 32) - 1

def stack(i, limit, value=0):
	if i >= limit:
		return {'i': i, 'value': value}
	line = sys.stdin.readline()
	while line:
		if i >= limit:
			break
		i += 1
		if re.search('add', line):
			value += 1
			if value > MAX:
				value = 'OVERFLOW!!!'
				break
		elif re.search('for[\\s]+(\\d+)', line):
			times = int(re.search('for[\\s]+(\\d+)', line).group(1))
			o = stack(i, limit)
			value += times * o['value']
			i = o['i']
			if value > MAX:
				value = 'OVERFLOW!!!'
				break
		elif re.search('end', line):
			break
		line = sys.stdin.readline()
	return {'i': i, 'value': value}

def main():
	limit = int(input())
	l1 = {'parent': None, 'list': []}
	line = sys.stdin.readline()
	i = 1
	while line:
		if i > limit:
			break
		i += 1
		if re.search('add', line):
			current_stack = l1['list']
			value = 0 if len(current_stack) == 0 else current_stack[-1]
			value += 1
			if value > MAX:
				print('OVERFLOW!!!')
				return
			if len(current_stack) == 0:
				current_stack.append(value)
			else:
				current_stack[-1] = value
		elif re.search('for[\\s]+(\\d+)', line):
			times = int(re.search('for[\\s]+(\\d+)', line).group(1))
			l1['list'].append(times)
			l2 = {'parent': l1, 'list': []}
			l1['list'].append(l1)
			l1 = l2
		elif re.search('end', line):
			value = 0 if len(l1['list']) == 0 else l1['list'][-1]
			if value > MAX:
				print('OVERFLOW!!!')
				return
			ans = value
			l1 = l1['parent']
			l1['list'].pop()
			if len(l1['list']):
				l1['list'][-1] *= ans
				if l1['list'][-1] > MAX:
					print('OVERFLOW!!!')
					return
			else:
				l1['list'].append(ans)
			while len(l1['list']) != 1:
				l1['list'][-2] += l1['list'][-1]
				l1['list'].pop()
		line = sys.stdin.readline()
	print(l1['list'][0])
main()


from sys import stdin, stdout
from itertools import combinations
from collections import defaultdict, OrderedDict
import math
import heapq

def listIn():
	return list(map(int, stdin.readline().strip().split()))

def stringListIn():
	return [x for x in stdin.readline().split()]

def intIn():
	return int(stdin.readline())

def stringIn():
	return stdin.readline().strip()
l = intIn()
st = [0]
ans = 0
MAX = 2 ** 32 - 1
m = 1
flag = False
li = []
for i in range(l):
	A = stringIn()
	if A[:3] == 'end':
		if li[-1][:3] == 'for':
			li.pop(-1)
		else:
			li.append(A)
	else:
		li.append(A)
for A in li:
	if A[:3] == 'add':
		if st[-1] == 0:
			ans += 1
		else:
			ans += m
	elif A[:3] == 'for':
		num = int(A[4:])
		m *= num
		if m > MAX:
			flag = True
			break
		else:
			st.append(num)
	else:
		ele = st.pop(-1)
		m //= ele
	if ans > MAX:
		flag = True
		break
if flag:
	print('OVERFLOW!!!')
else:
	print(ans)


from math import *
n = int(input())
limit = pow(2, 32)
stk = [1]
ans = 0
for i in range(n):
	s = input()
	if s[0] == 'f':
		a = s.split()
		x = int(a[1])
		stk.append(min(limit, stk[-1] * x))
	elif s[0] == 'e':
		stk.pop()
	else:
		ans += stk[-1]
if ans >= limit:
	print('OVERFLOW!!!')
else:
	print(ans)


l = int(input())
t = 0
f = []
a = []
limit = 1 << 32
done = False
for i in range(l):
	s = input().strip()
	if s == 'add':
		if len(f) == 0:
			t += 1
		else:
			a[-1] += 1
	elif s == 'end':
		fo = f.pop()
		ao = a.pop()
		if ao == 0:
			continue
		elif len(f) > 0:
			a[-1] += fo * ao
			if f[-1] * a[-1] >= limit:
				done = True
				print('OVERFLOW!!!')
				break
		else:
			t += fo * ao
	else:
		f.append(int(s.split()[1]))
		a.append(0)
if not done:
	if t >= limit:
		print('OVERFLOW!!!')
	else:
		print(t)


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)


s = [0]
t = []
i = input
for c in map(i, ' ' * int(i())):
	if c[0] > 'e':
		s += [0.0]
		t += [int(c[4:])]
	else:
		s[-1] = (s.pop() * t.pop() if 'a' < c[0] else 1) + s[-1]
print(int(s[0]) if s[0] < 2 ** 32 else 'OVERFLOW!!!')


n = int(input())
callstack = [[1, 0]]
bound = 1 << 32
for __ in range(n):
	if callstack[-1][1] >= bound:
		break
	line = input()
	if line[0] == 'a':
		callstack[-1][1] += 1
	elif line[0] == 'f':
		callstack.append([int(line[4:]), 0])
	else:
		k = callstack.pop()
		callstack[-1][1] += k[0] * k[1]
if callstack[-1][1] >= bound:
	print('OVERFLOW!!!')
else:
	print(callstack[-1][1])


def catch_overflow(o):
	stack = [1]
	output = 0
	for i in range(o):
		n = input()
		if n[:3] == 'for':
			stack.append(min(2 ** 32, stack[-1] * int(n[4:])))
		elif n == 'end':
			stack.pop()
		else:
			output += stack[-1]
	if output >= 2 ** 32:
		print('OVERFLOW!!!')
	else:
		print(output)
n = int(input())
catch_overflow(n)


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])
if res > 2 ** 32 - 1:
	print('OVERFLOW!!!')
else:
	print(res)


lines = int(input())
sum = 0
count = []
count.append(1)
limit = 4294967295
increased = True
multiplier = 1
mult_limit = 0
overflow = False
for i in range(lines):
	cur_input = input()
	if cur_input == 'add':
		if not overflow:
			if multiplier < limit:
				sum += multiplier
			else:
				overflow = True
	elif cur_input == 'end':
		if mult_limit == 0:
			multiplier = multiplier / count[-1]
			count.pop()
		else:
			mult_limit -= 1
	else:
		for_input = int(cur_input.split()[1])
		if multiplier < limit:
			count.append(for_input)
			multiplier *= for_input
		else:
			mult_limit += 1
if sum > limit or overflow:
	print('OVERFLOW!!!')
else:
	print(int(sum))


l = int(input())
mm = []
for i in range(l):
	s = input().split()
	if s[0] == 'for':
		ll = int(s[1])
		mm.append(s)
	elif s[0] == 'add':
		mm.append(s)
	elif mm[-1][0] == 'for':
		mm.pop()
	else:
		mm.append(s)
tmp = 1
ss = []
ans = 0
ok = True
for s in mm:
	if s[0] == 'for':
		ll = int(s[1])
		tmp = tmp * ll
		ss.append(ll)
	elif s[0] == 'add':
		ans = ans + tmp
	else:
		tmp = tmp / ss.pop()
	if ans > (1 << 32) - 1:
		print('OVERFLOW!!!')
		ok = False
		break
if ok:
	print(int(ans))


import sys
input = sys.stdin.readline
n = int(input())
f = []
cnt = []
som = 0
q = 0
ec = 0
for i in range(n):
	s = input()
	if s[0] == 'f':
		cnt.append(q)
		f.append(int(s[3:]))
		q = 0
	if s[0] == 'a':
		if len(f) == 0:
			som += 1
		else:
			q += 1
	if s[0] == 'e':
		x = f.pop()
		ans = x * q
		if ans >= 2 ** 32:
			ec = 1
			q = 0
		q = cnt.pop() + ans
		if q >= 2 ** 32:
			ec = 1
			q = 0
	if len(f) == 0:
		som += q
		q = 0
		if som >= 2 ** 32:
			ec = 1
			som = 0
if som >= 2 ** 32:
	ec = 1
if ec:
	print('OVERFLOW!!!')
else:
	print(som)


def gogo():
	cnt = 1
	i = 0
	while cnt != 0:
		i += 1
		t = input()
		if t[0] == 'e':
			cnt -= 1
		elif t[0] == 'a':
			return -1
		else:
			cnt += 1
	return i
x = 0
l = int(input())
ml = []
m = 1
f = False
while l != 0:
	l -= 1
	c = input()
	if c[0] == 'e':
		m //= ml.pop()
	elif c[0] == 'a':
		x += m
		if x > 4294967295:
			f = True
			break
	else:
		tc = int(c.split()[1])
		m *= tc
		ml.append(tc)
		if m > 4294967295:
			gr = gogo()
			if gr == -1:
				f = True
				break
			l -= gr
			m //= tc
			ml.pop()
if f:
	print('OVERFLOW!!!')
else:
	print(int(x))


import io, os
input = io.StringIO(os.read(0, os.fstat(0).st_size).decode()).readline
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
MX = 2 ** 32 - 1
bad = 0
add = [0]
mul = [1]
for _ in range(ii()):
	cmd = input().split()
	if cmd[0] == 'add':
		add[-1] += 1
	elif cmd[0] == 'for':
		x = int(cmd[1])
		add.append(0)
		mul.append(x)
	else:
		add[-2] += mul[-1] * add[-1]
		add.pop()
		mul.pop()
		if add[-1] > MX:
			bad = 1
			break
ans = add[0] * mul[0]
if ans > MX:
	bad = 1
print('OVERFLOW!!!' if bad else ans)


numberOfLines = int(input())
result = [0]
commandQueue = []
count = 0
while count < numberOfLines:
	commands = input().split()
	command = commands[0]
	if command == 'for':
		result.append(0.0)
		commandQueue.append(int(commands[1]))
	elif command == 'add':
		result[-1] = result[-1] + 1
	else:
		result[-1] = result.pop() * commandQueue.pop() + result[-1]
	count += 1
if result[0] >= 2 ** 32:
	print('OVERFLOW!!!')
else:
	print(int(result[0]))


n = int(input())
cmd = []
for i in range(n):
	temp = input()
	if temp[0] == 'f':
		temp = int(temp[4:])
	cmd.append(temp)
int_type = type(0)
x = 0
prev = [1]
for i in cmd:
	if type(i) == int_type:
		prev.append(min(i * prev[-1], 4294967296))
	elif i == 'end':
		prev.pop()
	else:
		x += prev[-1]
if x >= 4294967296:
	print('OVERFLOW!!!')
else:
	print(x)


from collections import deque
num_lines = int(input())
loop_stack = deque()
overflow = False
broken = False
for j in range(num_lines):
	line = input()
	if not overflow:
		if line[:3] == 'for':
			loop_stack.appendleft(line)
		elif line[:3] == 'end':
			k = loop_stack.popleft()
			loop_sum = 0
			if isinstance(k, int):
				loop_sum += k
				k = loop_stack.popleft()
			loop_iters = int(k.strip().split()[1])
			loop_sum *= loop_iters
			if loop_sum > 0:
				if len(loop_stack) > 0 and isinstance(loop_stack[0], int):
					loop_stack[0] += loop_sum
				else:
					loop_stack.appendleft(loop_sum)
		elif len(loop_stack) > 0 and isinstance(loop_stack[0], int):
			loop_stack[0] += 1
		else:
			loop_stack.appendleft(1)
	if len(loop_stack) > 0 and isinstance(loop_stack[0], int) and (loop_stack[0] > 2 ** 32):
		overflow = True
		broken = True
		break
if not broken:
	k = sum(loop_stack)
	if k < 2 ** 32:
		print(k)
	else:
		print('OVERFLOW!!!')
else:
	print('OVERFLOW!!!')


lines = int(input())
multiplier = 1
stack = []
cumul = 0
casser = False
for n in range(lines):
	line = input()
	if 'for' in line:
		num = int(line.split()[1])
		if multiplier * num > 2 ** 32 - 1:
			stack.append(2 ** 32 - 1)
		elif stack and stack[-1] == 2 ** 32 - 1:
			if stack[-1] == 2 ** 32 - 1:
				stack.append(2 ** 32 - 1)
		else:
			multiplier *= num
			stack.append(num)
	elif 'end' in line:
		num = stack[-1]
		if num != 2 ** 32 - 1:
			multiplier /= stack[-1]
		stack.pop()
	elif 'add' in line:
		if stack:
			if stack[-1] == 2 ** 32 - 1:
				casser = True
		cumul += multiplier
if casser or cumul > 2 ** 32 - 1:
	print('OVERFLOW!!!')
else:
	print(int(cumul))


import collections
l = int(input())
ans = 0
c = [input() for i in range(l)]
stack = [1]
for i in range(l):
	if c[i] == 'add':
		ans += stack[-1]
	elif c[i] == 'end':
		stack.pop()
	else:
		stack.append(min(stack[-1] * int(c[i].split()[1]), 2 ** 32))
	if ans >= 2 ** 32:
		ans = 'OVERFLOW!!!'
		break
print(ans)


s = [0]
p = []
f = 0
for i in range(int(input())):
	k = input().split()
	if len(k) == 1:
		if k[0] == 'add':
			s[-1] += 1
		else:
			s[len(s) - 2] += s.pop() * p.pop()
		if s[-1] > 2 ** 32 - 1 and f == 0:
			print('OVERFLOW!!!')
			exit(0)
	else:
		p.append(int(k[1]))
		s.append(0)
		if p[-1] == 0:
			f += 1
if s[0] <= 2 ** 32 - 1:
	print(s[0])
else:
	print('OVERFLOW!!!')


import sys
n = int(input())
ct = 0
mul = 1
st = [1]
for _ in range(n):
	t = input()
	if t == 'add':
		ct += st[-1]
		if ct > 4294967295:
			print('OVERFLOW!!!')
			sys.exit(0)
	elif t[0] == 'f':
		q = t[4:]
		q = int(q)
		st.append(min(st[-1] * q, 4294967296))
	else:
		st.pop()
print(ct)


import os
import sys
from math import *
from collections import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz/'
M = 1000000007
EPS = 1e-06

def Ceil(a, b):
	return a // b + int(a % b > 0)

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
st = []
ans = 0
MAX = 2 ** 32 - 1
for i in range(n):
	s = input()
	if s != 'end':
		if s[0] == 'f':
			st.append(('f', int(s[4:])))
		else:
			st.append(('a', 1))
	else:
		here = 0
		while st[-1][0] != 'f':
			here += st.pop()[1]
		here *= st.pop()[1]
		st.append(('a', here))
		if here > MAX:
			print('OVERFLOW!!!')
			exit()
ans = 0
while len(st):
	ans += st.pop()[1]
	if ans > MAX:
		print('OVERFLOW!!!')
		exit()
print(ans)


MyNumber = 0
MyFor = [1]
Bound = 2 ** 32
N = int(input())
for i in range(N):
	X = input()
	if X == 'add':
		MyNumber += MyFor[-1]
	elif X.startswith('for'):
		X = X.split()
		X = int(X[1])
		MyFor.append(min(X * MyFor[-1], Bound))
	else:
		MyFor.pop()
	if MyNumber >= Bound:
		MyNumber = 'OVERFLOW!!!'
		break
print(MyNumber)


n = int(input())
INF = pow(2, 32) - 1
stack = [1]
ans = 0
(i, k) = (0, 0)
for i in range(n):
	x = input().split()
	if x[0] == 'for':
		stack.append(min(stack[-1] * int(x[1]), INF + 1))
	elif x[0] == 'add':
		ans += stack[-1]
	else:
		stack.pop()
	pass
if ans > INF:
	print('OVERFLOW!!!')
else:
	print(ans)


n = int(input())
depth = [1]
result = 0
for j in range(n):
	command = input()
	if command == 'add':
		result += depth[-1]
	elif command == 'end':
		depth.pop()
	elif depth[-1] >= 4294967296:
		depth.append(4294967297)
	else:
		depth.append(depth[-1] * int(command[4:]))
if result >= 4294967296:
	print('OVERFLOW!!!')
else:
	print(result)


MN = 2 ** 32 - 1
loops = [1]
over = [0]
N = 0
for _ in range(int(input())):
	command = input().split()
	if command[0] == 'add':
		if over[-1]:
			print('OVERFLOW!!!')
			break
		N += loops[-1]
		if N > MN:
			print('OVERFLOW!!!')
			break
	if command[0] == 'end':
		loops.pop()
		over.pop()
	if command[0] == 'for':
		if over[-1]:
			loops.append(-1)
			over.append(1)
		else:
			v = loops[-1] * int(command[1])
			if v > MN:
				loops.append(-1)
				over.append(1)
			else:
				loops.append(v)
				over.append(0)
else:
	print(N)


n = int(input())
(lst, count) = ([1], 0)
const = 2 ** 32 - 1
for i in range(n):
	s = input()
	if s[0] == 'f':
		res = lst[-1] * int(s[4:])
		if res > const:
			res = const + 1
		lst.append(res)
	elif s[0] == 'e':
		lst.pop()
	elif len(lst) == 1:
		count += 1
	else:
		count += lst[-1]
		if count > const:
			count = 'OVERFLOW!!!'
			break
	if count > const:
		count = 'OVERFLOW!!!'
		break
print(count)


l = int(input())
b = float('inf')
curr = []
leng = 0
tot = 0
prod = 1
lim = None
save = None
k = 2 ** 32 - 1
for i in range(l):
	if tot == b:
		print('OVERFLOW!!!')
		exit()
	a = input().split()
	if a[0] == 'add':
		tot += prod
	elif a[0] == 'end':
		if lim is None:
			prod //= curr[-1]
			curr.pop()
			leng -= 1
		else:
			curr.pop()
			leng -= 1
			if leng == lim:
				prod = save
				lim = None
	else:
		curr.append(int(a[1]))
		leng += 1
		prod *= int(a[1])
		if prod > k and prod != b:
			save = prod // int(a[1])
			prod = b
			lim = leng - 1
if tot > k:
	print('OVERFLOW!!!')
else:
	print(tot)


import sys
lim = 2 ** 32

def main():
	numLines = int(sys.stdin.readline())
	lines = sys.stdin.read().split('\n')
	stack = []
	for line in lines:
		if len(line) < 3:
			continue
		if line.startswith('add'):
			stack.append(('a', 1))
		elif line.startswith('for'):
			stack.append(('f', int(line.split(' ')[1])))
		else:
			localSum = 0
			while stack[-1][0] == 'a':
				localSum += stack.pop()[1]
			loopNum = stack.pop()[-1]
			stack.append(('a', localSum * loopNum))
			if localSum >= lim:
				return 'OVERFLOW!!!'
	n = 0
	while stack:
		n += stack.pop()[1]
	if n >= lim:
		return 'OVERFLOW!!!'
	return n
print(main())


from sys import stdin

def solve():
	x = 0
	max_x = 2 ** 32 - 1
	loop = 1
	pre_fors = []
	mult = []
	flag = 0
	for _ in range(int(stdin.readline())):
		command = [k for k in stdin.readline().split()]
		if command[0] == 'add':
			if flag:
				x = max_x + 10
				break
			x += loop
		elif command[0] == 'for':
			k = int(command[1])
			if flag or loop * k > max_x:
				mult.append(k)
				flag = 1
			else:
				loop *= k
				pre_fors.append(k)
		elif flag:
			mult.pop()
			if not mult:
				flag = 0
		else:
			k = pre_fors.pop()
			loop //= k
	print('OVERFLOW!!!' if x > max_x else x)
solve()


stack = [1]
ans = 0
g = []
code = []
n = int(input())
for i in range(n):
	line = input()
	if line == 'add':
		ans += stack[-1]
	elif line == 'end':
		stack.pop()
	else:
		a = int(line.split()[-1])
		b = stack[-1]
		stack.append(min(a * b, 2 ** 32))
if ans >= 2 ** 32:
	print('OVERFLOW!!!')
else:
	print(ans)


arun = 1
tot = 0
tim = 1
sta = [1]
inf = 2 ** 32 - 1
for _ in range(int(input())):
	s = input()
	if s[0] == 'a':
		tot += sta[-1]
	elif s[0] == 'e':
		sta.pop()
	else:
		te = int(s[4:])
		te = te * sta[-1]
		if te > inf:
			te = inf + 1
		sta.append(te)
if tot > 2 ** 32 - 1:
	print('OVERFLOW!!!')
else:
	print(int(tot))


import sys, io, os
input = sys.stdin.readline
stack = [0]
cnt = 0
val = 0
k = 2 ** 32 - 1
flag = 0
for _ in range(int(input())):
	curr = input().strip().split()
	if len(curr) == 2:
		stack.append('for')
		stack.append(int(curr[1]))
		stack.append(0)
	elif curr == ['end']:
		cnt = stack.pop()
		times = stack.pop()
		stack.pop()
		curr = cnt * times
		stack[-1] += curr
		if curr > k:
			flag = 1
			break
	else:
		stack[-1] += 1
	if stack[-1] > k:
		flag = 1
		break
if flag:
	print('OVERFLOW!!!')
else:
	print(stack[0])


n = int(input())
x = 0
stack = []
i = 0
while i < n:
	st = input().split()
	if st[0] == 'add':
		stack.append(1)
	elif st[0] == 'for':
		st[1] = int(st[1])
		stack.append(st)
	else:
		temp = 0
		popped = stack.pop()
		while type(popped) == int:
			temp = temp + popped
			popped = stack.pop()
		temp = temp * popped[1]
		if temp > 2 ** 32 - 1:
			print('OVERFLOW!!!')
			exit(0)
		else:
			stack.append(temp)
	i = i + 1
ans = stack.pop()
while len(stack) != 0:
	ans = ans + stack.pop()
if ans > 2 ** 32 - 1:
	print('OVERFLOW!!!')
else:
	print(ans)


inputLines = int(input())
constant = 1
stack = []
init = 0
halt = False
for n in range(inputLines):
	l = input()
	if 'for' in l:
		value = int(l.split()[1])
		if constant * value > 2 ** 32 - 1:
			stack.append(2 ** 32 - 1)
		elif stack and stack[-1] == 2 ** 32 - 1:
			if stack[-1] == 2 ** 32 - 1:
				stack.append(2 ** 32 - 1)
		else:
			constant *= value
			stack.append(value)
	elif 'end' in l:
		value = stack[-1]
		if value != 2 ** 32 - 1:
			constant /= stack[-1]
		stack.pop()
	elif 'add' in l:
		if stack:
			if stack[-1] == 2 ** 32 - 1:
				halt = True
		init += constant
if init > 2 ** 32 - 1 or halt:
	print('OVERFLOW!!!')
else:
	print(int(init))


x = int(input())
x = 0
mx = 2 ** 32
good = True
import sys
mults = []
mult = 1
yeet = False
lastMult = 0
for line in sys.stdin:
	inp = line.split()
	if inp[0] == 'add':
		if lastMult == len(mults):
			x += mult
			if x >= mx:
				good = False
				print('OVERFLOW!!!')
				break
		else:
			good = False
			print('OVERFLOW!!!')
			break
	elif inp[0] == 'for':
		mults.append(int(inp[1]))
		if lastMult == len(mults) - 1:
			if mult * mults[-1] < mx:
				lastMult += 1
				mult *= mults[-1]
	else:
		if lastMult == len(mults):
			mult //= mults[-1]
			lastMult -= 1
		mults.pop()
if good:
	print(x)


lines = int(input())
mults = [1] * lines
val = 0
pos = 0
inc = 1
opos = lines
for i in range(lines):
	line = input().split()
	if line[0] == 'for':
		m = int(line[1])
		mults[pos] = m
		if inc < 2 ** 32:
			inc = inc * m
		elif opos == lines:
			opos = pos
		pos += 1
	elif line[0] == 'end':
		pos -= 1
		if pos < opos:
			opos = lines
			inc = inc // mults[pos]
	else:
		val = val + inc
		if val > 2 ** 32 - 1:
			val = -1
			break
if val == -1:
	print('OVERFLOW!!!')
else:
	print(val)


n = int(input())
l = []
for i in range(n):
	k = input().split(' ')
	l.append(k)
ans = 0
i = 0
lo = 2 ** 32 - 1
flag = 0
while i < n:
	z = l[i]
	if z[0] == 'for':
		ba = []
		x = i
		t = 1
		b = -1
		count = 0
		while x < n:
			if l[x][0] == 'for':
				m = int(l[x][1])
				ba.append(m)
				if t <= lo:
					count += 1
					t *= m
			elif l[x][0] == 'add':
				ans += t
				if ans > lo:
					flag = 1
					break
			elif l[x][0] == 'end':
				if count == len(ba):
					t = t // ba[-1]
					ba.pop(-1)
					count -= 1
				else:
					ba.pop(-1)
				if len(ba) == 0:
					x += 1
					break
			x += 1
		i = x
	elif z[0] == 'add':
		i += 1
		ans += 1
		if ans > lo:
			break
	else:
		i += 1
		if ans > lo:
			break
	if flag == 1:
		break
if ans > lo:
	print('OVERFLOW!!!')
else:
	print(ans)


l = int(input())
arr = []
arr.append(1)
num = 0
flag = 1
N = pow(2, 32) - 1
for i in range(l):
	s = str(input())
	s = s.split(' ')
	if s[0] == 'add':
		if arr[len(arr) - 1] >= N or arr[len(arr) - 1] == -1:
			flag = 0
		num += arr[len(arr) - 1]
	elif s[0] == 'end':
		arr.pop()
	elif arr[len(arr) - 1] * int(s[1]) < 0 or arr[len(arr) - 1] * int(s[1]) > N:
		arr.append(-1)
	else:
		arr.append(arr[len(arr) - 1] * int(s[1]))
if num < 0 or num > N:
	flag = 0
if flag:
	print(num)
else:
	print('OVERFLOW!!!')


from sys import stdin, stdout

def read():
	return stdin.readline().rstrip()

def write(s):
	stdout.write(s + '\n')

def solve():
	l = int(read())
	st = []
	lim = 2 * 2147483647 + 1
	cur = 1
	x = 0
	for i in range(l):
		s = read().split()
		if s[0] == 'for':
			y = int(s[1])
			cur = cur * y if cur * y <= lim else lim + 1
			st.append(cur)
		elif s[0] == 'end':
			st.pop()
			cur = 1 if not st else st[-1]
		else:
			x += cur
			if x > 2 ** 32 - 1:
				write('OVERFLOW!!!')
				break
	else:
		write(str(x))
solve()


l = []
x = 0
m = 2 ** 32 - 1
f = 0
for _ in range(int(input())):
	t = input()
	if f == 1:
		continue
	if t == 'add':
		if len(l) == 0:
			x += 1
		else:
			x += l[-1]
	elif t[:3] == 'for':
		n = int(t[4:])
		if len(l) != 0:
			l.append(min(l[-1] * n, 2 ** 32))
		else:
			l.append(n)
	else:
		l.pop()
	if x > m:
		f = 1
print(x) if f == 0 else print('OVERFLOW!!!')


l = int(input())
x = 0
overflow = False
multip = [1]
maxim = 2 ** 32 - 1
for i in range(l):
	ins = input().split(' ')
	if ins[0] == 'for':
		multip.append(min(maxim + 1, multip[-1] * int(ins[1])))
	if ins[0] == 'add':
		x += multip[-1]
	if ins[0] == 'end':
		del multip[-1]
	if x > maxim:
		overflow = True
		break
if overflow:
	print('OVERFLOW!!!')
else:
	print(x)


index = 1
x = 0
overflow = 2 ** 32 - 1
innerLoop = []
numberOfTimes = int(input())
while index <= numberOfTimes:
	entry = input().split()
	if entry[0] == 'for':
		if len(innerLoop) == 0:
			innerLoop.append(int(entry[1]))
		elif innerLoop[-1] != -1 and innerLoop[-1] * int(entry[1]) < overflow:
			innerLoop.append(innerLoop[-1] * int(entry[1]))
		else:
			innerLoop.append(-1)
	elif entry[0] == 'end':
		innerLoop.pop()
	elif len(innerLoop) != 0 and innerLoop[-1] == -1:
		x = 2 ** 33
		break
	elif len(innerLoop) == 0:
		x += 1
	else:
		x += innerLoop[-1]
	index += 1
if x > overflow:
	print('OVERFLOW!!!')
else:
	print(x)


N = int(input())
stack = []
ans = 0
Max = (1 << 32) - 1
total = 1
flag = False
for i in range(N):
	x = [x for x in input().split()]
	if x[0] == 'add':
		if not stack:
			ans += 1
		else:
			ans += stack[-1]
	elif x[0] == 'for':
		if stack:
			stack.append(min(Max + 1, int(x[1]) * stack[-1]))
		else:
			stack.append(int(x[1]))
	else:
		del stack[-1]
	if ans > Max:
		flag = True
		break
if flag:
	print('OVERFLOW!!!')
else:
	print(int(ans))


fors = []
adds = []
n = int(input())
total = 0
valid = True
while n:
	n -= 1
	string = input().split()
	strC = string[0]
	if strC == 'for':
		k = int(string[1])
		if len(fors) == 0:
			fors.append(k)
		else:
			lastK = fors[-1]
			res = lastK * k
			fors.append(min(res, 4294967299))
		adds.append(0)
	elif strC == 'add':
		if len(fors) == 0:
			total += 1
		else:
			adds[-1] = adds[-1] + 1
	elif strC == 'end':
		topF = fors[-1]
		fors.pop()
		topA = adds[-1]
		adds.pop()
		total += topF * topA
	if total > 4294967295:
		valid = False
if valid:
	print(total)
else:
	print('OVERFLOW!!!')


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:
			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()


result = 0
commands_stack = []
remaining_space = 2 ** 32 - 1
rolling_denominator = 1
overflow = False
ends_before_safe = 0
number_of_commands = int(input())
for line in range(number_of_commands):
	command = input().rstrip()
	if not overflow:
		if command == 'add':
			result += rolling_denominator
			if result > remaining_space or ends_before_safe > 0:
				overflow = True
		elif 'for' in command:
			if ends_before_safe > 0 or result + rolling_denominator * int(command.split(' ')[1]) > remaining_space:
				ends_before_safe += 1
			else:
				commands_stack.append(int(command.split(' ')[1]))
				rolling_denominator *= int(command.split(' ')[1])
		elif command == 'end':
			if ends_before_safe > 0:
				ends_before_safe -= 1
			else:
				rolling_denominator = max(rolling_denominator / commands_stack.pop(), 1)
if overflow:
	print('OVERFLOW!!!')
else:
	print(int(result))


from posixpath import split
import sys
from typing import List
total_users = int(sys.stdin.readline())
stack_result = [1]
limit = 2 ** 32
res = 0
overflow = False
for _ in range(total_users):
	line = sys.stdin.readline().rstrip()
	if 'for' in line:
		[_, value] = line.split(' ')
		stack_result.append(min(limit, stack_result[-1] * int(value)))
	elif 'end' in line:
		stack_result.pop()
	else:
		overflow = limit - stack_result[-1] <= res
		if not overflow:
			res += stack_result[-1]
	if overflow:
		print('OVERFLOW!!!')
		break
if not overflow:
	print(res)


from sys import stdin, stdout
import collections
import math
lines = int(input())
stack = []
times = 1
num = 0
valid = 1
L = 0
while L < lines:
	s = input()
	if s == 'add':
		if not stack:
			num += 1
		else:
			num += stack[-1]
	elif s[0] == 'f':
		(f, t) = s.split(' ')
		t = int(t)
		if not stack:
			stack.append(t)
		else:
			stack.append(min(stack[-1] * t, 4294967296))
	elif s == 'end':
		p = stack.pop()
	if num >= 4294967296:
		valid = 0
	L += 1
if valid == 1:
	print(num)
else:
	print('OVERFLOW!!!')


def solve(stack):
	res = 0
	mul = [1]
	for (op, n) in stack:
		if op == '+':
			res += mul[-1]
			if res > 2 ** 32 - 1:
				return -1
		elif op == '(':
			mul.append(min(2 ** 32, mul[-1] * n))
		else:
			mul.pop()
	return res
l = int(input())
stack = []
for _ in range(l):
	line = input()
	if line[:3] == 'add':
		stack.append(('+', 1))
	elif line[:3] == 'for':
		n = int(line[4:])
		stack.append(('(', n))
	elif stack[-1][0] == '(':
		stack.pop()
	else:
		stack.append((')', 0))
res = solve(stack)
print('OVERFLOW!!!' if res == -1 else res)


l = int(input())
stack = [1]
flag = False
x = 0
INF = 2 ** 32 - 1
for i in range(l):
	cmd = input()
	if cmd[0] == 'f':
		t = stack[-1] * int(cmd.split()[1])
		if t > INF:
			t = INF + 1
		stack.append(t)
	if cmd[0] == 'e':
		stack.pop()
	if cmd[0] == 'a':
		x += stack[-1]
		if x > INF:
			flag = True
if flag == True:
	print('OVERFLOW!!!')
else:
	print(x)


l = int(input())
(x, m, p) = (0, 1, 0)
st = []
for i in range(l):
	s = input()
	if s == 'add':
		x += m
	elif s == 'end':
		if p:
			p -= 1
			st.pop()
		else:
			m //= st.pop()
	else:
		s = int(s.split()[1])
		st.append(s)
		if m > 2 ** 32:
			p += 1
		else:
			m *= s
	if x >= 2 ** 32:
		print('OVERFLOW!!!')
		break
else:
	print(x)


from collections import deque
base = 2 ** 32 - 1
n = int(input())
s = deque()
s.append(1)
acc = 0
for _ in range(n):
	cmd = input()
	if cmd == 'add':
		acc += s[-1]
		if acc > base:
			print('OVERFLOW!!!')
			exit(0)
	elif cmd == 'end':
		s.pop()
	else:
		num = int(cmd[4:])
		nxt = s[-1] * num
		if nxt > base:
			nxt = base + 1
		s.append(nxt)
print(acc)


l = int(input())
loops = []
m = 2 ** 32
c_val = 0
val_loops = 1
num_of_zer = 0
tab = []
pom_tab = []
pom_licz = 0
for x in range(l):
	tab.append(str(input()))
for x in tab:
	if x[0] == 'a':
		pom_licz = 0
		pom_tab.append(x)
	elif x[0] == 'f':
		pom_tab.append(x)
		pom_licz += 1
	elif pom_licz > 0:
		pom_tab.pop()
		pom_licz -= 1
	else:
		pom_tab.append(x)
for x in pom_tab:
	c_line = x
	c_loop = 0
	if c_line[0] == 'a':
		if val_loops >= m:
			print('OVERFLOW!!!')
			exit(0)
		c_val += val_loops
		if c_val >= m:
			print('OVERFLOW!!!')
			exit(0)
	elif c_line[0] == 'e':
		val_loops = int(val_loops / loops[-1])
		loops.pop()
	else:
		loops.append(int(c_line.split(' ')[1]))
		val_loops = val_loops * int(c_line.split(' ')[1])
print(c_val)


def ii():
	return int(input())

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

def li():
	return list(mi())
overflow = 'OVERFLOW!!!'
maxx = pow(2, 32)
n = ii()
li = []
adds = []
tot = 0
ans = 0
lst = 0
for i in range(n):
	str = input()
	if str == 'add':
		if len(li) == 0:
			ans += 1
		else:
			adds[-1] += 1
			tot += 1
	elif str[:3] == 'for':
		lst = 0
		adds.append(0)
		(a, x) = str.split()
		x = int(x)
		if len(li) > 0:
			x *= li[-1]
		if x >= maxx:
			x = maxx
		li.append(x)
	else:
		vals = li[-1]
		li.pop()
		ans += vals * adds[-1]
		adds.pop()
		tot -= lst
		tot = 0
if ans >= maxx:
	print(overflow)
else:
	print(ans)


j = 0
k = 1
import re
a = []
p = 1
f = 2 ** 32
ch = 0
n = int(input())
for i in range(0, n):
	b = input()
	if b == 'add':
		if ch > 0:
			p = 0
		j += k
		if j >= f:
			p = 0
	if b[0] == 'f':
		(x, y) = re.split('\\s+', b)
		y = int(y)
		k *= y
		if k >= f or ch > 0:
			k = k // y
			ch += 1
			continue
		a.append(y)
	if b == 'end':
		if ch > 0:
			ch -= 1
			continue
		k = k // a[-1]
		a.pop()
if p == 1:
	print(int(j))
else:
	print('OVERFLOW!!!')


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

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

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n + 1)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def maxSubArraySum(a, size):
	maxint = 10 ** 10
	max_so_far = -maxint - 1
	max_ending_here = 0
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far
maxx = 2 ** 32

def solve():
	n = int(input())
	res = 0
	stack = [1]
	for _ in range(n):
		s = input()
		if s == 'add':
			res += stack[-1]
		elif 'for' in s:
			s = s.split()
			s = int(s[1])
			stack.append(min(s * stack[-1], maxx))
		else:
			stack.pop()
	if res < maxx:
		print(res)
		return
	print('OVERFLOW!!!')
t = 1
for _ in range(t):
	solve()


import sys

def fastio():
	from io import StringIO
	from atexit import register
	global input
	sys.stdin = StringIO(sys.stdin.read())
	input = lambda : sys.stdin.readline().rstrip('\r\n')
	sys.stdout = StringIO()
	register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

def debug(*var, sep=' ', end='\n'):
	print(*var, file=sys.stderr, end=end, sep=sep)
INF = 10 ** 20
MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

def error():
	print('OVERFLOW!!!')
	exit()
(l,) = I()
stack = []
ans = 0
count = 0
ins = []
ok = []
for i in range(l):
	ins.append(input())
	s = ins[-1]
for i in range(l):
	s = ins[i]
	if s == 'add':
		if not stack:
			ans += 1
		else:
			if count > 60:
				error()
			cur = 1
			for i in stack:
				cur *= i
				if cur > INF:
					cur = INF
			ans += cur
	elif s == 'end':
		k = ok.pop()
		if k > 1:
			stack.pop()
			count -= 1
	else:
		k = int(s[4:])
		if k > 1:
			stack.append(int(s[4:]))
			count += 1
		ok.append(k)
	if ans > 2 ** 32 - 1:
		error()
print(ans)


q = int(input())
ans = 0
l = [1]
for i in range(0, q):
	ss = input()
	if ss == 'add':
		ans += l[-1]
		if ans > 4294967295:
			print('OVERFLOW!!!')
			exit(0)
	elif ss == 'end':
		l.pop()
	else:
		n = int(ss[4:])
		l.append(min(n * l[-1], 4294967296))
print(int(ans))


import sys

def input():
	return sys.stdin.readline().strip()

def print(*x, sep=' ', end='\n'):
	return sys.stdout.write(sep.join(map(str, x)) + end)

def read():
	return sys.stdin.read()

def get():
	return map(int, input().split())

def out(*arg):
	if type(arg[0]) == list:
		for i in arg[0]:
			print(i)
	else:
		print(arg)

def main():
	x = 0
	over = 2 ** 32 - 1
	cur_mul = []
	last_good = 0
	good = -1
	cur = 1
	for i in range(int(input())):
		s = input()
		if s == 'end':
			val = cur_mul.pop()
			if len(cur_mul) == last_good:
				cur = good
			elif len(cur_mul) < last_good:
				cur //= val
				good = cur
				last_good = len(cur_mul)
		elif s == 'add':
			if len(cur_mul) > last_good:
				print('OVERFLOW!!!')
				return 0
			x += cur
			if x > over:
				print('OVERFLOW!!!')
				return 0
		else:
			val = int(s.split()[1])
			cur_mul.append(val)
			if cur < over:
				cur *= val
				good = cur
				last_good = len(cur_mul)
	print(x)
main()


from sys import stdin
inp = stdin.readline
n = int(inp())
overflow_num = 2 ** 32
overflow = False
stack = [1]
add_count = 0
loop_count = 1
ans = 0
while n:
	n -= 1
	inst = inp().split()
	if overflow:
		continue
	if inst[0] == 'add':
		ans += stack[-1]
		if ans >= overflow_num:
			overflow = True
	elif inst[0] == 'for':
		stack.append(min(int(inst[1]) * stack[-1], overflow_num))
	else:
		stack.pop()
print('OVERFLOW!!!' if overflow else ans)


from collections import deque
from sys import stdin
LIMIT = 2 ** 32 - 1

def solve():
	loops = deque([1])
	total = 0
	n = int(stdin.readline().rstrip())
	for _ in range(n):
		line = stdin.readline().rstrip()
		if line[0] == 'a':
			total += loops[-1]
		elif line[0] == 'f':
			loops.append(min(loops[-1] * int(line[3:]), LIMIT + 1))
		else:
			loops.pop()
		if total > LIMIT:
			print('OVERFLOW!!!')
			return
	print(total)
solve()


l = int(input())
q = 1
res = 0
c = []
d = []
u = 1
qwe = 0
for i in range(l):
	x = input()
	z = x[:3]
	if z == 'add':
		if u == 0:
			q = 1
			for j in c:
				q *= j
				if q > 2 ** 32 - 1:
					qwe = 1
					res = 2 ** 32
					break
			if qwe:
				print('OVERFLOW!!!')
				break
		res += q
		u = 1
	elif z == 'end':
		if d.pop() > 1:
			c.pop()
		u = 0
	else:
		y = int(x.split()[1])
		d.append(y)
		if y > 1:
			c.append(y)
			u = 0
	if res > 2 ** 32 - 1:
		print('OVERFLOW!!!')
		break
if res <= 2 ** 32 - 1:
	print(res)
else:
	pass


import sys
MAX_NUMBER = 2 ** 32 - 1

def solve():
	input = sys.stdin.readline
	n = int(input())
	stack = []
	for _ in range(n):
		oper = input().strip()
		if oper == 'add':
			stack.append(1)
		elif oper == 'end':
			cur = 0
			while len(stack) > 0:
				o = stack.pop()
				if type(o) == int:
					cur += o
				else:
					(_, loop) = o.split()
					loop = int(loop)
					cur *= loop
					break
				if cur > MAX_NUMBER:
					print('OVERFLOW!!!')
					return
			stack.append(cur)
		else:
			stack.append(oper)
	answer = sum(stack)
	if answer > MAX_NUMBER:
		print('OVERFLOW!!!')
	else:
		print(answer)
solve()


(s, t) = ([0.0], [])
for _ in range(int(input())):
	c = input()
	if c[0] == 'f':
		s.append(0.0)
		t.append(int(c.split()[1]))
	else:
		s[-1] = s[-1] + 1 if c[0] == 'a' else s.pop() * t.pop() + s[-1]
print('OVERFLOW!!!' if s[0] > 2 ** 32 - 1 else int(s.pop()))


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
from collections import defaultdict
from itertools import permutations
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
check = 2 ** 32 - 1
x = 0
f = list()
f.append(1)
j = 0
ch = 1
curr = 1
for i in range(n):
	a = list(map(str, input().split(' ')))
	if a[0] == 'for':
		curr = int(a[1]) * f[-1]
		curr = min(curr, check + 1)
		f.append(curr)
		j += 1
	elif a[0] == 'add':
		x += f[-1]
	else:
		f.pop()
	if x > check:
		ch = 0
		break
if ch == 1:
	print(x)
else:
	print('OVERFLOW!!!')


import sys
N = int(input())
stk = [1]
stk2 = [1]
x = 0
flag = 1

def check(x):
	if x < 2 ** 32:
		return True
	return False

def multcheck(stk):
	mult = 1
	for bar in stk:
		mult *= bar
		if mult >= 2 ** 32:
			return False
	return mult
for n in range(N):
	cmd = sys.stdin.readline()
	if cmd[0] == 'a':
		mlt = multcheck(stk2)
		if not mlt:
			flag = 0
			break
		x += mlt
		if not check(x):
			flag = 0
			break
		continue
	if cmd[0] == 'f':
		m = int(cmd[4:])
		stk.append(m)
		if m != 1:
			stk2.append(m)
		continue
	if cmd[0] == 'e':
		if stk.pop() != 1:
			stk2.pop()
		continue
if flag:
	print(int(x))
else:
	print('OVERFLOW!!!')


import sys

class Main:

	def __init__(self):
		self.buff = None
		self.index = 0

	def next(self):
		if self.buff is None or self.index == len(self.buff):
			self.buff = self.next_line()
			self.index = 0
		val = self.buff[self.index]
		self.index += 1
		return val

	def next_line(self):
		return sys.stdin.readline().split()

	def next_ints(self):
		return [int(x) for x in sys.stdin.readline().split()]

	def next_int(self):
		return int(self.next())

	def solve(self):
		n = self.next_int()
		try:
			print(self.f(n))
		except Exception as e:
			print('OVERFLOW!!!')

	def f(self, n):
		lmt = 2 ** 32 - 1
		stk = []
		x = 0
		while n > 0:
			cmd = self.next()
			n -= 1
			if cmd == 'add':
				x += 1
				if x > lmt:
					raise Exception()
			elif cmd == 'end':
				x = x * stk[-1][1] + stk[-1][0]
				if x > lmt:
					raise Exception()
				stk.pop()
			else:
				stk.append((x, self.next_int()))
				x = 0
		return x
Main().solve()


s = [0.0]
t = []
for _ in [0] * int(input()):
	c = input()
	if c[0] > 'e':
		s.append(0.0)
		t.append(int(c[4:]))
	else:
		s[-1] = s[-1] + 1 if c[0] < 'b' else s.pop() * t.pop() + s[-1]
print(int(s[0]) if s[0] < 2 ** 32 else 'OVERFLOW!!!')


from sys import stdin, setrecursionlimit
import heapq
import collections
setrecursionlimit(15000)
l = int(stdin.readline().strip())
commands = []
for _ in range(l):
	commands.append(stdin.readline().strip())
num = 0
mystack = []
for i in range(len(commands)):
	if num >= 2 ** 32:
		break
	if commands[i] == 'add':
		if len(mystack) > 0:
			num += mystack[-1][1]
		else:
			num += 1
	elif commands[i] == 'end':
		mystack.pop()
	else:
		commands[i] = commands[i].split()
		times = int(commands[i][1])
		if len(mystack) > 0:
			times = times * mystack[-1][1]
			if times > 10 ** 10:
				times = 10 ** 10
			mystack.append([-1, times])
		else:
			mystack.append([-1, times])
if num <= 2 ** 32 - 1:
	print(num)
else:
	print('OVERFLOW!!!')


import os
import heapq
import sys
import math
import bisect
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def gcd(a, b):
	if b == 0:
		return a
	else:
		return gcd(b, a % b)

def power(x, p, m):
	res = 1
	while p:
		if p & 1:
			res = res * x % m
		x = x * x % m
		p >>= 1
	return res

def inar():
	return [int(k) for k in input().split()]

def lcm(num1, num2):
	return num1 * num2 // gcd(num1, num2)

def binaryToDecimal(n):
	return int(n, 2)

def main():
	n = int(input())
	expression = []
	for i in range(n):
		lis = list(input().split())
		expression.append(lis)
	forr = []
	stack = [0]
	for i in range(n):
		if expression[i][0] == 'for':
			forr.append(expression[i][1])
			stack.append(0.0)
		if expression[i][0] == 'add':
			stack[-1] += 1
		if expression[i][0] == 'end':
			stack[-1] = stack.pop() * int(forr.pop()) + stack[-1]
	if stack[0] > 2 ** 32 - 1:
		print('OVERFLOW!!!')
	else:
		print(int(stack[0]))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
line = int(input())
res = 0
stack = [1]
ub = 2 ** 32
cmds = (sys.stdin.readline().split() for _ in range(line))
for cmd in cmds:
	if cmd[0] == 'add':
		res += stack[-1]
	elif cmd[0] == 'for':
		stack.append(min(ub, stack[-1] * int(cmd[1])))
	else:
		stack.pop()
print(res if res < ub else 'OVERFLOW!!!')


stk = list()
calcStk = list([0])
addMap = dict()
currentID = 0

def checkX(x):
	if x > pow(2, 32) - 1:
		raise ValueError()

def main():
	global currentID
	l = int(input())
	x = 0
	while l:
		inp = input().strip().split()
		(cmd, arg) = (None, None)
		if len(inp) > 1:
			(cmd, arg) = inp
		else:
			cmd = inp[0]
		if arg:
			stk.append(int(arg))
			calcStk.append(0)
			currentID += 1
		elif cmd == 'end':
			n = stk.pop()
			addTotal = n * addMap.get(currentID, 0)
			val = calcStk.pop() * n + addTotal
			calcStk[len(calcStk) - 1] += val
			addMap[currentID] = 0
			currentID -= 1
		else:
			try:
				addMap[currentID] += 1
			except KeyError:
				addMap[currentID] = 1
		l -= 1
		checkX(calcStk[len(calcStk) - 1])
	calcStk[0] += addMap.get(0, 0)
	checkX(calcStk[0])
	return calcStk[0]
try:
	print(main())
except ValueError:
	print('OVERFLOW!!!')


MAX = 2 ** 32 - 1
ANS = 'OVERFLOW!!!'

def main():
	n = int(input())
	x = 0
	m = 1
	stack = []
	overflow = 0
	for i in range(n):
		line = list(input().split())
		if line[0] == 'add':
			if overflow > 0:
				print(ANS)
				return
			x += m
		elif line[0] == 'for':
			if overflow == 0:
				if m * int(line[1]) <= MAX:
					m = m * int(line[1])
				else:
					overflow += 1
			else:
				overflow += 1
			stack.append(int(line[1]))
		elif line[0] == 'end':
			popped = stack.pop()
			if overflow > 0:
				overflow -= 1
			else:
				m = m // popped
		if x > MAX or x < 0:
			print(ANS)
			return
	print(x)
main()


lulu = int(input())
af = []
bf = []
for i in range(lulu + 5):
	bf.append(0)
	af.append(0)
temp = 1
ii = 1
for i in range(20):
	tub = 1
gandu = 2 ** 32 - 1
over = 0
ans = 0
af[0] = 1
bf[0] = 1
for i in range(lulu):
	x = list(input().split())
	if x[0] == 'add':
		ans += bf[ii - 1] * 1
	elif x[0] == 'for':
		af[ii] = int(x[1])
		bf[ii] = int(x[1]) * bf[ii - 1]
		if bf[ii] > gandu:
			bf[ii] = gandu + 2
		ii += 1
	elif x[0] == 'end':
		temp = bf[ii - 1] // af[ii - 1]
		ii -= 1
	if ans > gandu:
		over = 1
		break
for i in range(10):
	cunt = 0
if over == 1:
	print('OVERFLOW!!!')
else:
	print(ans)


l = int(input())
S = []
over = 2 ** 32
flg = True
for _ in range(l):
	s = input().split()
	if len(s) == 2:
		S.append(['(', int(s[1])])
	elif s[0] == 'end':
		add = 0
		while S[-1][0] != '(':
			add += S.pop()[0]
		mul = S.pop()[1]
		add = add * mul
		if add >= over:
			flg = False
			break
		S.append([add])
	else:
		S.append([1])
if flg == False:
	print('OVERFLOW!!!')
else:
	Sum = 0
	while len(S) > 0:
		Sum += S.pop()[0]
	if Sum >= over:
		print('OVERFLOW!!!')
	else:
		print(Sum)


linesInt = int(input())
overflowLimit = 2 ** 32 - 1
baseX = 0
cacheMulti = [1]
for i in range(linesInt):
	xd = input()
	if 'for' in xd:
		if cacheMulti[-1] * int(xd.split()[-1]) < overflowLimit:
			cacheMulti.append(cacheMulti[-1] * int(xd.split()[-1]))
		else:
			cacheMulti.append(overflowLimit + 1)
	elif 'add' in xd:
		baseX += cacheMulti[-1]
	elif 'end' in xd:
		cacheMulti.pop()
if baseX >= overflowLimit + 1:
	print('OVERFLOW!!!')
else:
	print(baseX)


def main():
	(stack_1, stack_2) = ([0.0], [])
	for _ in range(int(input())):
		command = input()
		if command == 'add':
			stack_1[-1] += 1.0
		elif command == 'end':
			cnt = stack_1.pop()
			stack_1[-1] += cnt * stack_2.pop()
		else:
			stack_1.append(0.0)
			stack_2.append(float(command.split()[1]))
	print('OVERFLOW!!!' if stack_1[0] > 2 ** 32 - 1 else int(stack_1.pop()))
main()


from collections import deque
MAX = 2 ** 32 - 1

def func(num):
	stack = deque()
	val = 0
	for _ in range(num):
		op = input().split(' ')
		if op[0] == 'for':
			stack.append((val, int(op[1])))
			val = 0
		elif op[0] == 'add':
			val += 1
		elif op[0] == 'end':
			(_val, n) = stack.pop()
			val = _val + val * n
		if val > MAX:
			return 'OVERFLOW!!!'
	return val
print(func(int(input())))


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)


owr = 4294967295
a = int(input())
stack = [1]
key = True
x = 0
for j in range(a):
	i = input()
	if i == 'add':
		if stack[-1] > owr:
			print('OVERFLOW!!!')
			key = False
			break
		x += stack[-1]
		if x > owr:
			print('OVERFLOW!!!')
			key = False
			break
	elif i[:3] == 'for':
		stack.append(min(int(i[4:]) * stack[-1], owr + 1))
	else:
		stack.pop()
if key:
	print(x)


n = int(input())
mxx = 4294967295
stack = [[1, 0]]
for i in range(n):
	str = input().split()
	if str[0] == 'add':
		stack[-1][1] += 1
	elif str[0] == 'for':
		stack.append([int(str[1]), 0])
	elif str[0] == 'end':
		stack[-2][1] += stack[-1][1] * stack[-1][0]
		if stack[-2][1] > mxx:
			stack[0][1] = mxx + 1
			break
		stack.pop()
x = stack[0][1]
if x > mxx:
	print('OVERFLOW!!!')
else:
	print(x)


t = int(input())
stack = []
ans = 0
over = 2 ** 32 - 1
final = []
for _ in range(t):
	n = list(input().split())
	if len(final) == 0:
		final.append(n)
	elif n[0] == 'end':
		if final[-1][0] == 'for':
			final.pop(-1)
		else:
			final.append(n)
	else:
		final.append(n)
flag = 0
for n in final:
	if n[0] == 'for':
		if len(stack) == 0:
			stack.append(int(n[1]))
		else:
			stack.append(int(n[1]) * stack[-1])
		if stack[-1] > over:
			flag = 1
			break
	if n[0] == 'end':
		stack.pop(-1)
	if n[0] == 'add':
		if len(stack) == 0:
			ans += 1
		else:
			ans += stack[-1]
if ans > over or flag == 1:
	print('OVERFLOW!!!')
else:
	print(ans)


l = int(input())
ans = 0
mul = [1]
lim = 2 ** 32
for i in range(l):
	s = input()
	if s == 'add':
		ans += mul[-1]
	elif s[:3] == 'for':
		s = int(s.split()[1])
		mul.append(min(s * mul[-1], lim))
	else:
		mul.pop()
	if ans >= lim:
		ans = 'OVERFLOW!!!'
		break
print(ans)


n = int(input())
ans = 0
maxi = 2 ** 32 - 1
st = [1]
m = 1
for k in range(n):
	s = input()
	if s == 'end':
		m //= st.pop()
	elif s == 'add':
		ans += m
		if ans > maxi:
			ans = 'OVERFLOW!!!'
			break
	else:
		t = int(s.split(' ')[1])
		if m > maxi * 2 ** 10:
			t = 1
		m *= t
		st.append(t)
print(ans)


l = int(input())
a = []
for _ in range(l):
	w = input()
	if w[0] == 'a':
		a.append('1')
	else:
		a.append(w)
st = []
for i in a:
	if i == '1':
		st.append(i)
	elif i[0] == 'f':
		st.append(i)
	else:
		c = 0
		while st[-1][0] != 'f':
			c += int(st.pop(-1))
		r = st.pop(-1)
		c = int(r[4:]) * c
		st.append(str(c))
		if c >= 2 ** 32:
			print('OVERFLOW!!!')
			exit()
x = 0
while st:
	x += int(st.pop(-1))
	if x >= 2 ** 32:
		print('OVERFLOW!!!')
		exit()
print(x)


n = int(input())
multipliers = [1]
x = 0
for i in range(n):
	s = input()
	if 'add' in s:
		x += multipliers[-1]
	elif 'for' in s:
		if multipliers[-1] * int(s[4:]) < 2 ** 32:
			multipliers.append(multipliers[-1] * int(s[4:]))
		else:
			multipliers.append(2 ** 32)
	elif 'end' in s:
		multipliers.pop()
	if x >= 2 ** 32:
		x = 'OVERFLOW!!!'
		break
print(x)


l = int(input())
factor = 1
x = 0
stack = []
bad = False
badcounter = 0
for i in range(l):
	cmd = input()
	if x >= 1 << 32:
		break
	if cmd.split()[0] == 'add':
		if bad:
			print('OVERFLOW!!!')
			exit(0)
		x += factor
	elif cmd.split()[0] == 'for':
		c = int(cmd.split()[1])
		if not bad:
			bad = factor * c >= 1 << 32
		if not bad:
			stack.append(c)
			factor *= c
		else:
			badcounter += 1
	elif cmd.split()[0] == 'end':
		if badcounter > 0:
			badcounter -= 1
			if badcounter == 0:
				bad = False
		else:
			c = stack.pop()
			factor //= c
			bad = False
if x >= 1 << 32:
	print('OVERFLOW!!!')
else:
	print(x)


n = int(input())
stack = [1]
counter = 0
for i in range(n):
	a = input().split()
	if a[0] == 'for':
		stack.append(min(2 ** 32, stack[-1] * int(a[1])))
	elif a[0] == 'add':
		counter += stack[-1]
	else:
		stack.pop()
if counter >= 2 ** 32:
	print('OVERFLOW!!!')
else:
	print(counter)


l = int(input())
x = 0
q = [1]
mx = (1 << 32) - 1
for i in range(l):
	s = input()
	if s == 'add':
		x += q[-1]
		if x > mx:
			print('OVERFLOW!!!')
			exit(0)
	elif s[0] == 'f':
		(s1, s2) = s.split(' ')
		s2 = int(s2)
		nxt = min(q[-1] * s2, mx + 1)
		q.append(nxt)
	else:
		q.pop()
print(x)


n = int(input())
s = []
sum1 = 0
f = False
for i in range(n):
	a = input()
	buf = 0
	if 'for' in a:
		s.append(a)
	elif a == 'add':
		s.append('1')
	else:
		while 'for' not in s[-1]:
			buf += int(s.pop())
		b = s.pop()
		t = int(b[4:]) * buf
		if t > 2 ** 32 - 1:
			f = True
			break
		s.append(str(t))
if f == True:
	print('OVERFLOW!!!')
else:
	while len(s) != 0:
		if sum1 > 2 ** 32 - 1:
			f = True
			print('OVERFLOW!!!')
			break
		else:
			sum1 += int(s.pop())
	if not f and sum1 <= 2 ** 32 - 1:
		print(sum1)
	else:
		print('OVERFLOW!!!')


def f(R):
	if R == 0:
		return 0
	F = 0
	S = 0
	cur = 1
	for i in range(150):
		t = min(cur, R - F - S)
		if i % 2 == 0:
			F = F + t
		else:
			S = S + t
		cur = cur * 2
		if R == F + S:
			break
	ans = F * F + S * S + S
	return ans
import math
N = int(input())
V = [1]
it = 1
den = 1
flag = 0
x = 0
for i in range(N):
	s = input()
	s += ' last'
	s = s.strip().split()
	if s[0] == 'for':
		n = int(s[1].strip())
		if it > 2 ** 32:
			n = 1
		it *= n
		V.append(n)
	elif s[0] == 'add':
		x += it
		if x >= 2 ** 32:
			flag = 1
			break
	elif s[0] == 'end':
		it /= V[-1]
		V.pop()
if flag == 1:
	print('OVERFLOW!!!')
else:
	print(int(x))


cf = 1
n = 0
a = []
f = 0
countextra = 0
for _ in range(int(input())):
	s = input()
	s = s.split()
	if 'add' == s[0]:
		if cf == 1:
			n = n + 1
		else:
			n = n + cf
	elif 'for' == s[0]:
		if f == 0:
			a.append(int(s[1]))
			cf = cf * int(s[1])
		else:
			countextra += 1
	elif 'end' == s[0]:
		if countextra == 0 and len(a) >= 1:
			cf = cf // a.pop(len(a) - 1)
		else:
			countextra -= 1
	if n > 2 ** 32 - 1:
		print('OVERFLOW!!!')
		exit()
	if cf > 2 ** 32 - 1:
		f = 1
	else:
		f = 0
print(n)


l = int(input())
mx = 2 ** 32 - 1
stk = []
mul = 1
res = 0
done = False
for pp in range(l):
	wor = input()
	data = wor.split()
	nn = 1
	if len(wor) > 3:
		wor = data[0]
		nn = int(data[1])
	if wor == 'for' and done == False:
		if mul <= mx:
			mul = mul * nn
			stk.append(nn)
		else:
			stk.append(-1)
	if wor == 'add' and done == False:
		res = res + mul
		if res > mx:
			done = True
	if wor == 'end' and done == False:
		div = stk.pop()
		if div != -1:
			mul = mul // div
if done == True:
	print('OVERFLOW!!!')
else:
	print(res)


n = int(input())
stk = []
ptr = -1
mx = 2 ** 32 - 1
cur = 0
flag = 0
for i in range(n):
	s = [x for x in input().split()]
	if cur > mx:
		flag = 1
		break
	if s[0] == 'add':
		if len(stk) > 0:
			if stk[-1] == 'inf':
				flag = 1
				break
			cur += stk[-1]
		else:
			cur += 1
	elif s[0] == 'for':
		if len(stk) > 0:
			if stk[-1] == 'inf':
				stk.append('inf')
				continue
			if stk[-1] * int(s[1]) >= mx + 1:
				stk.append('inf')
				continue
			stk.append(stk[-1] * int(s[1]))
		else:
			stk.append(int(s[1]))
	elif s[0] == 'end':
		stk.pop()
if cur > mx:
	flag = 1
print([cur, 'OVERFLOW!!!'][flag == 1])


n = int(input())
stack = []
limit = 2 ** 32 - 1
x = 0
f = 0
for i in range(n):
	inpt = input()
	if x > limit:
		f = 1
		break
	if inpt.startswith('for'):
		inp = [i for i in inpt.split()]
		if len(stack) > 0:
			if stack[-1] == 'inf':
				stack.append('inf')
				continue
			if stack[-1] * int(inp[1]) >= limit + 1:
				stack.append('inf')
				continue
			stack.append(stack[-1] * int(inp[1]))
		else:
			stack.append(int(inp[1]))
	elif inpt == 'add':
		if len(stack) > 0:
			if stack[-1] == 'inf':
				f = 1
				break
			x += stack[-1]
		else:
			x += 1
	elif inpt == 'end':
		stack.pop()
if x > limit:
	f = 1
if not f:
	print(x)
else:
	print('OVERFLOW!!!')


l = int(input())
st = []
ops = [0]
f = True
for _ in range(l):
	s = input().split()
	if not f:
		continue
	if s[0] == 'for':
		st.append(int(s[1]))
		ops.append(0)
	elif s[0] == 'add':
		ops[-1] += 1
	elif s[0] == 'end':
		x = ops.pop() * st.pop()
		ops[-1] += x
	if ops[-1] > (1 << 32) - 1:
		f = False
if f:
	print(ops[-1])
else:
	print('OVERFLOW!!!')


mx = 2 ** 32 - 1

class Stack:

	def __init__(self):
		self.items = []

	def isEmpty(self):
		return self.items == []

	def push(self, item):
		self.items.insert(0, item)

	def pop(self):
		return self.items.pop(0)

	def peek(self):
		return self.items[0]

	def size(self):
		return len(self.items)
l = int(input())
k = Stack()
k.push(1)
c = 0
for i in range(l):
	st = input().strip()
	if st == 'add':
		c += k.peek()
	elif st[:3] == 'for':
		k.push(min(k.peek() * int(st[4:]), mx + 1))
	elif st == 'end':
		k.pop()
	if c > mx:
		c = 'OVERFLOW!!!'
		break
print(c)


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)


from sys import stdin
input = stdin.readline
lim = 2 ** 32 - 1
n = int(input())
x = 0
ml = 1
reps = [1]
for _ in range(n):
	cmd = input().split()
	if len(cmd) == 2:
		if ml <= lim:
			reps.append(int(cmd[1]))
			ml *= reps[-1]
		else:
			reps.append(1)
	elif cmd[0] == 'end':
		ml //= reps.pop()
	else:
		x += ml
		if x > lim:
			print('OVERFLOW!!!')
			exit()
print(x)


n = int(input())
x = 0
tot = 1
stack = []
for i in range(n):
	c = input()
	if c == 'add':
		if len(stack):
			x += stack[-1]
		else:
			x += 1
	elif c == 'end':
		stack.pop()
	else:
		c = list(c.split())
		if len(stack):
			stack.append(min(stack[-1] * int(c[1]), 2 << 32 - 1))
		else:
			stack.append(int(c[1]))
print(x if x < 2 << 32 - 1 else 'OVERFLOW!!!')


l = int(input())
ans = 0
v = [1]
limit = 2 ** 32
while l:
	l -= 1
	s = input()
	if s == 'add':
		ans += v[-1]
	elif s.startswith('for'):
		s = s.split(' ')
		s = int(s[1])
		v.append(min(s * v[-1], limit))
	else:
		v.pop()
	if ans >= limit:
		ans = 'OVERFLOW!!!'
		break
print(ans)


number_of_lines = int(input())
n = 0
allowance = 2 ** 32 - 1
multipliers = []
multiplier = 1
multipliers_past_overflow = 0
is_overflow = False
for i in range(number_of_lines):
	operation = input()
	if is_overflow:
		pass
	elif operation[:3] == 'for':
		current_multiplier = int(operation.split()[1])
		if multipliers_past_overflow == 0 and current_multiplier <= allowance / multiplier:
			multiplier *= current_multiplier
			multipliers.append(current_multiplier)
		else:
			multipliers_past_overflow += 1
	elif operation == 'add':
		if multipliers_past_overflow > 0 or multiplier > allowance:
			is_overflow = True
		else:
			n += multiplier
			allowance -= multiplier
	elif operation == 'end':
		if multipliers_past_overflow == 0:
			multiplier = int(multiplier / multipliers.pop())
		else:
			multipliers_past_overflow -= 1
if is_overflow:
	print('OVERFLOW!!!')
else:
	print(n)


from collections import Counter, defaultdict, deque
import heapq as hq
from itertools import count, islice
import math
import sys
l = int(input())
stack = deque([1])
over = 2 ** 32
total = 0
for i in range(l):
	nxt = input()
	if nxt[0] == 'f':
		num = int(nxt[4:])
		stack.append(min(over, stack[-1] * num))
	elif nxt[0] == 'a':
		if len(stack):
			total += stack[-1]
		if total >= over:
			print('OVERFLOW!!!')
			exit()
	else:
		p = stack.pop()
print(total)


L = int(input())
stack = [0]
loops = [1]
for _ in range(L):
	line = input().strip()
	if line == 'add':
		stack[-1] += 1
	elif line == 'end':
		amount = stack.pop() * loops.pop()
		stack[-1] += amount
	elif line.startswith('for'):
		loop = int(line.split()[1])
		loops.append(loop)
		stack.append(0)
	if len(stack) > 1 and stack[-1] > pow(2, 32) - 1:
		print('OVERFLOW!!!')
		break
if len(stack) == 1:
	result = stack.pop() * loops.pop()
	if result > pow(2, 32) - 1:
		print('OVERFLOW!!!')
	else:
		print(result)


inf = 10 ** 12
val = 2 ** 32
import sys
n = int(input())
m = 1
st = []
st1 = []
st2 = [1]
ans = 0
for i in range(n):
	a = list(map(str, sys.stdin.readline().split()))
	if len(a) == 2:
		m = int(a[1])
		st1.append(m)
		if st1[-1] * st2[-1] <= val:
			st2.append(st1[-1] * st2[-1])
		else:
			st2.append(inf)
	x = a[0]
	m = st2[-1]
	if x == 'add':
		ans += m
	elif x == 'end':
		st1.pop()
		st2.pop()
	if ans >= 2 ** 32:
		exit(print('OVERFLOW!!!'))
print(ans)


t = int(input())
st = []
st_size = 0
ans = 0
mx = 4294967296
f = False
for i in range(t):
	inp = input()
	if inp == 'add':
		if st_size == 0:
			ans += 1
		else:
			ans += st[-1]
	elif inp == 'end':
		st_size -= 1
		st.pop()
	else:
		if st_size == 0:
			st.append(int(inp[4:]))
		else:
			st.append(min(mx, st[-1] * int(inp[4:])))
		st_size += 1
	if ans >= mx:
		print('OVERFLOW!!!')
		f = True
		break
if f == False:
	if ans >= mx:
		print('OVERFLOW!!!')
	else:
		print(ans)


import math
l = int(input())
lap = []
sl = len(lap)
x = 0
xlap = 0
thresh = int(math.pow(2, 32) - 1)
for i in range(l):
	t = input().split()
	sl = len(lap)
	if len(t) == 1:
		if t[0] == 'add':
			if sl == 0:
				x = x + 1
			else:
				x = x + lap[sl - 1]
		if t[0] == 'end':
			lap.pop()
	elif sl == 0:
		lap.append(min(int(t[1]), thresh + 1))
	else:
		tt = lap[sl - 1] * int(t[1])
		lap.append(min(tt, thresh + 1))
if x > thresh:
	print('OVERFLOW!!!')
else:
	print(x)


l = int(input())
a = [1]
x = 0
check = 0
countf = 0
counte = 0
for i in range(l):
	s = input()
	if s[0] == 'f':
		if check == 1:
			countf += 1
		elif a[len(a) - 1] * int(s[4:]) > 2 ** 32 - 1:
			check = 1
			countf += 1
		else:
			a.append(a[len(a) - 1] * int(s[4:]))
	elif s[0] == 'e':
		if check == 1:
			counte += 1
			if counte == countf:
				countf = 0
				counte = 0
				check = 0
		else:
			a.pop()
	else:
		if check == 1:
			print('OVERFLOW!!!')
			quit()
		x += a[len(a) - 1]
		if x > 2 ** 32 - 1:
			print('OVERFLOW!!!')
			quit()
print(x)


from functools import reduce
limit = 2 ** 32
lines = int(input())
x = 0
stack = [1]
for l in range(lines):
	arr = input().split(' ')
	if arr[0] == 'for':
		stack.append(min(limit, int(arr[1]) * stack[-1]))
	elif arr[0] == 'end':
		stack.pop()
	else:
		x = x + stack[-1]
if x >= limit:
	x = 'OVERFLOW!!!'
print(x)


import sys
input = sys.stdin.readline

class Problem:

	def __init__(self):
		pass

	def solve(self):
		print(self._solve())

	def _solve(self):
		l = int(input())
		q = []
		cur = 1
		ans = 0
		bad_count = 0
		lines = sys.stdin.readlines()
		for i in range(l):
			line = lines[i].strip()
			if line == 'add':
				if bad_count > 0:
					return 'OVERFLOW!!!'
				ans += cur
			elif line == 'end':
				if bad_count > 0:
					bad_count -= 1
				else:
					cur //= q[-1]
				q.pop()
			else:
				(_, n) = line.split()
				n = int(n)
				if bad_count > 0 or cur * n >= 2 ** 64:
					bad_count += 1
				else:
					cur *= n
				q.append(n)
			if ans >= 2 ** 32:
				return 'OVERFLOW!!!'
		return ans

def main():
	problem = Problem()
	problem.solve()
main()


import sys
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
l = int(input())
x = 0
stack = []
M = 2 ** 32
for i in range(l):
	s = list(map(str, input().split()))
	if s[0] == "b'for'":
		t = int(s[1][2:-1]) * M
		stack.append(t)
	elif s[0] == "b'end'":
		cnt = 0
		while stack:
			if stack[-1] < M:
				cnt += stack[-1]
				stack.pop()
			else:
				loop = stack.pop()
				loop //= M
				t = loop * cnt
				if t >= 2 ** 32:
					print('OVERFLOW!!!')
					exit()
				stack.append(t)
				break
	else:
		stack.append(1)
else:
	if stack:
		for c in stack:
			x += c
	if x >= M:
		print('OVERFLOW!!!')
	else:
		print(x)


n = int(input())
line = 0
memory = 0
stack = []
while line < n:
	line += 1
	cmd = input()
	if cmd[:3] == 'add':
		memory += 1
	if cmd[:3] == 'for':
		multiplicator = int(cmd.split(' ')[1])
		stack.append({'multi': multiplicator, 'add': memory})
		memory = 0
	if cmd[:3] == 'end':
		action = stack.pop()
		memory = action['add'] + action['multi'] * memory
	if memory >= 1 << 32:
		print('OVERFLOW!!!')
		exit()
print(memory)


l = int(input())
curr_val = 0
open_stack = [0 for i in range(100000 + 10)]
i = 0
while l:
	op = input()
	if op == 'add':
		open_stack[2 * i + 1] += 1
	elif op == 'end':
		i -= 1
		open_stack[2 * i + 1] += open_stack[2 * i + 2] * open_stack[2 * i + 3]
	else:
		i += 1
		open_stack[2 * i] = int(op.split()[1])
		open_stack[2 * i + 1] = 0
	if open_stack[2 * i + 1] > 2 ** 32 - 1:
		print('OVERFLOW!!!')
		exit()
	l -= 1
res = open_stack[1]
if res > 2 ** 32 - 1:
	res = 'OVERFLOW!!!'
print(res)


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!!!')


n = int(input())
MAX = 2 ** 32 - 1
stack = [1]
overflow = False
index = 0
x = 0
for i in range(n):
	cmd = input()
	if cmd[0] == 'a':
		if stack[-1] == -1 or x + stack[-1] > MAX:
			overflow = True
			break
		x += stack[-1]
	elif cmd[0] == 'e':
		stack.pop()
	elif cmd[0] == 'f':
		(_, value) = cmd.split()
		multiplier = int(value)
		if stack[-1] == -1 or stack[-1] * multiplier > MAX:
			stack.append(-1)
		else:
			stack.append(stack[-1] * multiplier)
if overflow:
	print('OVERFLOW!!!')
else:
	print(x)


s = [0]
lim = 2 ** 32
q = []
t = int(input())
for i in range(t):
	c = input()
	if c[0] > 'e':
		s.append(0.0)
		q.append(int(c[4:]))
	elif c[0] < 'b':
		s[-1] = s[-1] + 1
	else:
		s[-1] = s.pop() * q.pop() + s[-1]
print(int(s[0]) if s[0] < lim else 'OVERFLOW!!!')


l = int(input())
p = 2 ** 32 - 1
stack = [0]
stack_p = []
down = 0
while l != 0:
	s = input()
	l -= 1
	if s[0] == 'a':
		stack[down] += 1
		if stack[down] > p:
			print('OVERFLOW!!!')
			exit(0)
	elif s[0] == 'f':
		stack_p.append(int(s[4:]))
		stack.append(0)
		down += 1
	else:
		r = stack.pop() * stack_p.pop()
		down -= 1
		stack[down] += r
		if stack[down] > p:
			print('OVERFLOW!!!')
			exit(0)
print(stack[0])


M = 2 ** 64

def process(Q):
	start = 0
	queue = [1]
	for x in Q:
		if x == 'add':
			start += queue[-1]
			if start > 2 ** 32 - 1:
				return 'OVERFLOW!!!'
		elif x == 'end':
			queue.pop()
		else:
			n = int(x.split()[1])
			queue.append(min(M, queue[-1] * n))
	return start
n = int(input())
Q = []
for i in range(n):
	x = input()
	Q.append(x)
print(process(Q))


a = [1]
ans = 0
z = 2 ** 32
for _ in range(int(input())):
	t = input().split()
	if len(t) == 1:
		if t[0] == 'add':
			ans += a[-1]
		else:
			a.pop()
	else:
		x = int(t[1]) * a[-1]
		a.append(min(z, x))
	if ans >= z:
		print('OVERFLOW!!!')
		break
else:
	print(ans)


qwq = [1]
INF = (1 << 32) - 1
sum = 0
flag = True
for t in range(int(input())):
	line = input().split()
	if line[0] == 'for':
		num = int(line[1])
		qwq.append(min(num * qwq[-1], INF + 1))
	elif line[0] == 'add':
		sum += qwq[-1]
		if sum > INF:
			print('OVERFLOW!!!')
			exit(0)
	else:
		qwq.pop()
print(sum)


import math
n = int(input())
ans = 0
count = 1
lastfor = []
flag = 0
index = math.inf
countadd = []
countfor = 0
for q in range(n):
	str = input()
	if str == 'add':
		if countfor > 0:
			flag = 1
			break
		ans += count
	elif str == 'end':
		if countfor == 0:
			count //= lastfor[-1]
		else:
			countfor -= 1
			if countfor == 0:
				count //= lastfor[-1]
		lastfor.pop()
	else:
		str = str[3:]
		if count < 2 ** 32:
			count *= int(str)
		lastfor.append(int(str))
		if count >= 2 ** 32:
			countfor += 1
	if ans >= 2 ** 32:
		flag = 1
		break
if flag == 1:
	print('OVERFLOW!!!')
else:
	print(ans)


from collections import deque
n = int(input())
li = [list(input().split()) for i in range(n)]
ans = 0
k = 2 ** 32
sta = deque([1])
for i in li:
	if ans >= k:
		ans = -1
		break
	if i[0] == 'add':
		ans += sta[0]
	elif i[0] == 'for':
		i[1] = int(i[1])
		sta.appendleft(min(k, i[1] * sta[0]))
	else:
		sta.popleft()
if ans == -1 or ans >= k:
	print('OVERFLOW!!!')
else:
	print(ans)


import sys
input = sys.stdin.readline
n = int(input())
stack = []
ans = 0
flg = 0
for i in range(n):
	x = input().rstrip()
	tmp = 1
	if x[:3] == 'for':
		if int(x[4:]) == 1:
			flg += 1
		else:
			flg += 1
			stack.append((int(x[4:]), flg))
	elif x == 'add':
		for (j, _) in stack:
			tmp *= j
			if tmp > 2 ** 32 - 1:
				print('OVERFLOW!!!')
				exit()
		ans += tmp
	elif x == 'end':
		if not stack or flg > stack[-1][1]:
			flg -= 1
		else:
			stack.pop()
			flg -= 1
	if ans > 2 ** 32 - 1:
		print('OVERFLOW!!!')
		exit()
print(ans)


n = int(input())
stack = []
pro = 1
canextra = 0
sums = 0
poss = 1
z = (1 << 32) - 1
done = 0
for i in range(n):
	s = input().split()
	if s[0] == 'end' and canextra == 0:
		pro = pro // stack[-1]
		stack.pop(-1)
	elif s[0] == 'end' and canextra >= 1:
		stack.pop(-1)
		canextra -= 1
	elif s[0] == 'add':
		sums += pro
		if canextra > 0:
			poss = 0
			break
	else:
		stack.append(int(s[1]))
		if canextra > 0 or pro * int(s[1]) > z:
			canextra += 1
		else:
			pro *= int(s[1])
	if sums > z:
		poss = 0
		done = i
		break
if poss == 0:
	print('OVERFLOW!!!')
else:
	print(sums)


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
		elif 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!!!')


import sys
input = sys.stdin.readline
l = int(input())
ans = 0
fornow = [None] * (l + 1)
fornow[0] = 1
flag = 1
count = 0
for i in range(l):
	a = list(input().split())
	if len(a) == 1:
		if a[0] == 'add':
			ans += fornow[count]
		elif a[0] == 'end':
			count -= 1
	else:
		count += 1
		k = int(a[1])
		fornow[count] = min(10000000000, fornow[count - 1] * k)
	if ans > 2 ** 32 - 1:
		flag = 0
		for j in range(l - 1 - i):
			input()
		break
if flag == 1:
	print(ans)
else:
	print('OVERFLOW!!!')


n = int(input(''))
l = []
m = 0
for i in range(n):
	k = input('')
	if k == 'add':
		l.append(1)
	elif k == 'end':
		l.append('E')
	else:
		(x, y) = k.split()
		l.append(int(y))
		l.append('F')
i = 0
n = len(l)
while i != n:
	if l[i] == 'E':
		m = 0
		for j in range(i - 1, -1, -1):
			if l[j] == 'F':
				m = m * l[j - 1]
				l[j - 1] = m
				if m > 2 ** 32 - 1:
					print('OVERFLOW!!!')
					exit()
				break
			else:
				m += l[j]
		del l[i:j - 1:-1]
		n = n - (i - j + 1)
		i = j - 1
	i += 1
j = 0
for items in l:
	j += items
if j > 2 ** 32 - 1:
	print('OVERFLOW!!!')
else:
	print(j)


total = 0
stak = [1]
infinity = 2 ** 32 - 1
for _ in range(int(input())):
	str = input()
	if str[0] == 'a':
		total += stak[-1]
	elif str[0] == 'e':
		stak.pop()
	else:
		te = int(str[4:])
		te = te * stak[-1]
		if te > infinity:
			te = infinity + 1
		stak.append(te)
if total > infinity:
	print('OVERFLOW!!!')
else:
	print(int(total))


a = [0] * 100000
k = [0] * 100000
j = 0
ma = 2 ** 32 - 1
for n in range(int(input())):
	s = input().split(' ')
	if s[0] == 'add':
		a[j] += 1
	if s[0] == 'for':
		j += 1
		k[j] = int(s[1])
	if s[0] == 'end':
		j -= 1
		a[j] += a[j + 1] * k[j + 1]
		a[j + 1] = 0
	if a[j] > ma:
		break
if a[j] > ma:
	print('OVERFLOW!!!')
else:
	print(a[0])


n = int(input())
lim = 2 ** 32 - 1
to = [0] * 102
st = []
ans = 0
for i in range(n):
	ar = list(input().split())
	if len(ar) == 2:
		st.append(int(ar[1]))
		to[int(ar[1])] += 1
	elif ar[0] == 'add':
		res = 1
		for j in range(1, 101):
			res = res * j ** to[j]
		if res > lim or ans + res > lim:
			print('OVERFLOW!!!')
			exit(0)
		else:
			ans += res
	else:
		to[st[-1]] -= 1
		st.pop()
print(ans)