#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 1<<30
#define INF2 255
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const char ope[] = { '+', '-', '*' };

int rev_polish (string str )
{
	int len = str.length();
	int res = 0;
	stack <int> st;
	int i = 0;

	while (i < len ){
		if( isdigit( str[i] ) ){
			int n = (int)(str[i] - '0');
			st.push(n);
		}else{	// operator come
			if (st.empty() ){
				return INF;
			} // end if 
			int y = st.top();
			st.pop();
			if (st.empty() ){
				return INF;
			} // end if 
			int x = st.top();
			st.pop();
			char c = str[i];
			int res = 0;
			switch (c ){
				case '+':
					res = x + y; st.push(res ); break;
				case '-':
					res = x - y; st.push(res ); break;
				case '*':
					res = x * y; st.push(res ); break;
			} // end switch	
		} // end if
		++i;
	} // end while

	res = st.top();

	return res;
}


char tree[1000];
int m; // m は文字列の位置、
void dfs (int n, string s )	// n は木の位置
{
	if (m < 0 ) return;
	tree[n] = s[m--];

	if (isdigit (tree[n] ) ){
		return;
	} // end if
	dfs (2*n+2, s );
	dfs (2*n+1, s );
}

string res2;

void disp_exp (int n )
{
	if (tree[n] == (char)INF2 ) return;

	if (!isdigit (tree[n] ) ) res2 += '(';
	disp_exp (2*n+1);
	res2 += ' ';
	res2 += tree[n];
	res2 += ' ';
	disp_exp (2*n+2);
	if (!isdigit (tree[n] ) ) res2 += ')';
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.Expression", "r", stdin );

	int a, b, c, d;
	while (1 ){
		scanf ("%d %d %d %d", &a, &b, &c, &d );
		if (a == 0 && b == 0 && c == 0 && d == 0 ) break;
		string exp = "";
		exp += (char)(a+'0'); exp += (char)(b+'0'); exp += (char)(c+'0'); exp += (char)(d+'0');
		rep (i, 3 )
			exp += 'e';
		sort (ALL (exp ) );
		bool found = false;
		string res = "";
		do{
			rep (i, 27 ){
				int ans = INF;
				int n = exp.length();
				string e = exp;
				int cnt = 0;
				rep (j, n ){
					if (exp[j] == 'e' ){
						switch (cnt ){
							case 0: e[j] = ope[i/9]; break;
							case 1: e[j] = ope[(i/3) % 3]; break;
							case 2: e[j] = ope[i%3]; break;
						} // end switch
						cnt++;
					} // end if
				} // end rep
				if ((ans = rev_polish (e ) )!= INF ){
//					cout << e << " = " << ans << endl;
					if (ans == 10 ){
						res = e;
						found = true;
						break;
						//cout << e << endl;
					} // end if
				} // end if
			} // end rep
			if (found ) break;	
		}while (next_permutation (ALL (exp ) ) );

		if (!found ){
			cout << 0 << endl;
		}else{
			fill (tree, tree+1000, (char)INF2 );
			m = res.size() - 1;
			dfs (0, res );
			res2 = "";
			disp_exp (0 );
			cout << res2 << endl;
		} // end if	 
	} // end while

	return 0;
}
### Prompt

Construct a cpp code solution to the problem outlined:

Using the given four integers from 1 to 9, we create an expression that gives an answer of 10. When you enter four integers a, b, c, d, write a program that outputs an expression that gives an answer of 10 according to the following conditions. Also, if there are multiple answers, only the first answer found will be output. If there is no answer, output 0.

* Use only addition (+), subtraction (-), and multiplication (*) as operators. Do not use division (/). You can use three operators.
* You must use all four numbers.
* You can freely change the order of the four numbers.
* You can use parentheses. You can use up to 3 sets (6) of parentheses.



Input

Given multiple datasets. The format of each dataset is as follows:


a b c d

Input ends with four 0s. The number of datasets does not exceed 40.

Output

For each dataset, combine the given four integers with the above arithmetic symbols and parentheses to output an expression or 0 with a value of 10 on one line. The expression string must not exceed 1024 characters.

Example

Input

8 7 9 9
4 4 4 4
5 5 7 5
0 0 0 0


Output

((9 * (9 - 7)) - 8)
0
((7 * 5) - (5 * 5))

### Response

```cpp
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 1<<30
#define INF2 255
using namespace std;

typedef long long ll;
typedef pair<int, int> P;

const char ope[] = { '+', '-', '*' };

int rev_polish (string str )
{
	int len = str.length();
	int res = 0;
	stack <int> st;
	int i = 0;

	while (i < len ){
		if( isdigit( str[i] ) ){
			int n = (int)(str[i] - '0');
			st.push(n);
		}else{	// operator come
			if (st.empty() ){
				return INF;
			} // end if 
			int y = st.top();
			st.pop();
			if (st.empty() ){
				return INF;
			} // end if 
			int x = st.top();
			st.pop();
			char c = str[i];
			int res = 0;
			switch (c ){
				case '+':
					res = x + y; st.push(res ); break;
				case '-':
					res = x - y; st.push(res ); break;
				case '*':
					res = x * y; st.push(res ); break;
			} // end switch	
		} // end if
		++i;
	} // end while

	res = st.top();

	return res;
}


char tree[1000];
int m; // m は文字列の位置、
void dfs (int n, string s )	// n は木の位置
{
	if (m < 0 ) return;
	tree[n] = s[m--];

	if (isdigit (tree[n] ) ){
		return;
	} // end if
	dfs (2*n+2, s );
	dfs (2*n+1, s );
}

string res2;

void disp_exp (int n )
{
	if (tree[n] == (char)INF2 ) return;

	if (!isdigit (tree[n] ) ) res2 += '(';
	disp_exp (2*n+1);
	res2 += ' ';
	res2 += tree[n];
	res2 += ' ';
	disp_exp (2*n+2);
	if (!isdigit (tree[n] ) ) res2 += ')';
}

int main()
{
//	cut here before submit 
//	freopen ("testcase.Expression", "r", stdin );

	int a, b, c, d;
	while (1 ){
		scanf ("%d %d %d %d", &a, &b, &c, &d );
		if (a == 0 && b == 0 && c == 0 && d == 0 ) break;
		string exp = "";
		exp += (char)(a+'0'); exp += (char)(b+'0'); exp += (char)(c+'0'); exp += (char)(d+'0');
		rep (i, 3 )
			exp += 'e';
		sort (ALL (exp ) );
		bool found = false;
		string res = "";
		do{
			rep (i, 27 ){
				int ans = INF;
				int n = exp.length();
				string e = exp;
				int cnt = 0;
				rep (j, n ){
					if (exp[j] == 'e' ){
						switch (cnt ){
							case 0: e[j] = ope[i/9]; break;
							case 1: e[j] = ope[(i/3) % 3]; break;
							case 2: e[j] = ope[i%3]; break;
						} // end switch
						cnt++;
					} // end if
				} // end rep
				if ((ans = rev_polish (e ) )!= INF ){
//					cout << e << " = " << ans << endl;
					if (ans == 10 ){
						res = e;
						found = true;
						break;
						//cout << e << endl;
					} // end if
				} // end if
			} // end rep
			if (found ) break;	
		}while (next_permutation (ALL (exp ) ) );

		if (!found ){
			cout << 0 << endl;
		}else{
			fill (tree, tree+1000, (char)INF2 );
			m = res.size() - 1;
			dfs (0, res );
			res2 = "";
			disp_exp (0 );
			cout << res2 << endl;
		} // end if	 
	} // end while

	return 0;
}
```