//
//  Created by Ruslan Jankurazov.
//  Copyright © 2018 Ruslan Jankurazov. All rights reserved.
//

#pragma GCC optimize("Ofast")

#include "bits/stdc++.h"

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define f first
#define s second
#define uint unsigned int

using namespace std;

int q[2000];
int w[2000];
int d[2000];

int main() {
#define FILE_INPUT 0
#define FILE ""
#ifndef DEBUG
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
#if FILE_INPUT == 1
#warning "FREOPEN is on"
    freopen(FILE".in", "r", stdin);
    freopen(FILE".out", "w", stdout);
#endif
#endif
    int a, b, c;
    cin >> a >> b >> c;
    vector <int> v;
    for (int i = 1; i <= a; ++i) {
        cin >> q[i];
        v.pb(q[i]);
    }
    for (int i = 1; i <= b; ++i) {
        cin >> w[i];
        v.pb(w[i]);
    }
    for (int i = 1; i <= c; ++i) {
        cin >> d[i];
        v.pb(d[i]);
    }
    sort(q + 1, q + a + 1);
    sort(w + 1, w + b + 1);
    sort(d + 1, d + c + 1);
    ll ans = 0;
    for (auto i:v) {
        ll cnt1 = 0;
        for (int j = 1; j <= a; ++j) {
            if (q[j] >= i && q[j] <= i*2) {
                cnt1++;
            }
        }

        ll cnt2 = 0;
        for (int j = 1; j <= b; ++j) {
            if (w[j] >= i && w[j] <= i*2) {
                cnt2++;
            }
        }

        ll cnt3 = 0;
        for (int j = 1; j <= c; ++j) {
            if (d[j] >= i && d[j] <= i*2) {
                cnt3++;
            }
        }

        ans += cnt1 * (cnt2*(cnt2 - 1)/2) * (cnt3*(cnt3 - 1)*(cnt3 - 2)/6);
    }
    cout << ans;
    return 0;
}


#include <iostream>
#include <string>
#include <vector>
using namespace std;

int calc(vector<int> &v, int x)
{
	int s = 0;
	for (int y : v)
		if (x < y && y <= 2*x)
			s++;
	return s;
}

long long comb2(int x)
{
	return x * (x - 1) / 2;
}

long long comb3(int x)
{
	return x * (x - 1) * (x - 2) / 6;
}

