Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:
1+2*3=7
1*(2+3)=5
123=6
(1+2)*3=9
Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.
It's easy to see that the maximum value that you can obtain is 9.
Your task is: given a, b and c print the maximum value that you can get.
Input
The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
Output
Print the maximum value of the expression that you can obtain.
Examples
Input
1
2
3
Output
9
Input
2
10
3
Output
60
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We need to compute maximum value using operations + and * and parentheses between three numbers a, b, c in order. We have positions: between a and b, and between b and c. Parentheses can change order of operations. Since only two operations, there are essentially possible evaluation orders: either do left then right, or right then left. But also we can choose + or * for each operation. So all possible expressions:
(a op1 b) op2 c
a op1 (b op2 c)
where op1, op2 ∈ {+, *}.
But also we could consider cases where both ops are same but parentheses don't matter if operations are associative? Actually * and + are associative in arithmetic but they have different precedence. Without parentheses, the default precedence is * before +. But with parentheses we can force either order. However the two forms above cover all possible parse trees for three numbers with two binary operators. Also note that we could have expressions like (a op1 b op2 c) with no parentheses, which is equivalent to either left-associative or right-associative based on precedence. But since we can choose parentheses arbitrarily, the two forms capture the distinct ways to associate.
But careful: if both operators are the same and the operation is associative (both + and * are associative for integers), then (a op b) op c = a op (b op c). So they yield same result. However with different operators, the order matters.
Thus we can simply compute all possibilities: a+bc, a+b+c, ab+c, abc, but also with parentheses: (a+b)c, a(b+c), (ab)+c? Wait (ab)+c is same as ab+c because * has higher precedence? Actually in standard arithmetic, multiplication has higher precedence than addition, so ab+c is interpreted as (ab)+c. So if we want to compute (ab)+c, it's just ab+c. Similarly a+bc is a+(bc). So the expression a+bc is equivalent to a+(b*c) due to precedence. However we can also have (a+b)*c which is different. So the possible distinct expressions (considering precedence and parentheses) are:
a + b + c
a + b * c
a * b + c
a * b * c
(a + b) * c
a * (b + c)
But note: a + b + c is same as (a+b)+c and a+(b+c) so it's covered. a * b * c is same as (ab)c and a(bc). a + b * c is a+(bc). a * b + c is (ab)+c.
Also what about (ab) + (c)? That's same as ab+c. No other parentheses combinations.
Thus we can compute these six values and take max. But are there any other possibilities? For example, could we insert parentheses that group all three? Not needed.
But wait: Is there an expression like a + (b + c)? That's a+b+c. And (a + b + c) is same. So that's covered.
Thus answer is max of:
a + b + c
a + b * c
a * b + c
a * b * c
(a + b) * c
a * (b + c)
Given a, b, c ∈ [1,10], we can compute.
But note: The problem statement says "insert signs of operations '+' and '', and probably brackets". It does not say we must use both operations; we can use only one plus or one multiplication? Actually we have two positions, we must insert an operation in each? The description: "insert signs of operations '+' and '', and probably brackets between the numbers" implies we fill the two gaps with either '+' or '*'. So we must use exactly two binary operators? Possibly we could also not insert any? But there are three numbers, we must combine them. Usually we need two operators. So we must fill both gaps with either + or . So indeed we need two operations. So each expression uses two operators. So we have four combos for operators: ++, +, *+, **. For each, we can decide parentheses or not, but parentheses only make sense when operators differ. For ++ and **, parentheses don't change anything. So we have essentially four possibilities for the operators without parentheses? But we also have parentheses for mixed operators. However there are two distinct ways to associate: left and right. But note: In case of mixed operators, the default precedence of * over + may already produce one association if we don't add parentheses. But we are allowed to add parentheses arbitrarily, so we can override precedence. So the expressions we can form are:
For op1='+', op2='+': a+b+c.
For op1='+', op2='': either a+bc (default) or (a+b)*c.
For op1='', op2='+': either ab+c (default) or a*(b+c).
For op1='', op2='': abc.
Thus the six expressions above cover all.
Thus solution: read three ints, compute those six values, output max.
Check sample: a=1,2,3:
1+2+3=6
1+23=7
12+3=5
123=6
(1+2)3=9
1(2+3)=5 -> max 9. OK.
Second sample: 2,10,3:
2+10+3=15
2+103=2+30=32
210+3=20+3=23
2103=60
(2+10)3=123=36
2*(10+3)=2*13=26 -> max 60. Output 60. OK.
Thus correct.
Implementation: just compute.
Edge: all numbers up to 10, so max could be up to 101010=1000. Fine.
Let's produce final answer.
The problem might be from Codeforces 479A.
We'll code in Python.
We'll parse three lines input, or can read from sys.stdin.
Simplify: a,b,c = [int(input()) for _ in range(3)]
Compute:
values = [
a + b + c,
a + b * c,
a * b + c,
a * b * c,
(a + b) * c,
a * (b + c)
]
print(max(values))
That's it.
We'll output the solution accordingly.
But wait: There is also possibility of a+bc? Already included. Also (ab)+c? Already a*b+c. So done.
Thus final code.
```python
import sys
def main():
# Read three integers, each on its own line
data = sys.stdin.read().strip().split()
if len(data) < 3:
return
a, b, c = map(int, data[:3])
code
# Compute all possible expression values
values = [
a + b + c,
a + b * c,
a * b + c,
a * b * c,
(a + b) * c,
a * (b + c)
]
# Output the maximum
print(max(values))