# 喵喵的Logo

``````4
3 5 2 1
3 12 5 2
2 1 2
3 2 1 5
2
3 3 2 1
3 2 3 1
0
``````

``````2
2 3
``````

``````#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

int n,num,x;
ll base[]={1,1000,1000000,1000000000};

int main() {
// freopen("in.txt","r",stdin);
while (~scanf("%d",&n)&&n){
map<int,ll> mp;
vector<pair<int,ll> > ans;
map<int,ll>::iterator it;
for (int i=1;i<=n;i++) {
scanf("%d",&num);
for (int j=1;j<=num;j++) {
scanf("%d",&x);
mp[x]+=base[3]*(4-j);
mp[x]+=base[3-j];
}
}
for (it=mp.begin();it!=mp.end();++it) {
if (ans.empty()) ans.push_back(*it);
else {
if (it->second == ans[0].second) ans.push_back(*it);
else if(it->second > ans[0].second) {
ans.clear();
ans.push_back(*it);
}
}
}
printf("%d",ans[0].first);
for (int i=1;i<ans.size();i++)
printf(" %d",ans[i].first);
printf("\n");
}
return 0;
}
``````

``````#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define rep(i,a,b) for(int i=a;i<=b;i++)
int n,num,x;
ll base[]={1,1000,100000,100000000};

int main() {
int n;
while(scanf("%d",&n)!=EOF,n)
{
map<int ,ll > ma;
vector < pair<int ,ll> >ve;
rep(i,1,n)
{
int x;int val;
scanf("%d",&x);
rep(j,1,x){
scanf("%d",&val);
ma[val]+=base[3]*(4-j);
ma[val]+=base[3-j];
}
}
for(auto it=ma.begin();it!=ma.end();it++){
if(ve.empty())   ve.push_back(*it);
else{
if(it->second==ve.begin()->second)
ve.push_back(*it);
else if(it->second>ve[0].second)
{
ve.clear();ve.push_back(*it);
}
}
}
for(auto it=ve.begin();it!=ve.end();it++)
printf("%d ",it->first);
printf("\n");
}
return 0;
}
``````