#include <stdio.h>
#include <setjmp.h>
#include <math.h>

#define exch(A,B) {int tmp=A;A=B;B=tmp;}
#define OP_N NUM_N - 1
#define LEN NUM_N + OP_N

#define NUM_N 4
#define GOAL 10

/* ------------------------------------------------------ */

/* 0:constant 1:operator */
int isOperator[LEN];

/* numbers */
int nums[NUM_N] = {3, 4, 8, 2};

/* operators */
char ops[OP_N];

/* return if the structure is possible */
int possible()
{
     int n=0, i;
     for(i=LEN-1; i>=0; i--){
          if(!isOperator[i]) n++;
          else if(n<2) return 0;
          else n--;
     }
     return n==1;
}

/* return value of expression */
int getValueR(int init)
{
     static int np, op, p;
     if(init) np=op=p=0;

     if(isOperator[p++]){
          char t_op = ops[op++];
          int t_val = getValueR(0);

          switch(t_op){
          case '+': return t_val + getValueR(0);
          case '-': return t_val - getValueR(0);
          case '*': return t_val * getValueR(0);
          }
     }

     return nums[np++];
}
int getValue(){ return getValueR(1); }

/* print infix-notation of expression */
void showInfixR(int init)
{
     static int np, op, p;
     if(init) np=op=p=0;

     if(isOperator[p++]){
          char t_op = ops[op++];

          printf("( ");
          showInfixR(0);

          printf(" %c ", t_op);

          showInfixR(0);
          printf(" )");
     }else if(nums[np]<0)
          printf("(%d)", nums[np++]);
     else
          printf("%d", nums[np++]);
}
void showInfix(){ showInfixR(1); puts(""); }

/* ------------------------------------------------------ */

jmp_buf buf;

/* assign integers and operators to the structure then eval*/
void check(int n)
{
     int i;

     /* permutate numbers */
     if(n<NUM_N){
          check(n+1);
          for(i=n+1; i<NUM_N; i++)
               if(nums[n] != nums[i]){
                    exch(nums[i], nums[n]);
                    check(n+1);
                    exch(nums[n], nums[i]);
               }
     }

     /* eval each permutation of operators */
     else{
          /* there're 3^N permutations */
          for(i=0; i<=pow(3,OP_N); i++){
               int t=i, j=0;
               while(j < OP_N){
                    ops[j++] = t%3==2? '+': t%3==1? '-': '*';
                    t /= 3;
               }
               if(getValue() == GOAL) longjmp(buf, 1);
          }
     }
}


/* generate structures and call check */
void solveR(int n)
{
     int i;

     /* permutate "isOperator" */
     if(n<LEN){
          solveR(n+1);
          for(i=n+1; i<LEN; i++)
               if(isOperator[n] != isOperator[i]){
                    exch(isOperator[i], isOperator[n]);
                    solveR(n+1);
                    exch(isOperator[n], isOperator[i]);
               }
     }

     /* call check */
     else
          if(possible()) check(0);
}
void solve()
{
     int i=0;
     while(i<OP_N) isOperator[i++] = 1;
     while(i<LEN) isOperator[i++] = 0;
     solveR(0);
}


int main(void)
{
     int i, t;

     while(1){
          t = 0;
          for(i=0; i<NUM_N; t+=nums[i++])
               scanf("%d", &nums[i]);

          if(t==0) return 0;

          if(setjmp(buf) == 0){
               solve(); puts("0");
          }else
               showInfix();
     }
}

Measured memory_bytes: 612