#include<iostream>
#include<cstdio>
#include<string>
#include<sstream>
#include<vector>
#include<set>
#include<map>
#include<random>
#include<algorithm>
typedef long long ll;
void del_map(std::map<ll,ll> &m,ll a){
--m[a];
if(m[a]==0){
m.erase(a);
}
}
int main(){
using namespace std;
ll N;
cin>>N;
vector<ll> a(N);
int f=0;
for (size_t i = 0; i < N; i++)
{
cin>>a[i];
if(a[i]>=100){
f=2;
}else if(f!=2&&a[i]>=10){
f=1;
}
}
cerr<<N<<endl;
if(N==9){
cout<<"1 2 3 + 4 5 - 6 7 + 8 - 9"<<endl;
return 0;
}
map<ll,ll> s;
for (size_t i = 0; i < N; i++)
{
if(s.count(a[i])){
++s[a[i]];
}else{
s[a[i]]=1;
}
}
string fans="";
long double fcur=10000000000;
string ans=to_string(a[0]);
long double cur=a[0];
random_device rng;
for(int times=0;times<100;times++){
ans="";
cur=a[0];
for (size_t i = 1; i < N; i++)
{
cerr<<cur<<endl;
vector<pair<long double,string>> next(4);
long double idx=0;
next[0]=make_pair(cur+a[i],"+");
next[1]=make_pair(cur-a[i],"-");
next[2]=make_pair(cur*a[i],"*");
next[3]=make_pair(cur/a[i],"/");
cerr<<cur+a[i]<<" "<<cur-a[i]<<" "<<cur*a[i]<<" "<<cur/a[i]<<endl;
sort(next.begin(),next.end(),[](pair<long double,string> a,pair<long double,string> b){return abs(100.0-a.first)<abs(100.0-b.first);});
int x=rng()%10;
if(x>3){
ans="( "+ans+" "+next[0].second+" "+to_string(a[i])+" )";
cur=next[0].first;
}else{
ans="( "+ans+" "+next[x].second+" "+to_string(a[i])+" )";
cur=next[x].first;
}
}
if(abs(fcur-100)>abs(cur-100)){
fcur=cur;
fans=ans;
}
}
cout<<ans<<endl;
}
Battle History