Vanya is doing his maths homework. He has an expression of form $x_{1} \diamond x_{2} \diamond x_{3} \diamond \ldots \diamond x_{n}$, where x_1, x_2, ..., x_{n} are digits from 1 to 9, and sign [Image] represents either a plus '+' or the multiplication sign '*'. Vanya needs to add one pair of brackets in this expression so that to maximize the value of the resulting expression.


-----Input-----

The first line contains expression s (1 ≤ |s| ≤ 5001, |s| is odd), its odd positions only contain digits from 1 to 9, and even positions only contain signs  +  and  * . 

The number of signs  *  doesn't exceed 15.


-----Output-----

In the first line print the maximum possible value of an expression.


-----Examples-----
Input
3+5*7+8*4

Output
303

Input
2+3*5

Output
25

Input
3*4*5

Output
60



-----Note-----

Note to the first sample test. 3 + 5 * (7 + 8) * 4 = 303.

Note to the second sample test. (2 + 3) * 5 = 25.

Note to the third sample test. (3 * 4) * 5 = 60 (also many other variants are valid, for instance, (3) * 4 * 5 = 60).

Difficulty: HARD
Tags: String algorithms

Implementation

Greedy algorithms

Complete search

Dynamic programming
Skill types: Dynamic programming

Complete search

Greedy algorithms

Starter code:

Solutions:
s = input()
d = list(s.split('*'))
last = 0
po = []
ki = []
for i in range(len(d)):
	po += [last]
	ki += [len(d[i]) + last]
	last += len(d[i]) + 1
ans = [eval(s)]
for a in po:
	for b in ki:
		if a > b - 2:
			continue
		x = s[:a] + '(' + s[a:b] + ')' + s[b:]
		ans += [eval(x)]
print(max(ans))


src_str = input()
lenstr = len(src_str)
str = list(src_str)
listMulPos = []
for (i, c) in enumerate(str):
	if c == '*':
		listMulPos.append(i)
listLeftParPos = [0]
for i in listMulPos:
	listLeftParPos.append(i + 1)
listRightParPos = [lenstr]
for i in listMulPos:
	listRightParPos.append(i)
ans = 0
for leftPos in listLeftParPos:
	for rightPos in listRightParPos:
		tmp = []
		for i in str:
			tmp.append(i)
		if leftPos < rightPos + 1:
			tmp.insert(leftPos, '(')
			tmp.insert(rightPos + 1, ')')
			tmpval = eval(''.join(tmp))
			ans = max(ans, tmpval)
print(ans)


s = input()
pos = [-1]
for (i, x) in enumerate(s):
	if x == '*':
		pos.append(i)
pos.append(len(s))
max_v = 0
for i in range(len(pos) - 1):
	for j in range(i + 1, len(pos)):
		a = pos[i] + 1
		b = pos[j]
		ns = s[:a] + '(' + s[a:b] + ')' + s[b:]
		e = eval(ns)
		if e > max_v:
			max_v = e
print(max_v)


s = '1*' + input() + '*1'
a = ''
n = len(s)
s = s + '+'
i = 0
while i < n:
	if s[i + 1] == '*':
		while s[i + 1] == '*':
			a += s[i:i + 2]
			i += 2
		a += s[i:i + 2]
		i += 2
	else:
		sum = 0
		while i < n and s[i + 1] == '+':
			sum += int(s[i])
			i += 2
		a += str(sum) + '+'
a = a[0:-1]
ans = 0
for j in range(len(a)):
	for i in range(j):
		if (a[i] == '*' or a[i] == '+') and (a[j] == '*' or a[j] == '+'):
			ans = max(eval(a[:i + 1] + '(' + a[i + 1:j] + ')' + a[j:]), ans)
print(ans)


qw = input()
g = ['*']
s = [1]
for i in range(len(qw)):
	if i % 2 == 0:
		s.append(int(qw[i]))
	else:
		g.append(qw[i])
c = 0
g.append('*')
s.append(1)
for i in range(len(g)):
	if g[i] == '*':
		for j in range(i + 1, len(g)):
			if g[j] == '*':
				a = 0
				b = s[0]
				for k in range(i):
					if g[k] == '*':
						b *= s[k + 1]
					else:
						a += b
						b = s[k + 1]
				v = a
				w = b
				a = 0
				b = s[i + 1]
				for k in range(i + 1, j):
					if g[k] == '*':
						b *= s[k + 1]
					else:
						a += b
						b = s[k + 1]
				b = w * (a + b)
				a = v
				for k in range(j, len(g)):
					if g[k] == '*':
						b *= s[k + 1]
					else:
						a += b
						b = s[k + 1]
				c = max(c, a + b)
print(c)


s = '1*' + input() + '*1'
L = len(s)
ans = eval(s)
for i in range(L):
	if s[i] == '*':
		for j in range(i + 1, L):
			if s[j] == '*':
				ans = max(ans, eval(s[:i + 1] + '(' + s[i + 1:j] + ')' + s[j:]))
print(ans)


__author__ = 'artbataev'

