import Data.List
import qualified Data.Map as M
import Control.Monad

getInputData :: IO [(Int,Int)]
getInputData = do
 n <- read <$> getLine :: IO Int
 ans <- replicateM n ((\[x,y] -> (x-1,y)) . map read . words <$> getLine) 
 return ans

getHonestStatement ::  [[(Int, Int)]] -> [[(Int, Int)]] -> [Int] -> [[(Int, Int)]]
getHonestStatement statement ans choice
 | null choice = ans
 | otherwise   = getHonestStatement statement ((statement !! (head choice)):ans) (tail choice)
 
judge :: [(Int, Int)] -> Int
judge a = (\x -> if elem (-1) x then 0 else 1) $ map snd $ M.toList $ M.fromListWith (\x y -> if x == y then x else -1) a

getPremise :: Int -> [Int] -> [(Int, Int)]
getPremise n choise = union (zip ([0..(n-1)]\\choise) (repeat 0)) (zip (choise) (repeat 1))

main = do
 n <- read <$> getLine :: IO Int
 let choices = subsequences [0..(n-1)]
 statements <- replicateM n getInputData
 let ans1 = map length choices
 let ans2 = map judge $ zipWith (++) (map (getPremise n) choices) $ map (concat . (getHonestStatement statements [])) choices
 print $ maximum $ zipWith (*) ans1 ans2