Sam lives in Awesomeburg, its downtown has a triangular shape. Also, the following is true about the triangle:  its vertices have integer coordinates,  the coordinates of vertices are non-negative, and  its vertices are not on a single line. He calls a point on the downtown's border (that is the border of the triangle) safe if he can reach this point from at least one point of the line $$$y = 0$$$ walking along some straight line, without crossing the interior of the triangle.  In the picture the downtown is marked with grey color. The first path is invalid because it does not go along a straight line. The second path is invalid because it intersects with the interior of the downtown. The third and fourth paths are correct. Find the total length of the unsafe parts of the downtown border. It can be proven that these parts are segments and their number is finite.

Each test contains multiple test cases. The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. Description of the test cases follows. Each test case contains three lines, each of them contains two integers $$$x_i$$$, $$$y_i$$$ ($$$0 \le x_i, y_i \le 10^9$$$) — coordinates of the vertices of the downtown's border.

For each test case print a single number — the answer to the problem. Your answer will be considered correct if its absolute or relative error does not exceed $$$10^{-9}$$$. Formally let your answer be $$$a$$$, jury answer be $$$b$$$. Your answer will be considered correct if $$$\frac{|a - b|}{\max{(1, |b|)}} \le 10^{-9}$$$.

NoteIn the picture, the downtowns of the first three test cases are illustrated. Triangles are enumerated according to the indices of test cases they belong to.  In the first two test cases, all points on the borders of the downtowns are safe, thus the answers are $$$0$$$.In the following picture unsafe points for the third test case are marked with black color:  In the fourth test case, all points on the border of the downtown are safe.

-- 2022-10-10 07:00:20.583467 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-10 05:34:12.847108 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-10 03:05:57.80729 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-10 01:20:05.528045 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-10 01:11:57.544258 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-10 01:04:00.432705 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-10 00:57:39.012381 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 23:00:23.984016 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 21:55:37.897201 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 20:50:59.668161 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 20:21:45.535218 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 18:29:26.241871 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 18:28:05.760054 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 16:16:43.252694 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 16:13:18.714176 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 16:11:18.800261 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 16:11:07.522334 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.Bits
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
shiftLError :: Int -> Int -> Int
shiftLError i j | j < 0 = error "shiftLError: negative shift"
                | otherwise = Data.Bits.shiftL i j
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> (\triangle_6989586621679078054 -> Data.Maybe.fromMaybe 0 (distanceBetweenPointsOfLine <$> hasHorizontalLineAbove triangle_6989586621679078054)) a
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 05:24:13.766205 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> Data.Maybe.fromMaybe 0 (fmap (\b -> distanceBetweenPointsOfLine b) (hasHorizontalLineAbove a))
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-10-09 05:19:27.250997 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Bits
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty((:|)), (<|))
import Data.Map (Map)
import Data.Set (Set)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
safeFiveHeadTail :: [a] -> Maybe (a, a, a, a, a, [a])
safeFiveHeadTail (l1 : (l2 : (l3 : (l4 : (l5 : l6))))) = Just (l1,
                                                               l2,
                                                               l3,
                                                               l4,
                                                               l5,
                                                               l6)
safeFiveHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
          prettyPutStrLn a = prettyPutStr a >> putStrLn ""
          prettyPutStr :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStr = putStr . show
instance PrettyPutStrLn Integer
    where prettyPutStr = putStr . show
instance PrettyPutStrLn ([Char])
    where prettyPutStr = putStr
instance PrettyPutStrLn ([[Char]])
    where prettyPutStr a = mapM_ putStrLn (init a) >> putStr (last a)
instance PrettyPutStrLn Double
    where prettyPutStr d = putStrLn $ Numeric.showFFloat (Just 6) d ""
instance PrettyPutStrLn a => PrettyPutStrLn (a, a)
    where prettyPutStr (a,
                        b) = (prettyPutStr a >> putStrLn " ") >> prettyPutStr b
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Double Double deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving (Ord, Show)
data Slope = InfiniteSlope | FiniteSlope Double deriving Show
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((y1 - y0) / (x1 - x0))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
mkLineWithSlopeAndPoint :: Double -> Point -> Line2D
mkLineWithSlopeAndPoint slope (Point x
                                     y) = Line2D (Point x y) (Point (0 / 1) (y - (slope * x)))
