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, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
from decimal import Decimal
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
from decimal import *

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, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
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()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 

from decimal import *



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

for i in range(N):
	AB[i].append(sum(AB[i]))

AB.sort(key = lambda x: -x[2])

print(sum([AB[i][0] for i in range(0, N, 2)]) - sum([AB[i][1] for i in range(1, N, 2)]))

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

AB = sorted([s+t for s,t in zip(A,B)], reverse=True)
su = sum(AB[::2])
print(su-sum(B))

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

Solution (Python):
from collections import deque
N = int(input())
lis = []

A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    lis.append((Ain+Bin,i))
lis.sort()
lis.reverse()
lis = deque(lis)

takacnt = 0
aocnt = 0




for i in range(N):
    if i % 2 == 0:
        val = lis.popleft()
        takacnt += A[val[1]]
    else:
        val = lis.popleft()
        aocnt += B[val[1]]
print(takacnt-aocnt)

Solution (Python):
from collections import deque
N = int(input())
lis = []

A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    lis.append((Ain+Bin,i))
lis.sort()
lis.reverse()
lis = deque(lis)

takacnt = 0
aocnt = 0
st = set()




for i in range(N):
    if i % 2 == 0:
        while True:
            val = lis.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        while True:
            val = lis.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)

Solution (Python):
from collections import deque
N = int(input())
taka = []
ao = []
A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    taka.append((Bin+Ain,i))
    ao.append((Ain+Bin,i))
taka.sort()
taka.reverse()
ao.sort()
ao.reverse()
taka = deque(taka)
ao = deque(ao)
takacnt = 0
aocnt = 0
st = set()




for i in range(N):
    if i % 2 == 0:
        while True:
            val = taka.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        while True:
            val = ao.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)

Solution (Python):
n = int(input())
a = []
b = []
for i in range(n):
    t1,t2 = map(int,input().split())
    a.append(t1)
    b.append(t2)
wa = []
for i in range(n):
    wa.append(a[i] + b[i])
c = zip(wa,a,b)
c = sorted(c, reverse = True)
wa, a, b = zip(*c)
ans = 0
flg = 0
for i in range(n):
    if flg == 0:
        ans +=a[i]
        flg = 1
    else:
        ans -=b[i]
        flg = 0
print(ans)

Solution (Python):
n = int(input())
AB = [tuple(map(int, input().split())) for _ in range(n)]
AB.sort(key = lambda x : x[0] + x[1], reverse = 1)
ans = 0
for i in range(n):
  a, b = AB[i]
  if i & 1:
    ans -= b
  else:
    ans += a
print(ans)

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


if __name__ == '__main__':
    main()

Solution (Python):


import sys
from typing import Any, Callable, Deque, Dict, List, Mapping, Optional, Sequence, Set, Tuple, TypeVar, Union































def main():
    Num = Union[int, float]
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input():  return sys.stdin.readline().rstrip()
    def ii():     return int(input())
    def isp():    return input().split()
    def mi():     return map(int, input().split())
    def mi_0():   return map(lambda x: int(x)-1, input().split())
    def lmi():    return list(map(int, input().split()))
    def lmi_0():  return list(map(lambda x: int(x)-1, input().split()))
    def li():     return list(input())
    def debug(x): print(x, file=sys.stderr)
    
    
    
    n = ii()
    L = [lmi() for _ in range(n)]
    L.sort(key=lambda x: x[0] + x[1])
    
    turn = True
    takahashi, aoki = 0, 0
    while L:
        a, b = L.pop()
        if turn:
            takahashi += a
        else:
            aoki += b
        turn = not turn
    
    print(takahashi - aoki)


if __name__ == "__main__":
    main()

Solution (Python):

from collections import deque, Counter
from heapq import heappop, heappush
from bisect import bisect_right

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

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
point = [0] * n
total_b = 0
for i in range(n):
    a, b = map(int, input().split())
    point[i] = a + b
    total_b += b

point.sort(reverse = True)

