import Control.Monad
f pn an tn=let pr=map ((\x y->sum(zipWith (\a b->if a==1&&b==1 then 1 else 0)))tn) an in sum$zipWith (\x y->y!!x) pr pn 
 main=do
 n<-readLn
 an<-replicateM n (map read.words<$>getLine)
 pn<-replicateM n (map read.words<$>getLine)
 print$maximum [f pn an (replicate x 1++replicate y 1)|x<-[1..n],y<-[1..n],x+y==n]