Farmer John built $n$ fences on his farm. The $i$-th fence is a line segment in the plane
whose two endpoints are $(x_{1i}, y_{1i})$ and $(x_{2i}, y_{2i})$. Two different fences
can only intersect at their endpoints.
The following picture shows an example layout of fences.
To make cows happy, John will decorate the fences with rope lights.
A fence can hang several rope lights paralleling to itself.
However, a light can not be used alone.
John can only make a decoration by using some lights together (we call it a
string of lights) and these lights will form a circle to decorate some fences (a light corresponds to a fence).
In the example, he can use three lights decorate three fences numbered $1, 2, 5$ which form a circle.
A string of lights which decorate fences numbered $k_1,k_2,\cdots,k_m$ costs John $\sum_{i=1}^m p_{k_i}$ dollars. The total cost is the sum of costs of each string. Notice that the cost for more than one
strings of lights should be accumulated.
In the example, suppose that he decorate the fences with two strings of lights. One string decorate three fences numbered $1, 2, 5$ and the other string decorate three fences numbered $1, 2, 3, 4$. Then the total cost should be $2\times p_1+2\times p_2+p_3+p_4+p_5 = 106$ dollars.
John can control the switch of
each string of lights. He can switch on
all lights on that string or switch off
all of them, but he cannot switch on some of they while keeping other lights on that string switched off.
For a fence, if even number of strings on it are switched on, then all the lights on that fence will not work; otherwise,
all of them work. We define the shape of lights as a combination of status of each fence (considering the fences lit or not). A shape of lights might be achieved by arrangements of lights. The following picture shows all possible shape of
lights in the example. (Dash lines stands for fences where lights work and the solid stands for fences where lights
don't work.)
The cows love lights, but they are fickle too. They want the lights arranged to form
different shapes from day to day, so John need to make arrangement for decorations so that
every possible shapes can be formed by switching on
some of the strings of lights and switching off the others.
What is the minimum money John must spend to meet needs of cows.
In the example, he can decorate the fences with two strings of lights.
One string decorate three fences numbered $1, 2, 5$ and the other string decorate three fences numbered $1, 2, 3, 4$.
If he switch off all strings, then cows can get the first shape; if he switch on all strings, then cows can get the last shape; if he switch on only the first string, then then cows can get the third shape; if he switch on only the second string, then then cows can get the second shape. Thus, he can spend 106 dollars to meet need of cows, and it also
turns out to be the minimum cost.