Problem:
 Score : 400 points    Problem Statement There are N dishes of cuisine placed in front of Takahashi and Aoki.
For convenience, we call these dishes Dish 1 , Dish 2 , ..., Dish N .  When Takahashi eats Dish i , he earns A_i points of happiness ; when Aoki eats Dish i , she earns B_i points of happiness.  Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat.
Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end".  Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".      Constraints  1 \leq N \leq 10^5  1 \leq A_i \leq 10^9  1 \leq B_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  A_1  B_1  :  A_N  B_N       Output Print the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".        Sample Input 1 3
10 10
20 20
30 30      Sample Output 1 20  In this sample, both of them earns 10 points of happiness by eating Dish 1 , 20 points by eating Dish 2 , and 30 points by eating Dish 3 .  In this case, since Takahashi and Aoki have the same "taste", each time they will choose the dish with which they can earn the greatest happiness. Thus, first Takahashi will choose Dish 3 , then Aoki will choose Dish 2 , and finally Takahashi will choose Dish 1 , so the answer is (30 + 10) - 20 = 20 .       Sample Input 2 3
20 10
20 20
20 30      Sample Output 2 20  In this sample, Takahashi earns 20 points of happiness by eating any one of the dishes 1, 2 and 3 , but Aoki earns 10 points of happiness by eating Dish 1 , 20 points by eating Dish 2 , and 30 points by eating Dish 3 .  In this case, since only Aoki has likes and dislikes, each time they will choose the dish with which Aoki can earn the greatest happiness. Thus, first Takahashi will choose Dish 3 , then Aoki will choose Dish 2 , and finally Takahashi will choose Dish 1 , so the answer is (20 + 20) - 20 = 20 .       Sample Input 3 6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000      Sample Output 3 -2999999997  Note that the answer may not fit into a 32 -bit integer.

Solution (Python):
import sys

def solve():
    input = sys.stdin.readline
    N = int(input())
    T, A = [None] * N, [None] * N
    used = [False] * N
    for i in range(N):
        a, b = map(int, input().split())
        T[i] = (a + b, a, i)
        A[i] = (a + b, b, i)
    T.sort(reverse = True)
    A.sort(reverse = True)
    hapiness = 0
    ti, ai = 0, 0
    for i in range(N):
        if i % 2 == 0:
            while used[T[ti][2]]: ti += 1
            hapiness += T[ti][1]
            used[T[ti][2]] = True
            ti += 1           
        else:
            while used[A[ai][2]]: ai += 1
            hapiness -= A[ai][1]
            used[A[ai][2]] = True
            ai += 1
    print(hapiness)
   
    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
def main():
    n = int(input())
    answer = 0
    dish = []
    for _ in range(n):
        a, b = map(int, input().split())
        dish.append(a + b)
        answer -= b
    dish.sort(reverse=True)
    for i in range(0, n, 2):
        answer += dish[i]
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
import copy
n = int(input())
dish = []
for i in range(n):
    a,b = map(int,input().split())
    dish.append((a,b, a+b))
dish.sort(key=lambda x:x[2])
dish.reverse()
tk = dish[0:n:2]
ao = dish[1:n:2]
tkp = 0
aop = 0
for i in range(len(tk)):
    tkp += tk[i][0]
for i in range(len(ao)):
    aop += ao[i][1]
print(tkp-aop)

Solution (Python):
n = int(input())
AB = []
for i in range(n):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort(key=lambda x: x[0]+x[1], reverse=True)
A, B = [], []
for i in range(n):
    a, b = AB[i]
    if i % 2 == 0:
        A.append(a)
    else:
        B.append(b)
print(sum(A)-sum(B))