def countExpression(i, j):
	global matr, numbers, operations
	if i == 0 or operations[i - 1] == '+':
		return matr[j] - (0 if i == 0 else matr[i - 1])
	cur = numbers[i]
	k = i
	while k < j and operations[k] == '*':
		cur *= numbers[k + 1]
		k += 1
	if k >= j:
		return cur
	else:
		return cur + matr[j] - matr[k]
s = input().strip()
numbers = list(map(int, s[::2]))
operations = s[1::2]
n = len(numbers)
matr = [0 for i in range(n)]
matr[0] = numbers[0]
for i in range(1, n):
	if operations[i - 1] == '+':
		matr[i] = matr[i - 1] + numbers[i]
	else:
		k = i - 1
		cur = numbers[i]
		while k >= 0 and operations[k] == '*':
			cur *= numbers[k]
			k -= 1
		if k < 0:
			matr[i] = cur
		else:
			matr[i] = matr[k] + cur
maxRes = matr[n - 1]
for i in range(n - 1):
	if i == 0 or operations[i - 1] == '*':
		for j in range(i + 1, n):
			curExpr = countExpression(i, j)
			i1 = i - 1
			while i1 >= 0 and operations[i1] == '*':
				curExpr *= numbers[i1]
				i1 -= 1
			j1 = j
			while j1 < n - 1 and operations[j1] == '*':
				curExpr *= numbers[j1 + 1]
				j1 += 1
			if i1 >= 0:
				curExpr += matr[i1]
			if j1 + 1 <= n - 1:
				curExpr += matr[n - 1] - matr[j1]
			maxRes = max(maxRes, curExpr)
print(maxRes)


s = '1*' + input() + '*1'
n = len(s)
ans = 0
for i in range(2, n, 2):
	if s[i - 1] == '*':
		for j in range(i + 1, n, 2):
			if s[j] == '*':
				ans = max(ans, eval(s[:i] + '(' + s[i:j] + ')' + s[j:]))
print(ans)


s = '1*' + input() + '*1'
a = eval(s)
l = len(s)
for i in range(l):
	if s[i] == '*':
		for j in range(i + 1, l):
			if s[j] == '*':
				a = max(a, eval(s[:i + 1] + '(' + s[i + 1:j] + ')' + s[j:]))
print(a)


s = input().split('*')
ans = -1
for i in range(len(s)):
	for j in range(0, len(s)):
		ans = max(ans, eval('*'.join(s[:i] + [str(eval('*'.join(s[i:i + j + 1])))] + s[i + j + 1:])))
print(ans)


expr = input()
muls = []
expr = '1*' + expr + '*1'
for i in range(len(expr)):
	if expr[i] == '*':
		muls.append(i)
ans = eval(expr)
mc = len(muls)
for i in range(mc - 1):
	for j in range(i + 1, mc):
		t = eval(expr[:muls[i] + 1] + '(' + expr[muls[i] + 1:muls[j]] + ')' + expr[muls[j]:])
		if t > ans:
			ans = t
print(ans)


import sys

def f2(exp: str, index1: int, index2: int):
	return eval(exp[:index1] + '(' + exp[index1:index2 + 1] + ')' + exp[index2 + 1:])

def f1(exp: str):
	(res, pos) = (eval(exp), [-1])
	for i in range(1, len(exp), 2):
		if exp[i] == '*':
			pos.append(i)
	pos.append(len(exp))
	for i in range(0, len(pos)):
		for j in range(i + 1, len(pos)):
			res = max(res, f2(exp, pos[i] + 1, pos[j] - 1))
	return res
for line in sys.stdin:
	print(f1(line))


expr = list(input())
mul_pos = [-1]
add_cnt = [0] * len(expr)
for (i, _) in enumerate(expr):
	add_cnt[i] = add_cnt[i - 1]
	if _ == '*':
		mul_pos.append(i)
	elif _ == '+':
		add_cnt[i] += 1
mul_pos.append(len(expr))
add_cnt.append(add_cnt[-1])
add_cnt.append(0)
ans = 0
for i in range(len(mul_pos)):
	for j in range(i + 1, len(mul_pos)):
		if add_cnt[mul_pos[i]] - add_cnt[mul_pos[j]]:
			expr.insert(mul_pos[i] + 1, '(')
			expr.insert(mul_pos[j] + 1, ')')
			ans = max(ans, eval(''.join(expr)))
			expr.pop(mul_pos[j] + 1)
			expr.pop(mul_pos[i] + 1)
print(eval(''.join(expr)) if ans == 0 else ans)


s = input()
s = '1*' + s + '*1'
IL = []
for i in range(len(s)):
	if s[i] == '*':
		IL.append(i)
maks = 0
for i in range(len(IL)):
	for j in range(i + 1, len(IL)):
		a = eval(s[:IL[i] + 1] + '(' + s[IL[i] + 1:IL[j]] + ')' + s[IL[j]:])
		maks = max(maks, a)
print(maks)


