require 'mathn'

class Solver
  def initialize

    loop do
      numbers = gets.chomp.split(' ').map(&:to_i)

      $answer = nil
      $list = nil

      break if numbers.all?(&:zero?)

      solver(numbers)

      unless $answer.nil?
        p $answer
        p $list

        $answer.each do |index|
          $list[index*2..index*2+2] = "(#{$list[index*2]} #{$list[index*2+1]} #{$list[index*2+2]})"
        end

        puts $list
      else
        puts 0
      end
    end
  end

  def solver(numbers)
    operations = [:+, :-, :*]

    numbers.permutation(4) do |num_list|
      operations.repeated_permutation(3) do |opes|
        list = [ num_list[0], opes[0], num_list[1], opes[1], num_list[2], opes[2], num_list[3] ]
        index_list = []

        dfs( list, index_list )

        $list = list.dup
        return unless $answer.nil?
      end
    end
  end

  def dfs(list, index_list)

    if list.size == 3 && index_list.size == 2
      num = list[0].send(list[1], list[2])

      if num == 10
        index_list << 0

        $answer = index_list.dup
      end
    else
      0.upto(list.size/2-1) do |index|
        index_list << index
        tmp_list = list.dup
        r = tmp_list[index*2]
        o = tmp_list[index*2+1]
        t = tmp_list[index*2+2]


        tmp_list[index*2..index*2+2] = r.send(o, t)

        dfs( tmp_list, index_list )

        return index_list if index_list.size == 3
        index_list.pop
      end
    end

    index_list.pop
  end
end

Solver.new