a_sum, b_sum = *ARGF
  .each_line
  .drop(1)
  .lazy
  .map {|l| l.split(" ").map(&:to_i) }
  .map {|(a, b)|
    if a > b
      [a + b, 0]
    elsif a < b
      [0, a + b]
    else
      [a, b]
    end
  }
  .reduce([0, 0]) {|(a_ac, b_ac), (a_gain, b_gain)|
    [a_ac + a_gain, b_ac + b_gain]
  }

puts "#{a_sum} #{b_sum}"