s = input()
n = len(s)
p = [-1] + [i for i in range(n) if s[i] == '*'] + [n]
m = len(p)
ans = eval(s)
for i in range(m):
	for j in range(i + 1, m):
		(a, b) = (p[i] + 1, p[j])
		t = s[:a] + '(' + s[a:b] + ')' + s[b:]
		ans = max(ans, eval(t))
print(ans)


s = '1*' + input() + '*1'
res = 0
i = 0
for i in range(1, len(s), 2):
	if s[i] == '*':
		for j in range(i + 2, len(s), 2):
			if s[j] == '*':
				res = max(res, eval(s[:i + 1] + '(' + s[i + 1:j] + ')' + s[j:]))
print(res)


s = input()
mults = [-1]
for i in range(len(s)):
	if s[i] == '*':
		mults.append(i)
mults.append(len(s))
max = 0
for i in range(len(mults)):
	for j in range(i + 1, len(mults)):
		news = s[:mults[i] + 1] + '(' + s[mults[i] + 1:mults[j]] + ')' + s[mults[j]:]
		v = eval(news)
		if v > max:
			max = v
print(max)


def mul2val(s):
	res = 1
	for i in s.split('*'):
		res *= int(i)
	return res
s = '1*' + input() + '*1'
muls = s.split('+')
vals = list(map(mul2val, muls))
lvals = list(map(mul2val, [mul[:-2] if len(mul) > 1 else '0' for mul in muls]))
rvals = list(map(mul2val, [mul[2:] if len(mul) > 1 else '0' for mul in muls]))
cumvals = [0] + vals
for i in range(1, len(cumvals)):
	cumvals[i] += cumvals[i - 1]
total = cumvals[-1]
ans = total
for (i, mul1) in enumerate(muls):
	if len(mul1) == 1:
		continue
	for (j, mul2) in enumerate(muls[i + 1:], i + 1):
		if len(mul2) == 1:
			continue
		tval = cumvals[i] + lvals[i] * (int(mul1[-1]) + (cumvals[j] - cumvals[i + 1]) + int(mul2[0])) * rvals[j] + (total - cumvals[j + 1])
		if tval > ans:
			ans = tval
print(ans)


s = input()
w = '1*' + s + '*1'
n = len(w)
res = eval(w)
for i in range(n):
	if w[i] == '*':
		for j in range(i + 1, n):
			if w[j] == '*':
				temp = eval(w[:i + 1] + '(' + w[i + 1:j] + ')' + w[j:])
				res = max(res, temp)
print(res)


S = input()
ans = 0
for ll in range(len(S)):
	if not (ll == 0 or S[ll - 1] == '*'):
		continue
	for rr in range(ll + 1, len(S) + 1, 1):
		if not (rr == len(S) or S[rr] == '*'):
			continue
		ans = max(ans, eval(S[:ll] + '(' + S[ll:rr] + ')' + S[rr:]))
print(ans)


s = '1*' + input() + '*1'
indexes = []
for i in range(len(s)):
	if s[i] == '*':
		indexes.append(i)
ans = 0
for i in range(len(indexes)):
	for j in range(i + 1, len(indexes)):
		ans = max(ans, eval(s[:indexes[i] + 1] + '(' + s[indexes[i] + 1:indexes[j]] + ')' + s[indexes[j]:]))
print(ans)


s = input()
t = len(s)
res = eval(s)
for i in range(0, t):
	if i != 0 and s[i - 1] != '*':
		continue
	a = s[:i] + '(' + s[i:]
	for j in range(i, t + 2):
		if j != t + 1 and a[j] != '*':
			continue
		if j == t + 1:
			b = a[:j] + ')'
		else:
			b = a[:j] + ')' + a[j:]
		res = max(res, eval(b))
print(res)


s = input()
mx = eval(s)
m = [-1] + [i for (i, v) in enumerate(s) if v == '*'] + [len(s)]
for (i, a) in enumerate(m):
	for b in m[i + 1:]:
		t = s[:a + 1] + '(' + s[a + 1:b] + ')' + s[b:]
		mx = max(mx, eval(t))
print(mx)


expr = input()
ans = eval(expr)
factor = expr.split('*')
for i in range(1, len(factor)):
	ans = max(ans, eval('(' + '*'.join(factor[0:i]) + ')*' + '*'.join(factor[i:])))
	ans = max(ans, eval('*'.join(factor[0:i]) + '*(' + '*'.join(factor[i:]) + ')'))
	for j in range(i + 1, len(factor)):
		ans = max(ans, eval('*'.join(factor[0:i]) + '*(' + '*'.join(factor[i:j]) + ')*' + '*'.join(factor[j:])))
print(ans)


s = input()
res = eval(s)
n = len(s)
for i in range(-1, n):
	if i == -1 or s[i] == '*':
		for j in range(i + 1, n + 1):
			if j == n or s[j] == '*':
				new_s = s[0:i + 1] + '(' + s[i + 1:j] + ')' + s[j:n]
				res = max(res, eval(new_s))
print(res)