sum_t = 0
for i in range(n):
    if i % 2 == 0:
        sum_t += point[i]

print(sum_t - total_b)

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

Solution (Python):
import sys
from heapq import heappush, heappop
from collections import defaultdict

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    ab = []

    for i in range(N):
        a, b = in_nn()
        ab.append((a + b, a, b))

    ab.sort(reverse=True)

    taka = 0
    for i in range(0, N, 2):
        taka += ab[i][1]
    aoki = 0
    for i in range(1, N, 2):
        aoki += ab[i][2]

    ans = taka - aoki
    
    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):





import math
import fractions
import sys
import bisect
import heapq  
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr



def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod



def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

n = ir()
ab = [lr() 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):
n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]

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

sum_ab.sort(reverse=True)
for i in range(1, n, 2):
    sum_a -= sum_ab[i]
print(sum_a)

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

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N=I()
    L=[[0,0,0]for _ in range(N)]
    for i in range(N):
        a,b=MI()
        L[i]=[a+b,a,b]
        
    L.sort(reverse=True)
    
    a=0
    b=0
    for i in range(N):
        if i%2==0:
            a+=L[i][1]
        else:
            b+=L[i][2]
            
    print(a-b)

main()

Solution (Python):
n=int(input())
a=[]
b=[]
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)

ab=[a[i]+b[i] for i in range(n)]

ab.sort(reverse=True)
asum=sum(ab[::2])
print(asum-sum(b))

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)
b=[i[1]for i in ab]
s=[i[0]+i[1]for i in ab]
print(sum(s[::2])-sum(b))

Solution (Python):
from collections import deque
N=int(input())

C=[]
D=0
for _ in range(N):
    a,b=map(int,input().split())
    C.append((a,b))
    D+=b
    
C.sort(key=lambda x:x[0]+x[1])
C=deque(C)

i=0
A=0
while C:
    (a,b)=C.pop()
    if i==0:
        A+=a+b
    i^=1
print(A-D)

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

N = int(readline())
A = [0] * N
B = [0] * N
C = [0] * N
for i in range(N):
  A[i],B[i] = map(int,readline().split())
  C[i] = (A[i] + B[i], i)
  
C = sorted(C, key = lambda x:x[0], reverse = True)

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

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)


taka=0
aoki=0

for i in range(1,n+1):
    if i%2!=0:
        taka+=ab[i-1][1]
    else:
        aoki+=ab[i-1][2]
ans=taka-aoki
print(ans)

Solution (Python):
N, *AB = map(int, open(0).read().split())
AB = [(a, b) for a, b in zip(*[iter(AB)] * 2)]
AB.sort(key=lambda x: x[0] + x[1], reverse=True)
ans = sum(a for a, _ in AB)
for a, b in AB[1::2]:
    ans -= a + b
print(ans)

Solution (Python):
n = int(input())
l = [list(map(int,input().split())) for i in range(n)]
ab = []
ans = 0
for i,j in l:
    ab.append(i+j)
    ans -= j

ab.sort(reverse=True)
ans += sum(ab[::2])
print(ans)

Solution (Python):
n = int(input())
food = [[int(i) for i in input().split()] for _ in range(n)]
food.sort(key=lambda x:sum(x),reverse=True)
hpns = [0,0]
for i in range(n): hpns[i%2] += food[i][i%2]
print(hpns[0]-hpns[1])

Solution (Python):
import numpy as np
n = int(input())
al = np.zeros(n)
bl = np.zeros(n)
for i in range (n):
    al[i],bl[i] = map(int,input().split())
id = [*range(n)]
s=al+bl
id = sorted(id, key=lambda i: -s[i])
s=np.sort(s)
ans = 0 
for i in range(n):
    if i%2==0:
        ans+=al[id[i]]
    else:
        ans-=bl[id[i]]
print(int(ans))

Solution (Python):
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    for i in range(n):
        ab[i].append(ab[i][0] + ab[i][1])
    arr = sorted(ab, reverse=True, key=lambda x: x[2])
    ans = 0
    for i in range(n):
        if i % 2 == 0:
            ans += arr[i][0]
        else:
            ans -= arr[i][1]
    print(ans)


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()