offsetOfLine :: Line2D -> Double
offsetOfLine (l@(Line2D (Point x0 y0) _)) = y0 - (slope * x0)
                 where slope = case slopeOfLine l of
                                   InfiniteSlope -> error "offsetOfLine: InfiniteSlope"
                                   FiniteSlope s -> s
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
hasHigherX :: Point -> Point -> Bool
hasHigherX (Point x1 _) (Point x2 _) = x1 > x2
hasHigherY :: Point -> Point -> Bool
hasHigherY (Point _ y1) (Point _ y2) = y1 > y2
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
linesIntersect :: Line2D -> Line2D -> Bool
linesIntersect (l1@(Line2D (Point x1 _) _)) (l2@(Line2D (Point x2
                                                               _)
                                                        _)) = case (slopeOfLine l1,
                                                                    slopeOfLine l2) of
                                                                  (InfiniteSlope,
                                                                   InfiniteSlope) -> x1 == x2
                                                                  (InfiniteSlope,
                                                                   FiniteSlope _) -> True
                                                                  (FiniteSlope _,
                                                                   InfiniteSlope) -> True
                                                                  (FiniteSlope slope1,
                                                                   FiniteSlope slope2) -> slope1 /= slope2
class Show a => PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          shapeIntersectsAnother :: PolygonShape b => a -> b -> Bool
          shapeIntersectsAnother shapeA shapeB = f shapeA pointsB || f shapeB pointsA
                                     where pointsA = shapeCenter shapeA <| shapeCorners shapeA
                                           pointsB = shapeCenter shapeB <| shapeCorners shapeB
                                           f shape = any ((== LiesInside) . isInside shape)
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
          shapeCorners :: a -> NonEmpty Point
          shapeCenter :: a -> Point
data Rectangle
    = Rectangle Point Point Point Point
    deriving (Eq, Show)
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Rectangle p1
                                  p2
                                  p3
                                  p4) = Data.List.NonEmpty.fromList [p1, p2, p3, p4]
          shapeCenter (Rectangle _
                                 (Point x1 y1)
                                 _
                                 (Point x2
                                        y2)) = Point (x1 + ((x2 - x1) / 2)) (y1 + ((y2 - y1) / 2))
data Triangle = Triangle Point Point Point deriving (Eq, Show)
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
          shapeCorners (Triangle p1 p2 p3) = Data.List.NonEmpty.fromList [p1,
                                                                          p2,
                                                                          p3]
          shapeCenter _ = error "SHAPECENTER OF TRIANGLE NOT IMPLEMENTED YET"
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((x1 - x2) ^ (2 :: Int)) + ((y1 - y2) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
ifEvenOdd :: Int -> a -> a -> a
ifEvenOdd n a a' | (n `mod` 2) == 0 = a
                 | otherwise = a'
ifZero :: Int -> a -> a -> a
ifZero 0 a _ = a
ifZero _ _ a = a
sumOfIntsToN :: Int -> Int
sumOfIntsToN n = (n * (n - 1)) `div` 2
sumOfEvensToN :: Int -> Int
sumOfEvensToN n = n * (n + 1)
sumOfOddsToN :: Int -> Int
sumOfOddsToN n = n * n
countElemsThat :: (a -> Bool) -> [a] -> Int
countElemsThat f = length . Prelude.filter f
range :: Int -> Int -> [Int]
range a b = [a..b]
modError :: Integral a => a -> a -> a
modError a b | toInteger b == 0 = error "modError: division by zero"
             | otherwise = a `mod` b
mod10To9Plus7 :: Integral a => a -> a
mod10To9Plus7 = (`mod` 1000000007)
bigExponentiation :: Integer -> Int -> Integer
bigExponentiation = (^)
squares :: Set Int
squares = Data.Set.fromList $ map (\i -> i ^ (2 :: Int)) [1..1000000000]
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve :: Triangle -> Double
solve = \a -> (\triangle_6989586621680260963 -> Data.Maybe.fromMaybe 0 (distanceBetweenPointsOfLine <$> hasHorizontalLineAbove triangle_6989586621680260963)) a
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-09-02 18:18:29.066246 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty)
import Data.Map (Map)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStrLn = print
instance PrettyPutStrLn ([Char])
    where prettyPutStrLn = putStrLn
