import Control.Monad import Data.List import qualified Data.IntMap.Strict as M main = do n <- (read :: String -> Int) <$> getLine s <- replicateM (n-1) ((map read :: [String] -> [Int]) . words <$> getLine) print (solve s) solve :: [[Int]] -> Int solve xs = foldl (\n v -> (max (v - 2) 0) + n) 0 (counter (concat xs) M.empty) counter :: [Int] -> M.IntMap Int -> M.IntMap Int counter [] count = count counter (x : xs) count = case M.lookup x count of Nothing -> counter xs (M.insert x 1 count) Just n -> counter xs (M.insert x (n+1) count)