/*枚举出所有情况,在枚举的过程中,选出最优解。
大致题意:1、满足客户要求的即为可行解
2、种类最多即为最优解
3、在种类相同的情况下,张数少的更优
4、在张数相等的情况下,单个价值更大的更优
5、三者都相同,输出tie
*/
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
int stamp[1006];
int s[4];
int n,m,k,t,maxx;
int curK,curT,curM,curS[4];
bool curTie;
int temp;
bool ok(int temp)
{
int i,j;
for(i=0,j=0;i<n;i++)
if(stamp[i]==temp) j++;
return (j<5);
}
void Dodo(){
for ( s[0]=0; s[0]<=n; s[0]++)
for ( s[1]=s[0]; s[1]<=n; s[1]++)
for ( s[2]=s[1]; s[2]<=n; s[2]++)
for ( s[3] = s[2]; s[3]<=n; s[3]++) {
if ( stamp[s[0]]+stamp[s[1]]+stamp[s[2]]+stamp[s[3]] != m ) continue;
//cout<<stamp[s[0]]<<stamp[s[1]]<<stamp[s[2]]<<stamp[s[3]]<<endl;
k = 0;
t = 0;
maxx = 0;
if ( stamp[s[0]] ) {k++; t++; if ( stamp[s[0]]>maxx ) maxx = stamp[s[0]];}
if ( stamp[s[1]] ) {k++; if ( s[1]>s[0] ) t++; if ( stamp[s[1]]>maxx ) maxx = stamp[s[1]];}
if ( stamp[s[2]] ) {k++; if ( s[2]>s[1] ) t++; if ( stamp[s[2]]>maxx ) maxx = stamp[s[2]];}
if ( stamp[s[3]] ) {k++; if ( s[3]>s[2] ) t++; if ( stamp[s[3]]>maxx ) maxx = stamp[s[3]];}
if ( t<curT ) continue;
if ( t>curT ) {
curT = t;
curK = k;
curM = maxx;
curS[0]=s[0]; curS[1]=s[1];curS[2]=s[2];curS[3]=s[3];
curTie = false;
continue;
}
if ( k>curK ) continue;
if ( k<curK ) {
curT = t;
curK = k;
curM = maxx;
curS[0]=s[0]; curS[1]=s[1];curS[2]=s[2];curS[3]=s[3];
curTie = false;
continue;
}
if ( maxx<curM ) continue;
if ( maxx>curM ){
curT = t;
curK = k;
curM = maxx;
curS[0]=s[0]; curS[1]=s[1];curS[2]=s[2];curS[3]=s[3];
curTie = false;
continue;
}
curTie = true;
}
if ( curT == -1 ) {
cout<<m<<" ---- none"<<endl;
return;
}
cout<<m<<" ("<<curT<<"):";
if ( curTie ) {
cout<<" tie"<<endl;
return;
}
for ( int i=0; i<4; i++)
if ( stamp[curS[i]]>0 ) cout<<' '<<stamp[curS[i]];
cout<<endl;
}
int main()
{
int strs[255],k;
int i;
while(scanf("%d",&k)!=EOF)
{
i=0;
while(k!=0)
{
strs[i++]=k;
scanf("%d",&k);
}
strs[i]=0;
n=0;
memset(stamp,0,sizeof(stamp));
for(i=0;strs[i]!=0;i++)
{
if(ok(strs[i]))
stamp[n++]=strs[i];
}
i=0;
while(1)
{
scanf("%d",&strs[i++]);
if(strs[i-1]==0)
break;
}
for(i=0;strs[i]!=0;i++)
{
m=strs[i];
curK=100;
curT=-1;
curM=-1;
curTie=false;
Dodo();
}
}
return 0;
}