Distance from a point to a line segment
Given a point (P) with coordinates ((P_x, P_y)) and a line segment (AB), where the endpoints have coordinates ((A_x, A_y)) and ((B_x, B_y)). The segment is guaranteed to be non-degenerate, meaning that (A) and (B) are distinct points.
Write a program to calculate the distance between the point (P) and the segment (AB).
**Note**: The distance between a point and a segment is defined as follows: if the point lies on the segment, the distance is zero; otherwise, it is the length of the shortest line segment that connects the point to any point on the segment.
Input
Read the input from standard input (keyboard) in the format: (P_x) (P_y) (A_x) (A_y) (B_x) (B_y) (all on one line). All coordinates are integers and their absolute values do not exceed 10,000.
Output
Output a single number representing the distance from the point to the segment. The result can be in exponential form or as a standard decimal fraction. The solution is considered correct if the error does not exceed (10^-4).