Solution (Python):
import sys
def main():
    input = sys.stdin.readline
    N=int(input())
    AB=[tuple(map(int, input().split())) for _ in range(N)]
    scoresA = [(a+b,a,i) for i,(a,b) in enumerate(AB)]
    scoresB = [(b+a,b,i) for i,(a,b) in enumerate(AB)]
    scoresA.sort(reverse=True)
    scoresB.sort(reverse=True)
    ans=0
    used=[False]*N
    ai=bi=0
    for i in range(N):
        if i&1:
            while used[scoresB[bi][2]]: bi+=1
            ans-=scoresB[bi][1]
            used[scoresB[bi][2]]=True
        else:
            while used[scoresA[ai][2]]: ai+=1
            ans+=scoresA[ai][1]
            used[scoresA[ai][2]]=True
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda a: a[0] + a[1], reverse=True)

ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += AB[i][0]
    else:
        ans -= AB[i][1]
print(ans)

Solution (Python):
N = int(input())
AB = [tuple(map(int,input().split())) for i in range(N)]
AB.sort(key=lambda x:x[1]+x[0])

ans = 0
for i,(a,b) in enumerate(AB[::-1]):
    if i%2:
        ans -= b
    else:
        ans += a
print(ans)

Solution (Python):
n = int(input())
l = []
for _ in range(n):
    a,b = map(int,input().split())
    l.append((a+b,a,b))
l = sorted(l,reverse=True)
takahashi = 0
aoki = 0
for i in range(n):
    if i%2:
        aoki+=l[i][2]
    else:
        takahashi+=l[i][1]
print(takahashi-aoki)

Solution (Python):







n = int(input())
arr = []
used = [False for _ in range(n)]
for i in range(n):
    a, b = map(int, input().split())
    arr.append([i, a, b])

lis = sorted(arr, key=lambda x: x[1] + x[2], reverse=True)
takp, aokp = 0, 0

c = 0

while c < n:
    if c % 2 == 0:
        
        takp += lis[c][1]
    else:
        
        aokp += lis[c][2]
    c += 1
print(takp - aokp)

Solution (Python):
N = int(input())
X = [None]*N
a = 0
for i in range(N):
    A, B = map(int, input().split())
    X[i] = (A+B, A, B)
X.sort(reverse=1)
ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += X[i][1]
    else:
        ans -= X[i][2]
print(ans)

Solution (Python):
N=int(input())
net=[]
y=0
for i in range(0,N):
    a,b=map(int,input().split())
    y+=b
    net.append(a+b)

net.sort(reverse=True)

t=sum(net[i] for i in range(0,N) if i%2==0)
print(t-y)

Solution (Python):
N = int(input())
ABs = []
sum_B = 0
for i in range(N):
    a,b = map(int, input().split())
    ABs.append(a+b)
    sum_B += b 
ABs.sort(reverse=True)
ans = sum(ABs[::2])-sum_B
print(ans)

Solution (Python):
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): 
    return list(map(int,input().split()))
def m(): 
    return map(int,input().split())
def onem(): 
    return int(input())
def s(x): 
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): 
    return " ".join(map(str,x))
def max2(x): 
    return max(map(max,x))
def In(x,a): 
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False
"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""


n = onem()

po = []
su = 0
for i in range(n):
    a,b = m()
    po.append([a+b,a])
po.sort(reverse = True)

for i in range(n):
    if i % 2 == 0:
        su += po[i][1]
    else:
        su -= po[i][0] - po[i][1]
print(su)

Solution (Python):

import sys
from collections import defaultdict

def INT(): return int(input())
def MAP(): return map(int,input().split())
def LI(): return list(map(int,input().split()))


def main():
    N = INT()
    AB = [LI() for _ in range(N)]
    AB.sort(key=lambda x: -(x[0]+x[1]))

    answer = 0
    for i in range(N):
        if i%2 == 0:
            answer += AB[i][0]
        else:
            answer -= AB[i][1]
    
    print(answer)

    return


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
x=[]
ans=0
for _ in range(n):
    a,b=map(int,input().split())
    x.append(a+b)
    ans-=b
x.sort(reverse=True)
ans+=sum(x[i] for i in range(n) if i%2==0)
print(ans)

