// 若干修正
#include <iostream>
#include <sstream>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;
template <class N>
struct calculator {
typedef string op_type;
typedef map<op_type, function<N(N,N)> > op_map;
vector<N> elems;
vector<op_type> ops;
op_map s_opmap = {
{"+", plus<N>()}, {"-", minus<N>()},
{"/", divides<N>()}, {"*", multiplies<N>()} };
vector<vector<op_type>> prio = { {"*","/"}, {"+","-"} };
calculator(vector<N>& e) : elems(e) {}
bool validate(){
vector<N> cvals(elems);
vector<op_type> cops(ops);
for( auto ops: prio )
for( int i = 0; i < cops.size(); i++ )
if( any_of( ops.begin(), ops.end(),
bind( equal_to<op_type>(), cops[i], placeholders::_1 ) )
){
cvals[i] = s_opmap[ cops[i] ](cvals[i],cvals[i+1]);
cvals.erase(cvals.begin() + i+1);
cops.erase(cops.begin() + i--);
}
return ( cvals.size() == 2 && cvals.back() == cvals.front() );
}
void calculate(){
this->ops = vector<op_type>();
bool found = next_comb();
cout << elems[0] << " "; // head
for( size_t i = 1; i < elems.size() -1; i++ )
found && (cout << ops[i-1]), cout << " " << elems[i] << " ";
cout << (found ? "= " : "has no op-combs to be ") << elems.back() << endl;
}
bool next_comb(){
return ( ops.size() == (elems.size() -2) ) ? validate() :
any_of(s_opmap.begin(),s_opmap.end(),[&]( typename op_map::value_type& o ){
ops.push_back(o.first);
return next_comb() || (ops.pop_back(), false);
});
}
};
template < class num_type >
int main_deleg(){
for( string line; getline(cin,line); ){
replace (line.begin(), line.end(), ':', ' ');
istringstream iss(line);
vector<num_type> list;
for( num_type n; ! (iss >> n).fail(); list.push_back(n) );
if( list.size() > 1 )
calculator<num_type>(list).calculate();
else
cout << line << ": invalid line. skip. " << endl;
}
return 0;
}
int main(){ return main_deleg<double>(); }
Ly8g6Iul5bmy5L+u5q2jCiNpbmNsdWRlIDxpb3N0cmVhbT4KI2luY2x1ZGUgPHNzdHJlYW0+CiNpbmNsdWRlIDx2ZWN0b3I+CiNpbmNsdWRlIDxtYXA+CiNpbm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