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):
from heapq import heapify, heappush, heappop

N = int(input())
As, Bs = [], []
for _ in range(N):
    A, B = map(int, input().split())
    As.append(A)
    Bs.append(B)

PQ = [(-A-B, i) for i, (A, B) in enumerate(zip(As, Bs))]
heapify(PQ)

t = 1
hT = hA = 0
while PQ:
    H, i = heappop(PQ)
    if t % 2:
        hT += As[i]
    else:
        hA += Bs[i]
    t += 1

print(hT - hA)

Solution (Python):



from operator import itemgetter
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]
abps = [x+[x[0]+x[1]] for x in ab]
sabps = sorted(abps,key=itemgetter(2))[::-1]
takahashi_aoki=[0,0]
for i in range(n):
    takahashi_aoki[i%2]+=sabps[i][i%2]
print(takahashi_aoki[0]-takahashi_aoki[1])

Solution (Python):


import math
import fractions
import heapq
import collections
import re
import array
import bisect

from collections import Counter, defaultdict


def array2d(dim1, dim2, init=None):
    return [[init for _ in range(dim2)] for _ in range(dim1)]

II = lambda: int(input())
MI = lambda: map(int, input().split())


def main():
    N = II()
    qA = []                     
    qB = []                     
    for i in range(N):
        a, b = MI()
        t = a + b
        heapq.heappush(qA, (-t, -a, i))
        heapq.heappush(qB, (-t, -b, i))

    tA, tB = 0, 0
    used = set()
    for x in range(N):
        if x % 2 == 0:
            
            while True:
                t, a, i = heapq.heappop(qA)
                if i not in used: break
            tA -= a
            used.add(i)
        else:
            
            while True:
                t, b, i = heapq.heappop(qB)
                if i not in used: break
            tB -= b
            used.add(i)

    return tA - tB


if __name__ == "__main__":
    print(main())

Solution (Python):



from collections import deque
import heapq
import math
import bisect


def main():
    N = int(input())
    A, B = [0] * N, [0] * N
    S = []
    for i in range(N):
        A[i], B[i] = map(int, input().split())
        S.append((A[i]+B[i], i))

    S.sort(reverse=True)

    t = a = 0
    for i in range(N):
        idx = S[i][1]
        if not i % 2:
            t += A[idx]
        else:
            a += B[idx]

    print(t-a)


if __name__ == '__main__':
    main()

Solution (Python):

import math,string,itertools,fractions,heapq,collections,re,array,bisect

def s():
    return raw_input().strip()
def n():
    return int(raw_input())
def d():
    return float(raw_input())

def ls():
    return raw_input().strip().split()
def ln():
    return map(int, raw_input().strip().split())
def ld():
    return map(float, raw_input().strip().split())

def fs():
    return [raw_input().strip() for i in xrange(input())]
def fn():
    return [int(raw_input().strip()) for i in xrange(input())]
def fd():
    return [float(raw_input().strip()) for i in xrange(input())]

N = n()

items = []
for i in xrange(N):
    x, y = ln()
    items.append([x + y, x, y])

items.sort(reverse=True)

print sum(map(lambda x: x[1], items[0::2])) - sum(map(lambda x: x[2], items[1::2]))

Solution (Python):
N = int(input())
Takahashi = [None] * N
Aoki = [None] * N
Used = [False] * N
for i in range(N):
    a, b = map(int, input().split())
    Takahashi[i] = (-a-b, -a, i)
    Aoki[i] = (-b-a, -b, i)
Takahashi.sort()
Aoki.sort()
TotalPoint = 0

usedDish = 0
tnum, anum = 0, 0
while usedDish < N:
    if usedDish % 2 == 0:
        while Used[Takahashi[tnum][2]]:
            tnum += 1
        TotalPoint -= Takahashi[tnum][1]
        Used[Takahashi[tnum][2]] = True
        usedDish += 1
    else:
        while Used[Aoki[anum][2]]:
            anum += 1
        TotalPoint += Aoki[anum][1] 
        Used[Aoki[anum][2]] = True
        usedDish += 1
print(TotalPoint)

Solution (Python):
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
L=[]
for j in range(n):
  L.append([l[j][0]+l[j][1],j])
L.sort()
L.reverse()
cta=0;ctb=0
for k in range(n):
  if k%2==0:
    cta+=l[L[k][1]][0]
  else:
    ctb+=l[L[k][1]][1]
print(cta-ctb)

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

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

l = sorted(l, reverse=True)
sum_l = sum(l[0::2])
ans = sum_l - sum_b
print(ans)

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

