Chiaki has a special machine which can generate permutations. You can give any restrictions to the machine, it will generate all the permutation under the restrictions .Chiaki has generated n restrictions and the i-th of them is that the position of ai should be less than the position of bi and ci.The restrictions generated by Chiaki are somewhat special and the sequence a1,a2,...,an, b1,b2,...,bn, c1, c2, ..., cn is a permutation of 1,2,...,3n.Among all the permutations generated by the machine, Chiaki would like to find one with minimum value.
Chiaki has a special machine which can generate permutations. You can give any restrictions to the machine, it will generate all the permutation under the restrictions . Chiaki has generated n restrictions and the i-th of them is that the position of ai should be less than the position of bi and ci. The restrictions generated by Chiaki are somewhat special and the sequence a1,a2,...,an, b1,b2,...,bn, c1, c2, ..., cn is a permutation of 1,2,...,3n. Among all the permutations generated by the machine, Chiaki would like to find one with minimum value. The value of a permutation p1,p2,...,pn is sumlimits_{i=2}^{n}|p_i-p_{i-1}| i=2 ∑ n ∣p i −p i−1 ∣.