Solution (Python):
n=int(input())
ab=[list(map(int, input().split())) for _ in range(n)]
yusendo=[]
for i in range(n):
    yusendo.append([ab[i][0]+ab[i][1], ab[i][1]-ab[i][0], i])
yusendo.sort(reverse=True)


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


print(takahashi-aoki)

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

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

num = (n + 1) // 2
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())
L = []
for _ in range(n):
    a,b = map(int,input().split())
    L.append(((a+b),a,b))
L.sort(reverse=True)
ta = 0
ao = 0
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())
l = []
for i in range(N):
    a,b = map(int,input().split())
    l.append((a+b,a,b))
l.sort(reverse=True)
A,B = 0,0
for i in range(N):
    if i%2 == 0:
        A += l[i][1]
    else:
        B += l[i][2]
print(A-B)

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

a, b, ab = [], [], []
for _ in range(n):
    ai, bi = map(int, input().split())
    a.append(ai)
    b.append(bi)
    ab.append(ai + bi)
ab.sort(reverse=True)

ans = -sum(b)
for i in range(0, n, 2):
    ans += ab[i]
print(ans)

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

    C.sort(reverse=True)
    ans = -sum(B)
    for i, c in enumerate(C):
        if i % 2 == 0:
            ans += C[i]
    
    print(ans) 

    
    



if __name__ == "__main__":
    main()

Solution (Python):



def main():
    N = int(input())
    S = [None]*N
    for _ in range(N):
        a,b = map(int,input().split())
        S[_] = [a+b, a, b]
    S.sort(reverse = True)
    ret = 0
    for i in range(N):
        if i%2==0:
            ret += S[i][1]
        else:
            ret -= S[i][2]

    print(ret)

if __name__ == '__main__':
    main()

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

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())
datA = []
datB = []
buf = []
for i in range(n):
    a,b = map(int, input().split())
    datA.append(a)
    datB.append(b)
    buf.append([a+b,i])
buf.sort(reverse=True)
resA, resB = 0, 0
for i in range(n):
    if i%2 == 0:
        resA += datA[buf[i][1]]
    else:
        resB += datB[buf[i][1]]

print(resA - resB)

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

dishes = []
for _ in range(n):
    a, b = map(int, input().split())
    dishes.append((a+b, a, b))
dishes.sort(reverse=True)

T = A = 0
for i, (_, a, b) in enumerate(dishes):
    if not i & 1:
        T += a
    else:
        A += b
print(T-A)

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
import heapq
from collections import defaultdict
from collections import deque
from collections import Counter
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')
AtoZ = "abcdefghijklmnopqrstuvwxyz"






def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]


def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()


def DD(arg): return defaultdict(arg)



def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  divisors.sort()
  return divisors


def make_primes(N):
  max = int(math.sqrt(N))
  seachList = [i for i in range(2,N+1)]
  primeNum = []
  while seachList[0] <= max:
    primeNum.append(seachList[0])
    tmp = seachList[0]
    seachList = [i for i in seachList if i % tmp != 0]
  primeNum.extend(seachList)
  return primeNum


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i-1])*n**i for i in range(len(str(X))))


def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count




N = I()
D = []
for _ in range(N):
  a,b = IL()
  D.append((a,b))
D = sorted(D,key = lambda x:sum(x),reverse = True)

A = 0
B = 0
for i in range(N):
  a,b = D[i]
  if i%2:
    B+=b
  else:
    A+=a

print(A-B)

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


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

Solution (Python):
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
a = [None]*n
b = [None]*n
for i in range(n):
    a[i],b[i] = map(int, input().split())
    
ab = [(a[i]+b[i], i) for i in range(n)]
ab.sort()
takahashi = 0
aoki = 0
for i in range(n):
    if i%2==0:
        takahashi += a[ab[n-1-i][1]]
    else:
        aoki += b[ab[n-1-i][1]]
