A nineteenth century duke built a room for his valuables and chose the code of its safe in an unusual way. He was so afraid of being robbed that he told nobody the code. He only wrote down how to obtain it, on a sheet of paper meant for his heir after his death. The paper read:
? by +, - or *. Do that in all possible ways to get several arithmetic expressions.The ring carries k numbers and k symbols engraved in a circle, in the order n1, s1, n2, s2, ..., nk, sk. The number closest to the ruby is n1. The r-th sequence reads 2k−1 elements clockwise starting at nr, so it holds k numbers and the k−1 symbols between them, and the last symbol is left out.
The symbol choices and the evaluation order are decided separately for each sequence, and each ? may take a different symbol. The operators keep their positions, and only the order of evaluation changes. For instance 1 - 5 + 0 * -2 - -3 gives 11 when it is evaluated as ((((1 - 5) + 0) * -2) - -3), and it gives -4 when it is evaluated as (1 - (5 + (0 * (-2 - -3)))).
If the minimum of a sequence is -4 and the maximum is 11, the code of that sequence is 411, because the sign of a negative value is dropped and only its digits are written.
Given the numbers and the symbols engraved on the ring, find the safe secret.
The first line has one positive integer k, the number of (number, symbol) pairs that form the ring.
The second line has 2k elements n1, s1, n2, s2, ..., nk, sk, separated by single spaces. Each ni is a number and each si is +, -, * or ?.
Print the safe secret on a single line.