Solution (Python):
n=int(input())
x=[]
for _ in range(n):
    a,b=map(int,input().split())
    x.append([a+b,a,b])
x.sort(reverse=True)
ans=0
for i in range(n):
    if i%2==0: ans+=x[i][1]
    else: ans-=x[i][2]
print(ans)

Solution (Python):
n = int(input())
abc =[]
for i in range(n):
    a,b = [int(x) for x in input().split()]
    abc.append([a,b,a+b])
abc = sorted(abc,key=lambda x: x[2],reverse=True)
t=0
a=0
for i in range(n):
    if i%2==0:
        t+=abc[i][0]
    else:
        a+=abc[i][1]
print(t-a)

Solution (Python):
n = int(input())
a = []
b = []
c = []
for i in range(n):
    line = list(map(int, input().split()))
    a.append(line[0])
    b.append(line[1])
    c.append([line[0] + line[1], i])
c.sort(key = lambda x:x[0], reverse = True)
ans = 0
for i in range(n):
    if i%2 == 0:
        ans += a[c[i][1]]
    else:
        ans -= b[c[i][1]]
print(ans)

Solution (Python):

N = int(input())

a_b_ab_list = [ ]
for _ in range(N):
    a, b = map(int, input().split(' '))
    a_b_ab_list.append((a, b, a+b))

a_b_ab_list.sort(key=lambda x: x[2], reverse=True)

t, a = 0, 0
for i in range(0, N, 2):
    t += a_b_ab_list[i][0]

for i in range(1, N, 2):
    a += a_b_ab_list[i][1]

print(t - a)

Solution (Python):



def main():
  n = int(input())
  sb  = 0
  lab = [0] * n
  for i in range(n):
    a, b = map(int, input().split())
    sb += b
    lab[i] = a+b
  lab.sort(reverse=True)
  print(sum(lab[::2]) - sb)

if __name__=='__main__':
  main()

Solution (Python):

import sys,os
from collections import defaultdict, deque
from fractions import gcd
from math import ceil, floor
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = (lambda *something: print(*something)) if 'TERM_PROGRAM' in os.environ else lambda *x: 0
def main(given=sys.stdin.readline):
    input = lambda: given().rstrip()
    LMIIS = lambda: list(map(int,input().split()))
    II = lambda: int(input())
    XLMIIS = lambda x: [LMIIS() for _ in range(x)]
    YN = lambda c : print('Yes') if c else print('No')
    MOD = 10**9+7

    N = II()
    S = []
    for i in range(N):
        a,b = LMIIS()
        S.append((a+b,a,b))
    S.sort(reverse=True)
    
    ans = 0
    for i, item in enumerate(S):
        sumab,a,b = item
        if i % 2 == 0:
            ans += a
        else:
            ans -= b
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from sys import stdin
N = int(stdin.readline().rstrip())
data = []
for i in range(N):
    A,B = [int(x) for x in stdin.readline().rstrip().split()]
    data.append((A+B,A,B))
data.sort()
a = 0
b = 0
for ind,(i,j,k) in enumerate(data[::-1]):
    if ind % 2 == 0:
        a += j
    else:
        b += k
        
print(a-b)

Solution (Python):
n = int(input())
AB = []
for _ in range(n):
    a, b = map(int, input().split())
    tot = a+b
    AB.append([a, b, tot])

AB = sorted(AB, key=lambda x:x[2], reverse=True)

a_eat = 0
b_eat = 0

for i in range(n):
    if i%2 == 0:
        a_eat += AB[i][0]
    else:
        b_eat += AB[i][1]

ans = a_eat - b_eat
print(ans)

Solution (Python):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
d = [tuple(MI()) for _ in range(N)]
d.sort(reverse=True, key=lambda x: x[0] + x[1])

T = 0
A = 0
for i, (a, b) in enumerate(d):
    if i % 2 == 0:
        T += a
    else:
        A += b