instance PrettyPutStrLn ([[Char]])
    where prettyPutStrLn = mapM_ putStrLn
instance PrettyPutStrLn Double
    where prettyPutStrLn d = putStrLn $ Numeric.showFFloat (Just 6) d ""
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Int Int deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving Ord
data Slope = InfiniteSlope | FiniteSlope Double
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((fromIntegral $ (y1 - y0)) / (fromIntegral $ (x1 - x0)))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
class PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
data Rectangle = Rectangle Point Point Point Point deriving Eq
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
data Triangle = Triangle Point Point Point deriving Eq
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((fromIntegral $ (x1 - x2)) ^ (2 :: Int)) + ((fromIntegral $ (y1 - y2)) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve = \a -> (\triangle_6989586621680498911 -> Data.Maybe.fromMaybe 0 (distanceBetweenPointsOfLine <$> hasHorizontalLineAbove triangle_6989586621680498911)) a
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

-- 2022-09-02 18:15:34.006663 UTC
{-# LANGUAGE FlexibleInstances #-}

import Data.Graph (Graph, Vertex, Forest, Tree)
import qualified Data.Maybe
import qualified Data.Graph
import qualified Data.Char
import qualified Control.Monad
import qualified Text.Read
import qualified Data.Map
import qualified Data.Tree
import qualified Data.Array
import qualified Data.Set
import qualified Data.ByteString.Char8
import qualified Data.ByteString
import qualified Data.List
import qualified Data.List.NonEmpty
import qualified Numeric
import Data.List.NonEmpty (NonEmpty)
import Data.Map (Map)
import Data.Array (Array, (!))
import Data.ByteString (ByteString)
import Debug.Trace

data GraphForProblems key
    = GraphForProblems {gpGraph :: Graph,
                        gpVertexFromKey :: (key -> Vertex),
                        gpNodeFromVertex :: (Vertex -> key)}
newtype GraphVertex a = GraphVertex a
instance Eq a => Eq (GraphVertex a)
    where (==) (GraphVertex a) (GraphVertex b) = a == b
unwrapGraphVertex :: GraphVertex i -> i
unwrapGraphVertex (GraphVertex i) = i
type IntGraph = GraphForProblems Int
type StringGraph = GraphForProblems String
data GraphEdge a = GraphEdge (GraphVertex a) (GraphVertex a)
instance Show (GraphForProblems key)
    where show (GraphForProblems {gpGraph = gpGraph}) = show gpGraph
instance Ord a => Ord (GraphVertex a)
    where compare (GraphVertex a) (GraphVertex b) = compare a b
edgeSource :: GraphEdge a -> GraphVertex a
edgeSource (GraphEdge a _) = a
edgeDest :: GraphEdge a -> GraphVertex a
edgeDest (GraphEdge _ b) = b
mkGraph :: (Ord key, Show key) =>
           [(node, key, [key])] -> GraphForProblems key
mkGraph nodesAndEdges = GraphForProblems gpGraph gpVertexFromKey gpNodeFromVertex
            where (gpGraph,
                   nodeFromVertex,
                   vertexFromKey) = Data.Graph.graphFromEdges nodesAndEdges
                  gpVertexFromKey k = case vertexFromKey k of
                                          Nothing -> error $ ("vertexFromKey: " <> (show k <> " key not found"))
                                          Just k' -> k'
                  gpNodeFromVertex v = let (_, k, _) = nodeFromVertex v
                                        in k
vertices' :: GraphForProblems a -> [GraphVertex a]
vertices' (GraphForProblems {gpGraph = gpGraph,
                             gpNodeFromVertex = gpNodeFromVertex}) = (GraphVertex . gpNodeFromVertex) <$> Data.Graph.vertices gpGraph
edges' :: GraphForProblems a -> [GraphEdge a]
edges' (GraphForProblems {gpGraph = gpGraph,
                          gpNodeFromVertex = gpNodeFromVertex}) = (\(a,
                                                                     b) -> GraphEdge (GraphVertex $ gpNodeFromVertex a) (GraphVertex $ gpNodeFromVertex b)) <$> Data.Graph.edges gpGraph
