import Data.List
main=interact$f.map read.words
f(n:p)=unlines$map(unwords.map show)[a,reverse b]where
  q=map snd.sort$zip p[1..n]
  [a,b]=map g[q,reverse q]
g p=zipWith(+)[1..].scanl(\t v->t+max v 0)0.zipWith(-)(tail p)$p