main = do
  inputs <- getContents
  let n = read $ head . lines $ inputs :: Int
  let fs = map (\xs -> map read (words xs)) $ take n $ tail $ lines inputs :: [[Int]]
  let ps = map (\xs -> map read (words xs)) $ reverse $ take n $ reverse $ lines inputs :: [[Int]]
  print $ sum $ zipWith f (map sum fs) ps
  where
    f :: Int -> [Int] -> Int
    f x xs = maximum $ take (x+1) xs