dfs' :: GraphForProblems key ->
        [GraphVertex key] -> [Tree (GraphVertex key)]
dfs' (GraphForProblems {gpVertexFromKey = gpVertexFromKey,
                        gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (fmap (GraphVertex . gpNodeFromVertex)) . (Data.Graph.dfs gpGraph . fmap (gpVertexFromKey . unwrapGraphVertex))
dfsOnSingleVertex :: GraphForProblems key ->
                     GraphVertex key -> Tree (GraphVertex key)
dfsOnSingleVertex g v = case dfs' g [v] of
                            [] -> error "dfsOnSingleVertex: empty result"
                            x : _ -> x
scc' :: GraphForProblems key -> [Tree (GraphVertex key)]
scc' (GraphForProblems {gpGraph = gpGraph,
                        gpNodeFromVertex = gpNodeFromVertex}) = fmap (GraphVertex . gpNodeFromVertex) <$> Data.Graph.scc gpGraph
levels' :: Tree (GraphVertex key) -> [[GraphVertex key]]
levels' = Data.Tree.levels
getSingleEnd :: Eq a =>
                GraphForProblems a -> GraphVertex a -> GraphVertex a
getSingleEnd g vertex = edgeDest $ (head $ (Prelude.filter ((== vertex) . edgeSource) $ edges' g))
getSingleLeaf :: Tree (GraphVertex a) -> GraphVertex a
getSingleLeaf = last . Data.Tree.flatten
flatten' :: Tree (GraphVertex a) -> [GraphVertex a]
flatten' = Data.Tree.flatten
elemTreeInt :: GraphVertex Int -> Tree (GraphVertex Int) -> Bool
elemTreeInt = elem
minimumTree :: Tree Int -> Int
minimumTree = minimum
mapTree :: (a -> b) -> Tree a -> Tree b
mapTree = fmap
newtype OutDegreeTable
  = OutDegreeTable {unOutDegreeTable :: (Array Vertex Int)}
linearGraph :: OutDegreeTable -> Bool
linearGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = twoOnes && restTwos
                where values = Data.Array.elems unOutDegreeTable
                      numValues = length values
                      twoOnes = 2 == length (Prelude.filter (== 1) values)
                      restTwos = (numValues - 2) == length (Prelude.filter (== 2) values)
cycleGraph :: OutDegreeTable -> Bool
cycleGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = allTwos
               where values = Data.Array.elems unOutDegreeTable
                     allTwos = all (== 2) values
starGraph :: OutDegreeTable -> Bool
starGraph (OutDegreeTable {unOutDegreeTable = unOutDegreeTable}) = onlyOneCenter && restOnes
              where values = Data.Array.elems unOutDegreeTable
                    numValues = length values
                    onlyOneCenter = 1 == length (Prelude.filter (== numValues - 1) values)
                    restOnes = (numValues - 1) == length (Prelude.filter (== 1) values)
outdegree' :: GraphForProblems a -> OutDegreeTable
outdegree' (GraphForProblems {gpGraph = gpGraph}) = OutDegreeTable{unOutDegreeTable = unOutDegreeTable}
               where unOutDegreeTable = Data.Graph.outdegree gpGraph
safeElems2 :: [a] -> Maybe (a, a)
safeElems2 [x1, x2] = Just (x1, x2)
safeElems2 _ = Nothing
safeElems3 :: [a] -> Maybe (a, a, a)
safeElems3 [x1, x2, x3] = Just (x1, x2, x3)
safeElems3 _ = Nothing
safeElems4 :: [a] -> Maybe (a, a, a, a)
safeElems4 [x1, x2, x3, x4] = Just (x1, x2, x3, x4)
safeElems4 _ = Nothing
safeElems5 :: [a] -> Maybe (a, a, a, a, a)
safeElems5 [x1, x2, x3, x4, x5] = Just (x1, x2, x3, x4, x5)
safeElems5 _ = Nothing
compareLength :: Int -> [b] -> Ordering
compareLength 0 ([]) = EQ
compareLength 0 _ = LT
compareLength i (_ : xs) | i < 0 = error "compareLength: negative length comparison does not make sense"
                         | otherwise = compareLength (i - 1) xs
consumeNElems :: Int -> [b] -> Maybe ([b], [b])
consumeNElems 0 ([]) = Just ([], [])
consumeNElems 0 xs = Just ([], xs)
consumeNElems _ ([]) = Nothing
consumeNElems i (x : xs) | i < 0 = error "consumeNElems: negative length comparison does not make sense"
                         | otherwise = do {(ys, zs) <- consumeNElems (i - 1) xs;
                                           return (x : ys, zs)}
groupTups2 :: [a] -> Maybe ([(a, a)])
groupTups2 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : rest)) = go ((x, y) : acc) rest
          go _ _ = Nothing