print(T - A)

Solution (Python):

import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

n = int(input())
AB = [tuple(map(int,input().split())) for i in range(n)]
AB.sort(key = lambda tup:tup[0]+tup[1],reverse  = True)
for i in range(n):
  if i % 2 == 0:
    ans += AB[i][0]
  else:
    ans -= AB[i][1]
print(ans)

Solution (Python):
def main():
    dishes = int(input())
    aoki_happiness = []
    difference = []
    for i in range(dishes):
        t, a = map(int, input().split())
        aoki_happiness.append(a)
        difference.append(t + a)
    difference.sort(reverse=True)
    answer = -sum(aoki_happiness)
    for i in range(dishes):
        if i % 2 == 0:
            answer += difference[i]
    print(answer)


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
AB = []
for i in range(N):
    a,b = map(int,input().split())
    AB.append([a,b,a+b])

AB = sorted(AB, key=lambda x:x[2]*(-1))

A = 0
B = 0
for i in range(N):
    if i%2==0:
        A += AB[i][2]
    B += AB[i][1]
        
print(A-B)

Solution (Python):

N=int(input())
AB=[]

for i in range(N):
    A,B=map(int,input().split())
    AB.append([A+B,A,B])

AB.sort(reverse=True)
Ta=0
Ao=0

for i in range(N):
    if i%2==0:
        Ta+=AB[i][1]
    else:
        Ao+=AB[i][2]

print(Ta-Ao)

Solution (Python):
def main():
    n = int(input())
    a = [None]*n
    for i in range(n):
        x, y = map(int, input().split())
        a[i] = [x, y]
    a.sort(key=lambda x: (x[0]+x[1]), reverse=True)
    score = 0
    for i in range(n):
        if i % 2 == 0:
            score += a[i][0]
        else:
            score -= a[i][1]
    print(score)

if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
AB=[]
B=[]
for _ in range(n):
    a,b=map(int,input().split())
    AB.append(a+b)
    B.append(b)
AB=sorted(AB,reverse=True)

X=-sum(B)
for i in range(0,n,2):
    X+=AB[i]
print(X)

Solution (Python):
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
B=[]
c=0
for i in range(N):
  a=A[i][0]+A[i][1]
  c-=A[i][1]
  B.append(a)
B=sorted(B)[::-1]
d=(N+1)//2
for i in range(d):
  c+=B[2*i]
print(c)

Solution (Python):
n = int(input())
lst = []
for _ in range(n):
    a,b = map(int,input().split())
    lst.append((a,b,a+b))
lst.sort(key=lambda x:x[2], reverse=True)
x,y = 0,0
for i in range(n):
    if i%2==0:
        x += lst[i][0]
    else:
        y += lst[i][1]
print(x - y)

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
AB = [LIST() for _ in range(N)]

X = -sum([x[1] for x in AB])

for i, (A, B) in enumerate(sorted(AB, key=lambda x:x[0]+x[1], reverse=True)):
	if i%2 == 0:
		X += A+B
print(X)

Solution (Python):
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    food = []
    sc = 0
    for _ in range(N):
        a,b = map(int,input().split())
        sc -= b
        food.append(a+b)
    
    food.sort(reverse= True)
    tf = sum(food[::2])
    print(tf+sc)

if __name__ == "__main__":
    main()

Solution (Python):
N=int(input())
AB=[tuple(map(int, input().split()))for _ in range(N)]
AB.sort(key=lambda ab: ab[0]+ab[1], reverse=True)
print(sum(a for a,b in AB[0::2])-sum(b for a,b in AB[1::2]))

Solution (Python):
N = int(input())
A, B, AB = [], [],  []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
    AB.append(a + b)
AB.sort(reverse=True)
print(sum(AB[::2]) - sum(B))