print(takahashi-aoki)

Solution (Python):
import numpy as np
n = int(input())

aab = []

for i in range(n):
    a, b = map(int, input().split())
    aab.append([a + b, a, b])

aab.sort(reverse=True)
aab = np.array(aab)

a = aab[:, 1][0::2].sum()
b = aab[:, 2][1::2].sum()

print(a - b)

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

Solution (Python):
N = int(input())
l = []
for _ in range(N):
    A, B = map(int, input().split())
    l.append((-abs(A+B), -A, -B))
l.sort()
a, b = 0, 0
for i in range(N):
    if i%2:
        b -= l[i][2]
    else:
        a -= l[i][1]

print(a-b)

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

l = []
T,A = 0,0

for a,b in AB:
  l.append(a+b)
  T += a
  A += b

ans = -A
l.sort(reverse = True)

check = 0

for i in range(N):
  if check == 0:
    ans += l[i]
    check = 1
  else:
    check = 0
print(ans)

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

Solution (Python):
n = int(input())
A, B, AB = [], [], []
for i in range(n):
    ai, bi = map(int, input().split())
    A.append(ai)
    B.append(bi)
    AB.append((ai + bi, i))
AB.sort(reverse=True)


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

Solution (Python):
def main():
    import sys
    N = int(input())
    C = [0] * N
    for n in range(N):
        a, b = [int(x) for x in input().strip().split()]
        C[n] = (a+b, a, b)
    C.sort(reverse=True)
    ans = 0
    for n in range(N):
        if n % 2:
            ans -= C[n][2]
        else:
            ans += C[n][1]

    print(ans)
    
if __name__ == '__main__':
    main()

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

Solution (Python):
def f():
    import sys
    input=sys.stdin.buffer.readline
    sys.setrecursionlimit(10**9)
    n=int(input())
    l=sorted([list(map(int,input().split())) for i in range(n)],key=sum,reverse=1)
    ans=0
    for i in range(n):
        if i%2:ans-=l[i][1]
        else:ans+=l[i][0]
    print(ans)
if __name__ == "__main__":
    f()

Solution (Python):
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=int(input())
a=[0]*n
b=[0]*n
l=[0]*n
for i in range(n):
    x,y=mp()
    a[i]=x
    b[i]=y
    l[i]=[x,y,x+y]
l=sorted(l,key=lambda X: X[2],reverse=True)
ans=0
for i in range(n):
    if i%2==0:
        ans+=l[i][0]
    else:
        ans-=l[i][1]
print(ans)

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)

if len(AB)%2==1:
    AB.append([0,0])

s=0
for i in range(0,len(AB),2):
    s+=AB[i][0]-AB[i+1][1]

print(s)

Solution (Python):
import sys
import heapq
import re
from heapq import heapify, heappop, heappush
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt, ceil
from functools import lru_cache, reduce
INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


def dijkstra_heap(s, edge, n):
    
    d = [10**20] * n
    used = [True] * n 
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm, numbers, 1)


def gcd_list(numbers):
    return reduce(gcd, numbers)


def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True



def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P


def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret


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


ans = 0
used = [0 for i in range(n)]
takahashi = True
t_cnt = 0
a_cnt = 0
cnt = 0
while cnt < n:
    if takahashi and t_cnt < n:
        if used[x[t_cnt][2]] == 0:
            ans += x[t_cnt][1]
            takahashi = False
            cnt += 1
            used[x[t_cnt][2]] = 1
        t_cnt += 1
    elif (not takahashi) and a_cnt < n:
        if used[y[a_cnt][2]] == 0:
            ans -= y[a_cnt][1]
            takahashi = True
            cnt += 1
            used[y[a_cnt][2]] = 1
        a_cnt += 1
    
print(ans)

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(key= lambda x:x[0])

ans = 0
for i in range(n):
    v, a, b = ab.pop()
    if i % 2 == 0:
        ans += a
    else:
        ans -= b

print(ans)

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