import           Control.Applicative
import           Control.Monad
import           Control.Monad.State

convert :: Int -> String -> [Int]
convert n str = l ++ [sum l] where l = (take n . map read . words) str

sumrow :: [Int] -> [[Int]] -> [Int]
sumrow is = foldl sumrowf is

sumrowf :: [Int] -> [Int] -> [Int]
sumrowf []       _        = []
sumrowf _        []       = []
sumrowf (x : xs) (y : ys) = (x + y) : sumrowf xs ys

main = do
  n <- readLn
  case n of
    0 -> return ()
    _ -> do
      lines <- replicateM n (convert n <$> getLine)
      let result = lines ++ [sumrow (replicate (n + 1) 0) lines]
      sequence_ $ putStrLn . unwords . map show <$> result
      main