Solution (Python):
n = int(input())
ab =[tuple(map(int, input().split( ))) for i in range(n)]
ab.sort(key = lambda x:x[0]+x[1],reverse = True)
ans = 0
for i in range(n):
    if i%2==0:
        ans += ab[i][0]
    else:
        ans -= ab[i][1]
print(ans)

Solution (Python):
import sys
input=sys.stdin.readline
n = int(input())
l = []
for _ in range(n):
    tmp = list(map(int,input().split()))
    sm = tmp[0] + tmp[1]
    l.append([tmp[0],tmp[1],sm])

l.sort(key=lambda x:x[2])
l.reverse()

t_sm=0
a_sm=0
cnt=0
for dish in l:
    if cnt%2==0:
        t_sm+=dish[0]
    else:
        a_sm+=dish[1]
    cnt+=1
print(t_sm-a_sm)

Solution (Python):
N = int(input())
nums = [  list(map(int,input().split(" "))) for _ in range(N) ]

for i in range(N):
    a,b = nums[i]
    nums[i].append(a + b)
nums =sorted(nums,key = lambda x:-x[2])

takahasi = [nums[i][0] for i  in  range(N) if i % 2 == 0]
aokis= [nums[i][1] for i  in  range(N) if i % 2 != 0]
print(sum(takahasi) - sum(aokis))

Solution (Python):
n=int(input())
AB=[list(map(int,input().split())) for _ in range(n)]

A,B=[],[]
for i,j in AB:
    A.append(i+j)
    B.append(-j)

ans=sum(B)
A=sorted(A)[::-1]
for i in range(0,n,2):
    ans +=A[i]

print(ans)

Solution (Python):
n=int(input())
s=[0]*n
t=0
for i in range(n):
  a,b=map(int,input().split())
  s[i]=a+b
  t+=b
s.sort()
s=s[::-1]
print(sum(s[::2])-t)

Solution (Python):
n = int(input())
a = [list(map(int,input().split())) for i in range(n)]
x = []
for i in range(n):
  x.append((a[i][0]+a[i][1],i))
x.sort(reverse=True)
tk,ao = 0,0
for i in range(n):
  if i%2 == 0:
    tk += a[x[i][1]][0]
  else:
    ao += a[x[i][1]][1]
print(tk-ao)

Solution (Python):
import bisect
import math
import sys
from collections import Counter, defaultdict, deque
from copy import copy, deepcopy
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations
from queue import Queue

read = sys.stdin.read
readline = sys.stdin.readline 
readlines = sys.stdin.readlines 

def SI():
    return int(readline())
def MI():
    return map(int, readline().split())
def MLI():
    return map(int, open(0).read().split())

inf = float("inf")


def main():
    N, *AB = MLI()
    
    happiness = defaultdict(list) 
    for A, B in zip(*[iter(AB)]*2):
        happiness[A+B].append((A, B))
        
    turn = -1
    score_A = 0
    score_B = 0
    for key in sorted(happiness.keys())[::-1]:
        values = deque(sorted(happiness[key]))
        while len(values) > 0:
            if turn == -1:
                A, B = values.pop()
                score_A += A
            else:
                A, B = values.popleft()
                score_B += B
            turn *= -1
            
    print(score_A - score_B)
    

if __name__ == "__main__":
    main()

Solution (Python):
from sys import stdin
n = int(stdin.readline().rstrip())
AB = [list(map(int,stdin.readline().rstrip().split())) for _ in range(n)]
kouhuku = [i[0]+i[1] for i in AB]
kouhuku.sort(reverse=True)
aoki = sum(i[1] for i in AB)
takahashi = sum(kouhuku[::2])
print(takahashi-aoki)

Solution (Python):
N = int(input())
ab = [[int(i) for i in input().split()] for _ in range(N)]
ab.sort(key=lambda x: sum(x), reverse=True)
ans = 0
for i, x in enumerate(ab):
    ans += -x[1] if i % 2 else x[0]
print(ans)

Solution (Python):
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]

li = []
sumb = 0
for a,b in ab:
    li.append(a+b)
    sumb += b