s = '1*' + input() + '*1'
L = len(s)
r = eval(s)
for j in range(L):
	if s[j] == '*':
		for i in range(j + 1, L):
			if s[i] == '*':
				r = max(r, eval(s[0:j + 1] + '(' + s[j + 1:i] + ')' + s[i:L]))
print(r)


from itertools import combinations
s = str(input())
ans = eval(s)
op = [-1] + [i for (i, d) in enumerate(s) if d == '*'] + [len(s)]
for (i, j) in combinations(op, 2):
	ans = max(ans, eval('{}({}){}'.format(s[:i + 1], s[i + 1:j], s[j:])))
print(ans)


s = '*' + input() + '*'
n = len(s)
ans = eval(s[1:n - 1])
for i in range(n):
	if s[i] != '*':
		continue
	for j in range(i + 1, n):
		if s[j] != '*':
			continue
		r = s[1:i + 1] + '(' + s[i + 1:j] + ')' + s[j:n - 1]
		ans = max(ans, eval(r))
print(ans)


s = input()
processed = True
i1 = 1
while i1 < len(s):
	while i1 < len(s):
		if s[i1] == '+':
			break
		i1 += 2
	if i1 >= len(s):
		break
	i2 = i1 + 2
	while i2 < len(s):
		if s[i2] == '*':
			break
		i2 += 2
	i2 = i2 - 2
	if i2 - i1 > 2:
		s1 = eval(s[i1 + 1:i2])
		s = s[:i1 + 1] + str(s1) + s[i2:]
		i1 += 4
	else:
		i1 += 2
mults = [-1]
for i in range(len(s)):
	if s[i] == '*':
		mults.append(i)
mults.append(len(s))
max = 0
for i in range(len(mults)):
	for j in range(i + 1, len(mults)):
		news = s[:mults[i] + 1] + '(' + s[mults[i] + 1:mults[j]] + ')' + s[mults[j]:]
		v = eval(news)
		if v > max:
			max = v
print(max)


s = '1*' + input() + '*1'
ans = eval(s)
for i in range(2, len(s) - 1, 2):
	if s[i - 1] != '*':
		continue
	for j in range(i + 1, len(s) - 1, 2):
		if s[j] != '*':
			continue
		ans = max(ans, eval(s[:i] + '(' + s[i:j] + ')' + s[j:]))
print(ans)


import math
s = '*'
s = s + input()
s = s + '*'
n = len(s)
ans = 0
for i in range(0, n):
	if s[i] == '*':
		for j in range(i + 1, n - 1):
			if s[j + 1] == '*':
				a = ''
				for k in range(0, n - 1):
					if k > 0:
						a = a + s[k]
					if k == i:
						a = a + '('
					if k == j:
						a = a + ')'
				t = eval(a)
				if t > ans:
					ans = t
print(ans)


str = input()
(n, result) = (len(str), eval(str))
for i in range(-1, n):
	if i == -1 or str[i] == '*':
		for j in range(i + 1, n + 1):
			if j == n or str[j] == '*':
				result = max(result, eval(str[:i + 1] + '(' + str[i + 1:j] + ')' + str[j:]))
print(result)


s = input()
(lb, rb) = ([], [])
n = len(s)
lb.append(0)
rb.append(n)
for i in range(n):
	if s[i] == '*':
		lb.append(i + 1)
		rb.append(i)
ans = 0
for l in lb:
	for r in rb:
		if l >= r:
			continue
		t = s[:l] + '(' + s[l:r] + ')' + s[r:]
		ans = max(ans, eval(t))
print(ans)


from collections import deque
s = input()
n = len(s)
ans = eval(s)
for i in range(n):
	if s[i] == '*':
		_s = '(' + s[:i] + ')' + s[i:]
		ans = max(ans, eval(_s))
		_s = s[:i + 1] + '(' + s[i + 1:] + ')'
		ans = max(ans, eval(_s))
		for j in range(i):
			if s[j] == '*':
				_s = s[:j + 1] + '(' + s[j + 1:i] + ')' + s[i:]
				ans = max(ans, eval(_s))
print(ans)


maxx = 0
x = []
s = input()
maxx = max(maxx, eval(s))
for i in range(len(s)):
	if s[i] == '*':
		x.append(i)
		maxx = max(maxx, eval('(' + s[:i] + ')' + s[i:]))
		maxx = max(maxx, eval(s[:i + 1] + '(' + s[i + 1:] + ')'))
for f in range(len(x)):
	for g in range(f + 1, len(x)):
		i = x[f]
		j = x[g]
		maxx = max(maxx, eval(s[:i + 1] + '(' + s[i + 1:j] + ')' + s[j:]))
print(maxx)


from fractions import gcd
import sys

def solve():
	s = input()
	res = eval(s)
	for l in range(-1, len(s)):
		if s[l] == '*' or l == -1:
			for r in range(l + 2, len(s) + 1, 2):
				if r == len(s) or s[r] == '*':
					temp = s[:l + 1] + '(' + s[l + 1:r] + ')' + s[r:]
					try:
						res = max(res, eval(temp))
					except:
						pass
	print(res)
