a = 0
b = 0

begin
  File.open('cardGame.txt') do |file|
    file.read.split("\n").each do |line|

      line = line.split(" ").map {|num| num.to_i}

      # game start
      if a == 0 && b == 0 && line.length < 2
        p line[0]
        next
      end

      # game end
      if line.length < 2
        print a, " ", b, "\n"
        a = 0
        b = 0
        p line[0]
        next
      end

      if line[0] > line[1]
        a += line[0] + line[1]
      elsif line[0] < line[1]
        b += line[0] + line[1]
      else
        a += line[0]
        b += line[1]
      end
    end
  end

rescue SystemCallError => e
  puts %Q(class=[#{e.class}] message=[#{e.message}])
rescue IOError => e
  puts %Q(class=[#{e.class}] message=[#{e.message}])
end

print a, " ", b, "\n"