int main()
{
	ios_base::sync_with_stdio(false);

	int a, b, c;
	cin >> a >> b >> c;

	vector<int> A(a);
	for (int &x : A)
		cin >> x;
	vector<int> B(b);
	for (int &x : B)
		cin >> x;
	vector<int> C(c);
	for (int &x : C)
		cin >> x;

	long long ans = 0;
	for (int x : A)
		ans += comb2(calc(B, x)) * comb3(calc(C, x));
	for (int x : B)
		ans += calc(A, x) * calc(B, x) * comb3(calc(C, x));
	for (int x : C)
		ans += calc(A, x) * comb2(calc(B, x)) * comb2(calc(C, x));
	cout << ans;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> la, lb, lc;
int ans = 0;

int c2(int n) {
    return n * (n - 1) / 2;
}

int c3(int n) {
    return n * (n - 1) * (n - 2) / 6;
}

int c(int n, int k) {
    if (k == 0) {
        return 1;
    } else if (k == 1) {
        return n;
    } else if (k == 2) {
        return c2(n);
    } else if (k == 3) {
        return c3(n);
    }
    return 100;
}

int len_for_mn(const vector<int> &l, int mn, int mx) {
    long umn = upper_bound(l.begin(), l.end(), mn * 2) - l.begin();
    long umx = upper_bound(l.begin(), l.end(), mx) - l.begin();
    long lmn = lower_bound(l.begin(), l.end(), mn) - l.begin();
    return (int) std::max(
            std::min(
                    umn,
                    umx
            ) - lmn,
            0l
    );
}

void calc(int mn, int mx, int fmn, int fmx) {
    int occ[] = {1, 2, 3};
    occ[fmn - 1] -= 1;
    occ[fmx - 1] -= 1;

    if (mn * 2 < mx) {
        return;
    }
    if (mx <= mn) {
        return;
    }

    ans +=
            c(len_for_mn(la, mn, mx) - (1 - occ[0]), occ[0]) *
            c(len_for_mn(lb, mn, mx) - (2 - occ[1]), occ[1]) *
            c(len_for_mn(lc, mn, mx) - (3 - occ[2]), occ[2]);
}

void for_min(int mn, int f) {
    if (f != 1) {
        for (int mx : la) {
            calc(mn, mx, f, 1);
        }
    }
    for (int mx : lb) {
        calc(mn, mx, f, 2);
    }
    for (int mx : lc) {
        calc(mn, mx, f, 3);
    }
}

int main() {
    ios::sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;
    la.resize(a);
    lb.resize(b);
    lc.resize(c);
    for (int i = 0; i < a; i++) {
        cin >> la[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> lb[i];
    }
    for (int i = 0; i < c; i++) {
        cin >> lc[i];
    }
    sort(la.begin(), la.end());
    sort(lb.begin(), lb.end());
    sort(lc.begin(), lc.end());

    for (int mn : la) {
        for_min(mn, 1);
    }
    for (int mn : lb) {
        for_min(mn, 2);
    }
    for (int mn : lc) {
        for_min(mn, 3);
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>

using namespace std;

vector<unsigned long long> la, lb, lc;
unsigned long long ans = 0;

unsigned long long c2(unsigned long long n) {
    return n * (n - 1) / 2;
}

unsigned long long c3(unsigned long long n) {
    return n * (n - 1) * (n - 2) / 6;
}

unsigned long long c(unsigned long long n, unsigned long long k) {
    if (k == 0) {
        return 1;
    } else if (k == 1) {
        return n;
    } else if (k == 2) {
        return c2(n);
    } else if (k == 3) {
        return c3(n);
    }
    return 100;
}

unsigned long long len_for_mn(const vector<unsigned long long> &l, unsigned long long mn, unsigned long long mx) {
    long umn = upper_bound(l.begin(), l.end(), mn * 2) - l.begin();
    long umx = upper_bound(l.begin(), l.end(), mx) - l.begin();
    long lmn = lower_bound(l.begin(), l.end(), mn) - l.begin();
    return (unsigned long long) std::max(
            std::min(
                    umn,
                    umx
            ) - lmn,
            0l
    );
}

void calc(unsigned long long mn, unsigned long long mx, unsigned long long fmn, unsigned long long fmx) {
    unsigned long long occ[] = {1, 2, 3};
    occ[fmn - 1] -= 1;
    occ[fmx - 1] -= 1;

    if (mn * 2 < mx) {
        return;
    }
    if (mx <= mn) {
        return;
    }

    ans +=
            c(len_for_mn(la, mn, mx) - (1 - occ[0]), occ[0]) *
            c(len_for_mn(lb, mn, mx) - (2 - occ[1]), occ[1]) *
            c(len_for_mn(lc, mn, mx) - (3 - occ[2]), occ[2]);
}

void for_min(unsigned long long mn, unsigned long long f) {
    if (f != 1) {
        for (unsigned long long mx : la) {
            calc(mn, mx, f, 1);
        }
    }
    for (unsigned long long mx : lb) {
        calc(mn, mx, f, 2);
    }
    for (unsigned long long mx : lc) {
        calc(mn, mx, f, 3);
    }
}

int main() {
    ios::sync_with_stdio(false);

    unsigned long long a, b, c;
    cin >> a >> b >> c;
    la.resize(a);
    lb.resize(b);
    lc.resize(c);
    for (unsigned long long i = 0; i < a; i++) {
        cin >> la[i];
    }
    for (unsigned long long i = 0; i < b; i++) {
        cin >> lb[i];
    }
    for (unsigned long long i = 0; i < c; i++) {
        cin >> lc[i];
    }
    sort(la.begin(), la.end());
    sort(lb.begin(), lb.end());
    sort(lc.begin(), lc.end());

    for (unsigned long long mn : la) {
        for_min(mn, 1);
    }
    for (unsigned long long mn : lb) {
        for_min(mn, 2);
    }
    for (unsigned long long mn : lc) {
        for_min(mn, 3);
    }

    cout << ans;

    return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iomanip>
#include <deque>

using namespace std;

int main() {
    int g, d, f;
    cin >> g >> d >> f;
    vector <int> gk(g), def(d), forw(f);

    for (int i = 0; i < g; i++) {
        cin >> gk[i];
    }

    for (int i = 0; i < d; i++) {
        cin >> def[i];
    }

    for (int i = 0; i < f; i++) {
        cin >> forw[i];
    }

    sort(gk.begin(), gk.end());
    sort(def.begin(), def.end());
    sort(forw.begin(), forw.end());

    long long ans = 0;

    for (int i = 0; i < g; i++) {
        for (int j = 0; j < d - 1; j++) {
            if (gk[i] > 2 * def[j]) {
                continue;
            }
            for (int k = 0; k < f - 2; k++) {
                if (gk[i] > 2 * forw[k]) {
                    continue;
                }
                int min_num = min(min(gk[i], def[j]), forw[k]);
                int num_def = upper_bound(def.begin() + j, def.end(), min_num * 2) - (def.begin() + j + 1);
                int num_forw = upper_bound(forw.begin() + k, forw.end(), min_num * 2) - (forw.begin() + k + 1);
                if (num_def && num_forw > 1) {
                    ans += 1ll * num_def * num_forw * 1ll * (num_forw - 1) / 2;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iomanip>
#include <deque>

using namespace std;

int main() {
    int g, d, f;
    cin >> g >> d >> f;
    vector <int> gk(g), def(d), forw(f);

    for (int i = 0; i < g; i++) {
        cin >> gk[i];
    }

    for (int i = 0; i < d; i++) {
        cin >> def[i];
    }

    for (int i = 0; i < f; i++) {
        cin >> forw[i];
    }

    sort(gk.begin(), gk.end());
    sort(def.begin(), def.end());
    sort(forw.begin(), forw.end());

    long long ans = 0;

    for (int i = 0; i < g; i++) {
        for (int j = 0; j < d - 1; j++) {
            if (gk[i] > 2 * def[j]) {
                break;
            }
            for (int k = 0; k < f - 2; k++) {
                if (gk[i] > 2 * forw[k]) {
                    break;
                }
                int min_num = min(min(gk[i], def[j]), forw[k]);
                int num_def = upper_bound(def.begin() + j, def.end(), min_num * 2) - (def.begin() + j + 1);
                int num_forw = upper_bound(forw.begin() + k, forw.end(), min_num * 2) - (forw.begin() + k + 1);
                if (num_def && num_forw > 1) {
                    ans += 1ll * num_def * num_forw * (num_forw - 1) / 2;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iomanip>
#include <deque>
using namespace std;

int gk[1007], def[1007], forw[1007], players_new[1007];
pair<int, int> players[1007];

long long C(int n, int k) {
    if (k == 0) {
        return 0;
    }
    if (k == 1) {
        return n;
    }
    if (k == 2) {
        return n * (n - 1) / 2;
    }
    return 1ll * n * (n - 1) * (n - 2) / 6;
}

int main() {
    int g, d, f;
    cin >> g >> d >> f;
    int n = g + d + f;
    int ind = 0;

    for (int i = 0; i < g; i++) {
        int x;
        cin >> x;
        players[ind] = {x, 1};
        players_new[ind] = x;
        ind++;
    }

    for (int i = 0; i < d; i++) {
        int x;
        cin >> x;
        players[ind] = {x, 2};
        players_new[ind] = x;
        ind++;
    }

    for (int i = 0; i < f; i++) {
        int x;
        cin >> x;
        players[ind] = {x, 3};
        players_new[ind] = x;
        ind++;
    }

    sort(players, players + n);
    sort(players_new, players_new + n);

    if (players[0].second == 1) {
        gk[0] = 1;
    }

    if (players[0].second == 2) {
        def[0] = 1;
    }

    if (players[0].second == 3) {
        forw[0] = 1;
    }

    for (int i = 1; i < n; i++) {

        gk[i] = gk[i - 1] + (players[i].second == 1);
        def[i] = def[i - 1] + (players[i].second == 2);
        forw[i] = forw[i - 1] + (players[i].second == 3);

    }

    long long ans = 0;

    for (int i = 0; i < n; i++) {
        int last_pos = (upper_bound(players_new + i, players_new + n, players[i].first * 2) - (players_new + 1));
        int keepers = 0, defenders = 0, forwards = 0;

        int cnt2 = 2, cnt3 = 3;

        if (last_pos) {
            keepers = gk[last_pos] - gk[i];
        }
        if (last_pos) {
            defenders = def[last_pos] - def[i];
        }
        if (last_pos) {
            forwards = forw[last_pos] - forw[i];
        }

        if (players[i].second == 1) {
            keepers = 1;
        }
        if (players[i].second == 2) {
            cnt2--;
        }
        if (players[i].second == 3) {
            cnt3--;
        }

        ans += 1ll * C(keepers, 1) * C(defenders, cnt2) * C(forwards, cnt3);

    }

    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <iomanip>
#include <deque>

using namespace std;

int main() {
    int g, d, f;
    cin >> g >> d >> f;
    vector <int> gk(g), def(d), forw(f);

    for (int i = 0; i < g; i++) {
        cin >> gk[i];
    }

    for (int i = 0; i < d; i++) {
        cin >> def[i];
    }

    for (int i = 0; i < f; i++) {
        cin >> forw[i];
    }

    sort(gk.begin(), gk.end());
    sort(def.begin(), def.end());
    sort(forw.begin(), forw.end());

    long long ans = 0;

    for (int i = 0; i < g; i++) {
        for (int j = 0; j < d - 1; j++) {
            if (gk[i] > 2 * def[j]) {
                continue;
            }
            for (int k = 0; k < f - 2; k++) {
                if (gk[i] > 2 * forw[k] || def[j] > 2 * forw[k]) {
                    continue;
                }
                int min_num = min(min(gk[i], def[j]), forw[k]);
                int num_def = upper_bound(def.begin() + j, def.end(), min_num * 2) - (def.begin() + j + 1);
                int num_forw = upper_bound(forw.begin() + k, forw.end(), min_num * 2) - (forw.begin() + k + 1);
                if (num_def && num_forw > 1) {
                    ans += 1ll * num_def * num_forw * (num_forw - 1) / 2;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int fact(int x) {
  if(x==0) return 1;
  else if(x==1) return 1;
  else return x*fact(x-1);
}

int main()
{
    map<int,int> task;
    int g,d,f;
    cin >> g >> d >> f;
    int x;
    for(int i = 0; i < g; i++)
    {
        cin >> x;
        task.insert(pair<int,int>(x,1));
    }
    for(int i = 0; i < d; i++)
    {
        cin >> x;
        task.insert(pair<int,int>(x,2));
    }
    for(int i = 0; i < f; i++)
    {
        cin >> x;
        task.insert(pair<int,int>(x,3));
    }
    std::map<int,int>::iterator s_it = task.begin();
    int cG=0;
    int cD=0;
    int cF=0;
    int s_cG =0;
    int s_cD = 0;
    int s_cF = 0;
    int res = 0;
    for (std::map<int,int>::iterator it=task.begin(); it!=task.end(); ++it)
    {

        if(2*s_it->first < it->first)
        {
            //считаем
            if(cG >=1 && cD >= 2 && cF >= 3)
            {
                res = res + fact(cG)/fact(cG-1)*fact(cD)/(2*fact(cD-2))*fact(cF)/(6*fact(cF-3));
                if(s_cG >=1 && s_cD >= 2 && s_cF >= 3)
                {
                    res = res - fact(s_cG)/fact(s_cG-1)*fact(s_cD)/(2*fact(s_cD-2))*fact(s_cF)/(6*fact(s_cF-3));
                }
            }
            if(s_it->second == 1) cG--;
            else if(s_it->second == 2) cD--;
            else if(s_it->second == 3) cF--;
            s_it++;
            s_cG = cG;
            s_cD = cD;
            s_cF = cF;
            it--;
        }
        else
        {
            if(it->second == 1) cG++;
            else if(it->second == 2) cD++;
            else if(it->second == 3) cF++;
        }
    }
    if(cG >=1 && cD >= 2 && cF >= 3)
    {
        res = res + fact(cG)/fact(cG-1)*fact(cD)/(2*fact(cD-2))*fact(cF)/(6*fact(cF-3));
        if(s_cG >=1 && s_cD >= 2 && s_cF >= 3)
        {
            res = res - fact(s_cG)/fact(s_cG-1)*fact(s_cD)/(2*fact(s_cD-2))*fact(s_cF)/(6*fact(s_cF-3));
        }

    }
    cout << res;

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int main()
{
    map<int,int> task;
    int g,d,f;
    cin >> g >> d >> f;
    int x;
    for(int i = 0; i < g; i++)
    {
        cin >> x;
        task.insert(pair<int,int>(x,1));
    }
    for(int i = 0; i < d; i++)
    {
        cin >> x;
        task.insert(pair<int,int>(x,2));
    }
    for(int i = 0; i < f; i++)
    {
        cin >> x;
        task.insert(pair<int,int>(x,3));
    }
    std::map<int,int>::iterator s_it = task.begin();
    int cG=0;
    int cD=0;
    int cF=0;
    int s_cG =0;
    int s_cD = 0;
    int s_cF = 0;
    long long res = 0;
    for (std::map<int,int>::iterator it=task.begin(); it!=task.end(); ++it)
    {
        //cout << s_it->first <<" " << it->first << endl;
        //cout << cG << " " << cD<< " " << cF << endl;
        if(2*s_it->first < it->first)
        {
            //считаем
            if(cG >=1 && cD >= 2 && cF >= 3)
            {
                res = res + cG*cD*(cD-1)/2*cF*(cF-1)*(cF-2)/6;
                //cout << res << endl;
                if(s_cG >=1 && s_cD >= 2 && s_cF >= 3)
                {
                    res = res - s_cG*s_cD*(s_cD-1)/2*s_cF*(s_cF-1)*(s_cF-2)/6;
                   // cout << res << endl;
                }
            }
            if(s_it->second == 1) cG--;
            else if(s_it->second == 2) cD--;
            else if(s_it->second == 3) cF--;
            s_it++;
            s_cG = cG;
            s_cD = cD;
            s_cF = cF;
            it--;
        }
        else
        {
            if(it->second == 1) cG++;
            else if(it->second == 2) cD++;
            else if(it->second == 3) cF++;
        }
    }
   //cout << cG << " " << cD<< " " << cF << endl;
    if(cG >=1 && cD >= 2 && cF >= 3)
    {
        res = res + cG*cD*(cD-1)/2*cF*(cF-1)*(cF-2)/6;
        //cout << res << endl;
        if(s_cG >=1 && s_cD >= 2 && s_cF >= 3)
        {
            res = res - s_cG*s_cD*(s_cD-1)/2*s_cF*(s_cF-1)*(s_cF-2)/6;
            //cout << res << endl;
        }

    }

    cout << res;

	return 0;
}


#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

int main()
{
    map<int,int> task;
    int g,d,f;
    cin >> g >> d >> f;
    int x;
    for(int i = 0; i < g; i++)
    {
        cin >> x;
        task.insert(pair<int,int>(x,1));
    }
    for(int i = 0; i < d; i++)
    {
        cin >> x;
        task.insert(pair<int,int>(x,2));
    }
    for(int i = 0; i < f; i++)
    {
        cin >> x;
        task.insert(pair<int,int>(x,3));
    }
    std::map<int,int>::iterator s_it = task.begin();
    long long cG=0;
    long long cD=0;
    long long cF=0;
    long long s_cG =0;
    long long s_cD = 0;
    long long s_cF = 0;
    long long res = 0;
    for (std::map<int,int>::iterator it=task.begin(); it!=task.end(); ++it)
    {
        //cout << s_it->first <<" " << it->first << endl;
        //cout << cG << " " << cD<< " " << cF << endl;
        if(2*s_it->first < it->first)
        {
            //считаем
            if(cG >=1 && cD >= 2 && cF >= 3)
            {
                res = res + cG*cD*(cD-1)/2*cF*(cF-1)*(cF-2)/6;
                //cout << res << endl;
                if(s_cG >=1 && s_cD >= 2 && s_cF >= 3)
                {
                    res = res - s_cG*s_cD*(s_cD-1)/2*s_cF*(s_cF-1)*(s_cF-2)/6;
                   // cout << res << endl;
                }
            }
            if(s_it->second == 1) cG--;
            else if(s_it->second == 2) cD--;
            else if(s_it->second == 3) cF--;
            s_it++;
            s_cG = cG;
            s_cD = cD;
            s_cF = cF;
            it--;
        }
        else
        {
            if(it->second == 1) cG++;
            else if(it->second == 2) cD++;
            else if(it->second == 3) cF++;
        }
    }
   //cout << cG << " " << cD<< " " << cF << endl;
    if(cG >=1 && cD >= 2 && cF >= 3)
    {
        res = res + cG*cD*(cD-1)/2*cF*(cF-1)*(cF-2)/6;
        //cout << res << endl;
        if(s_cG >=1 && s_cD >= 2 && s_cF >= 3)
        {
            res = res - s_cG*s_cD*(s_cD-1)/2*s_cF*(s_cF-1)*(s_cF-2)/6;
            //cout << res << endl;
        }

    }

   cout << res;

	return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll fac(ll n,ll k)
{
    if (k==0) return 1;
    if (n==k) return 1;
    ll y;
    y=1;
    for(ll i=k+1;i<=n;i++)
        y=y*i;
    ll r;
    r=n-k;
    for(ll i=1;i<=r;i++)
        y=y/i;
    return y;
}
int main()
{
   // ifstream cin("input.txt");
   // ofstream cout("output.txt");
    ll x,y,z;
    cin>>x>>y>>z;
    pair<ll, ll> v[1003];
    for(ll i=0;i<x;i++)
    {
        cin>>v[i].F;
        v[i].S=1;
    }
    for(ll i=x;i<x+y;i++)
    {
        cin>>v[i].F;
        v[i].S=2;
    }
    for(ll i=x+y;i<x+y+z;i++)
    {
        cin>>v[i].F;
        v[i].S=3;
    }
    ll n;
    n=x+y+z;
    sort(v,v+n);///������ ���� �� �������
    vector <ll> q(n);
    for(ll i=0;i<n;i++)
    {
        ll na,za,vr;///���������� �������� ����������
        na=0; vr=0; za=0;
        ll k=i+1;
        ll a,s,d;
        a=1;
        s=2;
        d=3;
        if (v[i].S==1)
            a--;
        if (v[i].S==2)
            s--;
        if (v[i].S==3)
            d--;
        while(v[k].F<=v[i].F*2&&k<n)
        {
            if (v[k].S==1)
                vr++;
            if (v[k].S==2)
                za++;
            if (v[k].S==3)
                na++;
            k++;
        }
        if (vr>=a&&za>=s&&na>=d)///���� �� ������ ������� �������
        {
           q[i]=1;
           q[i]=q[i]*fac(vr,a)*fac(za,s)*fac(na,d);///���-�� ��������� �� �������� �� ���������� ��������� �������
        } else
        q[i]=0;
        if (k==n-1&&q[i]==0)
            break;
    }
    ll sum;
    sum=0;
    for(ll i=0;i<n;i++)
        sum+=q[i];
    cout<<sum<<"\n";
    return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll fac(ll n,ll k)
{
    if (k==0LL) return 1LL;
    if (n==k) return 1LL;
    ll y;
    y=1LL;
    for(ll i=k+1LL;i<=n;i++)
        y=y*i;
    ll r;
    r=n-k;
    for(ll i=1LL;i<=r;i++)
        y=y/i;
    return y;
}
int main()
{
   // ifstream cin("input.txt");
   // ofstream cout("output.txt");
    ll x,y,z;
    cin>>x>>y>>z;
    pair<ll, ll> v[3006];
    for(ll i=0;i<x;i++)
    {
        cin>>v[i].F;
        v[i].S=1LL;
    }
    for(ll i=x;i<x+y;i++)
    {
        cin>>v[i].F;
        v[i].S=2LL;
    }
    for(ll i=x+y;i<x+y+z;i++)
    {
        cin>>v[i].F;
        v[i].S=3LL;
    }
    ll n;
    n=x+y+z;
    sort(v,v+n);///������ ���� �� �������
    vector <ll> q(n);
    for(ll i=0;i<n;i++)
    {
        ll na,za,vr;///���������� �������� ����������
        na=0LL; vr=0LL; za=0LL;
        ll k=i+1LL;
        ll a,s,d;
        a=1LL;
        s=2LL;
        d=3LL;
        if (v[i].S==1LL)
            a--;
        if (v[i].S==2LL)
            s--;
        if (v[i].S==3LL)
            d--;
        while(v[k].F<=v[i].F*2LL&&k<n)
        {
            if (v[k].S==1LL)
                vr++;
            if (v[k].S==2LL)
                za++;
            if (v[k].S==3LL)
                na++;
            k++;
        }
        if (vr>=a&&za>=s&&na>=d)///���� �� ������ ������� �������
        {
           q[i]=1LL;
           q[i]=q[i]*fac(vr,a)*fac(za,s)*fac(na,d);///���-�� ��������� �� �������� �� ���������� ��������� �������
        } else
        q[i]=0LL;
        if (k==n-1LL&&q[i]==0LL)
            break;
    }
    ll sum;
    sum=0LL;
    for(ll i=0LL;i<n;i++)
        sum+=q[i];
    cout<<sum<<"\n";
    return 0;
}


#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll fac (ll n, ll k) {
	double res = 1;
	for (ll i=1; i<=k; ++i)
		res = res * (n-k+i) / i;
	return (ll) (res + 0.01);
}
/*int main()
{
    ifstream in("input.txt");
    ofstream out("output.txt");
    for(int i=0;i<100;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(C(i,j)!=fac(i,j))
                out<<i<<" "<<j<<"\n";
        }
    }
    return 0;
}*/
int main()
{
   // ifstream cin("input.txt");
   // ofstream cout("output.txt");
    ll x,y,z;
    cin>>x>>y>>z;
    pair<ll, ll> v[3006];
    for(ll i=0LL;i<x;i++)
    {
        cin>>v[i].F;
        v[i].S=1LL;
    }
    for(ll i=x;i<x+y;i++)
    {
        cin>>v[i].F;
        v[i].S=2LL;
    }
    for(ll i=x+y;i<x+y+z;i++)
    {
        cin>>v[i].F;
        v[i].S=3LL;
    }
    ll n;
    n=x+y+z;
    sort(v,v+n);///сортим всех по номерам
    vector <ll> q(n);
    for(ll i=0LL;i<n;i++)
    {
        ll na,za,vr;///нападающих вратарей защитников
        na=0LL; vr=0LL; za=0LL;
        ll k=i+1LL;
        ll a,s,d;
        a=1LL;
        s=2LL;
        d=3LL;
        if (v[i].S==1LL)
            a--;
        if (v[i].S==2LL)
            s--;
        if (v[i].S==3LL)
            d--;
        while(v[k].F<=v[i].F*2LL&&k<n)
        {
            if (v[k].S==1LL)
                vr++;
            if (v[k].S==2LL)
                za++;
            if (v[k].S==3LL)
                na++;
            k++;
        }
        if (vr>=a&&za>=s&&na>=d)///если мы смогли набрать команду
        {
           q[i]=1LL;
           q[i]=q[i]*fac(vr,a)*fac(za,s)*fac(na,d);///кол-во сочетаний из вратарей по количеству свободных ампулуа
        } else
        q[i]=0LL;
        if (k==n-1LL&&q[i]==0LL)
            break;
    }
    ll sum;
    sum=0LL;
    for(ll i=0LL;i<n;i++)
        sum+=q[i];
    cout<<sum<<"\n";
    return 0;
}


#include <iostream>
#include <vector>
#include <string>
#include <list>
#include <algorithm>
#define F first
#define S second
using namespace std;
typedef long long ll;
ll fac(ll n,ll k)
{
    if (k==0) return 1;
    if (n==k) return 1;
    ll y;
    y=1;
    for(ll i=k+1;i<=n;i++)
        y=y*i;
    ll r;
    r=n-k;
    for(ll i=1;i<=r;i++)
        y=y/i;
    return y;
}
int main()
{
   // ifstream cin("input.txt");
   // ofstream cout("output.txt");
    ll x,y,z;
    cin>>x>>y>>z;
    pair<ll, ll> v[3006];
    for(ll i=0;i<x;i++)
    {
        cin>>v[i].F;
        v[i].S=1;
    }
    for(ll i=x;i<x+y;i++)
    {
        cin>>v[i].F;
        v[i].S=2;
    }
    for(ll i=x+y;i<x+y+z;i++)
    {
        cin>>v[i].F;
        v[i].S=3;
    }
    ll n;
    n=x+y+z;
    sort(v,v+n);///������ ���� �� �������
    vector <ll> q(n);
    for(ll i=0;i<n;i++)
    {
        ll na,za,vr;///���������� �������� ����������
        na=0; vr=0; za=0;
        ll k=i+1;
        ll a,s,d;
        a=1;
        s=2;
        d=3;
        if (v[i].S==1)
            a--;
        if (v[i].S==2)
            s--;
        if (v[i].S==3)
            d--;
        while(v[k].F<=v[i].F*2&&k<n)
        {
            if (v[k].S==1)
                vr++;
            if (v[k].S==2)
                za++;
            if (v[k].S==3)
                na++;
            k++;
        }
        if (vr>=a&&za>=s&&na>=d)///���� �� ������ ������� �������
        {
           q[i]=1;
           q[i]=q[i]*fac(vr,a)*fac(za,s)*fac(na,d);///���-�� ��������� �� �������� �� ���������� ��������� �������
        } else
        q[i]=0;
        if (k==n-1&&q[i]==0)
            break;
    }
    ll sum;
    sum=0;
    for(ll i=0;i<n;i++)
        sum+=q[i];
    cout<<sum<<"\n";
    return 0;
}


#include<cstdio>
#include<algorithm>
using namespace std;

int a[1005],b[1005],c[1005];
typedef long long LL;
LL ans;
int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=m;i++) scanf("%d",&b[i]);
	for(int i=1;i<=k;i++) scanf("%d",&c[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	sort(c+1,c+k+1);
	for(int i=1;i<=n;i++)
	{
		int x=a[i];
		LL cnt=1;
		int l=lower_bound(b+1,b+m+1,x)-b,r=upper_bound(b+1,b+m+1,x*2)-b;
		cnt=cnt*((r-l)*(r-l-1)/2);
		l=lower_bound(c+1,c+k+1,x)-c,r=upper_bound(c+1,c+k+1,x*2)-c;
		cnt=cnt*((r-l)*(r-l-1)*(r-l-2)/6);
		ans=ans+cnt;
	}
	for(int i=1;i<=m;i++)
	{
		int x=b[i];
		LL cnt=1;
		int l=lower_bound(a+1,a+n+1,x)-a,r=upper_bound(a+1,a+n+1,x*2)-a;
		cnt=cnt*(r-l);
		l=upper_bound(b+1,b+m+1,x)-b,r=upper_bound(b+1,b+m+1,x*2)-b;
		cnt=cnt*(r-l);
		l=lower_bound(c+1,c+k+1,x)-c,r=upper_bound(c+1,c+k+1,x*2)-c;
		cnt=cnt*((r-l)*(r-l-1)*(r-l-2)/6);
		ans=(ans+cnt);
	}
	for(int i=1;i<=k;i++)
	{
		int x=c[i];
		LL cnt=1;
		int l=lower_bound(a+1,a+n+1,x)-a,r=upper_bound(a+1,a+n+1,x*2)-a;
		cnt=cnt*(r-l);
		l=lower_bound(b+1,b+m+1,x)-b,r=upper_bound(b+1,b+m+1,x*2)-b;
		cnt=cnt*((r-l)*(r-l-1)/2);
		l=upper_bound(c+1,c+k+1,x)-c,r=upper_bound(c+1,c+k+1,x*2)-c;
		cnt=cnt*((r-l)*(r-l-1)/2);
		ans=(ans+cnt);
	}
	printf("%lld",ans);
}


#include<cstdio>
#include<algorithm>
using namespace std;

int a[1005],b[1005],c[1005];
typedef long long LL;
LL mo=1e9+7;
LL ans;
int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	for(int i=1;i<=m;i++) scanf("%d",&b[i]);
	for(int i=1;i<=k;i++) scanf("%d",&c[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	sort(c+1,c+k+1);
	for(int i=1;i<=n;i++)
	{
		int x=a[i];
		LL cnt=1;
		int l=lower_bound(b+1,b+m+1,x)-b,r=upper_bound(b+1,b+m+1,x*2)-b;
		cnt=cnt*((r-l)*(r-l-1)/2)%mo;
		l=lower_bound(c+1,c+k+1,x)-c,r=upper_bound(c+1,c+k+1,x*2)-c;
		cnt=cnt*((r-l)*(r-l-1)*(r-l-2)/6)%mo;
		ans=ans+cnt;
	}
	for(int i=1;i<=m;i++)
	{
		int x=b[i];
		LL cnt=1;
		int l=lower_bound(a+1,a+n+1,x)-a,r=upper_bound(a+1,a+n+1,x*2)-a;
		cnt=cnt*(r-l)%mo;
		l=upper_bound(b+1,b+m+1,x)-b,r=upper_bound(b+1,b+m+1,x*2)-b;
		cnt=cnt*(r-l)%mo;
		l=lower_bound(c+1,c+k+1,x)-c,r=upper_bound(c+1,c+k+1,x*2)-c;
		cnt=cnt*((r-l)*(r-l-1)*(r-l-2)/6)%mo;
		ans=(ans+cnt);
	}
	for(int i=1;i<=k;i++)
	{
		int x=c[i];
		LL cnt=1;
		int l=lower_bound(a+1,a+n+1,x)-a,r=upper_bound(a+1,a+n+1,x*2)-a;
		cnt=cnt*(r-l)%mo;
		l=lower_bound(b+1,b+m+1,x)-b,r=upper_bound(b+1,b+m+1,x*2)-b;
		cnt=cnt*((r-l)*(r-l-1)/2)%mo;
		l=upper_bound(c+1,c+k+1,x)-c,r=upper_bound(c+1,c+k+1,x*2)-c;
		cnt=cnt*((r-l)*(r-l-1)/2)%mo;
		ans=(ans+cnt)%mo;
	}
	printf("%lld",ans);
}


#include<bits/stdc++.h>
using namespace std;
int n;
const int maxn=1e5+5;
int a[maxn][3];
int cnt[maxn];
bool use[maxn];
#define pr pair<int,int>
#define mk(a,b) make_pair(a,b)
multimap<pr,int>mp,tp;
map<pr,bool>exist;
vector<int>ans;
void getans(int id){
    for(int k=0;k<3;k++)ans.push_back(a[id][k]);
}
void srh(int u,int v,int deep){
    if(u>v)swap(u,v);
    while((!mp.empty())&&use[mp.lower_bound(mk(u,v))->second]){
        mp.erase(mp.lower_bound(mk(u,v)));
    }
    int id=mp.empty()?0:mp.lower_bound(mk(u,v))->second;
    use[id]=true;
    int nu;
    for(int k=0;k<3;k++)if(u!=a[id][k]&&v!=a[id][k]){
        nu=a[id][k];
        break;
    }
    int nv=(u==ans[ans.size()-1]?v:u);
    ans.push_back(nv);
    if(deep)srh(nv,nu,deep-1);
    else ans.push_back(nu);
}
bool rit[maxn];
int main()
{
 //   freopen("in.txt","r",stdin);
    scanf("%d",&n);
    bool tmpid=0;
    for(int i=1;i<=n-2;i++){
        for(int k=0;k<3;k++){
                scanf("%d",&a[i][k]),cnt[a[i][k]]++;
        }
        sort(a[i],a[i]+3);
        mp.insert(mk(mk(a[i][0],a[i][1]),i));
        mp.insert(mk(mk(a[i][0],a[i][2]),i));
        mp.insert(mk(mk(a[i][1],a[i][2]),i));
        exist.insert(mk(mk(a[i][0],a[i][1]),true));
        exist.insert(mk(mk(a[i][0],a[i][2]),true));
        exist.insert(mk(mk(a[i][1],a[i][2]),true));
    }

    for(int i=1;i<=n;i++){
        if(cnt[i]==1){
            for(int j=1;j<=n;j++){
                int u=i,v=j;
                if(u>v)swap(u,v);
                if(exist[mk(u,v)]){
                    ans.push_back(i);
                    for(int k=1;k<=n;k++)use[k]=false;
                    tp=mp;
                    srh(u,v,n-3);
                    mp=tp;
                }
            /*    if(u>v)swap(u,v);
                if(mp[mk(u,v)]){
                    auto it=mp.lower_bound(mk(u,v));
                    use[it->second]=true;
                    getans(it->second);
                    mp.erase(it);

                }*/

            }
            break;
        }
    }
    for(int i=0;i<n;i++)rit[ans[i]]^=1;
    bool flag=true;
    for(int i=1;i<=n;i++)if(!rit[i])flag=false;
    for(int i=flag?0:n;i<(flag?n:2*n);i++)printf("%d ",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
int n;
const int maxn=1e5+5;
int a[maxn][3];
int cnt[maxn];
bool use[maxn];
#define pr pair<int,int>
#define mk(a,b) make_pair(a,b)
multimap<pr,int>mp,tp;
map<pr,bool>exist;
vector<int>ans;
void getans(int id){
    for(int k=0;k<3;k++)ans.push_back(a[id][k]);
}
void srh(int u,int v,int deep){
    if(u>v)swap(u,v);
    while((!mp.empty())&&mp.lower_bound(mk(u,v))!=mp.end()&&use[mp.lower_bound(mk(u,v))->second]){
        mp.erase(mp.lower_bound(mk(u,v)));
    }
    int id=mp.empty()?0:mp.lower_bound(mk(u,v))->second;
    use[id]=true;
    int nu;
    for(int k=0;k<3;k++)if(u!=a[id][k]&&v!=a[id][k]){
        nu=a[id][k];
        break;
    }
    int nv=(u==ans[ans.size()-1]?v:u);
    ans.push_back(nv);
    if(deep)srh(nv,nu,deep-1);
    else ans.push_back(nu);
}
bool rit[maxn];
int main()
{
    scanf("%d",&n);
    bool tmpid=0;
    for(int i=1;i<=n-2;i++){
        for(int k=0;k<3;k++){
                scanf("%d",&a[i][k]),cnt[a[i][k]]++;
        }
        sort(a[i],a[i]+3);
        mp.insert(mk(mk(a[i][0],a[i][1]),i));
        mp.insert(mk(mk(a[i][0],a[i][2]),i));
        mp.insert(mk(mk(a[i][1],a[i][2]),i));
        exist.insert(mk(mk(a[i][0],a[i][1]),true));
        exist.insert(mk(mk(a[i][0],a[i][2]),true));
        exist.insert(mk(mk(a[i][1],a[i][2]),true));
    }

    for(int i=1;i<=n;i++){
        if(cnt[i]==1){
            for(int j=1;j<=n;j++){
                int u=i,v=j;
                if(u>v)swap(u,v);
                if(exist[mk(u,v)]){
                    ans.push_back(i);
                    for(int k=1;k<=n;k++)use[k]=false;
                    tp=mp;
                    srh(u,v,n-3);
                    mp=tp;
                }
            /*    if(u>v)swap(u,v);
                if(mp[mk(u,v)]){
                    auto it=mp.lower_bound(mk(u,v));
                    use[it->second]=true;
                    getans(it->second);
                    mp.erase(it);

                }*/

            }
            break;
        }
    }
    for(int i=0;i<n;i++)rit[ans[i]]^=1;
    bool flag=true;
    for(int i=1;i<=n;i++)if(!rit[i])flag=false;
    for(int i=flag?0:n;i<(flag?n:2*n);i++)printf("%d ",ans[i]);
}


#include<bits/stdc++.h>
using namespace std;
int n;
const int maxn=1e5+5;
int a[maxn][3];
int cnt[maxn];
bool use[maxn];
#define pr pair<int,int>
#define mk(a,b) make_pair(a,b)
multimap<pr,int>mp,tp;
map<pr,bool>exist;
vector<int>ans;
void getans(int id){
    for(int k=0;k<3;k++)ans.push_back(a[id][k]);
}
void srh(int u,int v,int deep){
    if(u>v)swap(u,v);
    while((!mp.empty())&&mp.lower_bound(mk(u,v))!=mp.end()&&use[mp.lower_bound(mk(u,v))->second]){
        mp.erase(mp.lower_bound(mk(u,v)));
    }
    int id=(mp.empty()||mp.lower_bound(mk(u,v))==mp.end())?0:mp.lower_bound(mk(u,v))->second;
    use[id]=true;
    int nu;
    for(int k=0;k<3;k++)if(u!=a[id][k]&&v!=a[id][k]){
        nu=a[id][k];
        break;
    }
    int nv=(u==ans[ans.size()-1]?v:u);
    ans.push_back(nv);
    if(deep)srh(nv,nu,deep-1);
    else ans.push_back(nu);
}
bool rit[maxn];
int main()
{
    scanf("%d",&n);
    bool tmpid=0;
    for(int i=1;i<=n-2;i++){
        for(int k=0;k<3;k++){
                scanf("%d",&a[i][k]),cnt[a[i][k]]++;
        }
        sort(a[i],a[i]+3);
        mp.insert(mk(mk(a[i][0],a[i][1]),i));
        mp.insert(mk(mk(a[i][0],a[i][2]),i));
        mp.insert(mk(mk(a[i][1],a[i][2]),i));
        exist.insert(mk(mk(a[i][0],a[i][1]),true));
        exist.insert(mk(mk(a[i][0],a[i][2]),true));
        exist.insert(mk(mk(a[i][1],a[i][2]),true));
    }

    for(int i=1;i<=n;i++){
        if(cnt[i]==1){
            for(int j=1;j<=n;j++){
                int u=i,v=j;
                if(u>v)swap(u,v);
                if(exist[mk(u,v)]){
                    ans.push_back(i);
                    for(int k=1;k<=n;k++)use[k]=false;
                    tp=mp;
                    srh(u,v,n-3);
                    mp=tp;
                }
            /*    if(u>v)swap(u,v);
                if(mp[mk(u,v)]){
                    auto it=mp.lower_bound(mk(u,v));
                    use[it->second]=true;
                    getans(it->second);
                    mp.erase(it);

                }*/

            }
            break;
        }
    }
    for(int i=0;i<n;i++)rit[ans[i]]^=1;
    bool flag=true;
    for(int i=1;i<=n;i++)if(!rit[i])flag=false;
    for(int i=flag?0:n;i<(flag?n:2*n);i++)printf("%d ",ans[i]);
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    vector<int> oc[n+1];
    int a[n-2], b[n-2], c[n-2];
    int sz[n+1]; memset(sz,0,sizeof(sz));
    for (int i = 0; i < n-2; i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        oc[a[i]].push_back(i);
        oc[b[i]].push_back(i);
        oc[c[i]].push_back(i);
        sz[a[i]]++, sz[b[i]]++, sz[c[i]]++;
    }
    int cur = 0;
    for (int i = 1; i <= n; i++){
        if (sz[i] == 1){
            cur = i;
            sz[a[oc[i][0]]]--, sz[b[oc[i][0]]]--, sz[c[oc[i][0]]]--;
            break;
        }
    }
    int num = 1;
    while (num < n){
        num++;
        printf("%d ",cur);
        for (auto x : oc[cur]){
            if (sz[a[x]] == 1){
                cur = a[x];
                sz[a[x]]--, sz[b[x]]--, sz[c[x]]--;
                break;
            }
            else if (sz[b[x]] == 1){
                cur = b[x];
                sz[a[x]]--, sz[b[x]]--, sz[c[x]]--;
                break;
            }
            else if (sz[c[x]] == 1){
                cur = c[x];
                sz[a[x]]--, sz[b[x]]--, sz[c[x]]--;
                break;
            }
            else{

            }

        }

    }
    printf("%d ",cur);
}


#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005], c[100005];
int works(int id, int x, int y){
    return (a[id] == x || b[id] == x || c[id] == x) && (a[id] == y || b[id] == y || c[id] == y);
}
int main(){
    int n;
    scanf("%d",&n);
    vector<int> oc[n+1];
    int sz[n+1]; memset(sz,0,sizeof(sz));
    int s[n-2]; memset(s,0,sizeof(s));
    int sum = 0; for (int i = 1; i <= n; i++) sum += i;
    for (int i = 0; i < n-2; i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        oc[a[i]].push_back(i);
        oc[b[i]].push_back(i);
        oc[c[i]].push_back(i);
        sz[a[i]]++, sz[b[i]]++, sz[c[i]]++;
        s[i] += a[i] + b[i] + c[i];
    }
    int used[n+1]; memset(used,0,sizeof(used));
    int last = 0;
    int cur = 0;
    vector<int> ans;
    for (int i = 1; i <= n; i++){
        if (sz[i] == 1){
            cur = i;
            sz[a[oc[i][0]]]--, sz[b[oc[i][0]]]--, sz[c[oc[i][0]]]--;
            //printf("%d %d %d\n",sz[a[oc[i][0]]], sz[b[oc[i][0]]], sz[c[oc[i][0]]]);
            if (sz[a[oc[i][0]]] <= 1 && a[oc[i][0]] != i){
                cur = a[oc[i][0]];
                last = i;
            }
            else if (sz[b[oc[i][0]]] <= 1 && b[oc[i][0]] != i){
                cur = b[oc[i][0]];
                last = i;
            }
            else if (sz[c[oc[i][0]]] <= 1 && c[oc[i][0]] != i){
                cur = c[oc[i][0]];
                last = i;
            }
            ans.push_back(last);
            ans.push_back(cur);
            break;
        }
    }
    used[last] = used[cur] = 1;
    printf("%d ",last);
    sum -= last;
    int num = 2;
    while (num < n){
        num++;
        sum -= cur;
        printf("%d ",cur);
        for (auto x : oc[cur]){
            if (works(x,cur,last)){
                //printf("%d %d %d works\n",a[x],b[x],c[x]);
                int next= s[x] - cur-last;
                //printf("%d %d %d %d %d %d\n",a[x],b[x],c[x],cur,last,next);
                if (used[next]) continue;
                last = cur;
                cur = next;
                break;
            }
        }
    }
    printf("%d ",sum);
}


#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    vector<int> oc[n+1];
    int a[n-2], b[n-2], c[n-2];
    int sz[n+1]; memset(sz,0,sizeof(sz));

    int sum = 0; for (int i = 1; i <= n; i++) sum += i;
    for (int i = 0; i < n-2; i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        oc[a[i]].push_back(i);
        oc[b[i]].push_back(i);
        oc[c[i]].push_back(i);
        sz[a[i]]++, sz[b[i]]++, sz[c[i]]++;
    }
    int cur = 0;
    int used[n-2]; memset(used,0,sizeof(used));
    for (int i = 1; i <= n; i++){
        if (sz[i] == 1){
            cur = i;
            sz[a[oc[i][0]]]--, sz[b[oc[i][0]]]--, sz[c[oc[i][0]]]--;
            break;
        }
    }
    int num = 1;

    while (num < n){
        num++;
        sum -= cur;
        printf("%d ",cur);
        for (auto x : oc[cur]){
            if (used[x]) continue;
            if (a[x] != cur && sz[a[x]] <= 1){
                cur = a[x];
                sz[a[x]]--, sz[b[x]]--, sz[c[x]]--;
                used[x] = 1;
                break;
            }
            else if (b[x] != cur && sz[b[x]] <= 1){
                cur = b[x];
                sz[a[x]]--, sz[b[x]]--, sz[c[x]]--;
                used[x] = 1;
                break;
            }
            else if (c[x] != cur && sz[c[x]] <= 1){
                cur = c[x];
                sz[a[x]]--, sz[b[x]]--, sz[c[x]]--;
                used[x] = 1;
                break;
            }
        }
    }
    printf("%d ",sum);
}


#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005], c[100005];
int works(int id, int x, int y){
    return (a[id] == x || b[id] == x || c[id] == x) && (a[id] == y || b[id] == y || c[id] == y);
}
int main(){
    int n;
    scanf("%d",&n);
    vector<int> oc[n+1];
    int sz[n+1]; memset(sz,0,sizeof(sz));
    int s[n-2]; memset(s,0,sizeof(s));
    long long sum = 0; for (int i = 1; i <= n; i++) sum += i;
    for (int i = 0; i < n-2; i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        oc[a[i]].push_back(i);
        oc[b[i]].push_back(i);
        oc[c[i]].push_back(i);
        sz[a[i]]++, sz[b[i]]++, sz[c[i]]++;
        s[i] = a[i] + b[i] + c[i];
    }
    int used[n+1]; memset(used,0,sizeof(used));
    int last = 0;
    int cur = 0;
    vector<int> ans;
    for (int i = 1; i <= n; i++){
        if (sz[i] == 1){
            cur = i;
            sz[a[oc[i][0]]]--, sz[b[oc[i][0]]]--, sz[c[oc[i][0]]]--;
            //printf("%d %d %d\n",sz[a[oc[i][0]]], sz[b[oc[i][0]]], sz[c[oc[i][0]]]);
            if (sz[a[oc[i][0]]] <= 1 && a[oc[i][0]] != i){
                cur = a[oc[i][0]];
                last = i;
            }
            else if (sz[b[oc[i][0]]] <= 1 && b[oc[i][0]] != i){
                cur = b[oc[i][0]];
                last = i;
            }
            else if (sz[c[oc[i][0]]] <= 1 && c[oc[i][0]] != i){
                cur = c[oc[i][0]];
                last = i;
            }
            ans.push_back(last);
            ans.push_back(cur);
            break;
        }
    }
    used[last] = used[cur] = 1;
    printf("%d ",last);
    sum -= last;
    int num = 2;
    while (num < n){
        num++;
        sum -= cur;
        printf("%d ",cur);
        for (auto x : oc[cur]){
            if (works(x,cur,last)){
                //printf("%d %d %d works\n",a[x],b[x],c[x]);
                int next= s[x]-cur-last;
                //printf("%d %d %d %d %d %d\n",a[x],b[x],c[x],cur,last,next);
                if (used[next]) continue;
                used[next] = 1;
                last = cur;
                cur = next;
                break;
            }
        }
    }
    printf("%lld ",sum);
}


#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005], c[100005];
int works(int id, int x, int y){
    return (a[id] == x || b[id] == x || c[id] == x) && (a[id] == y || b[id] == y || c[id] == y);
}
int main(){
    int n;
    scanf("%d",&n);
    vector<int> oc[n+1];
    int sz[n+1]; memset(sz,0,sizeof(sz));
    int s[n-2]; memset(s,0,sizeof(s));
    long long sum = 0; for (int i = 1; i <= n; i++) sum += i;
    for (int i = 0; i < n-2; i++){
        scanf("%d%d%d",&a[i],&b[i],&c[i]);
        oc[a[i]].push_back(i);
        oc[b[i]].push_back(i);
        oc[c[i]].push_back(i);
        sz[a[i]]++, sz[b[i]]++, sz[c[i]]++;
        s[i] += a[i] + b[i] + c[i];
    }
    int used[n+1]; memset(used,0,sizeof(used));
    int last = 0;
    int cur = 0;
    vector<int> ans;
    for (int i = 1; i <= n; i++){
        if (sz[i] == 1){
            cur = i;
            sz[a[oc[i][0]]]--, sz[b[oc[i][0]]]--, sz[c[oc[i][0]]]--;
            //printf("%d %d %d\n",sz[a[oc[i][0]]], sz[b[oc[i][0]]], sz[c[oc[i][0]]]);
            if (sz[a[oc[i][0]]] <= 1 && a[oc[i][0]] != i){
                cur = a[oc[i][0]];
                last = i;
            }
            else if (sz[b[oc[i][0]]] <= 1 && b[oc[i][0]] != i){
                cur = b[oc[i][0]];
                last = i;
            }
            else if (sz[c[oc[i][0]]] <= 1 && c[oc[i][0]] != i){
                cur = c[oc[i][0]];
                last = i;
            }
            ans.push_back(last);
            ans.push_back(cur);
            break;
        }
    }
    used[last] = used[cur] = 1;
    printf("%d ",last);
    sum -= last;
    int num = 2;
    while (num < n){
        num++;
        sum -= cur;
        printf("%d ",cur);
        for (auto x : oc[cur]){
            if (works(x,cur,last)){
                //printf("%d %d %d works\n",a[x],b[x],c[x]);
                int next= s[x] - cur-last;
                //printf("%d %d %d %d %d %d\n",a[x],b[x],c[x],cur,last,next);
                if (used[next]) continue;
                last = cur;
                cur = next;
                break;
            }
        }
    }
    printf("%lld ",sum);
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin >>n;
	vector< vector<int> > ar[n-2];
	vector <int> in[3];
	vector <int> ::iterator j;
	int t;
	for(vector< vector <int> > ::iterator it= ar.begin();it!=iar.end();it++)
	{
		ar.push_back(in);
		for(j=in.begin();j!=in.end();j++)
		{
			cin >> t;
			ar[it].push_back(t);
		}

	}
	for(int i=0;i<n-2;i++)
	{
		for(int k=0;k<3;k++)
			cout<< ar[i][k];
		cout<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,temp;
	cin >> n;
	int vect[n+5][3];
	int rec[n+5];
	for(int i=1;i<=n;i++)
	{
		rec[i]=0;
		vect[i][0]=vect[i][1]=vect[i][2]=-1;
	}
	int triplet[n+5][3];
	for(int i=1;i<n-1;i++)
	{
		for(int j=0;j<3;j++)
		{
		cin >> temp;
		vect[temp][rec[temp]]=i;
		rec[temp]++;
		triplet[i][j]=temp;
		}
	}
	vector <int> one,two;
	for(int i=1;i<n+1;i++)
	{
		if(rec[i]==1)
			one.push_back(i);
		if(rec[i]==2)
			two.push_back(i);
	}
	pair <int,int> start;
	pair <int,int> end;
	//making pairs
	if(vect[one[0]][0]==vect[two[0]][0] || vect[one[0]][0]==vect[two[0]][1])
		start=make_pair(one[0],two[0]);
	if(vect[one[0]][0]==vect[two[1]][0] || vect[one[0]][0]==vect[two[1]][1])
                start=make_pair(one[0],two[1]);
	if(vect[one[1]][0]==vect[two[0]][0] || vect[one[1]][0]==vect[two[0]][1])
                end=make_pair(two[0],one[1]);
	if(vect[one[1]][0]==vect[two[1]][0] || vect[one[1]][0]==vect[two[1]][1])
                end=make_pair(two[1],one[1]);
	//pair start and end made

	pair <int,int> curr;
	curr.first=start.first;
	curr.second=start.second;
	int now;
	 for(int i=0;i<3;i++)
                {
			for(int j=0;j<3;j++)
			{
                        if(vect[curr.first][i]==vect[curr.second][j] && vect[curr.first][i]!=-1)
				now=vect[curr.first][i];
                	}
		}
	for(int i=0;i<3;i++)
	{
		if(vect[curr.second][i]==now)
			vect[curr.second][i]=-1;
	}
	while(curr.first!=end.first)
	{
		cout<<curr.first<<" ";
		 for(int i=0;i<3;i++)
                {
                        for(int j=0;j<3;j++)
                        {
                        if(vect[curr.first][i]==vect[curr.second][j] && vect[curr.first][i]!=-1)
                                now=vect[curr.first][i];
                        }
                }
		int next;
		for(int i=0;i<3;i++)
		{
			if(triplet[now][i]!=curr.first && triplet[now][i]!=curr.second)
				next=triplet[now][i];
		}
		for(int i=0;i<3;i++)
			if(vect[curr.first][i]==now)
				vect[curr.first][i]=-1;
		curr.first=curr.second;
		curr.second=next;
	}
	cout<<end.first<<" "<<end.second<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,temp;
	cin >> n;
	bool printed[n+5];
	int vect[n+5][3];
	int rec[n+5];
	for(int i=1;i<=n;i++)
	{
		printed[i]=false;
		rec[i]=0;
		vect[i][0]=vect[i][1]=vect[i][2]=-1;
	}
	int triplet[n+5][3];
	for(int i=1;i<n-1;i++)
	{
		for(int j=0;j<3;j++)
		{
		cin >> temp;
		vect[temp][rec[temp]]=i;
		rec[temp]++;
		triplet[i][j]=temp;
		}
	}
	vector <int> one,two;
	for(int i=1;i<n+1;i++)
	{
		if(rec[i]==1)
			one.push_back(i);
		if(rec[i]==2)
			two.push_back(i);
	}
	pair <int,int> start;
	pair <int,int> end;
	//making pairs
	if(vect[one[0]][0]==vect[two[0]][0] || vect[one[0]][0]==vect[two[0]][1])
		start=make_pair(one[0],two[0]);
	if(vect[one[0]][0]==vect[two[1]][0] || vect[one[0]][0]==vect[two[1]][1])
                start=make_pair(one[0],two[1]);
	if(vect[one[1]][0]==vect[two[0]][0] || vect[one[1]][0]==vect[two[0]][1])
                end=make_pair(two[0],one[1]);
	if(vect[one[1]][0]==vect[two[1]][0] || vect[one[1]][0]==vect[two[1]][1])
                end=make_pair(two[1],one[1]);
	//pair start and end made

	pair <int,int> curr;
	curr.first=start.first;
	curr.second=start.second;
	int now;
	 for(int i=0;i<3;i++)
                {
			for(int j=0;j<3;j++)
			{
                        if(vect[curr.first][i]==vect[curr.second][j] && vect[curr.first][i]!=-1)
				now=vect[curr.first][i];
                	}
		}
	for(int i=0;i<3;i++)
	{
		if(vect[curr.second][i]==now)
			vect[curr.second][i]=-1;
	}
	while(curr.first!=end.first)
	{
		if(!printed[curr.first])
			cout<<curr.first<<" ";
		printed[curr.first]=true;
		 for(int i=0;i<3;i++)
                {
                        for(int j=0;j<3;j++)
                        {
                        if(vect[curr.first][i]==vect[curr.second][j] && vect[curr.first][i]!=-1)
                                now=vect[curr.first][i];
                        }
                }
		int next;
		for(int i=0;i<3;i++)
		{
			if(triplet[now][i]!=curr.first && triplet[now][i]!=curr.second)
				next=triplet[now][i];
		}
		for(int i=0;i<3;i++)
			if(vect[curr.first][i]==now)
				vect[curr.first][i]=-1;
		curr.first=curr.second;
		curr.second=next;
	}
	cout<<end.first<<" "<<end.second<<endl;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,temp;
	cin >> n;
	bool printed[n+5];
	int vect[n+5][3];
	int rec[n+5];
	for(int i=1;i<=n;i++)
	{
		printed[i]=false;
		rec[i]=0;
		vect[i][0]=vect[i][1]=vect[i][2]=-1;
	}
	int triplet[n+5][3];
	for(int i=1;i<n-1;i++)
	{
		for(int j=0;j<3;j++)
		{
			cin >> temp;
			vect[temp][rec[temp]]=i;
			rec[temp]++;
			triplet[i][j]=temp;
		}
	}
	vector <int> one,two;
	for(int i=1;i<n+1;i++)
	{
		if(rec[i]==1)
			one.push_back(i);
		if(rec[i]==2)
			two.push_back(i);
	}
	pair <int,int> start;
	pair <int,int> end;
	//making pairs
	if(vect[one[0]][0]==vect[two[0]][0] || vect[one[0]][0]==vect[two[0]][1])
		start=make_pair(one[0],two[0]);
	if(vect[one[0]][0]==vect[two[1]][0] || vect[one[0]][0]==vect[two[1]][1])
		start=make_pair(one[0],two[1]);
	if(vect[one[1]][0]==vect[two[0]][0] || vect[one[1]][0]==vect[two[0]][1])
		end=make_pair(two[0],one[1]);
	if(vect[one[1]][0]==vect[two[1]][0] || vect[one[1]][0]==vect[two[1]][1])
		end=make_pair(two[1],one[1]);
	//pair start and end made

	pair <int,int> curr;
	curr.first=start.first;
	curr.second=start.second;
	int now;
	for(int i=0;i<3;i++)
	{
		for(int j=0;j<3;j++)
		{
			if(vect[curr.first][i]==vect[curr.second][j] && vect[curr.first][i]!=-1)
				now=vect[curr.first][i];
		}
	}
	int f;
	while(curr.first!=end.first)
	{
		f=0;
		cout<<curr.first<<" ";
		printed[curr.first]=true;
		for(int i=0;i<3;i++)
		{
			for(int j=0;j<3;j++)
			{
				if(vect[curr.first][i]==vect[curr.second][j] && vect[curr.first][i]!=-1 && vect[curr.first][i]!=now)
				{
					now=vect[curr.first][i];
					vect[curr.first][i]=-1;
					f=-1;
					break;

				}
			}
			if(f==-1)
				break;
		}
		int next;
		for(int i=0;i<3;i++)
		{
			if(triplet[now][i]!=curr.first && triplet[now][i]!=curr.second)
				next=triplet[now][i];
		}
		for(int i=0;i<3;i++)
			if(vect[curr.first][i]==now)
				vect[curr.first][i]=-1;
		curr.first=curr.second;
		curr.second=next;
	}
	cout<<end.first<<" "<<end.second<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repx(i, a, b) for (int i = (int)a; i < (int)b; i++)

typedef vector<int> vi;
typedef pair<int, int> par;
typedef vector<par> vp;
typedef long long ll;

int n, q1, q2, q3;
map<int, set<int>> counts;
vector<vector<int>> sets;

int main()
{
    cin >> n;

    rep(i, n) counts[i + 1] = {};

    sets.resize(n - 2);
    rep(i, n - 2)
    {
        cin >> q1 >> q2 >> q3;
        counts[q1].insert(i);
        counts[q2].insert(i);
        counts[q3].insert(i);
        sets[i] = {q1, q2, q3};
    }

    int curr, last;
    rep(i, n)
    {
        if (counts[i + 1].size() == 1)
        {
            curr = *(counts[i + 1].begin());
            last = i + 1;
            cout << i + 1 << '\n';
            break;
        }
    }

    set<int> aux;
    while (true)
    {
        if (counts[last].size() == 3)
        {
            int sum = 0;
            for (int q : sets[curr])
                sum += counts[q].size();

            if (sum == 6)
            {
                for (int q : sets[curr])
                    if (counts[q].size() == 2)
                        cout << q << '\n';
                for (int q : sets[curr])
                    if (counts[q].size() == 1)
                        cout << q << '\n';
                break;
            }

            if (sum == 8)
            {
                for (int q : sets[curr])
                {
                    if (q != last && counts[q].size() == 3)
                    {
                        aux.clear();
                        set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                        cout << q << '\n';
                        last = q;
                        curr = *(aux.begin());
                    }
                }
                continue;
            }

            for (int q : sets[curr])
            {
                if (q != last)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    if (aux.size() == 1)
                    {
                        last = q;
                        curr = *(aux.begin());
                        cout << q << '\n';
                        break;
                    }
                }
            }
        }

        if (counts[last].size() == 1)
        {
            for (int q : sets[curr])
            {
                if (counts[q].size() == 2)
                {
                    cout << q << '\n';
                    last = q;
                }
            }
            for (int q : sets[curr])
            {
                if (counts[q].size() == 3)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    cout << q << '\n';
                    last = q;
                    curr = *(aux.begin());
                }
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repx(i, a, b) for (int i = (int)a; i < (int)b; i++)

typedef vector<int> vi;
typedef pair<int, int> par;
typedef vector<par> vp;
typedef long long ll;

int n, q1, q2, q3;
map<int, set<int>> counts;
vector<vector<int>> sets;

int main()
{
    cin >> n;

    rep(i, n) counts[i + 1] = {};

    sets.resize(n - 2);
    rep(i, n - 2)
    {
        cin >> q1 >> q2 >> q3;
        counts[q1].insert(i);
        counts[q2].insert(i);
        counts[q3].insert(i);
        sets[i] = {q1, q2, q3};
    }

    int curr, last;
    rep(i, n)
    {
        if (counts[i + 1].size() == 1)
        {
            curr = *(counts[i + 1].begin());
            last = i + 1;
            cout << i + 1 << '\n';
            break;
        }
    }

    set<int> aux;
    while (true)
    {
        if (counts[last].size() == 3)
        {
            bool done = false;
            for (int q : sets[curr])
                if (counts[q].size() == 2)
                    cout << q << '\n';
            for (int q : sets[curr])
            {
                if (counts[q].size() == 1)
                {
                    cout << q << '\n';
                    done = true;
                }
            }

            if (done)
                break;

            for (int q : sets[curr])
            {
                if (q != last)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    if (aux.size() == 1)
                    {
                        last = q;
                        curr = *(aux.begin());
                        cout << q << '\n';
                        break;
                    }
                }
            }
            break;
        }

        if (counts[last].size() == 1)
        {
            for (int q : sets[curr])
            {
                if (counts[q].size() == 2)
                {
                    cout << q << '\n';
                    last = q;
                }
            }
            for (int q : sets[curr])
            {
                if (counts[q].size() == 3)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    cout << q << '\n';
                    last = q;
                    curr = *(aux.begin());
                }
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repx(i, a, b) for (int i = (int)a; i < (int)b; i++)

typedef vector<int> vi;
typedef pair<int, int> par;
typedef vector<par> vp;
typedef long long ll;

int n, q1, q2, q3;
map<int, set<int>> counts;
vector<vector<int>> sets;

int main()
{
    cin >> n;

    rep(i, n) counts[i + 1] = {};

    sets.resize(n - 2);
    rep(i, n - 2)
    {
        cin >> q1 >> q2 >> q3;
        counts[q1].insert(i);
        counts[q2].insert(i);
        counts[q3].insert(i);
        sets[i] = {q1, q2, q3};
    }

    int curr, last;
    rep(i, n)
    {
        if (counts[i + 1].size() == 1)
        {
            curr = *(counts[i + 1].begin());
            last = i + 1;
            cout << i + 1 << '\n';
            break;
        }
    }

    set<int> aux;
    while (true)
    {
        if (counts[last].size() == 3)
        {
            bool done = false;
            for (int q : sets[curr])
                if (counts[q].size() == 2)
                    cout << q << '\n';
            for (int q : sets[curr])
            {
                if (counts[q].size() == 1)
                {
                    cout << q << '\n';
                    done = true;
                }
            }

            if (done)
                break;

            for (int q : sets[curr])
            {
                if (q != last)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    if (aux.size() == 1)
                    {
                        last = q;
                        curr = *(aux.begin());
                        cout << q << '\n';
                        continue;
                    }
                }
            }
            break;
        }

        if (counts[last].size() == 1)
        {
            for (int q : sets[curr])
            {
                if (counts[q].size() == 2)
                {
                    cout << q << '\n';
                    last = q;
                }
            }
            for (int q : sets[curr])
            {
                if (counts[q].size() == 3)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    cout << q << '\n';
                    last = q;
                    curr = *(aux.begin());
                }
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repx(i, a, b) for (int i = (int)a; i < (int)b; i++)

typedef vector<int> vi;
typedef pair<int, int> par;
typedef vector<par> vp;
typedef long long ll;

int n, q1, q2, q3;
map<int, set<int>> counts;
vector<vector<int>> sets;

int main()
{
    cin >> n;

    rep(i, n) counts[i + 1] = {};

    sets.resize(n - 2);
    rep(i, n - 2)
    {
        cin >> q1 >> q2 >> q3;
        counts[q1].insert(i);
        counts[q2].insert(i);
        counts[q3].insert(i);
        sets[i] = {q1, q2, q3};
    }

    int curr, last;
    rep(i, n)
    {
        if (counts[i + 1].size() == 1)
        {
            curr = *(counts[i + 1].begin());
            last = i + 1;
            cout << i + 1 << '\n';
            break;
        }
    }

    set<int> aux;
    while (true)
    {
        if (counts[last].size() == 3)
        {
            bool done = false;
            for (int q : sets[curr])
                if (counts[q].size() == 2)
                    cout << q << '\n';
            for (int q : sets[curr])
            {
                if (counts[q].size() == 1)
                {
                    cout << q << '\n';
                    done = true;
                }
            }

            if (done)
                break;

            for (int q : sets[curr])
            {
                if (q != last)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    if (aux.size() == 1)
                    {
                        last = q;
                        curr = *(aux.begin());
                        cout << q << '\n';
                        done = true;
                        break;
                    }
                }
            }

            if (done)
                continue;

            break;
        }

        if (counts[last].size() == 1)
        {
            for (int q : sets[curr])
            {
                if (counts[q].size() == 2)
                {
                    cout << q << '\n';
                    last = q;
                }
            }
            for (int q : sets[curr])
            {
                if (counts[q].size() == 3)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    cout << q << '\n';
                    last = q;
                    curr = *(aux.begin());
                }
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repx(i, a, b) for (int i = (int)a; i < (int)b; i++)

typedef vector<int> vi;
typedef pair<int, int> par;
typedef vector<par> vp;
typedef long long ll;

int n, q1, q2, q3;
map<int, set<int>> counts;
vector<vector<int>> sets;

int main()
{
    cin >> n;

    rep(i, n) counts[i + 1] = {};

    sets.resize(n - 2);
    rep(i, n - 2)
    {
        cin >> q1 >> q2 >> q3;
        counts[q1].insert(i);
        counts[q2].insert(i);
        counts[q3].insert(i);
        sets[i] = {q1, q2, q3};
    }

    int curr, last;
    rep(i, n)
    {
        if (counts[i + 1].size() == 1)
        {
            curr = *(counts[i + 1].begin());
            last = i + 1;
            cout << i + 1 << '\n';
            break;
        }
    }

    set<int> aux;
    while (true)
    {
        if (counts[last].size() == 3)
        {
            bool done = false;
            for (int q : sets[curr])
                if (counts[q].size() == 2)
                    cout << q << '\n';
            for (int q : sets[curr])
            {
                if (counts[q].size() == 1)
                {
                    cout << q << '\n';
                    done = true;
                }
            }

            if (done)
                break;

            for (int q : sets[curr])
            {
                if (q != last)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    if (aux.size() == 1)
                    {
                        last = q;
                        curr = *(aux.begin());
                        cout << q << '\n';
                        break;
                    }
                }
            }
        }

        if (counts[last].size() == 1)
        {
            for (int q : sets[curr])
            {
                if (counts[q].size() == 2)
                {
                    cout << q << '\n';
                    last = q;
                }
            }
            for (int q : sets[curr])
            {
                if (counts[q].size() == 3)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    cout << q << '\n';
                    last = q;
                    curr = *(aux.begin());
                }
            }
        }
    }
}


#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define repx(i, a, b) for (int i = (int)a; i < (int)b; i++)

typedef vector<int> vi;
typedef pair<int, int> par;
typedef vector<par> vp;
typedef long long ll;

int n, q1, q2, q3;
map<int, set<int>> counts;
vector<vector<int>> sets;

int main()
{
    cin >> n;

    rep(i, n) counts[i + 1] = {};

    sets.resize(n - 2);
    rep(i, n - 2)
    {
        cin >> q1 >> q2 >> q3;
        counts[q1].insert(i);
        counts[q2].insert(i);
        counts[q3].insert(i);
        sets[i] = {q1, q2, q3};
    }

    int curr, last;
    rep(i, n)
    {
        if (counts[i + 1].size() == 1)
        {
            curr = *(counts[i + 1].begin());
            last = i + 1;
            cout << i + 1 << '\n';
            break;
        }
    }

    set<int> aux;
    while (true)
    {
        if (counts[last].size() == 3)
        {
            int sum = 0;
            for (int q : sets[curr])
                sum += counts[q].size();

            if (sum == 6)
            {
                for (int q : sets[curr])
                    if (counts[q].size() == 2)
                        cout << q << '\n';
                for (int q : sets[curr])
                    if (counts[q].size() == 1)
                        cout << q << '\n';
                break;
            }

            if (sum == 8)
            {
                for (int q : sets[curr])
                {
                    if (q != last && counts[q].size() == 3)
                    {
                        aux.clear();
                        set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                        cout << q << '\n';
                        last = q;
                        curr = *(aux.begin());
                        break;
                    }
                }
                continue;
            }

            for (int q : sets[curr])
            {
                if (q != last)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    if (aux.size() == 1)
                    {
                        last = q;
                        curr = *(aux.begin());
                        cout << q << '\n';
                        break;
                    }
                }
            }
        }

        if (counts[last].size() == 1)
        {
            for (int q : sets[curr])
            {
                if (counts[q].size() == 2)
                {
                    cout << q << '\n';
                    last = q;
                }
            }
            for (int q : sets[curr])
            {
                if (counts[q].size() == 3)
                {
                    aux.clear();
                    set_difference(counts[q].begin(), counts[q].end(), counts[last].begin(), counts[last].end(), inserter(aux, aux.end()));
                    cout << q << '\n';
                    last = q;
                    curr = *(aux.begin());
                }
            }
        }
    }
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
const int N = 1e5+5;
int n, a, b, c, x[N], q[N];
vector<int> v[N];
int main() {
    cin >> n;

    int fi, se, gr;
    for (int i = 0; i < n-2; i++) {
        cin >> a >> b >> c;
        v[a].pb(b); v[a].pb(c);
        v[b].pb(a); v[b].pb(c);
        v[c].pb(a); v[c].pb(b);
        q[a]++; q[b]++; q[c]++;
        if (q[a] == 1) fi = a;
        if (q[b] == 1) fi = b;
        if (q[c] == 1) fi = c;
    }
    x[fi] = 1;

    for (int i = 0; i <= v[fi].size(); i++) {
        if (q[v[fi][i]] == 2) {
            se = v[fi][i];
            x[se] = 1;
            break;
        }
    }

    cout << fi << " " << se << " ";

    for (int i = 3; i <= n; i++) {
        int tmp;
        for (int j = 0; j < v[fi].size(); j++) {
            if (x[v[fi][j]] == 0) {
                cout << v[fi][j] << " ";
                tmp = v[fi][j];
                x[tmp] = 1;
                break;
            }
        }
        fi = se;
        se = tmp;
    }

    cout << endl;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, a, b, c, s[100001], o[100001][4], l[100001], n1[2], n2[2], l1, nl1, nl2;
bool f(int self, int nei) {
    for (int i = 0; i < l[self]; i++)
        if (o[self][i] == nei) return true;
    return false;
}
void addF(int self, int fr) {
    bool has = false;
    for (int i = 0; i < l[self]; i++)
        if (o[self][i] == fr) has = true;
    if (!has) o[self][l[self]++] = fr;
}
int getF(int self) {
    if (s[self] == 1) {
        for (int i = 0; i < l[self]; i++) {
            int fr = o[self][i];
            if (s[fr] == 2) {
                s[self] = 0;
                return fr;
            }
        }
        return 0;
    } else if (s[self] > 1) {
        int fr1 = 0, fr2 = 0;
        for (int i = 0; i < l[self]; i++) {
            int fr = o[self][i];
            if (s[fr] == 1) fr1 = fr; else
                if (s[fr] == 2) fr2 = fr; else {
                    if (s[fr] == 3) {
                        s[self] = 0;
                        return fr;
                    }
                }
        }
        if (fr2) { s[self] = 0;  return fr2; } else { s[self] = 0; return fr1; }
    }
    return 0;
}

int main() {
    cin >> n;
    for (int i = 0; i<n-2; i++) {
        cin >> a >> b >> c;
        s[a]++; s[b]++; s[c]++;
        addF(a, b); addF(a, c);
        addF(b, a); addF(b, c);
        addF(c, a); addF(c, b);
    }
    for (int i = 1; i<=100000; i++) {
        if (s[i] == 1) { n1[nl1++] = i; }
        if (s[i] == 2) { n2[nl2++] = i; }
    }
    int v = n1[0];
    for (int i = 0; i < n; i++) {
        cout << v << " ";
        v = getF(v);
    }
    cout << endl;

    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
typedef long long ll;
using namespace std;
const int N = 1e5+5;
int n, a, b, c, x[N], q[N];
vector<int> v[N];
int main() {
    cin >> n;

    int fi, se, gr;
    for (int i = 0; i < n-2; i++) {
        cin >> a >> b >> c;
        v[a].pb(b); v[a].pb(c);
        v[b].pb(a); v[b].pb(c);
        v[c].pb(a); v[c].pb(b);
        q[a]++; q[b]++; q[c]++;
    }

    for (int i = 0; i < n; i++) {
        if (q[i] == 1) {
            fi = i;
            x[fi] = 1;
            break;
        }
    }

    for (int i = 0; i <= v[fi].size(); i++) {
        if (q[v[fi][i]] == 2) {
            se = v[fi][i];
            x[se] = 1;
            break;
        }
    }

    cout << fi << " " << se << " ";

    for (int i = 3; i <= n; i++) {
        int tmp;
        for (int j = 0; j < v[fi].size(); j++) {
            if (x[v[fi][j]] == 0) {
                cout << v[fi][j] << " ";
                tmp = v[fi][j];
                x[tmp] = 1;
                break;
            }
        }
        fi = se;
        se = tmp;
    }

    cout << endl;

    return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
int n;
vector<int> p[N];
unordered_map<int, int> q;
int v[N];
bool used[N];

int check(int pre1, int pre2, vector<int> p)
{
	int flag = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (p[i] != pre1 && p[i] != pre2)
		{
			flag = p[i];
			break;
		}
	}
	return flag;
}

int main()
{
	scanf("%d", &n);
	memset(v, 0, sizeof v);
	int a, b, c;
	for (int i = 1; i <= n - 2; ++i)
	{
		scanf("%d%d%d", &a, &b, &c);
		p[i].push_back(a);
		p[i].push_back(b);
		p[i].push_back(c);
		++q[a], ++q[b], ++q[c];
	}

	for (int i = 1; i <= n; ++i)
	{
		if (q[i] == 1 && v[1] == 0)
		{
			v[1] = i;
			used[i] = true;
		}
		else if (q[i] == 1 && v[1] != 0)
		{
			v[n] = i;
			used[i] = true;
		}
		else if (q[i] == 2 && v[2] == 0)
		{
			v[2] = i;
			used[i] = true;
		}
		else if (q[i] == 2 && v[2] != 0)
		{
			v[n - 1] = i;
			used[i] = true;
		}
	}

	int pre1 = v[1], pre2 = v[2];
	//构造3 ~ n - 2
	for (int i = 3; i <= n - 2; ++i)
	{
		//遍历三元组
		for (int j = 1; j <= n - 2; ++j)
		{
			int m = check(pre1, pre2, p[j]);
			if (!used[m])
			{
				used[m] = true;
				v[i] = m;
				pre1 = pre2;
				pre2 = m;
			}
		}
	}

	for (int i = 1; i <= n; ++i)
	{
		printf("%d ", v[i]);
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1e5 + 5;
int q[N][3];
int t[N];
int v[N];
bool used[N];
bool used2[N];

int check(int pre1, int pre2, int q[])
{
	int flag = 0;
	int d = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (q[i] == pre1 || q[i] == pre2)
		{
			++d;
		}
		else
		{
			flag = q[i];
		}
	}
	if (d == 2)
		return flag;
	return -1;
}
int main()
{
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n - 2; ++i)
	{
		scanf("%d%d%d", &q[i][0], &q[i][1], &q[i][2]);
		++t[q[i][0]], ++t[q[i][1]], ++t[q[i][2]];
	}

	for (int i = 1; i <= n - 2; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			if (t[q[i][j]] == 1 && v[1] == 0)
			{
				v[1] = q[i][j];
				used[q[i][j]] = true;
				//将同一个组中出现次数为2的数标记
				for(int k = 0; k <= 3; ++k)
					if (t[q[i][k]] == 2)
					{
						v[2] = q[i][k];
						used[q[i][k]] = true;
						break;
					}
			}
			else if (t[q[i][j]] == 1)
			{
				v[n] = q[i][j];
				used[q[i][j]] = true;
				for (int k = 0; k <= 3; ++k)
					if (t[q[i][k]] == 2)
					{
						v[n - 1] = q[i][k];
						used[q[i][k]] = true;
						break;
					}
			}
		}
	}

	int pre1 = v[1], pre2 = v[2];

	//第i个数
	for (int i = 3; i <= n - 2; ++i)
	{
		for (int j = 1; j <= n - 2; ++j)
		{
			if (!used2[j])
			{
				int m = check(pre1, pre2, q[j]);
				if (m != -1 && !used[m])
				{
					v[i] = m;
					used[m] = true;
					used2[j] = true;
					pre1 = pre2;
					pre2 = m;
					break;
				}
			}
		}
	}

	for (int i = 1; i <= n; ++i)
	{
		printf("%d ", v[i]);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;
const int N = 1e5 + 5;
int t[N];
vector<int> v[N];
bool used[N];
int ans[N];
int main()
{
	int n;
	scanf("%d", &n);

	int a, b, c;
	for (int i = 1; i <= n - 2; ++i)
	{
		scanf("%d%d%d", &a, &b, &c);
		++t[a], ++t[b], ++t[c];
		v[a].push_back(b), v[a].push_back(c);
		v[b].push_back(a), v[b].push_back(c);
		v[c].push_back(a), v[c].push_back(b);
	}
	int pre1, pre2;
	for (int i = 1; i <= n; ++i)
	{
		if (t[i] == 1)
		{
			ans[1] = i;
			used[i] = true;
			for (auto e : v[i])
			{
				if (t[e] == 2)
				{
					ans[2] = e;
					used[e] = true;
				}
			}
			break;
		}
	}

	for (int i = 3; i <= n; ++i)
	{
		for (auto e1 : v[ans[i - 2]])
		{
			for (auto e2 : v[ans[i - 1]])
			{
				if (e1 == e2)
				{
					ans[i] = e1;
					used[e1] = true;
					goto here;
				}
			}
		}
		here:;//标签地方
	}

	for (int i = 1; i <= n; ++i)
	{
		printf("%d ", ans[i]);
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
int n;
vector<int> p[N];
unordered_map<int, int> q;
int v[N];
bool used[N];

int check(int pre1, int pre2, vector<int> p)
{
	int flag = 0;
	int q = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (p[i] == pre1 || p[i] == pre2)
		{
			++q;
		}
		else
		{
			flag = p[i];
		}
	}
	if (q == 2)
		return flag;
	return -1;
}

bool check(int a, int b)
{
	for (int i = 1; i <= n - 2; ++i)
	{
		if (find(p[i].begin(), p[i].end(), a) != p[i].end() && find(p[i].begin(), p[i].end(), b) != p[i].end())
		{
			return true;
		}
	}
	return false;
}

int main()
{
	scanf("%d", &n);
	int a, b, c;
	for (int i = 1; i <= n - 2; ++i)
	{
		scanf("%d%d%d", &a, &b, &c);
		p[i].push_back(a);
		p[i].push_back(b);
		p[i].push_back(c);
		++q[a], ++q[b], ++q[c];
	}

	for (int i = 1; i <= n; ++i)
	{
		if (q[i] == 1 && v[1] == 0)
		{
			v[1] = i;
			used[i] = true;
		}
		else if (q[i] == 1 && v[1] != 0)
		{
			v[n] = i;
			used[i] = true;
		}
	}

	for (int i = 1; i <= n; ++i)
	{
		if (q[i] == 2 && check(v[1], i) && v[2] == 0)
		{
			v[2] = i;
			used[i] = true;
		}
		else if (q[i] == 2 && check(v[n], i) && v[n - 1] == 0)
		{
			v[n - 1] = i;
			used[i] = true;
		}
	}

	int pre1 = v[1], pre2 = v[2];
	//构造3 ~ n - 2
	for (int i = 3; i <= n - 2; ++i)
	{
		//遍历三元组
		for (int j = 1; j <= n - 2; ++j)
		{
			int m = check(pre1, pre2, p[j]);
			if (m != -1 && !used[m])
			{
				used[m] = true;
				v[i] = m;
				pre1 = pre2;
				pre2 = m;
				break;
			}
		}
	}

	for (int i = 1; i <= n; ++i)
	{
		printf("%d ", v[i]);
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 1e5 + 5;
int n;
vector<int> p[N];
unordered_map<int, int> q;
int v[N];
bool used[N];

int check(int pre1, int pre2, vector<int> p)
{
	int flag = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (p[i] != pre1 && p[i] != pre2)
		{
			flag = p[i];
			break;
		}
	}
	return flag;
}

bool check(int a, int b)
{
	for (int i = 1; i <= n - 2; ++i)
	{
		if (find(p[i].begin(), p[i].end(), a) != p[i].end() && find(p[i].begin(), p[i].end(), b) != p[i].end())
		{
			return true;
		}
	}
	return false;
}

int main()
{
	scanf("%d", &n);
	int a, b, c;
	for (int i = 1; i <= n - 2; ++i)
	{
		scanf("%d%d%d", &a, &b, &c);
		p[i].push_back(a);
		p[i].push_back(b);
		p[i].push_back(c);
		++q[a], ++q[b], ++q[c];
	}

	for (int i = 1; i <= n; ++i)
	{
		if (q[i] == 1 && v[1] == 0)
		{
			v[1] = i;
			used[i] = true;
		}
		else if (q[i] == 1 && v[1] != 0)
		{
			v[n] = i;
			used[i] = true;
		}
	}

	for (int i = 1; i <= n; ++i)
	{
		if (q[i] == 2 && check(v[1], i) && v[2] == 0)
		{
			v[2] = i;
			used[i] = true;
		}
		else if (q[i] == 2 && check(v[n], i) && v[n - 1] == 0)
		{
			v[n - 1] = i;
			used[i] = true;
		}
	}

	int pre1 = v[1], pre2 = v[2];
	//构造3 ~ n - 2
	for (int i = 3; i <= n - 2; ++i)
	{
		//遍历三元组
		for (int j = 1; j <= n - 2; ++j)
		{
			int m = check(pre1, pre2, p[j]);
			if (!used[m])
			{
				used[m] = true;
				v[i] = m;
				pre1 = pre2;
				pre2 = m;
			}
		}
	}

	for (int i = 1; i <= n; ++i)
	{
		printf("%d ", v[i]);
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <unordered_map>
#include <algorithm>

using namespace std;
const int N = 1e5 + 5;
int q[N][3];
unordered_map<int, int> t;
int v[N];
bool used[N];
bool used2[N];

int check(int pre1, int pre2, int q[])
{
	int flag = 0;
	int d = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (q[i] == pre1 || q[i] == pre2)
		{
			++d;
		}
		else
		{
			flag = q[i];
		}
	}
	if (d == 2)
		return flag;
	return -1;
}
int main()
{
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n - 2; ++i)
	{
		scanf("%d%d%d", &q[i][0], &q[i][1], &q[i][2]);
		++t[q[i][0]], ++t[q[i][1]], ++t[q[i][2]];
	}

	for (int i = 1; i <= n - 2; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			if (t[q[i][j]] == 1 && !used[q[i][j]] && !v[1])
			{
				v[1] = q[i][j];
				used[v[1]] = true;
				for (int j = 0; j < 3; ++j)
				{
					if (t[q[i][j]] == 2)
					{
						v[2] = q[i][j];
						used[v[2]] = true;
						break;
					}
				}
			}
			else if (t[q[i][j]] == 1 && !used[q[i][j]] && !v[n])
			{
				v[n] = q[i][j];
				used[v[n]] = true;
				for (int j = 0; j < 3; ++j)
				{
					if (t[q[i][j]] == 2)
					{
						v[n - 1] = q[i][j];
						used[v[n - 1]] = true;
						break;
					}
				}
			}
		}
	}

	int pre1 = v[1], pre2 = v[2];

	//第i个数
	for (int i = 3; i <= n - 2; ++i)
	{
		for (int j = 1; j <= n - 2; ++j)
		{
			if (!used2[j])
			{
				int m = check(pre1, pre2, q[j]);
				if (m != -1 && !used[m] && t[m] == 3)
				{
					v[i] = m;
					used[m] = true;
					used2[j] = true;
					pre1 = pre2;
					pre2 = m;
					break;
				}
			}
		}
	}

	for (int i = 1; i <= n; ++i)
	{
		printf("%d ", v[i]);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1e5 + 5;
int q[N][3];
int t[N];
int v[N];
bool used[N];

int check(int pre1, int pre2, int q[])
{
	int flag = 0;
	int d = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (q[i] == pre1 || q[i] == pre2)
		{
			++d;
		}
		else
		{
			flag = q[i];
		}
	}
	if (d == 2)
		return flag;
	return -1;
}
int main()
{
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n - 2; ++i)
	{
		scanf("%d%d%d", &q[i][0], &q[i][1], &q[i][2]);
		++t[q[i][0]], ++t[q[i][1]], ++t[q[i][2]];
	}

	for (int i = 1; i <= n - 2; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			if (t[q[i][j]] == 1 && v[1] == 0)
			{
				v[1] = q[i][j];
				used[q[i][j]] = true;
				//将同一个组中出现次数为2的数标记
				for(int k = 0; k <= 3; ++k)
					if (t[q[i][k]] == 2)
					{
						v[2] = q[i][k];
						used[q[i][k]] = true;
						break;
					}
			}
			else if (t[q[i][j]] == 1)
			{
				v[n] = q[i][j];
				used[q[i][j]] = true;
				for (int k = 0; k <= 3; ++k)
					if (t[q[i][k]] == 2)
					{
						v[n - 1] = q[i][k];
						used[q[i][k]] = true;
						break;
					}
			}
		}
	}

	int pre1 = v[1], pre2 = v[2];

	//第i个数
	for (int i = 3; i <= n - 2; ++i)
	{
		for (int j = 1; j <= n - 2; ++j)
		{
			int m = check(pre1, pre2, q[j]);
			if (m != -1 && !used[m])
			{
				v[i] = m;
				pre1 = pre2;
				pre2 = m;
				break;
			}
		}
	}

	for (int i = 1; i <= n; ++i)
	{
		printf("%d ", v[i]);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;
const int N = 1e5 + 5;
int t[N];
vector<int> v[N];
bool used[N];
int ans[N];
int main()
{
	int n;
	scanf("%d", &n);

	int a, b, c;
	for (int i = 1; i <= n - 2; ++i)
	{
		scanf("%d%d%d", &a, &b, &c);
		++t[a], ++t[b], ++t[c];
		v[a].push_back(b), v[a].push_back(c);
		v[b].push_back(a), v[b].push_back(c);
		v[c].push_back(a), v[c].push_back(b);
	}
	int pre1, pre2;
	for (int i = 1; i <= n; ++i)
	{
		if (t[i] == 1)
		{
			ans[1] = i;
			used[i] = true;
			for (auto e : v[i])
			{
				if (t[e] == 2)
				{
					ans[2] = e;
					used[e] = true;
				}
			}
			break;
		}
	}

	for (int i = 3; i <= n; ++i)
	{
		for (auto e1 : v[ans[i - 2]])
		{
			for (auto e2 : v[ans[i - 1]])
			{
				if (e1 == e2)
				{
					ans[i] = e1;
					used[e1] = true;
					goto here;
				}
			}
		}
		here://标签地方
	}

	for (int i = 1; i <= n; ++i)
	{
		printf("%d ", ans[i]);
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int N = 1e5 + 5;
int q[N][3];
int t[N];
int v[N];
bool used[N];

int check(int pre1, int pre2, int q[])
{
	int flag = 0;
	int d = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (q[i] == pre1 || q[i] == pre2)
		{
			++d;
		}
		else
		{
			flag = q[i];
		}
	}
	if (d == 2)
		return flag;
	return -1;
}
int main()
{
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n - 2; ++i)
	{
		scanf("%d%d%d", &q[i][0], &q[i][1], &q[i][2]);
		++t[q[i][0]], ++t[q[i][1]], ++t[q[i][2]];
	}

	for (int i = 1; i <= n - 2; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			if (t[q[i][j]] == 1 && v[1] == 0)
			{
				v[1] = q[i][j];
				used[q[i][j]] = true;
				//将同一个组中出现次数为2的数标记
				for(int k = 0; k <= 3; ++k)
					if (t[q[i][k]] == 2)
					{
						v[2] = q[i][k];
						used[q[i][k]] = true;
						break;
					}
			}
			else if (t[q[i][j]] == 1)
			{
				v[n] = q[i][j];
				used[q[i][j]] = true;
				for (int k = 0; k <= 3; ++k)
					if (t[q[i][k]] == 2)
					{
						v[n - 1] = q[i][k];
						used[q[i][k]] = true;
						break;
					}
			}
		}
	}

	int pre1 = v[1], pre2 = v[2];

	//第i个数
	for (int i = 3; i <= n - 2; ++i)
	{
		for (int j = 1; j <= n - 2; ++j)
		{
			int m = check(pre1, pre2, q[j]);
			if (m != -1 && !used[m])
			{
				v[i] = m;
				pre2 = pre1;
				pre2 = m;
				break;
			}
		}
	}

	for (int i = 1; i <= n; ++i)
	{
		printf("%d ", v[i]);
	}
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;
const int N = 1e5 + 5;
int t[N];
vector<int> v[N];
bool used[N];
int ans[N];
int main()
{
	int n;
	scanf("%d", &n);

	int a, b, c;
	for (int i = 1; i <= n - 2; ++i)
	{
		scanf("%d%d%d", &a, &b, &c);
		++t[a], ++t[b], ++t[c];
		v[a].push_back(b), v[a].push_back(c);
		v[b].push_back(a), v[b].push_back(c);
		v[c].push_back(a), v[c].push_back(b);
	}
	int pre1, pre2;
	for (int i = 1; i <= n; ++i)
	{
		if (t[i] == 1)
		{
			ans[1] = i;
			used[i] = true;
			for (auto e : v[i])
			{
				if (t[e] == 2)
				{
					ans[2] = e;
					used[e] = true;
				}
			}
			break;
		}
	}

	for (int i = 3; i <= n; ++i)
	{
		for (auto e1 : v[ans[i - 2]])
		{
			for (auto e2 : v[ans[i - 1]])
			{
				if (e1 == e2 && !used[e1])
				{
					ans[i] = e1;
					used[e1] = true;
					goto here;
				}
			}
		}
		here:;//标签地方
	}

	for (int i = 1; i <= n; ++i)
	{
		printf("%d ", ans[i]);
	}

	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstring>
#include <unordered_map>
#include <algorithm>

using namespace std;
const int N = 1e5 + 5;
int q[N][3];
unordered_map<int, int> t;
int v[N];
bool used[N];
bool used2[N];

int check(int pre1, int pre2, int q[])
{
	int flag = 0;
	int d = 0;
	for (int i = 0; i < 3; ++i)
	{
		if (q[i] == pre1 || q[i] == pre2)
		{
			++d;
		}
		else
		{
			flag = q[i];
		}
	}
	if (d == 2)
		return flag;
	return -1;
}
int main()
{
	int n;
	scanf("%d", &n);

	for (int i = 1; i <= n - 2; ++i)
	{
		scanf("%d%d%d", &q[i][0], &q[i][1], &q[i][2]);
		++t[q[i][0]], ++t[q[i][1]], ++t[q[i][2]];
	}

	for (int i = 1; i <= n - 2; ++i)
	{
		if (v[1] != 0 && v[n] != 0)
			break;
		for (int j = 0; j < 3; ++j)
		{
			if (t[q[i][j]] == 1 && !used[q[i][j]] && v[1] == 0)
			{
				v[1] = q[i][j];
				used[q[i][j]] = true;
				int m1, m2;
				if (j == 0) m1 = j + 1, m2 = j + 2;
				else if (j == 1) m1 = j - 1, m2 = j + 1;
				else if (j == 2) m1 = j - 2, m2 = j - 1;
				if (t[q[i][m1]] == 2)
				{
					v[2] = q[i][m1];
					used[q[i][m1]] = true;
					break;
				}
				else if (t[q[i][m2]] == 2)
				{
					v[2] = q[i][m2];
					used[q[i][m2]] = true;
					break;
				}
			}
			else if (t[q[i][j]] == 1 && !used[q[i][j]] && v[n] == 0)
			{
				v[n] = q[i][j];
				used[q[i][j]] = true;
				int m1, m2;
				if (j == 0) m1 = j + 1, m2 = j + 2;
				else if (j == 1) m1 = j - 1, m2 = j + 1;
				else if (j == 2) m1 = j - 2, m2 = j - 1;
				if (t[q[i][m1]] == 2)
				{
					v[n - 1] = q[i][m1];
					used[q[i][m1]] = true;
					break;
				}
				else if (t[q[i][m2]] == 2)
				{
					v[n - 1] = q[i][m2];
					used[q[i][m2]] = true;
					break;
				}
			}
		}
	}

	int pre1 = v[1], pre2 = v[2];

	//第i个数
	for (int i = 3; i <= n - 2; ++i)
	{
		for (int j = 1; j <= n - 2; ++j)
		{
			if (!used2[j])
			{
				int m = check(pre1, pre2, q[j]);
				if (m != -1 && !used[m] && t[m] == 3)
				{
					v[i] = m;
					used[m] = true;
					used2[j] = true;
					pre1 = pre2;
					pre2 = m;
					break;
				}
			}
		}
	}

	for (int i = 1; i <= n; ++i)
	{
		printf("%d ", v[i]);
	}
	return 0;
}


/******************************************
* AUTHOR : SOMU KUMAR *
* INSTITUTION : IIT BHUBANESWAR *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define maxi(a,b,c) max(max(a,b),c)
#define mini(a,b,c) min(min(a,b),c)
struct node
{
	int x,y,z;

};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//code here...............//
int n;
cin>>n;
node arr[n-2];
int cnt[n+1];
map<pair<int,int> ,vector<int> >bchale;
for(int i=1;i<=n;i++)cnt[i]=0;
for(int i=0;i<n-2;i++){
	int a,b,c;
	cin>>a>>b>>c;
	arr[i].x=a;
	arr[i].y=b;
	arr[i].z=c;
	cnt[a]++;
	cnt[b]++;
	cnt[c]++;
	bchale[make_pair(a,b)].push_back(c);
	bchale[make_pair(a,c)].push_back(b);
	bchale[make_pair(b,a)].push_back(c);
	bchale[make_pair(c,a)].push_back(b);
	bchale[make_pair(b,c)].push_back(a);
	bchale[make_pair(c,b)].push_back(a);
}
for(int i=0;i<n-2;i++){
	if(cnt[arr[i].x]==1||cnt[arr[i].y]==1||cnt[arr[i].z]==1){
		node tmp;
		tmp=arr[i];
		arr[i]=arr[0];
		arr[0]=tmp;
		int a,b,c;
		if(cnt[arr[0].x]==1)a=arr[0].x;
		else if(cnt[arr[0].x]==2)b=arr[0].x;
		else c=arr[0].x;
		if(cnt[arr[0].y]==1)a=arr[0].y;
		else if(cnt[arr[0].y]==2)b=arr[0].y;
		else c=arr[0].y;
		if(cnt[arr[0].z]==1)a=arr[0].z;
		else if(cnt[arr[0].z]==2)b=arr[0].z;
		else c=arr[0].z;
		arr[0].x=a;
		arr[0].y=b;
		arr[0].z=c;
	}
}
int a,b,c;
cout<<arr[0].x<<" "<<arr[0].y<<" "<<arr[0].z<<" ";
a=arr[0].y;
b=arr[0].z;
bool vis[n+1];
for(int i=1;i<=n;i++)vis[i]=false;
vis[arr[0].x]=true;
vis[arr[0].y]=true;
vis[arr[0].z]=true;
for(int i=0;i<n-3;i++){
	 c=bchale[make_pair(a,b)][0];
	 if(!vis[c]){
	 	vis[c]=true;
        a=b;
	    b=c;
	   cout<<c<<" ";
	 }
	else{
	 c=bchale[make_pair(a,b)][1];
	 vis[c]=true;
	 a=b;
	    b=c;
	   cout<<c<<" ";
	}

}
cout<<endl;
return 0;
}


/******************************************
* AUTHOR : SOMU KUMAR *
* INSTITUTION : IIT BHUBANESWAR *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define maxi(a,b,c) max(max(a,b),c)
#define mini(a,b,c) min(min(a,b),c)
struct node
{
	int x,y,z;

};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//code here...............//
int n;
cin>>n;
node arr[n-2];
int cnt[n+1];
map<pair<int,int> ,vector<int> >bchale;
for(int i=1;i<=n;i++)cnt[i]=0;
for(int i=0;i<n-2;i++){
	int a,b,c;
	cin>>a>>b>>c;
	arr[i].x=a;
	arr[i].y=b;
	arr[i].z=c;
	cnt[a]++;
	cnt[b]++;
	cnt[c]++;
	bchale[make_pair(a,b)].push_back(c);
	bchale[make_pair(a,c)].push_back(b);
	bchale[make_pair(b,a)].push_back(c);
	bchale[make_pair(c,a)].push_back(b);
	bchale[make_pair(b,c)].push_back(a);
	bchale[make_pair(c,b)].push_back(a);
}
for(int i=0;i<n-2;i++){
	if(cnt[arr[i].x]==1||cnt[arr[i].y]==1||cnt[arr[i].z]==1){
		node tmp;
		tmp=arr[i];
		arr[i]=arr[0];
		arr[0]=tmp;
		int a,b,c;
		if(cnt[arr[0].x]==1)a=arr[0].x;
		else if(cnt[arr[0].x]==2)b=arr[0].x;
		else c=arr[0].x;
		if(cnt[arr[0].y]==1)a=arr[0].y;
		else if(cnt[arr[0].y]==2)b=arr[0].y;
		else c=arr[0].y;
		if(cnt[arr[0].z]==1)a=arr[0].z;
		else if(cnt[arr[0].z]==2)b=arr[0].z;
		else c=arr[0].z;
		arr[0].x=a;
		arr[0].y=b;
		arr[0].z=c;
	}
}
int a,b,c;
cout<<arr[0].x<<" "<<arr[0].y<<" "<<arr[0].z<<" ";
a=arr[0].y;
b=arr[0].z;
map<pair<int,int> ,int>hii;
bool vis[n+1];
for(int i=1;i<=n;i++)vis[i]=false;
vis[arr[0].x]=true;
vis[arr[0].y]=true;
vis[arr[0].z]=true;
for(int i=0;i<n-3;i++){
	 c=bchale[make_pair(a,b)][hii[make_pair(a,b)]];
	 if(!vis[c]){
	 	vis[c]=true;
        a=b;
	    b=c;
	   cout<<c<<" ";
	 }
	 hii[make_pair(a,b)]++;

}
cout<<endl;
return 0;
}


/******************************************
* AUTHOR : SOMU KUMAR *
* INSTITUTION : IIT BHUBANESWAR *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define maxi(a,b,c) max(max(a,b),c)
#define mini(a,b,c) min(min(a,b),c)
struct node
{
	int x,y,z;

};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//code here...............//
int n;
cin>>n;
node arr[n-2];
int cnt[n+1];
map<pair<int,int> ,vector<int> >bchale;
for(int i=1;i<=n;i++)cnt[i]=0;
for(int i=0;i<n-2;i++){
	int a,b,c;
	cin>>a>>b>>c;
	arr[i].x=a;
	arr[i].y=b;
	arr[i].z=c;
	cnt[a]++;
	cnt[b]++;
	cnt[c]++;
	bchale[make_pair(a,b)].push_back(c);
	bchale[make_pair(a,c)].push_back(b);
	bchale[make_pair(b,a)].push_back(c);
	bchale[make_pair(c,a)].push_back(b);
	bchale[make_pair(b,c)].push_back(a);
	bchale[make_pair(c,b)].push_back(a);
}
for(int i=0;i<n-2;i++){
	if(cnt[arr[i].x]==1||cnt[arr[i].y]==1||cnt[arr[i].z]==1){
		node tmp;
		tmp=arr[i];
		arr[i]=arr[0];
		arr[0]=tmp;
		int a,b,c;
		if(cnt[arr[0].x]==1)a=arr[0].x;
		else if(cnt[arr[0].x]==2)b=arr[0].x;
		else c=arr[0].x;
		if(cnt[arr[0].y]==1)a=arr[0].y;
		else if(cnt[arr[0].y]==2)b=arr[0].y;
		else c=arr[0].y;
		if(cnt[arr[0].z]==1)a=arr[0].z;
		else if(cnt[arr[0].z]==2)b=arr[0].z;
		else c=arr[0].z;
		arr[0].x=a;
		arr[0].y=b;
		arr[0].z=c;
	}
}
int a,b,c;
cout<<arr[0].x<<" "<<arr[0].y<<" "<<arr[0].z<<" ";
a=arr[0].y;
b=arr[0].z;
map<pair<int,int> ,int>hii;
bool vis[n+1];
for(int i=1;i<=n;i++)vis[i]=false;
vis[arr[0].x]=true;
vis[arr[0].y]=true;
vis[arr[0].z]=true;
for(int i=0;i<n-3;i++){
	 c=bchale[make_pair(a,b)][hii[make_pair(a,b)]];
	 if(!vis[c]){
	 	vis[c]=true;
        a=b;
	    b=c;
	 }
	 cout<<c<<" ";
	 hii[make_pair(a,b)]++;

}
cout<<endl;
return 0;
}


/******************************************
* AUTHOR : SOMU KUMAR *
* INSTITUTION : IIT BHUBANESWAR *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define maxi(a,b,c) max(max(a,b),c)
#define mini(a,b,c) min(min(a,b),c)
struct node
{
	int x,y,z;

};
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//code here...............//
int n;
cin>>n;
node arr[n-2];
int cnt[n+1];
for(int i=1;i<=n;i++)cnt[i]=0;
for(int i=0;i<n-2;i++){
	int a,b,c;
	cin>>a>>b>>c;
	arr[i].x=a;
	arr[i].y=b;
	arr[i].z=c;
	cnt[a]++;
	cnt[b]++;
	cnt[c]++;
}
for(int i=0;i<n-2;i++){
	if(cnt[arr[i].x]==1||cnt[arr[i].y]==1||cnt[arr[i].z]==1){
		node tmp;
		tmp=arr[i];
		arr[i]=arr[0];
		arr[0]=tmp;
		int a,b,c;
		if(cnt[arr[0].x]==1)a=arr[0].x;
		else if(cnt[arr[0].x]==2)b=arr[0].x;
		else c=arr[0].x;
		if(cnt[arr[0].y]==1)a=arr[0].y;
		else if(cnt[arr[0].y]==2)b=arr[0].y;
		else c=arr[0].y;
		if(cnt[arr[0].z]==1)a=arr[0].z;
		else if(cnt[arr[0].z]==2)b=arr[0].z;
		else c=arr[0].z;
		arr[0].x=a;
		arr[0].y=b;
		arr[0].z=c;
	}
}
for(int i=0;i<n-2;i++){
	int a=arr[0].y;
	int b=arr[0].z;
	//search for triplet which contain a and b;
	for(int j=i+1;j<n-2;j++){
		map<int,bool >m;
		m[arr[j].x]=true;
		m[arr[j].y]=true;
		m[arr[j].z]=true;
		if(m[a]&&m[b]){
			//mil gya;
			node tmp=arr[i+1];
			arr[i+1].x=a;
			m.erase(a);
			arr[i+1].y=b;
			m.erase(b);
			map<int,bool>::iterator itr=m.begin();
			arr[i+1].z=itr->first;
			arr[j]=tmp;
           break;
		}
	}
}
bool vis[n+1];
vector<int>v;
for(int i=1;i<=n;i++)vis[i]=false;
for(int i=0;i<n-2;i++){
   if(!vis[arr[i].x])v.push_back(arr[i].x);
   if(!vis[arr[i].y])v.push_back(arr[i].y);
   if(!vis[arr[i].z])v.push_back(arr[i].z);
   vis[arr[i].x]=true;
   vis[arr[i].y]=true;
   vis[arr[i].z]=true;
}
for(int i=0;i<v.size();i++)cout<<v[i]<<" ";
cout<<endl;

return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5+2;
vector<int> v[maxn];
int n,x,y,z;
int cnt[maxn];
int vist[maxn];
int main()
{
    cin>>n;
    for(int i=0;i<n-2;i++){
        cin>>x>>y>>z;
        v[x].push_back(y);v[x].push_back(z);
        v[y].push_back(x);v[y].push_back(z);
        v[z].push_back(y);v[z].push_back(x);
    }
    for(int i=1;i<=n;i++){
        if(cnt[i]==1){
            x=i;
            break;
        }
    }
    if(cnt[v[x][0]]==2)
        y=v[x][0];
    else
        y=v[x][1];
    vis[x]=vis[y]=1;
    cout<<x<<" "<<y<<" ";
    for(int i=0;i<n-2;i++){
        for(int j=0;j<v[x].size();j++){
            if(!vis[v[x][j]]==0){
                z=v[x][j];
            }
        }
        vis[z]=1;
        cout<<z<<" ";
        x = y;
        y = z;
    }
    return 0;
}


#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 1e5+2;
vector<int> v[maxn];
int n,x,y,z;
int cnt[maxn];
int vis[maxn];
int main()
{
    cin>>n;
    for(int i=0;i<n-2;i++){
        cin>>x>>y>>z;
        v[x].push_back(y);v[x].push_back(z);
        v[y].push_back(x);v[y].push_back(z);
        v[z].push_back(y);v[z].push_back(x);
    }
    for(int i=1;i<=n;i++){
        if(cnt[i]==1){
            x=i;
            break;
        }
    }
    if(cnt[v[x][0]]==2)
        y=v[x][0];
    else
        y=v[x][1];
    vis[x]=vis[y]=1;
    cout<<x<<" "<<y<<" ";
    for(int i=0;i<n-2;i++){
        for(int j=0;j<v[x].size();j++){
            if(!vis[v[x][j]]==0){
                z=v[x][j];
            }
        }
        vis[z]=1;
        cout<<z<<" ";
        x = y;
        y = z;
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5+2;
vector<int> v[maxn];
int n,x,y,z;
int cnt[maxn];
int vis[maxn];
int main()
{
    cin>>n;
    for(int i=0;i<n-2;i++){
        cin>>x>>y>>z;
        cnt[x]++; cnt[y]++; cnt[z]++;
        v[x].push_back(y);v[x].push_back(z);
        v[y].push_back(x);v[y].push_back(z);
        v[z].push_back(y);v[z].push_back(x);
    }
    for(int i=1;i<=n;i++){
        if(cnt[i]==1){
            x=i;
            break;
        }
    }
    if(cnt[v[x][0]]==2)
        y=v[x][0];
    else
        y=v[x][1];
    vis[x]=vis[y]=1;
    cout<<x<<" "<<y<<" ";
    for(int i=0;i<n-2;i++){
        for(int j=0;j<v[x].size();j++){
            if(!vis[v[x][j]]==0){
                z=v[x][j];
            }
        }
        vis[z]=1;
        cout<<z<<" ";
        x = y;
        y = z;
    }
    return 0;
}