N-Sumaehwa Sword Technique
Time limit2sMemory limit1024 MB
Order N weighted line segments so that the total cost is minimized, where each stroke costs its weight times one plus the number of unperformed segments it crosses.
Problem
Elder Woo Kyung of Hwasan Sect created a new martial art, N-Sumaehwa Sword Technique. It is an advanced version of the Twenty-Four Sumaehwa Sword Technique and consists of strokes (cuts made with the sword).
The technique is performed on a two-dimensional plane. Stroke cuts in a straight line from point to point . The path the sword travels is called the path of stroke .
While performing the technique, each stroke costs internal energy according to the following principle.
- Stroke has a weight . Performing stroke costs units of internal energy, where is the number of strokes not yet performed at that moment whose paths intersect the path of stroke .
To complete the N-Sumaehwa Sword Technique, each of the strokes must be performed exactly once, in any order. Elder Woo Kyung wants to complete the technique using as little internal energy as possible. Find the minimum total internal energy needed to complete the N-Sumaehwa Sword Technique.
Input
The first line contains the number of strokes .
Each of the next lines gives, for stroke , the coordinates of , the coordinates of , and the weight , separated by spaces. ;
The points are all distinct, and no three of them lie on the same straight line.
All numbers in the input are integers.
Output
Print the minimum total internal energy needed to complete the N-Sumaehwa Sword Technique.