N=int(input()) A_B=[input().split(" ") for i in range(N)] #A[i]:i+1の問題をAが解く時間 A=[int(x[0]) for x in A_B] #B[i]:i+1の問題をBが解く時間 B=[int(x[1]) for x in A_B] upper_A=sum([A[i] for i in range(N) if A[i]<=B[i]]) upper_B=sum([B[i] for i in range(N) if B[i]