if sys.hexversion == 50594544:
	sys.stdin = open('test.txt')
solve()


s = input()
s = '1*' + s + '*1'
ans = eval(s)
for i in range(len(s)):
	if s[i] == '*':
		for j in range(i + 1, len(s)):
			if s[j] == '*':
				tmp = s[:i + 1] + '(' + s[i + 1:j] + ')' + s[j:]
				ans = max(ans, int(eval(tmp)))
print(ans)


s = input()
s = 'm = max(m, ' + s + ')'
pu = [10]
for a in range(len(s)):
	if s[a] == '*':
		pu += [a]
pu += [len(s)]
m = 0
exec(s)
for i in range(len(pu)):
	for j in range(i + 1, len(pu)):
		exec(s[:pu[i] + 1] + '(' + s[pu[i] + 1:pu[j]] + ')' + s[pu[j]:])
print(m)


s = input()
s = '0+1*' + s + '*1+0'
answer = eval(s)
n = len(s)
p = []
for i in range(0, n):
	if s[i] == '*':
		p.append(i)
for i in p:
	for j in p:
		if i >= j:
			continue
		test = eval(s[:i + 1] + '(' + s[i + 1:j] + ')' + s[j:])
		if test > answer:
			answer = test
print(answer)


S = input()
N = len(S)
Ans = eval(S)
for i in range(0, N, 2):
	for j in range(i, N, 2):
		if (i == 0 or (i > 0 and S[i - 1] == '*')) and (j == N - 1 or (j < N - 1 and S[j + 1] == '*')):
			SS = S[:i] + str(eval(S[i:j + 1])) + S[j + 1:]
			if int(eval(SS)) > Ans:
				Ans = int(eval(SS))
print(Ans)


s = input()
mult_list = []
for i in range(len(s)):
	if s[i] == '*':
		mult_list.append(i)
best = eval(s)
for k in mult_list:
	t = '(' + s[:k] + ')' + s[k:]
	q = eval(t)
	if q > best:
		best = q
	t = s[:k + 1] + '(' + s[k + 1:] + ')'
	q = eval(t)
	if q > best:
		best = q
	for j in mult_list:
		if j >= k:
			continue
		if j < k:
			t = s[:j + 1] + '(' + s[j + 1:k] + ')' + s[k:]
			q = eval(t)
			if q > best:
				best = q
print(best)


s = '1*' + input() + '*1'
mx = 0
v = []
for i in range(len(s)):
	if s[i] == '*':
		v.append(i)
for i in range(len(v)):
	for j in range(i + 1, len(v)):
		z = eval(s[v[i] + 1:v[j]])
		mx = max(mx, eval(s[:v[i] + 1] + str(z) + s[v[j]:]))
print(mx)


s = input()
ans = eval(s)
for i in range(len(s) - 1):
	if s[i] == '*':
		k = '(' + s[0:i] + ')' + s[i:len(s)]
		t = eval(k)
		if t > ans:
			ans = t
		k = s[0:i + 1] + '(' + s[i + 1:len(s)] + ')'
		t = eval(k)
		if t > ans:
			ans = t
		for j in range(i + 2, len(s)):
			if s[j] == '*':
				k = s[0:i + 1] + '(' + s[i + 1:j] + ')' + s[j:len(s)]
				t = eval(k)
				if t > ans:
					ans = t
print(ans)


from heapq import heapify, heappush, heappop
from collections import Counter, defaultdict, deque, OrderedDict
from sys import setrecursionlimit, maxsize
from bisect import bisect_left, bisect, insort_left, insort
from math import ceil, log, factorial, hypot, pi
from fractions import gcd
from copy import deepcopy
from functools import reduce
from operator import mul
from itertools import product, permutations, combinations, accumulate, cycle
from string import ascii_uppercase, ascii_lowercase, ascii_letters, digits, hexdigits, octdigits
prod = lambda l: reduce(mul, l)
prodmod = lambda l, mod: reduce(lambda x, y: mul(x, y) % mod, l)

def read_list(t):
	return [t(x) for x in input().split()]

def read_line(t):
	return t(input())

def read_lines(t, N):
	return [t(input()) for _ in range(N)]
exp = read_line(str)
len_exp = len(exp)
ans = eval(exp)
mul_p = [i for (i, s) in enumerate(exp) if s == '*']
mul_p = [-1] + mul_p + [len(exp)]
for (i1, i2) in combinations(mul_p, 2):
	ans = max(ans, eval('{}({}){}'.format(exp[:i1 + 1], exp[i1 + 1:i2], exp[i2:])))
print(ans)


import sys, os

def solve():
	s = input()
	res = eval(s)
	for l in range(-1, len(s)):
		if s[l] == '*' or l == -1:
			for r in range(l + 2, len(s) + 1, 2):
				if r == len(s) or s[r] == '*':
					temp = s[:l + 1] + '(' + s[l + 1:r] + ')' + s[r:]
					try:
						res = max(res, eval(temp))
					except:
						pass
	print(res)