A,B,C = [],[],[]
for i in range(N):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
    C.append((i,a+b))
    
C = sorted(C,key=lambda x:x[1],reverse=True)

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

Solution (Python):
from heapq import heappush, heappop

N = int(input())
xs = []
for i in range(N):
  a, b = map(int, input().split())
  heappush(xs, (-a-b,a,b))

y = 0
for i in range(N):
  x,a,b = heappop(xs)
  if i % 2 == 0:
  	y += a
  else:
    y -= b

print(y)

Solution (Python):
from operator import itemgetter

n = int(input())
ab = []
for i in range(n):
    a, b = map(int, input().split())
    c = a + b
    ab.append((a, b, c))
ab = sorted(ab, key=itemgetter(2), reverse=True)
taka = 0
ao = 0
for i in range(n):
    if i % 2 == 0:
        taka += ab[i][0]
    else:
        ao += ab[i][1]
print(taka - ao)

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

N=int(input())
AB=[list(map(int,input().split())) for i in range(N)]

SUM=[[sum(AB[i])]+[i] for i in range(N)]

SUM.sort(key=lambda x:x[0],reverse=True)

T=[]
A=[]

for j in range(N):
    s,i=SUM[j]

    if j%2==0:
        T.append(i)
    else:
        A.append(i)

ANS=0
for t in T:
    ANS+=AB[t][0]
for a in A:
    ANS-=AB[a][1]

print(ANS)

Solution (Python):
N = int(input())
S = [0] *  N
A,B = [0]*N,[0]*N
for i in range(N):
    A[i],B[i] = map(int,input().split(" "))
    S[i] = (A[i]+B[i],i)
S.sort(reverse=True)

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

print(ans)

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

print(ans)

Solution (Python):
N =int(input())
l=[[int(i)for i in input().split()]for j in range(N)]
l =sorted(l,key=lambda x:sum(x),reverse=True)
ans =[0,0]
nu = 0
for i in l:
    ans[nu] += i[nu]
    if nu == 0:
        nu = 1
    else:
        nu = 0
print(ans[0]-ans[1])

Solution (Python):
N = int(input())
A = []
B = []
diff = []
tasu = []
tmp = []
for i in range(N):
    a,b = map(int,input().split())
    tmp.append((a+b, a, b))
    
    
    
    

tmp = sorted(tmp, reverse=True)

Ta = 0
Ao = 0
for i in range(N):
    a = tmp[i][1]
    b = tmp[i][2]
    if i%2 == 0:
        Ta += a
    else:
        Ao += b
ans = Ta - Ao
print(ans)

Solution (Python):
from operator import itemgetter

N = int(input())
ab = []
for i in range(N):
    a, b = [int(v) for v in input().split()]
    ab.append((a + b, a, b))

ab.sort(reverse=True, key=itemgetter(0))

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

print(takahashi - aoki)

Solution (Python):
n = int(input())
gap = []
for i in range(n):
    ai, bi = [int(_) for _ in input().split()]
    gap.append([ai+bi, ai, bi])

gap_sorted = sorted(gap, reverse=True)

res = 0
for j in range(n):
    if j % 2 == 0:
        res += gap_sorted[j][1]
    else:
        res -= gap_sorted[j][2]

print(int(res))

Solution (Python):
if __name__ == '__main__':
    import sys
    input = sys.stdin.readline
    n = int(input())
    ns = [0]*n
    for i in range(n):
        a,b = map(int, input().split())
        ns[i] = [a,b,a+b]
    ns.sort(key=lambda x: x[2], reverse=True)
    count = 0
    for i in ns[::2]:
        count+=i[0]
    for i in ns[1::2]:
        count-=i[1]
    print(count)

Solution (Python):



n=int(input())
a=[0]*n
b=[0]*n
d=[0]*n

for i in range(n):
    aa,bb=[int(i) for i in input().split()]
    a[i] = aa
    d[i] = aa+bb

d.sort(reverse = True)


print(sum(a) - sum(d[1::2]))

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

TA=0
AO=0
L=[]
for i in range(N):
    A,B=map(int,input().split())
    L.append([[A+B],A,B])
L.sort(reverse=True)

for i in range(N):
    if i%2==0:
        TA+=L[i][1]
    else:
        AO+=L[i][2]

print(TA-AO)

Solution (Python):
N = int(input())
A = [0] * N
B = [0] * N
C = [[] for i in range(N)]
for i in range(N):
  A[i], B[i] = map(int, input().split())
  C[i] = [A[i], B[i], A[i] + B[i]]
C.sort(reverse=True, key=lambda x: x[2])
print(sum([c[0] for c in C[0::2]]) - sum([c[1] for c in C[1::2]]))

