#P7056. Scandalous University Rating

    ID: 20262 Type: Default 1000ms 256MiB

Scandalous University Rating

Scandalous University Rating

Irene, a journalist, has received insider information consisting of several triples ((a_i, b_i, c_i)) from Ian. In each triple, university (b_i) is positioned between universities (a_i) and (c_i) in the upcoming rating, meaning that either the order is (a_i < b_i < c_i) or (c_i < b_i < a_i). All triples are consistent, so there exists a rating (i.e. a permutation of the universities) that satisfies all the triples. However, since constructing the perfect rating might be too hard, your task is to propose a rating that satisfies at least half of the given triples.

Input Format: The input begins with an integer (T) indicating the number of triples. Each of the following (T) lines contains three integers (a), (b), and (c), representing a triple ((a, b, c)). The set of universities is the union of all integers that appear in any triple.

Output Format: Output a permutation (a space‐separated list) of all the universities such that at least half of the triples are satisfied (i.e. for at least (\frac{T}{2}) of the triples, the university (b) appears between (a) and (c) in your ordering).

Note: A triple ((a, b, c)) is satisfied if in your permutation either (a < b < c) or (c < b < a) holds. It can be shown that for any set of triples, one can always find a permutation that satisfies at least half of them.

inputFormat

The first line contains an integer T indicating the number of triples. Each of the next T lines contains three integers a, b, and c separated by spaces, representing a triple \((a, b, c)\).

outputFormat

Output a single line containing a permutation (space-separated) of all distinct universities (integers) that appear in the input such that at least half of the triples are satisfied, where a triple \((a, b, c)\) is satisfied if either \(a < b < c\) or \(c < b < a\) in your permutation.

sample

3
1 2 3
1 3 4
2 3 4
1 2 3 4