def prt(l):
	return print(' '.join(l))

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

def rl(n):
	return [list(map(int, input().split())) for _ in range(n)]
if os.path.exists('test.txt'):
	sys.stdin = open('test.txt')
solve()


exp = input()
if exp.count('+') == 0:
	print(eval(exp))
elif exp.count('*') == 0:
	print(eval(exp))
else:
	maximum = 0
	exp = '1*' + exp + '*1'
	for index1 in range(0, len(exp)):
		value = 0
		if exp[index1:index1 + 1] == '*':
			for index2 in range(index1 + 1, len(exp)):
				if exp[index2:index2 + 1] == '*':
					value = eval(exp[index1 + 1:index2])
					sub_exp = exp[0:index1 + 1] + str(value) + exp[index2:]
					value = eval(sub_exp)
					if value > maximum:
						maximum = value
	print(maximum)


s = input()
if len(s) == 1:
	print(s)
else:
	ans = eval(s)
	l = []
	for i in range(len(s)):
		if s[i] == '*':
			l += [i]
	if len(l) == 0:
		print(ans)
	else:
		l = [-1] + l
		l = l + [len(s)]
		for i in range(len(l)):
			for j in range(i + 1, len(l)):
				temp = s[:l[i] + 1]
				temp += '('
				temp += s[l[i] + 1:l[j]]
				temp += ')'
				temp += s[l[j]:]
				ans = max(ans, eval(temp))
		print(ans)


e = '1*' + input() + '*1'
l = len(e)
a = 0
for i in range(2, l, 2):
	if e[i - 1] == '*':
		for j in range(i + 1, l, 2):
			if e[j] == '*':
				a = max(a, eval(e[:i] + '(' + e[i:j] + ')' + e[j:]))
print(a)


s = '1*' + input() + '*1'
n = len(s)
ans = eval(s)
pos = []
for i in range(n):
	if s[i] == '*':
		pos.append(i)
for i in [x + 1 for x in pos]:
	for j in [x for x in pos]:
		if i < j:
			ans = max(ans, eval(s[:i] + '(' + s[i:j] + ')' + s[j:]))
print(ans)


s = '1*' + input() + '*1'
n = len(s)
ans = eval(s)
for i in range(n):
	if s[i] != '*':
		continue
	for j in range(i + 1, n):
		if s[j] != '*':
			continue
		t = s[0:i + 1] + '(' + s[i + 1:j] + ')' + s[j:n]
		ans = max(ans, eval(t))
print(ans)


s = input()
s = '1*' + s + '*1'
lx = len(s)
rep = eval(s)
pos = []
for i in range(lx):
	if s[i] == '*':
		pos.append(i)
sz = len(pos)
for aa1 in range(sz):
	for aa2 in range(aa1 + 1, sz):
		a1 = pos[aa1]
		a2 = pos[aa2]
		ns = ''
		for i in range(lx):
			if i == a2:
				ns += ')'
			ns += s[i]
			if i == a1:
				ns += '('
		rep = max(rep, eval(ns))
print(rep)


s = input()
r = [0]
t = s.find('*')
while -1 != t:
	r += [t]
	t = s.find('*', t + 1)
r += [len(s)]
R = 0
for i in range(len(r)):
	for j in range(i + 1, len(r)):
		a = r[i]
		b = r[j]
		t = s[:a]
		if t:
			t += '*'
			a += 1
		t += '(' + s[a:b] + ')' + s[b:]
		R = max(R, eval(t))
print(R)


s = input()
ans = eval(s)
n = len(s)
pos = [i for (i, x) in enumerate(s) if x == '*']
for x in pos:
	s2 = f'({s[0:x]}){s[x:]}'
	ans = max(ans, eval(s2))
	s2 = f'{s[:x + 1]}({s[x + 1:]})'
	ans = max(ans, eval(s2))
	for y in pos:
		if y >= x:
			continue
		s2 = f'{s[:y + 1]}({s[y + 1:x]}){s[x:]}'
		ans = max(ans, eval(s2))
print(ans)


str = '1*' + input() + '*1'
l = len(str)
ans = 0
for i in range(2, l, 2):
	if str[i - 1] == '*':
		for j in range(i + 1, l, 2):
			if str[j] == '*':
				ans = max(ans, eval(str[:i] + '(' + str[i:j] + ')' + str[j:]))
print(ans)


s = input()
f = eval
s = '1*' + s + '*1'
a = []
for i in range(len(s)):
	if s[i] == '*':
		a.append(i)
r = f(s)
n = len(a)
for i in range(n - 1):
	for j in range(i + 1, n):
		t = f(s[:a[i] + 1] + '(' + s[a[i] + 1:a[j]] + ')' + s[a[j]:])
		r = max(r, t)
print(r)


def find_best(s):
	best = eval(s)
	for i in range(0, len(s), 2):
		if i > 0 and s[i - 1] == '*' or i == 0:
			for j in range(i + 2, len(s), 2):
				if j < len(s) - 1 and s[j + 1] == '*' or j == len(s) - 1:
					sp = s[:i] + '(' + s[i:j + 1] + ')' + s[j + 1:]
					best = max(best, eval(sp))
	return best