groupTups3 :: [a] -> Maybe ([(a, a, a)])
groupTups3 = go []
    where go acc ([]) = Just (reverse acc)
          go acc (x : (y : (z : rest))) = go ((x, y, z) : acc) rest
          go _ _ = Nothing
safeHeadTail :: [a] -> Maybe (a, [a])
safeHeadTail (l1 : l2) = Just (l1, l2)
safeHeadTail _ = Nothing
safeTwoHeadTail :: [a] -> Maybe (a, a, [a])
safeTwoHeadTail (l1 : (l2 : l3)) = Just (l1, l2, l3)
safeTwoHeadTail _ = Nothing
safeThreeHeadTail :: [a] -> Maybe (a, a, a, [a])
safeThreeHeadTail (l1 : (l2 : (l3 : l4))) = Just (l1, l2, l3, l4)
safeThreeHeadTail _ = Nothing
safeFourHeadTail :: [a] -> Maybe (a, a, a, a, [a])
safeFourHeadTail (l1 : (l2 : (l3 : (l4 : l5)))) = Just (l1,
                                                        l2,
                                                        l3,
                                                        l4,
                                                        l5)
safeFourHeadTail _ = Nothing
singleLine :: [ByteString] -> Maybe ByteString
singleLine [l] = Just l
singleLine _ = Nothing
class PrettyPutStrLn a
    where prettyPutStrLn :: a -> IO ()
instance PrettyPutStrLn Int
    where prettyPutStrLn = print
instance PrettyPutStrLn ([Char])
    where prettyPutStrLn = putStrLn
instance PrettyPutStrLn ([[Char]])
    where prettyPutStrLn = mapM_ putStrLn
instance PrettyPutStrLn Double
    where prettyPutStrLn d = putStrLn $ Numeric.showFFloat (Just 6) d ""
type ProblemInputOutputParser a = [ByteString] ->
                                  Maybe (a, [ByteString])
data Point = Point Int Int deriving (Eq, Ord)
instance Show Point
    where show (Point x y) = show (x, y)
data PointLiesInside = LiesInside | LiesOutside deriving Eq
liesInsideToBool :: PointLiesInside -> Bool
liesInsideToBool (LiesInside) = True
liesInsideToBool (LiesOutside) = False
data Line2D = Line2D Point Point deriving Ord
data Slope = InfiniteSlope | FiniteSlope Double
slopeOfLine :: Line2D -> Slope
slopeOfLine (Line2D (Point x0 y0)
                    (Point x1 y1)) | x0 == x1 = InfiniteSlope
                                   | otherwise = FiniteSlope $ ((fromIntegral $ (y1 - y0)) / (fromIntegral $ (x1 - x0)))
instance Eq Line2D
    where (==) l1 (Line2D p1 p2) = isInLine p1 l1 && isInLine p2 l1
data LinePointTest
    = AboveOrLeft | BelowOrRight | InLine
    deriving Eq
mkLineFromTwoPoints :: Point -> Point -> Line2D
mkLineFromTwoPoints p1 p2 | p1 == p2 = error $ ("p1 == p2: p1 = " <> (show p1 <> (" p2 = " <> show p2)))
                          | p1 < p2 = Line2D p1 p2
                          | otherwise = Line2D p2 p1
pointsInSameLine :: Point -> Point -> Point -> Bool
pointsInSameLine (Point x1 y1) (Point x2 y2) (Point x3
                                                    y3) = ((y3 - y1) * (x2 - x1)) == ((x3 - x1) * (y2 - y1))
isPointAboveLine :: Point -> Line2D -> LinePointTest
isPointAboveLine (Point x3 y3) (Line2D (Point x1 y1)
                                       (Point x2 y2)) = if l == 0
                                                         then InLine
                                                         else if l > 0
                                                               then AboveOrLeft
                                                               else BelowOrRight
                     where l = ((y3 - y1) * (x2 - x1)) - ((x3 - x1) * (y2 - y1))
