import heapq



n = int(eval(input()))

happy = []

ans = 0

for i in range(n):

    a, b = tuple(map(int, input().split()))

    heapq.heappush(happy, - (a + b))

    ans += a

while len(happy) != 0:

    heapq.heappop(happy)

    if len(happy) != 0:

        h = heapq.heappop(happy)

        ans += h

    else:

        break

print(ans)

n = int(eval(input()))

happy = []

ans = 0

for i in range(n):

    a, b = tuple(map(int, input().split()))

    happy.append(a + b)

    ans += a

happy.sort(reverse=True)

for i in range(1, n, 2):

    ans -= happy[i]

print(ans)

import heapq

n = int(eval(input()))
happy = []
ans = 0
for i in range(n):
    a, b = tuple(map(int, input().split()))
    heapq.heappush(happy, -(a + b))
    ans += a
while len(happy) != 0:
    heapq.heappop(happy)
    if len(happy) != 0:
        h = heapq.heappop(happy)
        ans += h
    else:
        break
print(ans)

n = int(eval(input()))
happy = []
ans = 0
for i in range(n):
    a, b = tuple(map(int, input().split()))
    happy.append(a + b)
    ans += a
happy.sort(reverse=True)
for i in range(1, n, 2):
    ans -= happy[i]
print(ans)

-import heapq - -    heapq.heappush(happy, -(a + b)) +    happy.append(a + b) -while len(happy) != 0: -    heapq.heappop(happy) -    if len(happy) != 0: -        h = heapq.heappop(happy) -        ans += h -    else: -        break +happy.sort(reverse=True) +for i in range(1, n, 2): +    ans -= happy[i]