loop do
    nums = gets.split.map(&:to_i)
    break if nums[0] == 0

    catch(:ok) do
        [:*, :+, :-].repeated_combination(3) do |ops|
            (nums + ops).permutation(7) do |polish|
                stack = []
                begin
                    until polish.empty?
                        x = polish.pop
                        if x.class == Symbol
                            v2, e2 = stack.pop || raise
                            v1, e1 = stack.pop || raise
                            v3 = v1.send(x, v2)
                            e3 = "(#{e1}#{x}#{e2})"
                            stack << [v3, e3]
                        else
                            stack << [x, x.to_s]
                        end
                    end
                    if stack[0][0] == 10
                        puts stack[0][1]
                        throw :ok
                    end
                rescue
                end
            end
        end
        p 0
    end
end