s = input()
print(find_best(s))


def main():
	import sys
	import re
	expr = '1*' + sys.stdin.read().rstrip() + '*1'
	muls = [i for i in range(len(expr)) if expr[i] == '*']
	result = eval(expr)
	for i in muls:
		for j in muls:
			if j > i:
				s = expr[:i + 1] + '(' + expr[i + 1:j] + ')' + expr[j:]
				result = max(result, eval(s))
	print(result)
main()


s = input()
s = '0+1*' + s + '*1+0'
n = len(s)
ans = eval(s)
p = []
for i in range(0, n):
	if s[i] == '*':
		p.append(i)
for i in p:
	for j in p:
		if i >= j:
			continue
		if s[i] == '*' and s[j] == '*':
			t = s[:i + 1] + '(' + s[i + 1:j] + ')' + s[j:]
			res = eval(t)
			if res > ans:
				ans = res
print(ans)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy
from itertools import chain, dropwhile, permutations, combinations
from collections import defaultdict, deque
import operator as op

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

def I():
	return int(input())

def LIST(n, m=None):
	return [0] * n if m is None else [[0] * m for i in range(n)]

def ELIST(n):
	return [[] for i in range(n)]

def MI(n=None, m=None):
	if n is None:
		(n, m) = VI()
	arr = LIST(n)
	for i in range(n):
		arr[i] = VI()
	return arr

def MS(n=None, m=None):
	if n is None:
		(n, m) = VI()
	arr = LIST(n)
	for i in range(n):
		arr[i] = input()
	return arr

def MIT(n=None, m=None):
	if n is None:
		(n, m) = VI()
	a = MI(n, m)
	arr = LIST(m, n)
	for (i, l) in enumerate(a):
		for (j, x) in enumerate(l):
			arr[j][i] = x
	return arr

def bfs(l, sgn, r, best, par=0):
	if len(r) == 1:
		return max(best, sgn(l, r[0]))
	if sng == op.add:
		if par == 0:
			return max(bfs(op.add(l, r[1]), r[2], r[3:], best, par), bfs(op.add(l, r[1]), r[2], r[3:], best, par + 1))
		if r[1] == op.add:
			return bfs(op.add(l, r[1]), r[2], r[3:], best)
		else:
			return max()

def run_bfs(s):
	x = list(s)
	lst = [int(v) if i % 2 == 0 else op.add if v == '+' else op.mul for (i, v) in enumerate(x)]
	b = bfs(lst[0], lst[1], lst[2:], 0)

def run2(s):
	best = eval(s)
	n = len(s)
	if n <= 3:
		print(eval(s))
		return
	x = list(s)
	for i in range(1, n - 2, 2):
		if s[i] == '+' and (i == 1 or s[i - 2] == '*'):
			l = i - 1
			for j in range(i + 2, n, 2):
				if s[j] == '*':
					exp = s[:l] + '(' + s[l:j] + ')' + s[j:]
					best = max(best, eval(exp))
			best = max(best, eval(s[:l] + '(' + s[l:] + ')'))
	print(best)

def run3(s):
	best = eval(s)
	n = len(s)
	if n <= 3:
		print(eval(s))
		return
	m = [i for (i, v) in enumerate(s) if v == '*']
	l = [0]
	r = [n]
	for x in m:
		if x < n - 2 and s[x + 2] == '+':
			l.append(x + 1)
		if x > 2 and s[x - 2] == '+':
			r.append(x)
	for v in l:
		for w in r:
			if v >= w:
				continue
			exp = s[:v] + '(' + s[v:w] + ')' + s[w:]
			best = max(best, eval(exp))
	print(best)

def run(s):
	best = eval(s)
	n = len(s)
	if n <= 3:
		print(best)
		return
	for i in range(1, n - 1, 2):
		if s[i] == '+' and (i == 1 or s[i - 2] == '*'):
			for j in range(i + 2, n, 2):
				if s[j] == '*':
					best = max(best, eval(s[:i - 1] + '(' + s[i - 1:j] + ')' + s[j:]))
			best = max(best, eval(s[:i - 1] + '(' + s[i - 1:] + ')'))
	print(best)

def main(info=0):
	s = input()
	run(s)

def __starting_point():
	main()
__starting_point()


s = '1*' + input() + '*1'
L = len(s)
f = eval
p = f(s)
for j in range(L):
	if s[j] == '*':
		for i in range(j + 1, L):
			if s[i] == '*':
				p = max(p, f(s[:j + 1] + '(' + s[j + 1:i] + ')' + s[i:]))
print(p)


s = input()
length = len(s)
ans = eval(s)
for j in range(0, length, 2):
	if j == 0 or s[j - 1] == '*':
		for k in range(j + 3, length + 1, 2):
			if k == length or s[k] == '*':
				tmp = eval(s[:j] + str(eval(s[j:k])) + s[k:])
				ans = ans if tmp < ans else tmp
