eolymp
bolt
Try our new interface for solving problems
Problems

Factory

Factory

There are three machines on the new toy factory: \textbf{A}, \textbf{B} and \textbf{C}. The factory makes toys by processing each toy on these machines in order \textbf{A}, \textbf{B}, \textbf{C}. Your task is to create \textbf{N} toys as soon as possible. You know the time to process each toy on each machine: \textbf{a_i}, \textbf{b_i} and \textbf{c_i}. You can select an arbitrary order of processing toys. The second machine is so fast that at least one of the following two statements holds: \textbf{max(b_i)} ≤ \textbf{min(a_i)}, or \textbf{max(b_i)} ≤ \textbf{min(c_i)}. \InputFile The first line of the input contains the number of toys (\textbf{1} ≤ \textbf{n} ≤ \textbf{100000}). The next \textbf{N} lines contain three integers each: \textbf{a_i}, \textbf{b_i} and \textbf{c_i} (\textbf{1} ≤ \textbf{a_i}, \textbf{b_i},\textbf{c_i} ≤ \textbf{1000000}). \OutputFile Output the minimal possible processing time on the first line. The second line must contain an example of optimal processing order --- a permutation of toy numbers from \textbf{1} to \textbf{N}.
Time limit 2 seconds
Memory limit 64 MiB
Input example #1
5
3 1 6
1 1 2
5 2 5
7 1 4
10 2 8
Output example #1
33
2 1 3 5 4
Author Dmitry Gozman
Source Dmitry Gozman Contest 1, Petrozavodsk training camp, January 2007