Buggy python submission (verdict: Runtime Error):
import itertools
def f(a):
 if len(a)<2:yield(a[0],a[0])
 for i in range(1,len(a)):
  for p,s in f(a[:i]):
   for q,t in f(a[i:]):
    yield(p+q,f'({s}+{t})')
    yield(p-q,f'({s}-{t})')
    yield(p*q,f'({s}*{t})')
def s(a):
 for p in itertools.permutations(a):
  for n,s in f(p):
   if n==10:print(s);return 1
while 1:
 a=list(map(int,input().split()))
 if sum(a)and not s(a):print(0)


Fixed submission:
from itertools import *
g=lambda a,x,b:{'+':a+b,'-':a-b,'*':a*b}[x]
def f(s):
 for a,b,c,d in permutations(s):
  for x,y,z in product('+-*',repeat=3):
   if g(g(g(a,x,b),y,c),z,d)==10:return f"(({a}{x}{b}){y}{c}){z}{d}"
   if g(g(a,x,b),y,g(c,z,d))==10:return f"({a}{x}{b}){y}({c}{z}{d})"
 return 0
for e in iter(input,'0 0 0 0'):print(f(list(map(int,e.split()))))

Buggy python submission (verdict: Runtime Error):
import itertools,sys
def f(a):
 if len(a)<2:yield[a[0]]*2
 for i in range(1,len(a)):
  for p,s in f(a[:i]):
   for q,t in f(a[i:]):
    yield(p+q,f'({s} + {t})')
    yield(p-q,f'({s} - {t})')
    yield(p*q,f'({s} * {t})')
def s(a):
 for p in itertools.permutations(a):
  for n,s in f(p):
   if n==10:print(s);return 1
for e in iter(input,'0 0 0 0\n'):
 a=list(map(int,e.split()))
 if not s(a):print(0)


Fixed submission:
from itertools import *
g=lambda a,x,b:{'+':a+b,'-':a-b,'*':a*b}[x]
def f(s):
 for a,b,c,d in permutations(s):
  for x,y,z in product('+-*',repeat=3):
   if g(g(g(a,x,b),y,c),z,d)==10:return f"(({a}{x}{b}){y}{c}){z}{d}"
   if g(g(a,x,b),y,g(c,z,d))==10:return f"({a}{x}{b}){y}({c}{z}{d})"
 return 0
for e in iter(input,'0 0 0 0'):print(f(list(map(int,e.split()))))

Buggy python submission (verdict: Runtime Error):
from itertools import *
def f(s):
 for t in[f"({a} {x} {b}) {y} ({c} {z} {d})",f"(({a} {x} {b}) {y} {c}) {z} {d}",f"{a} {x} ({b} {y} ({c} {z} {d}))",f"({a} {x} ({b} {y} {c})) {z} {d}",f"{a} {x} (({b} {y} {c}) {z} {d})"]:
  for a,b,c,d in permutations(s):
   for x,y,z in product('+-*',repeat=3):
    if eval(t)==10:return'('+t+')'
 else:return 0
for e in iter(input,'0 0 0 0'):print(f(list(map(int,e.split()))))


Fixed submission:
from itertools import *
g=lambda a,x,b:{'+':a+b,'-':a-b,'*':a*b}[x]
def f(s):
 for a,b,c,d in permutations(s):
  for x,y,z in product('+-*',repeat=3):
   if g(g(g(a,x,b),y,c),z,d)==10:return f"(({a}{x}{b}){y}{c}){z}{d}"
   if g(g(a,x,b),y,g(c,z,d))==10:return f"({a}{x}{b}){y}({c}{z}{d})"
 return 0
for e in iter(input,'0 0 0 0'):print(f(list(map(int,e.split()))))

Buggy python submission (verdict: Runtime Error):
from itertools import *
def f(s):
 for t in["({a} {x} {b}) {y} ({c} {z} {d})","(({a} {x} {b}) {y} {c}) {z} {d}","{a} {x} ({b} {y} ({c} {z} {d}))","({a} {x} ({b} {y} {c})) {z} {d}","{a} {x} (({b} {y} {c}) {z} {d})"]:
  for a,b,c,d in permutations(s):
   for x,y,z in product('+-*',repeat=3):
    t='f"'+t+'"'
    if eval(eval(t))==10:return'('+eval(t)+')'
 else:return 0
for e in iter(input,'0 0 0 0'):print(f(list(map(int,e.split()))))


Fixed submission:
from itertools import *
g=lambda a,x,b:{'+':a+b,'-':a-b,'*':a*b}[x]
def f(s):
 for a,b,c,d in permutations(s):
  for x,y,z in product('+-*',repeat=3):
   if g(g(g(a,x,b),y,c),z,d)==10:return f"(({a}{x}{b}){y}{c}){z}{d}"
   if g(g(a,x,b),y,g(c,z,d))==10:return f"({a}{x}{b}){y}({c}{z}{d})"
 return 0
for e in iter(input,'0 0 0 0'):print(f(list(map(int,e.split()))))