type Point = (Double,Double) distance :: Point -> Point -> Double distance (px,py) (qx,qy) = sqrt (xd*xd + yd*yd) where xd = qx - px yd = qy - py pairs :: [a] -> [(a,a)] pairs [] = [] pairs (a:bs) = [(a,b) | b <- bs] ++ pairs bs solve :: [Point] -> Int solve [] = 0 solve ps = maximum (1 : xs) where xs = do (p,q) <- pairs ps c <- circles p q return $ length [x | x <- ps, distance c x <= 1 || x==p || x==q] -- 点p,qが円周にあるような円の中心点のリスト circles :: Point -> Point -> [Point] circles p@(px,py) q@(qx,qy) | d > 2 = [] | otherwise = [ (px + cos t, py + sin t) | let a = atan2 (qy - py) (qx - px) , let b = acos (d / 2) , t <- [a+b, a-b] ] where d = distance p q parseProblems :: String -> [[Point]] parseProblems s = f (lines s) where f (l:ls) | n==0 = [] | otherwise = case splitAt n ls of (ps,rest) -> map parsePoint ps : f rest where n = read l parsePoint :: String -> Point parsePoint s = case break (' '==) s of (x,y) -> (read x, read y) main :: IO () main = do s <- getContents let problems = parseProblems s answers = map solve problems mapM_ (putStrLn . show) answers