li.sort(reverse = True)


print(sum(li[::2]) - sumb)

Solution (Python):
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

AB.sort(reverse=True, key=lambda x:x[0]+x[1])

t = sum(x[0] for x in AB[0::2])
a = sum(x[1] for x in AB[1::2])

print(t-a)

Solution (Python):
n=int(input())
ab=[list(map(int,input().split())) for _ in range(n)]
b=[y for x,y in ab]
c=[x+y for x,y in ab]
c.sort(reverse=True)
print(sum(c[::2])-sum(b))

Solution (Python):
n = int(input())
dif = []
sumb = 0
for i in range(n):
    a, b = map(int, input().split())
    sumb += b
    dif.append(a+b)
dif.sort(reverse=True)
ans = -sumb
for i in range(n):
    if i%2 == 0:
        ans += dif[i]
print(ans)

Solution (Python):
N = int(input())
AB = sorted([list(map(int,input().split())) for i in range(N)],key = lambda x:-x[0]-x[1])
Tsum = sum(AB[i][0] for i in range(N) if i%2 == 0)
Asum = sum(AB[i][1] for i in range(N) if i%2 == 1)
print(Tsum-Asum)

Solution (Python):
n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
C = sorted([(i+j, i, j) for i,j in AB], reverse=True)
ans = 0
for i in range(n):
  s, t, a = C[i]
  if i%2 == 0:
    ans += t
  else:
    ans -= a
print(ans)

Solution (Python):
N = int(input())
base = 0
L = []
for _ in range(N):
	ta,tb = map(int,input().split())
	base -= tb
	L.append(ta+tb)

L.sort(reverse = True)

takahashi = 0

for i in range(0,N,2):
	takahashi += L[i]

print(takahashi + base)

Solution (Python):
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

A = [a for a, b in AB]
C = [a + b for a, b in AB]
C.sort()
C = C[::-1]
print(sum(A) - sum(C[1::2]))

Solution (Python):

n = int(input())
aoki, takahashi = [], []
for i in range(n):
    t, a = [ int(v) for v in input().split() ]
    aoki.append((-t-a, -a, i))
    takahashi.append((-a-t, -t, i))
dish_list = [1] * n
aoki.sort(), takahashi.sort()

a_score, t_score = 0, 0
a_counter, t_counter = 0, 0
for i in range(n):
    stop = 0
    if i % 2 == 0:
        while not stop:
            if dish_list[takahashi[t_counter][2]] == 1:
                t_score -= takahashi[t_counter][1]
                dish_list[takahashi[t_counter][2]] = 0
                stop = 1
            t_counter += 1
    else:
        while not stop:
            if dish_list[aoki[a_counter][2]] == 1:
                a_score -= aoki[a_counter][1]
                dish_list[aoki[a_counter][2]] = 0
                stop = 1
            a_counter += 1
print(t_score - a_score)

