#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define ELEMENTS 4

/* input */
char input[ELEMENTS * 2];

int table[ELEMENTS * 2];

int clac(char str[]) {
	int stack[16];
	int stack_top = 0;
	int i;

	for(i = 0; str[i]; i++) {
		if('0' <= str[i] && str[i] <= '9') {
			stack[stack_top] = str[i] - '0';
			stack_top++;
		}

		else {
			int a, b;

			stack_top--;
			b = stack[stack_top];
			stack_top--;
			a = stack[stack_top];

			switch(str[i]) {
				case '+':
					stack[stack_top] = a + b;
					stack_top++;
					break;
				case '-':
					stack[stack_top] = a - b;
					stack_top++;
					break;
				case '*':
					stack[stack_top] = a * b;
					stack_top++;
					break;
				default:
					fprintf(stderr, "error in clac. unexpected charctor.\n");
			}
		}
	}

	if(stack_top != 1) {
		fprintf(stderr, "error in clac. stack_top is not zero. stack_top : %d\n", stack_top);
	}

	return stack[--stack_top];
}

char* restore(char str[]) {
	char* ret = malloc(sizeof(char) * 32);
	int ret_index = 0;
	int num, op;

	char stack[16][32];
	int stack_top = 0;

	char *a, *b;

	int i;

	for(i = 0; str[i]; i++) {
		if('0' <= str[i] && str[i] <= '9') {
			stack[stack_top][0] = str[i];
			stack[stack_top][1] = '\0';
			stack_top++;
		}

		else {
			char temp[16];
			int len;

			b = stack[--stack_top];
			a = stack[--stack_top];

			temp[0] = '(';
			temp[1] = '\0';
			strcat(temp, a);
			len = strlen(temp);
			temp[len] = str[i];
			temp[len + 1] = '\0';
			strcat(temp, b);
			len = strlen(temp);
			temp[len] = ')';
			temp[len + 1] = '\0';

			strcpy(stack[stack_top++], temp);
		}
	}

	strcpy(ret, stack[--stack_top]);
	return ret;
}

char* solve(char str[], int num_used, int op_used) {
	int i;
	char *ret;

	if(num_used == ELEMENTS && op_used == ELEMENTS - 1) {
		str[num_used + op_used] = '\0';
		if(clac(str) == 10) {
			ret = restore(str);
			return ret;
		}

		else
			return NULL;
	}

	else {
		if(num_used - op_used < 2) {
			for(i = 0; i < ELEMENTS; i++) {
				if(!table[i]) {
					table[i] = 1;
					str[num_used + op_used] = input[i];
					if((ret = solve(str, num_used + 1, op_used)) != NULL)
						return ret;
					table[i] = 0;
				}
			}
		}

		else {
			str[num_used + op_used] = '+';
			if((ret = solve(str, num_used, op_used + 1)) != NULL)
				return ret;

			str[num_used + op_used] = '-';
			if((ret = solve(str, num_used, op_used + 1)) != NULL)
				return ret;

			str[num_used + op_used] = '*';
			if((ret = solve(str, num_used, op_used + 1)) != NULL)
				return ret;

			if(num_used < ELEMENTS) {
				for(i = 0; i < ELEMENTS; i++) {
					if(!table[i]) {
						table[i] = 1;
						str[num_used + op_used] = input[i];
						if((ret = solve(str, num_used + 1, op_used)) != NULL)
							return ret;
						table[i] = 0;
					}
				}
			}
		}
	}

	return NULL;
}

int main(void) {
	char* ans;
	char str[16];
	int i;

	while(1) {
		for(i = 0; i < ELEMENTS; i++) {
			scanf("%d", &input[i]);
			input[i] += '0';
			table[i] = 0;
		}

		if(input[0] == '0' && input[1] == '0' && input[2] == '0' && input[3] == '0')
			break;

		ans = solve(str, 0, 0);
		if(ans != NULL) {
			printf("%s\n", ans);
			free(ans);
			ans = NULL;
		}

		else
			printf("0\n");
	}

	return 0;
}

Measured memory_bytes: 600