Problem B.

One just needs to calculate all possible answers and find the minimum. For example one may run on a set of numbers, for all pairs of numbers apply next operation to that pair and recursively run on a new set of numbers. When only one number remains, compare it to the already obtained minimum, and change that minimum if it's needed.

1 1 1 1

+ + *

i proceed this way

+

2 2 1 1

+

2 3 3 1

*

2 3 3 3

???

1 1 1 1

+

2 1 1

+

3 1

*

3

In 1st test we have:

1 1 1 1

+

2 1 1

+

3 1

*

3

We apologize for that ambiguity, but believe that it is not very hard to resolve it by reading statement carefully one more time.

Meh, I am too slow.

i thought "them" in the problem statement refered both of the numbers.

Time: 30 ms, memory: 3636 KB Verdict: WRONG_ANSWER Input 323 771 559 347 + * * Participant's output 443006 Jury's answer 149067730 Checker comment wrong answer 1st numbers differ — expected: '149067730', found: '443006'

This was one of the testcases my program failed but clearly my program finds the smaller output and the jury's output is the larger one. I multiplied the first two numbers and added it with the multiplication of the last two numbers.