Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the League of Leesins World Championship comes to an end!

The tournament consisted of nn (n≥5n≥5) teams around the world. Before the tournament starts, Bob has made a prediction of the rankings of each team, from 11-st to nn-th. After the final, he compared the prediction with the actual result and found out that the ii-th team according to his prediction ended up at the pipi-th position (1≤pi≤n1≤pi≤n, all pipi are unique). In other words, pp is a permutation of 1,2,…,n1,2,…,n.

As Bob's favorite League player is the famous "3ga", he decided to write down every 33 consecutive elements of the permutation pp. Formally, Bob created an array qq of n−2n−2 triples, where qi=(pi,pi+1,pi+2)qi=(pi,pi+1,pi+2) for each 1≤i≤n−21≤i≤n−2. Bob was very proud of his array, so he showed it to his friend Alice.

After learning of Bob's array, Alice declared that she could retrieve the permutation pp even if Bob rearranges the elements of qq and the elements within each triple. Of course, Bob did not believe in such magic, so he did just the same as above to see Alice's respond.

For example, if n=5n=5 and p=[1,4,2,3,5]p=[1,4,2,3,5], then the original array qq will be [(1,4,2),(4,2,3),(2,3,5)][(1,4,2),(4,2,3),(2,3,5)]. Bob can then rearrange the numbers within each triple and the positions of the triples to get [(4,3,2),(2,3,5),(4,1,2)][(4,3,2),(2,3,5),(4,1,2)]. Note that [(1,4,2),(4,2,2),(3,3,5)][(1,4,2),(4,2,2),(3,3,5)] is not a valid rearrangement of qq, as Bob is not allowed to swap numbers belong to different triples.

As Alice's friend, you know for sure that Alice was just trying to show off, so you decided to save her some face by giving her any permutation pp that is consistent with the array qq she was given.

Input

The first line contains a single integer nn (5≤n≤1055≤n≤105) — the size of permutation pp.

The ii-th of the next n−2n−2 lines contains 33 integers qi,1qi,1, qi,2qi,2, qi,3qi,3 (1≤qi,j≤n1≤qi,j≤n) — the elements of the ii-th triple of the rearranged (shuffled) array qiqi, in random order. Remember, that the numbers within each triple can be rearranged and also the positions of the triples can be rearranged.

It is guaranteed that there is at least one permutation pp that is consistent with the input.

Output

Print nn distinct integers p1,p2,…,pnp1,p2,…,pn (1≤pi≤n1≤pi≤n) such that pp is consistent with array qq.

If there are multiple answers, print any.

Example

Input

5
4 3 2
2 3 5
4 1 2

Output

1 4 2 3 5 

这个题,出现次数最少的在两边,确定了第一个为出现次数 1 2 3的那一组,然后根据那一组暴力即可,用STL优化了一下,不然会超时。

#include<bits/stdc++.h>
using namespace std;
int a[100000],b[100000],c[100000],vis[1000000],n;
vector<int> v[1000000];
int main()
{
cin>>n;
for(int i=0;i<n-2;++i)
{
cin>>a[i]>>b[i]>>c[i];
v[a[i]-1].push_back(i);
v[b[i]-1].push_back(i);
v[c[i]-1].push_back(i);
vis[a[i]-1]=1;
vis[b[i]-1]=1;
vis[c[i]-1]=1;
}
int x=0;
for(;v[x].size()!=1;++x);
vis[x]=0;
cout<<x+1<<" ";
int y,z;
if(v[a[v[x][0]]-1].size()==2)
{
y=a[v[x][0]]-1;
vis[y]=0;
}
else if(v[a[v[x][0]]-1].size()==3)
{
z=a[v[x][0]]-1;
vis[z]=0;
}
if(v[b[v[x][0]]-1].size()==2)
{
y=b[v[x][0]]-1;
vis[y]=0;
}
else if(v[b[v[x][0]]-1].size()==3)
{
z=b[v[x][0]]-1;
vis[z]=0; }
if(v[c[v[x][0]]-1].size()==2)
{
y=c[v[x][0]]-1;
vis[y]=0;
}
else if(v[c[v[x][0]]-1].size()==3)
{
z=c[v[x][0]]-1;
vis[z]=0;
}
cout<<y+1<<" "<<z+1<<" ";
int h=z;
int cnt=3;
while(cnt++<n)
{
for(int i=0;i<v[h].size();++i)
{ if(vis[a[v[h][i]]-1]+vis[b[v[h][i]]-1]+vis[c[v[h][i]]-1]==1)
{
if(vis[a[v[h][i]]-1]==1){
cout<<a[v[h][i]]<<" ";
vis[a[v[h][i]]-1]=0;
h=a[v[h][i]]-1;
}
else if(vis[b[v[h][i]]-1]==1){
cout<<b[v[h][i]]<<" ";
vis[b[v[h][i]]-1]=0;
h=b[v[h][i]]-1;
}
else if(vis[c[v[h][i]]-1]==1){
cout<<c[v[h][i]]<<" ";
vis[c[v[h][i]]-1]=0;
h=c[v[h][i]]-1;
}
break;
}
}
}
}

最新文章

  1. 小白死去活来的安装ros_qtc_plugin
  2. FingerGestures 屏蔽NGUI的方法
  3. c中动态使用数组
  4. 【linux】cut
  5. 1 storm基本概念 + storm编程规范及demo编写
  6. xcode设置项目图标玻璃镜效果
  7. c++Socket 异步通讯
  8. ubuntu rc.local 无效 解决方案(转)
  9. css版hover现边框
  10. 编写高质量JavaScript代码绳之以法(The Essentials of Writing High Quality JavaScript)翻译
  11. 学习mysql语法--基础篇(一)
  12. Github:修改Github仓库中项目语言类型
  13. 在DOS命令中输入ipconfig /all,出现“该命令不是系统内部命令......”
  14. 团队项目:Recycle
  15. [ipsec][crypto] 什么是AEAD加密算法中的AAD 及aad length
  16. 【EF6学习笔记】(六)创建复杂的数据模型
  17. python爬虫解析库学习
  18. spring boot 配置注入
  19. 数据库---mysql的介绍和安装
  20. [leetcode]Remove Duplicates from Sorted List @ Python

热门文章

  1. docker-compose错误
  2. Java第十三天,内部类
  3. 30.3 Collections 集合体系的工具类
  4. loadrunner vuser 限制修改
  5. Jmeter连接mysql数据库?so easy!!!
  6. 泛型方法或泛型类中的方法是内部调用、PInvoke 或是在 COM 导入类中定义的。
  7. C. Primes and Multiplication
  8. 初探Redis-基础类型String
  9. python-Django与Nginx整合gunicorn模块
  10. 解决centos ping不通外网