Solution (Python):
import sys
import math
import collections
import itertools
import array
import inspect


sys.setrecursionlimit(1000000)



def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))



def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v



def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk



def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


def comb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])

    return result

def bisearch(L, target):
    low = 0
    high = len(L) - 1
    
    while low <= high:
        mid = (low + high) // 2
        guess = L[mid]
        if guess == target:
            return True
        elif guess < target:
            low = mid + 1
        elif guess > target:
            high = mid - 1
    if guess != target:
        return False



dp = None


def main():
    N = int(input())
    A = [li_input() for _ in range(N)]

    P1 = [x[:] for x in A]
    P2 = [x[:] for x in A]

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

    
    

    p1_ans = 0
    p2_ans = 0

    for i in range(len(P1)):
        if i % 2 == 0:
            p1_ans += P1[i][0]
        else:
            p2_ans += P1[i][1]
        
    print(p1_ans - p2_ans)



main()

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from heapq import heappush, heappop

n = ni()
ab = [tuple(li()) for _ in range(n)]

que = []
for ai, bi in ab:
    heappush(que, [-ai-bi, ai, bi])
    
cnt = 0
tak = 0
aok = 0
while que:
    sm, ai, bi = heappop(que)
    if cnt % 2 == 0:
        tak += ai
    else:
        aok += bi
        
    cnt += 1
        
print(tak-aok)

Solution (Python):
def read():
    return int(input())


def readlist():
    return list(map(int, input().split()))


def readmap():
    return map(int, input().split())


N = read()
A = []
B = []
C = []
D = []
for _ in range(N):
    a, b = readmap()
    A.append(a)
    B.append(b)
    C.append(a+b)
    D.append((a, b))







D.sort(key=dict(zip(D, C)).get)
D.reverse()








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

print(ans)

Solution (Python):
n=int(input())
taka=[]
ao=[]
s=set()
for i in range(n):
    a,b=map(int,input().split())
    taka.append([a+b,a,i])
    ao.append([a+b,b,i])
    s.add(i)
taka.sort(reverse=True)
ao.sort(reverse=True)
takapt=0
takaind=0
aopt=0
aoind=0
while len(s)>0:
    while taka[takaind][2] not in s:
        takaind+=1
    s.remove(taka[takaind][2])
    takapt+=taka[takaind][1]
    if len(s)==0:
        break
    while ao[aoind][2] not in s:
        aoind+=1
    s.remove(ao[aoind][2])
    aopt+=ao[aoind][1]
print(takapt-aopt)

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


Dishes.sort(key=lambda x: x[0], reverse=True)


T_point, A_point = 0, 0
for i, (add, a, b) in enumerate(Dishes):
    if i % 2 == 0:
        T_point += a
    else:
        A_point += b


print(T_point - A_point)

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

Solution (Python):
N = int(input())
arr = []
for _ in range(N):
    a,b = map(int,input().split())
    arr.append([a,b,a+b])
arr = sorted(arr,key = lambda x:x[2])
takahasi = 0
aoki = 0
i = 0
while arr:
    tmp = arr.pop()
    if i%2 == 0:
        takahasi += tmp[0]
    else:
        aoki += tmp[1]
    i += 1
print(takahasi-aoki)

Solution (Python):
n=int(input())
a=[]
for i in range(n):
  x,y=map(int,input().split())
  z=x+y
  a.append([z,x,y])
a.sort(reverse=True)
f=True
s=0
for z,x,y in a:
  if f:
    s+=x
  else:
    s-=y
  f= not f
print(s)

Solution (Python):

from collections import defaultdict
import math
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007


"""
n,a,b = LI()
ans = [min(a,b),max(0,a+b-n)]
print(ans[0],ans[1])
"""


"""
n = II()
a = S()
b = S()
c = S()
ans = 0
for i in range(n):
    if a[i] == b[i]:
        if b[i] == c[i]:
            continue
        else:
            ans += 1
    else:
        if b[i] == c[i] or c[i] == a[i]:
            ans += 1
        else:
            ans += 2
print(ans)
"""


n = II()
c = LIR(n)
c.sort(key = lambda x:-x[0]-x[1])
ans = 0
i = 0
for i in range(n):
    x,y = c.pop(0)
    if i%2 == 0:
        ans += x
    else:
        ans -= y
print(ans)

Solution (Python):


