• + 0 comments
    import Control.Monad (replicateM)
    
    -- Enter your code here. Read input from STDIN. Print output to STDOUT
    
    solve pairs = sum lengths
                where lines                    = zip pairs (tail pairs ++ [head pairs])
                      dst ( (x1,y1), (x2,y2) ) = ((x1 - x2)**2 + (y1 - y2)**2)**0.5
                      lengths                  = map (dst) lines
    main = do
        let toInt s  = read s :: Int
        let toDoub s = read s :: Double
        lines <- getLine >>= (\line -> return $ toInt line) >>= (\n -> replicateM n getLine)
        let pairs = map (\[x,y] -> (toDoub x, toDoub y)) . map words $ lines
        print (solve pairs)