cho.sh
Notes
Loading...

Nuclear Bomb

Time limit

2s

Memory limit

128 MB

Problem

A dangerous waste point remains at one location in a peaceful city. The residents do not fully understand the danger, but they decide to surround that point with a wall.

There used to be N walls around the waste. Each wall is given as the line segment connecting its two endpoints, and rebuilding each collapsed wall has its own cost. The city may choose some or all of the given walls and wants to enclose the waste with minimum total cost.

The completed wall must be a convex polygon whose selected segments are completely connected at their endpoints. The waste point is never located on any given segment. However, because the old wall records may be inaccurate, two different input segments may cross each other.

Given the position of the waste and the wall information, compute the minimum cost needed to build a convex polygon-shaped wall enclosing the waste.

Input

The first line contains three integers N, X, and Y. (X, Y) is the position of the waste. 3 <= N <= 100.

Each of the next N lines contains five integers x1 y1 x2 y2 C, describing one wall. Rebuilding the wall segment connecting (x1, y1) and (x2, y2) costs C. 1 <= C <= 10000, and every coordinate is an integer whose absolute value is at most 10000.

Output

If it is possible to build a convex polygon-shaped wall enclosing the waste, print the minimum required cost. Otherwise, print -1.