P1834 Quick Calculation Game

Description

jyx and cyy made a bet to see who can compute $24$ faster; the slower person treats. The rules of the $24$ Game are as follows: given $4$ integers from $1\sim 9$, use parentheses to change the order of operations and perform a sequence of operations among addition, subtraction, multiplication, and division to obtain the integer $24$. Note that all intermediate results must be integers (for example, $(2\times 2)/4$ is allowed, while $2\times (2/4)$ is not allowed). To win this match, please write a program to help me cheat by quickly computing $24$.

Input Format

One line with $4$ integers, which are the given $4$ numbers. The input testdata is guaranteed to have a solution.

Output Format

One line, output the result as a string. Make sure to include parentheses for every step of the operations (for example, $(3+5)+6$ and $3\times(5+6)$). If there are multiple solutions, output the lexicographically smallest one.

Explanation/Hint

Translated by ChatGPT 5