def solve():
    N = int(input())
    scores = [0]*N
    A = [0]*N
    B = [0]*N
    for i in range(N):
        a, b = map(int, input().split())
        A[i] = a
        B[i] = b
        scores[i] = (i, a + b)
    scores = sorted(scores, key=lambda x: x[1], reverse=True)
    
    ans = 0
    for i in range(N):
        if i%2 ==0:
            ans += A[scores[i][0]]
        else:
            ans -= B[scores[i][0]]
    print(ans)

if __name__ == "__main__":
    solve()

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

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

result = 0
result = sum(a for a, b in AB[0::2]) - sum(b for a, b in AB[1::2])

print(result)

Solution (Python):
import heapq as hq

N = int(input())
H = []
for n in range(N):
    A, B = map(int, input().split())
    hq.heappush(H, (A + B, A, B))

res_a = 0
res_b = 0
for n in range(N):
    s, a, b = hq.heappop(H)
    if N % 2 == 0:
        if n % 2 == 0:
            res_b += b
        else:
            res_a += a
    else:
        if n % 2 == 0:
            res_a += a
        else:
            res_b += b

print(res_a - res_b)

Solution (Python):
N = int(input())
L = []
for i in range(N):
  Data = list(map(int, input().split()))
  L.append([Data[0] + Data[1], Data[0], Data[1]])

L.sort(reverse = True)

Taka = 0
Aoki = 0

for i in range(N):
  if i % 2 == 0:
    Taka += L[i][1]
  else:
    Aoki += L[i][2]

print(Taka - Aoki)

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

C = sorted(C,key=lambda x: x[0])
C = C[::-1]
t_sum=0
a_sum=0
for i in range(N):
    if i%2==0:
        t_sum+=A[C[i][1]]
    else:
        a_sum+=B[C[i][1]]

print(t_sum-a_sum)

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

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=True, key=lambda x: x[2])

takahashi = 0
aoki = 0

for i, (a, b, s) in enumerate(c):
    if i % 2 == 0:
        takahashi += a
    else:
        aoki += b

print(takahashi - aoki)

Solution (Python):
N = int(input())
AB = []

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

AB.sort()
result = [0, 0]

for i in range(N):
    result[i%2] += AB[-1][i%2+1]
    del AB[-1]

print(result[0] - result[1])

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

taka, aoki = 0, 0
b.sort()
b.reverse()
for i in range(n):
  if i % 2 == 0:
    taka += a[b[i][1]][0]
  else:
    aoki += a[b[i][1]][1]

print(taka-aoki)

Solution (Python):
N = int(input())
X = []
A = []
C = []
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    C.append(b+a)
C = sorted(C)[::-1]
print(sum(A)-sum(C[1::2]))

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()
AB.reverse()
ans = 0
for i in range(N):
	if i % 2 == 0:
		ans += AB[i][1]
	else:
		ans -= AB[i][2]
print(ans)

Solution (Python):
N=int(input())
table=[]
for i in range(N):
    a,b=map(int,input().split())
    table.append((a+b,a,b))
table=sorted(table,reverse=True)
t=0
ao=0
for i in range(N):
    s,a,b=table[i]
    if i%2==0:
        t+=a
    else:
        ao+=b
print(t-ao)

Solution (Python):
import numpy as np



N = int(input())
A, B = [], []

for _ in range(N):
    a, b = list(map(int, input().split(" ")))
    A.append(a)
    B.append(b)

C = [a + b for a, b in zip(A, B)]

order = np.argsort(C)[::-1]

res = 0

for i in order[::2]:
    res += A[i]
for i in order[1:][::2]:
    res -= B[i]

print(res)

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


AB = [tuple(map(int,input().split()))for _ in range(N)]

total_a = sum(a for a,b in AB)
total_b = sum(b for a,b in AB)

x = sorted((a+b for a,b in AB),reverse=True)

ans = total_a-total_b
for i,v in enumerate(x):
    if i%2==0:
        ans +=v
    else:
        ans -=v