Solution (Python):
def main():
    N = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(N)]
    ans = 0
    for i in range(N):
        ls[i].append(ls[i][0]+ls[i][1])
    ls = sorted(ls,key=lambda x:-x[2])
    if N==1:
        print(ls[0][1])
        exit()
    for i in range(N):
        ans -= ls[i][1]

    for i in range(N//2):
        ans += ls[2*i][2]

    if N%2==1:
        ans += ls[2*i+2][2]
    
    print(ans)
if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
A = []
for i in range(N):
    a,b = map(int,input().split())
    A.append((a,b,a+b))
A = sorted(A,key=lambda x:x[2],reverse=True)
a = 0
for i in range(N):
    if i%2==0:
        a += A[i][0]
    else:
        a -= A[i][1]
print(a)

Solution (Python):
N = int(input())
foods = []
for i in range(N):
    food = list(map(int,input().split()))
    foods.append(food)
foods.sort(key=lambda x: -(x[0]+x[1]))

ans = 0
for i in range(N):
    if i%2 == 0:
        ans += foods[i][i%2]
    else:
        ans -= foods[i][i%2]
print(ans)

Solution (Python):
N = int(input())
foods = []
for i in range(N):
    food = list(map(int,input().split()))
    foods.append(food)
foods.sort(key=lambda x: -(x[0]+x[1]))

ans = 0
for i in range(N):
    if i%2 == 0:
        ans += foods[i][0]
    else:
        ans -= foods[i][1]
print(ans)

Solution (Python):
n=int(input())
l=[None]*n
for i in range(n):
  a,b=map(int,input().split())
  l[i]=[a,b]
l.sort(key=lambda x:x[0]+x[1], reverse=True)

ans=0
for i in range(n):
  if i%2:
    ans-=l[i][1]
  else:
    ans+=l[i][0]
print(ans)

Solution (Python):
N=int(input())
AB=[list(map(int,input().split()))+[i] for i in range(N)]
A=sorted(AB,key=lambda x:x[1]+x[0],reverse=True)
value=0
for i in range(N):
    if i%2==0:
        value+=A[i][0]
    else:
        value-=A[i][1]
print(value)

Solution (Python):
n = int(input())

e = []
curr = 0
for _ in range(n):
    a, b = map(int, input().split())
    e.append(a + b)
    curr -= b

e.sort(reverse=True)
print(curr + sum(e[::2]))

Solution (Python):

import sys
input = sys.stdin.readline

N = int(input())
AB = [tuple(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda k: k[0]+k[1], reverse=True)
takahashi, aoki = 0, 0

for i in range(N):
    if i%2==0:
        takahashi += AB[i][0]
    else:
        aoki += AB[i][1]

print(takahashi-aoki)

Solution (Python):
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]

A = []
C = []
for a, b in AB:
  A.append(a)
  C.append(a + b)


C.sort()
C = C[::-1]

print(sum(A) - sum(C[1::2]))

Solution (Python):
N=int(input())
A=[0]*N
B=[0]*N
diff=[0]*N
for i in range(N):
  A[i],B[i]=map(int,input().split())
  diff[i]=[A[i]+B[i],i]
  
diff=sorted(diff,key=lambda x:x[0])[::-1]
taka=0
aoki=0
for i in range(len(diff)):
  if i%2==0:
    taka+=A[diff[i][1]]
  else:
    aoki+=B[diff[i][1]]

print(taka-aoki)

Solution (Python):
N = int(input())
AB = []
ans = 0
for _ in range(N):
  a,b = map(int,input().split())
  AB.append(a+b)
  ans -= b
AB.sort(reverse=True)

print(ans+sum(AB[::2]))

Solution (Python):
N = int(input())
C = []
for i in range(N):
    a, b = map(int, input().split())
    C.append((a+b, a, b))

C.sort(reverse=1)

ans = 0
for i in range(N):
    _, a, b = C[i]
    if i % 2 == 0:
        ans += a
    else:
        ans -= b
print(ans)

Solution (Python):
N = int(input())
AB = [list(map(int,input().split())) for _ in range(N)]

scores = [(A+B, A, B) for A,B in AB]
scores.sort(key=lambda x:x[0], reverse=True)
takahashi = 0
aoki = 0
takahashi_turn = True
for score in scores:
    if takahashi_turn:
        takahashi += score[1]
    else:
        aoki += score[2]
    takahashi_turn = not takahashi_turn
print(takahashi-aoki)

Solution (Python):
N = int(input())
cuisine = []
ans = 0
for _ in range(N):
    a, b = map(int, input().split())
    ans -= b
    cuisine.append(a+b)
cuisine = sorted(cuisine, reverse=True)
for i in range(N):
    if i % 2 == 1:
        continue
    ans += cuisine[i]
print(ans)

Solution (Python):
n=int(input())
x=0
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append(a+b)
  x+=b
print(sum(sorted(l)[(n+1)%2::2])-x)

Solution (Python):
N=int(input())
l=[]
for i in range(N):
    A,B=map(int,input().split())
    l.append((A,B))
l.sort(reverse=True,key=lambda x:(x[0]+x[1],x[0]))
ans=0
for i,e in enumerate(l):
    if i%2==0:
        ans+=e[0]
    elif i%2==1:
        ans+=-e[1]
print(ans)

Solution (Python):
def examC():
    N = I()
    A = [0]*N; B = [0]*N
    for i in range(N):
        A[i], B[i] = LI()
    taka = 0; aoki = 0
    value = [[i] for i in range(N)]
    for i in range(N):
        cur = A[i]+B[i]
        value[i].append(cur)
    value.sort(key=lambda x:x[1],reverse = True)

    for i in range(N):
        if i%2==0:

            taka += A[value[i][0]]
        else:

            aoki += B[value[i][0]]
    ans = taka-aoki
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

if __name__ == '__main__':
    examC()

Solution (Python):
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = []
    for i in range(N):
        a, b = map(int, input().split())
        A.append((a+b, a, b))
    A.sort(reverse=True)
    takahashi = aoki = 0
    for i, (_, a, b) in enumerate(A):
        if i % 2 == 0:
            takahashi += a
        else:
            aoki += b
    print(takahashi - aoki)


if __name__ == '__main__':
    main()

Solution (Python):
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


N = int(sys.stdin.buffer.readline())
A, B = list(zip(*[map(int, sys.stdin.buffer.readline().split()) for _ in range(N)]))

A = np.array(A, dtype=int)
B = np.array(B, dtype=int)

order = (A + B).argsort()[::-1]
a = A[order[::2]].sum()
b = B[order[1::2]].sum()
print(a - b)

Solution (Python):











import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log 
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    AB=[]
    BA=[]
    for i in range(N):
        a,b = MI()
        AB.append((a,b,i))
        BA.append((b,a,i))
    AB.sort(key = lambda x:x[0]+x[1],reverse = False)
    BA.sort(key = lambda x:x[0]+x[1],reverse = False)
    takahashi = 0
    aoki = 0
    eaten = set()
    for i in range(N):  
        if i&1:
            a,b,c = BA.pop()
            while c in eaten:
                a,b,c = BA.pop()
            aoki += a
        else:
            a,b,c = AB.pop()
            while c in eaten:
                a,b,c = AB.pop()
            takahashi += a
        eaten.add(c)
    ans = takahashi-aoki
    print(ans)

    

    


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
h = []
for _ in range(N) :
    A, B = map(int, input().split())
    h.append((A + B, A, B))
    
h.sort(reverse=True)
print(sum([h[i][1] for i in range(0, N, 2)]) - sum([h[i][2] for i in range(1, N, 2)]))

Solution (Python):
from collections import Counter,defaultdict,deque
import sys
from itertools import permutations, combinations
from heapq import heappop, heappush

sys.setrecursionlimit(10**8)
mod = 10**9+7
    
def inp(): 
    return int(input())
def inpm(): 
    return map(int,input().split())
def inpl(): 
    return list(map(int, input().split()))
def inpls(): 
    return list(input().split())
def inplm(n): 
    return list(int(input()) for _ in range(n))
def inpll(n): 
    return sorted([list(map(int, input().split())) for _ in range(n)])

def main():
    n=inp()
    ab=[]
    for _ in range(n):
        x,y=inpm()
        ab.append((x+y,x,y))
    ab.sort(reverse=True)
    pa=0
    pb=0
    for i in range(n):
        if i%2 == 0:
            pa+=ab[i][1]
        else:
            pb+=ab[i][2]
    print(pa-pb)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
items = [None] * n
for i in range(n):
    a, b = map(int, input().split())
    items[i] = (a+b, a, b)
items.sort(reverse=True)
ans = 0
for i in range(n):
    if i % 2: ans -= items[i][2]
    else: ans += items[i][1]
print(ans)