isInLine :: Point -> Line2D -> Bool
isInLine p = (== InLine) . isPointAboveLine p
class PolygonShape a
    where isInside :: a -> Point -> PointLiesInside
          isInside polygon point = if and $ (fmap f $ linesOfWithComparisons polygon)
                                    then LiesInside
                                    else LiesOutside
                       where f (lineEq,
                                lineComps) = isPointAboveLine point lineEq `elem` lineComps
          linesOfWithComparisons :: a -> NonEmpty (Line2D, [LinePointTest])
data Rectangle = Rectangle Point Point Point Point deriving Eq
mkRectangle :: Point -> Point -> Point -> Point -> Maybe Rectangle
mkRectangle p1 p2 p3 p4 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p1 /= p4)));
                              Control.Monad.guard $ ((p2 /= p3) && (p2 /= p4));
                              Control.Monad.guard $ (p3 /= p4);
                              return $ Rectangle pymin pxmin pymax pxmax}
                where points = [p2, p3, p4]
                      pymin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y < accy
                                                                                then p
                                                                                else if y > accy
                                                                                then acc
                                                                                else if x > accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmin = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x < accx
                                                                                then p
                                                                                else if x > accx
                                                                                then acc
                                                                                else if y > accy
                                                                                then p
                                                                                else acc) p1 points
                      pymax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if y > accy
                                                                                then p
                                                                                else if y < accy
                                                                                then acc
                                                                                else if x < accx
                                                                                then p
                                                                                else acc) p1 points
                      pxmax = foldl (\(acc@(Point accx accy)) (p@(Point x
                                                                        y)) -> if x > accx
                                                                                then p
                                                                                else if x < accx
                                                                                then acc
                                                                                else if y < accy
                                                                                then p
                                                                                else acc) p1 points
isInsideRect :: Rectangle -> Point -> PointLiesInside
isInsideRect = isInside
instance PolygonShape Rectangle
    where linesOfWithComparisons (Rectangle p1
                                            p2
                                            p3
                                            p4) = Data.List.NonEmpty.fromList [(mk p1 p2,
                                                                                [AboveOrLeft,
                                                                                InLine]),
                                                                               (mk p2 p3,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p3 p4,
                                                                                [BelowOrRight,
                                                                                InLine]),
                                                                               (mk p4 p1,
                                                                                [AboveOrLeft,
                                                                                InLine])]
                                     where mk = mkLineFromTwoPoints
data Triangle = Triangle Point Point Point deriving Eq
mkTriangle :: Point -> Point -> Point -> Maybe Triangle
mkTriangle p1 p2 p3 = do {Control.Monad.guard $ ((p1 /= p2) && ((p1 /= p3) && (p2 /= p3)));
                          return $ Triangle p1 p2 p3}
instance PolygonShape Triangle
    where linesOfWithComparisons (Triangle p1
                                           p2
                                           p3) = Data.List.NonEmpty.fromList [(mk p1 p2, []),
                                                                              (mk p2 p3, []),
                                                                              (mk p3 p1, [])]
                                     where mk = mkLineFromTwoPoints
hasHorizontalLineAbove :: Triangle -> Maybe Line2D
hasHorizontalLineAbove (triangle@(Triangle p1
                                           p2
                                           p3)) = case Data.Maybe.mapMaybe horizontalLine triangleLines of
                                                      [l] -> case Prelude.filter (BelowOrRight ==) $ map (flip isPointAboveLine l) trianglePoints of
                                                                 [_] -> Just l
                                                                 [] -> Nothing
                                                                 _ -> error "INVALID CASE MORE THAN ONE BELOW VS ABOVE TEST hasHorizontalLineAbove"
                                                      [] -> Nothing
                                                      _ -> error "INVALID CASE MORE THAN ONE HORIZONTAL LINE hasHorizontalLineAbove"
                           where trianglePoints = [p1, p2, p3]
                                 triangleLines = map fst $ (Data.List.NonEmpty.toList $ linesOfWithComparisons triangle)
                                 horizontalLine (l@(Line2D (Point _ y1)
                                                           (Point _ y2))) | y1 == y2 = Just l
                                                                          | otherwise = Nothing
