#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <iterator>
#include <functional>
#include <complex>
#include <queue>
#include <stack>
#include <cmath>
#include <cassert>
#include <cstring>
#ifdef __GNUC__
#include <ext/hash_map>
#define unordered_map __gnu_cxx::hash_map
#else
#include <unordered_map>
#endif
using namespace std;
typedef long long LL;
typedef complex<double> CMP;
class EllysJuice { public:
vector <string> getWinners(vector <string> players)
{
set<string> winners;
sort(players.begin(), players.end());
do
winners.insert( play(players) );
while( next_permutation(players.begin(), players.end()) );
winners.erase("");
return vector<string>(winners.begin(), winners.end());
}
string play(const vector<string>& p)
{
int juice[2] = {65536, 65536};
map<string, int> total;
for(int i=0; i<p.size(); ++i)
total[p[i]] += (juice[i%2]/=2);
string best_name;
int best = 0;
bool tie = false;
for(map<string, int>::iterator it=total.begin(); it!=total.end(); ++it)
if( it->second > best ) {
best_name = it->first;
best = it->second;
tie = false;
}
else if( it->second == best )
tie = true;
return tie ? "" : best_name;
}
};
// BEGIN CUT HERE
#include <ctime>
double start_time; string timer()
{ ostringstream os; os << " (" << int((clock()-start_time)/CLOCKS_PER_SEC*1000) << " msec)"; return os.str(); }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v)
{ os << "{ ";
for(typename vector<T>::const_iterator it=v.begin(); it!=v.end(); ++it)
os << '\"' << *it << '\"' << (it+1==v.end() ? "" : ", "); os << " }"; return os; }
void verify_case(const vector <string>& Expected, const vector <string>& Received) {
bool ok = (Expected == Received);
if(ok) cerr << "PASSED" << timer() << endl; else { cerr << "FAILED" << timer() << endl;
cerr << "\to: " << Expected << endl << "\tx: " << Received << endl; } }
#define CASE(N) {cerr << "Test Case #" << N << "..." << flush; start_time=clock();
#define END verify_case(_, EllysJuice().getWinners(players));}
int main(){
CASE(0)
string players_[] = { "elly", "kriss", "stancho", "elly", "stancho" };
vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_));
string __[] = {"elly", "stancho" };
vector <string> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(1)
string players_[] = {"torb", "elly", "stancho", "kriss"};
vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_));
vector <string> _;
END
CASE(2)
string players_[] = {"elly", "elly", "elly", "elly", "elly"};
vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_));
string __[] = {"elly" };
vector <string> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(3)
string players_[] = { "ariadne", "elly", "ariadne", "stancho", "stancho", "kriss", "stancho", "elly" };
vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_));
string __[] = {"ariadne", "elly", "stancho" };
vector <string> _(__, __+sizeof(__)/sizeof(*__));
END
CASE(4)
string players_[] = {"b","b","a","a"};
vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_));
string __[] = {"a","b"};
vector <string> _(__, __+sizeof(__)/sizeof(*__));
END
/*
CASE(5)
string players_[] = ;
vector <string> players(players_, players_+sizeof(players_)/sizeof(*players_));
string __[] = ;
vector <string> _(__, __+sizeof(__)/sizeof(*__));
END
*/
}
// END CUT HERE