print(ans)


def main():
	s = input()
	n = len(s)
	ans = -10 ** 18
	for i in range(1, n + 1, 2):
		for j in range(0, i, 2):
			if (j == 0 or s[j - 1] == '*') and (i == n or s[i] == '*'):
				ans = max(ans, eval(s[:j] + '(' + s[j:i] + ')' + s[i:]))
	print(ans)
main()


s = '1*' + input() + '*1'
poses = []
for i in range(len(s)):
	if s[i] == '*':
		poses.append(i)
ans = 0
for i in poses:
	for j in poses:
		if i < j:
			t = s[:i + 1] + '(' + s[i + 1:j] + ')' + s[j:]
			ans = max(ans, eval(t))
print(ans)


input_str = input()
str = '1*' + input_str + '*1'
str_len = len(str)
ans = 0
for i in range(2, str_len, 2):
	if str[i - 1] == '*':
		for j in range(i + 1, str_len, 2):
			if str[j] == '*':
				ans = max(ans, eval(str[:i] + '(' + str[i:j] + ')' + str[j:]))
print(ans)


s = input()
a = [0]
for i in range(len(s)):
	if s[i] == '*':
		a.append(i + 1)
a.append(len(s) + 1)
maxRes = eval(s)
for i in a:
	for j in a:
		if j > i:
			maxRes = max(maxRes, eval(s[:i] + '(' + s[i:j - 1] + ')' + s[j - 1:]))
print(maxRes)


s = input()
n = len(s)
ans = eval(s)
for i in range(0, n):
	for j in range(i + 1, n):
		if s[i] == '*' and s[j] == '*':
			e = s[0:i + 1] + '(' + s[i + 1:j] + ')' + s[j:]
			ans = max(ans, eval(e))
for i in range(0, n):
	if s[i] == '*':
		e = '(' + s[0:i] + ')' + s[i:]
		ans = max(ans, eval(e))
		e = s[0:i + 1] + '(' + s[i + 1:] + ')'
		ans = max(ans, eval(e))
print(ans)


s = input()
ma = eval(s)
for i in range(len(s)):
	if s[i] == '*':
		s1 = s[:i]
		s2 = s[i - len(s) + 1:]
		s3 = '(' + s1 + ')*' + s2
		ma = max(ma, eval(s3))
		s3 = s1 + '*(' + s2 + ')'
		ma = max(ma, eval(s3))
		for j in range(i):
			if s[j] == '*':
				s1 = s[:j]
				s3 = s[j + 1:i - len(s)]
				s4 = s1 + '*(' + s3 + ')*' + s2
				ma = max(ma, eval(s4))
print(ma)


s = '1*' + input() + '*1'
muls = [1]
for i in range(3, len(s) - 2, 2):
	if s[i] == '*' and (s[i - 2] == '+' or s[i + 2] == '+'):
		muls.append(i)
muls.append(len(s) - 2)
m = eval(s)
for i in range(len(muls)):
	for j in range(i + 1, len(muls)):
		(a, b) = (muls[i], muls[j])
		new_s = s[:a + 1] + '(' + s[a + 1:b] + ')' + s[b:]
		m = max(m, eval(new_s))
print(m)


S = '1*' + input() + '*1'
n = len(S)
ans = eval(S)
for i in range(2, n + 1, 2):
	if S[i - 1] == '*':
		for j in range(i + 1, n, 2):
			if S[j] == '*':
				T = S[0:i] + '(' + S[i:j] + ')' + S[j:]
				ans = max(ans, eval(T))
print(ans)


s = input()
exec('ans = ' + s)
n = s.count('*')
last_s = s
for i in range(n + 1):
	for j in range(i + 1, n + 2):
		new_s = ''
		if i == 0:
			new_s += '('
		k = 1
		for elem in s:
			if elem == '*':
				if i == k:
					new_s += '*('
				elif j == k:
					new_s += ')*'
				else:
					new_s += '*'
				k += 1
			else:
				new_s += elem
		if j == n + 1:
			new_s += ')'
		exec('_ans = ' + new_s)
		if _ans > ans:
			ans = _ans
			last_s = new_s
print(ans)


str = '1*' + input() + '*1'
n = len(str)
max_z = eval(str)
arr = []
for i in range(1, n, 2):
	if str[i] == '*':
		arr.append(i)
for i in range(len(arr)):
	s1 = str[:arr[i] + 1] + '(' + str[arr[i] + 1:]
	for j in range(i + 1, len(arr)):
		s2 = s1[:arr[j] + 1] + ')' + s1[arr[j] + 1:]
		max_z = max(eval(s2), max_z)
print(max_z)


expr = '1*' + input() + '*1'
muls = [i for i in range(len(expr)) if expr[i] == '*']
result = 0
for i in muls:
	for j in muls:
		if j > i:
			s = expr[:i + 1] + '(' + expr[i + 1:j] + ')' + expr[j:]
			result = max(result, eval(s))
print(result)