distanceBetweenPoints :: Point -> Point -> Double
distanceBetweenPoints (Point x1 y1) (Point x2
                                           y2) = sqrt $ (((fromIntegral $ (x1 - x2)) ^ (2 :: Int)) + ((fromIntegral $ (y1 - y2)) ^ (2 :: Int)))
distanceBetweenPointsOfLine :: Line2D -> Double
distanceBetweenPointsOfLine (Line2D p1
                                    p2) = distanceBetweenPoints p1 p2
nat_para :: Integral i => i -> a -> (i -> a -> a) -> a
nat_para i x f = np (abs i)
             where np 0 = x
                   np i = let i' = i - 1
                           in f i' (np i')
iF :: Bool -> a -> a -> a
iF (True) t f = t
iF (False) t f = f
list_para :: [b] -> a -> (b -> [b] -> a -> a) -> a
list_para ([]) x f = x
list_para (y : ys) x f = f y ys (list_para ys x f)
parseTriangle :: ProblemInputOutputParser Triangle
parseTriangle ws = do {(x0,
                        y0,
                        x1,
                        rest) <- safeThreeHeadTail ws >>= (\(x0Bs,
                                                             x1Bs,
                                                             x2Bs,
                                                             rest) -> do {(x0,
                                                                           _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                          (x1,
                                                                           _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                          (x2,
                                                                           _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                          return (x0,
                                                                                x1,
                                                                                x2,
                                                                                rest)});
                       (y1, x2, y2, remainingTkns) <- safeThreeHeadTail rest >>= (\(x0Bs,
                                                                                x1Bs,
                                                                                x2Bs,
                                                                                rest') -> do {(x0',
                                                                                _) <- Data.ByteString.Char8.readInt x0Bs;
                                                                                (x1',
                                                                                _) <- Data.ByteString.Char8.readInt x1Bs;
                                                                                (x2',
                                                                                _) <- Data.ByteString.Char8.readInt x2Bs;
                                                                                return (x0',
                                                                                x1',
                                                                                x2',
                                                                                rest')});
                       return (Triangle (Point (fromIntegral x0) (fromIntegral y0)) (Point (fromIntegral x1) (fromIntegral y1)) (Point (fromIntegral x2) (fromIntegral y2)),
                               remainingTkns)}
unpackParser f x1 = f x1
parser = parseTriangle
solve = \a -> (\triangle_6989586621680514869 -> Data.Maybe.fromMaybe 0 (distanceBetweenPointsOfLine <$> hasHorizontalLineAbove triangle_6989586621680514869)) a
applyFunctionWithParserUntilExhausted solver parser = go
                                          where go ([]) = return ()
                                                go inputBs = do case parser inputBs of
                                                                    Nothing -> error "UNEXPECTED ERROR WHILE PARSING"
                                                                    Just (result,
                                                                          remainingTkns) -> do {prettyPutStrLn $ solver result;
                                                                                go remainingTkns}
main :: IO ()
main = Data.ByteString.getContents >>= (applyFunctionWithParserUntilExhausted (unpackParser solve) parser . (tail . Data.ByteString.Char8.words))

import Data.List (permutations)
chunksOf :: Int -> [a] -> [[a]]
chunksOf _ [] = []
chunksOf i xs = take i xs : chunksOf i (drop i xs)

showArr :: Show a => [a] -> String
showArr = concatMap (\x -> show x ++ " ")

toArr :: Read a => String -> [a]
toArr = map read . words

getPair :: String -> (Int, Int)
getPair s = case toArr s of
              [x, y] -> (x, y)
              _      -> error "getPair failed"

type InType  = [(Int, Int)]
type OutType = Int

solve :: InType -> OutType
solve cs = maximum $ map test $ permutations cs

test :: [(Int, Int)] -> Int
test [(x1, y1), (x2, y2), (x3, y3)]
  | y1 == y2 && y1 > y3 = max x2 x1 - min x2 x1
  | otherwise           = 0
test _ = error "test failed"

receive :: [String] -> InType
receive = map getPair

main :: IO ()
main = interact $ unlines . map (show . solve . receive) . chunksOf 3 . tail . lines