// we have defined the necessary header files here for this problem.
// If additional header files are needed in your program, please import here.
#include<iostream>
#include<string>
#include<unordered_map>
#include<vector>
#include<algorithm>
using namespace std;
unordered_map<string,int>memo1;
unordered_map<string,int>memo2;
unordered_map<string,int>all;
int times=0;
void dfs(string s,int j){
s.push_back(' ');
int flag=0;
for(int i=0;i<s.size();i++){
if(s[i]==' '){
times++;
string t=s.substr(flag,i-flag);
if(memo1[t]+memo2[t]==0)all[t]=times;
if(j==0) memo1[t]+=3;
else memo2[t]+=1;
flag=i+1;
}
}
}
int main()
{
// please define the C++ input here. For example: int a,b; cin>>a>>b;;
// please finish the function body here.
// please define the C++ output here. For example:cout<<____<<endl;
int n,m;
cin>>n>>m;
vector<string>strs;
for(int i=0;i<m;i++){
for(int j=0;j<2;j++){
cin.sync();
string s;
getline(cin,s);
dfs(s,j);
}
}
for(auto i:memo1){
strs.push_back(i.first);
}
sort(strs.begin(),strs.end(),[&](const string&l,const string &r ){
if(memo1[l]+memo2[l]==memo1[r]+memo2[r]){
if(memo1[l]==memo1[r]){
if(memo2[l]==memo2[r]){
return all[l]<all[r];
}
return memo2[l]>memo2[r];
}
else return memo1[l]>memo1[r];
}
else return memo1[l]+memo2[l]>memo1[r]+memo2[r];
});
for(int i=0;i<n;i++){
cout<<strs[i]<<" ";
}
return 0;
}
#华为#