print(ans//2)

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

taka = ao = 0

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

Solution (Python):


import bisect


def IT():  
    return int(input())

def IL():  
    return [int(_) for _ in input().split()]

def IS():  
    return [_ for _ in input().split()]

def ILS(n):  
    return [int(input()) for _ in range(n)]

def SLS(n):  
    return [input() for _ in range(n)]

def ILSS(n):  
    return [[int(_) for _ in input().split()] for j in range(n)]


def bit_full_search(ss):
    n = len(ss)
    for i in range(1 << n):
        s = ""
        for j in range(n + 1):
            if ((1 & i >> j) == 1):
                s += ss[j]
        print(s)

def bit_full_search2(A):
    
    value = []
    for i in range(1 << len(A)):
        output = []

        for j in range(len(A)):
            if ((i >> j) & 1) == 1:
                
                output.append(A[j])
        value.append([format(i, 'b').zfill(16), sum(output)])

    value.sort(key=lambda x: x[1])
    bin = [value[k][0] for k in range(len(value))]
    val = [value[k][1] for k in range(len(value))]
    return bin, val

def matching_bisect(list1_val, list2_val, n):
    
    j = 0
    for i in range(len(list1_val)):
        j = bisect.bisect_left(list2_val, n - list1_val[i])
        if j < len(list2_val):
            if list1_val[i] + list2_val[j] == n:
                
                break
    return j

"""ここからメインコード"""

def main():
    n = IT()
    AB = ILSS(n)


    for i in range(n):
        AB[i].append(AB[i][1] + AB[i][0])
    AB.sort(key=lambda x: x[2], reverse = True)

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

main()

Solution (Python):
n = int(input())
items = []
for _ in range(n):
    a, b = map(int, input().split())
    items.append((a, b))
items.sort(key=lambda x:-x[0] + -x[1])
t = sum([items[i][0] for i in range(0, n, 2)])
a = sum([items[i][1] for i in range(1, n, 2)])
print(t - a)

Solution (Python):
N = int(input())
A = []
for i in range(N):
  a, b = map(int, input().split())
  c = a + b
  A += [[a, b, c]]
  
A.sort(key=lambda x:x[2], reverse = True)

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

Solution (Python):
N = int(input())
AB = sorted([[int(_) for _ in input().split()] for _ in range(N)],
            key=lambda x: sum(x))
print(sum([a for a, b in AB][-1::-2]) - sum([b for a, b in AB][-2::-2]))

Solution (Python):

from sys import stdin
import numpy as np

s_in = lambda: stdin.readline()[:-1]  
d_in = lambda: int(stdin.readline())  
ds_in = lambda: list(map(int, stdin.readline().split()))  


N = d_in()
A_list = []
B_list = []
C_list = []
for _ in range(N):
    a, b = ds_in()
    A_list.append(a)
    B_list.append(b)
    C_list.append(a+b)

c_np = np.array(C_list)
c_idx = np.argsort(c_np)[::-1]

a_h, b_h = 0, 0
for i in range(N):
    if i % 2 == 0:
        a_h += A_list[c_idx[i]]
    else:
        b_h += B_list[c_idx[i]]
print(a_h - b_h)

Solution (Python):
N = int(input())
arr = [list(map(int, input().split())) for _ in range(N)]
arr.sort(key=lambda a:-(a[0]+a[1]))
print(sum([a[0] for a in arr[::2]]) - sum([a[1] for a in arr[1::2]]))

Solution (Python):
n = int(input())
ds = []
for i in range(n):
    a,b = map(int, input().split())
    ds.append((a+b, a, b))
ds.sort(reverse=True)
a = 0
b = 0
for i in range(0,n,2):
    a += ds[i][1]
for i in range(1,n,2):
    b += ds[i][2]

print(a-b)

Solution (Python):
def main():
    n = input()
    ab = []
    for _ in xrange(n):
        a, b = map(int, raw_input().split())
        ab.append([a, b])
    ab.sort(key=lambda x: x[0] + x[1], reverse=True)
    x = sum(a[0] for a in ab[0::2])
    y = sum(a[1] for a in ab[1::2])
    print x - y


if __name__ == '__main__':
    main()

Solution (Python):
def ii():
    return int(input())
def mi():
    return map(int, input().split())
def li():
    return list(mi())

n = ii()
a = []
for i in range(n):
    x, y = mi()
    a.append((x + y, x, y))
a.sort(reverse=True)
ans = 0
for i in range(n):
    if i % 2: ans -= a[i][2]
    else: ans += a[i][1]
print(ans)

Solution (Python):
from sys import exit, setrecursionlimit, stderr
from functools import reduce
from itertools import *
from collections import defaultdict, Counter
from bisect import bisect

setrecursionlimit(10**7)

def read():
  return int(input())

def reads():
  return [int(x) for x in input().split()]

N = read()
A = [0] * N
B = [0] * N

for i in range(N):
  A[i], B[i] = reads()

ans = sum(A)
C = [A[i] + B[i] for i in range(N)]
C.sort()
C.reverse()

for i in range(1, N, 2):
  ans -= C[i]

print(ans)

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):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    a = []
    for _ in range(n):
        b,c = LI()
        a.append([b+c,b,c])
    d = sorted(a,reverse=True)
    r = 0
    for i in range(n):
        if i % 2 == 0:
            r += d[i][1]
        else:
            r -= d[i][2]

    return r



print(main())