class TwentyFourGame
  EXPRESSIONS = [
    '((%dr%s%dr)%s%dr)%s%dr',
    '(%dr%s (%dr%s%dr))%s%dr',
    '(%dr%s%dr)%s (%dr%s%dr)',
    '%dr%s ((%dr%s%dr)%s%dr)',
    '%dr%s (%dr%s (%dr%s%dr))',
  ]

  OPERATORS = [:+,:-,:*,:/].repeated_permutation(3).to_a

  def self.solve(digits)
    solutions = []
    perms = digits.permutation.to_a.uniq
    perms.product(OPERATORS, EXPRESSIONS) do |(a,b,c,d), (op1,op2,op3), expr|
      
      text = expr % [a, op1, b, op2, c, op3, d]
      value = eval(text)  rescue next                 
      solutions << text.delete()  if value == 24
    end
    solutions
  end
end


digits = ARGV.map do |arg| 
  begin
    Integer(arg)
  rescue ArgumentError
    raise 
  end
end
digits.size == 4 or raise 

solutions = TwentyFourGame.solve(digits)
if solutions.empty?
  puts 
else
  puts 
  puts solutions.sort
end