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 time

import numpy as np

N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = []
aoki = []

start = time.time()

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


D = np.array(A) + np.array(B)
for i in range(N):
  C[i] = [i, D[i]]


elapsed_time = time.time() - start

start = time.time()

C = sorted(C, key=lambda x:x[1])


elapsed_time = time.time() - start

start = time.time()


if N %2 == 0 :
  for i in range(1,N,2):
    tmp_max = C[-i][0]
    takahashi.append(A[tmp_max])
    tmp_max = C[-i-1][0]
    aoki.append(B[tmp_max])

elif N %2 != 0 :
  for i in range(1,N-1,2):
    tmp_max = C[-i][0]
    takahashi.append(A[tmp_max])
    tmp_max = C[-i-1][0]
    aoki.append(B[tmp_max])
  tmp_max = C[-N][0]
  takahashi.append(A[tmp_max])

print(sum(takahashi)-sum(aoki))

elapsed_time = time.time() - start

Solution (Python):
import numpy as np
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())

a = np.array(A)
b = np.array(B)
c = np.zeros(N)


c = a + b

csorted = np.sort(c)[::-1]

bsum = np.sum(b)

csum = 0
for i in range(N):
    if i % 2 == 0:
        csum += int(csorted[i])

ans = csum - bsum

print(ans)

Solution (Python):

import numpy as np
N = int(input())
A = [0]*N
B = [0]*N
for i in range(N):
    A[i], B[i] = map(int, input().split())
 
a = np.array(A)
b = np.array(B)
 

c = a + b

csorted = np.sort(c)[::-1]

bsum = np.sum(b)

csum = 0
for i in range(N):
    if i % 2 == 0:
        csum += int(csorted[i])
 
ans = csum - bsum
 
print(ans)

Solution (Python):

def main():
    n = int(input())
    a = []
    b = []
    s = []
    for i in range(n):
        atmp,btmp = map(int,input().split())
        a.append(atmp)
        b.append(btmp)
        s.append([atmp+btmp,i])


    s = sorted(s, key=lambda x: x[0], reverse=True)

    rem = [1 for i in range(n)]

    takahashi = 0
    aoki = 0

    for e,i in enumerate(s):
        if not e % 2:
            takahashi += a[i[1]]
        else:
            aoki += b[i[1]]
        

    print(takahashi-aoki)




main()

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

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

value.sort(reverse=True)
takahashi = 0
aoki = 0
flag = 1
for i in range(N):
    if flag == 1:
        takahashi += value[i][1]
    else:
        aoki += value[i][2]
    flag *= -1
print(takahashi - aoki)

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
AB=[]
append=AB.append
for i in range(n):
  a,b=map(int,input().split())
  append((a+b,a,b))
AB.sort(key=lambda x:x[0],reverse=True)
ans=0
sign=0
for i in range(n):
  ab,a,b=AB[i]
  if sign==0:
    ans+=a
    sign=1
  else:
    ans-=b
    sign=0
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
AB=[]
append=AB.append
for i in range(n):
  a,b=map(int,input().split())
  append((a+b,a,b))
AB.sort(key=lambda x:x[0],reverse=True)
ans=0
sign=0
for i in range(n):
  ab,a,b=AB[i]
  if sign==0:
    ans+=a
    sign=1
  else:
    ans-=b
    sign=0
print(ans)

Solution (Python):
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)




n = ip()                      




b = []
for i in range(n):
    b.append(iprow())
a = []
for i in range(n):
    c = [sum(b[i]),b[i][0],b[i][1]]
    a.append(c)
a.sort(reverse=True)
s = 0
ct = 0
for i in range(n):
    a[i][2]*=-1
for i in a:
    s+=i[ct+1]
    ct+=1
    ct%=2
print(s)

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

dish=[]

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

dish.sort()
dish.reverse()

ans=0
takahashi=True

for turn in dish:
    if takahashi:
        takahashi=False
        ans+=turn[1]
    else:
        takahashi=True
        ans-=turn[2]

    
print(ans)

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

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

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

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

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

    AB.append(A+B)
    X += B * -1

AB.sort(reverse=True)


for i in range(0, N, 2):
    X += AB[i]


print(X)

Solution (Python):
n = int(input())
ab = [[int(item) for item in input().split()] for _ in range(n)]
ab.sort(key=lambda x: x[0] + x[1], reverse=True)

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

Solution (Python):
N = int(input())
dish = [list(map(int, input().split())) for _ in range(N)]
ans = 0
for i in range(N):
    ans -= dish[i][1]
def f(l):
    a, b = l
    return a+b
dish.sort(key = f)
cnt = 0
while dish:
    a, b = dish.pop()
    if cnt % 2 == 0:
        ans += a+b
        cnt += 1
    else:
        cnt += 1
print(ans)

Solution (Python):
n = int(input())
ans = 0
l = []
for i in range(n):
    x,y = map(int,input().split())
    ans-=y
    l.append(x+y)
l.sort()
for i in l[::-2]:
    ans+=i
print(ans)

Solution (Python):
n = int(input())
ans = 0
l = []
for i in range(n):
    x,y = map(int,input().split())
    ans-=y
    l.append(x+y)
l.sort()
l = l[::-1]
for i in l[::2]:
    ans+=i
print(ans)

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

po = [0]*N
for i in range(N):
  po[i] = ( sum(li[i]) , i )
po.sort ( key = lambda x: -x[0] )

s = 0
it = 0
for i in range(N):
  s += li[ po[i][1] ][it] * ( 1 - it * 2  )
  it = 1-it           
print (s)

Solution (Python):
N = int(input())
ABs = [list(map(int,input().split())) for i in range(N)]
li = []
for A,B in ABs:
  li.append([A+B,A,B])
  
li.sort(reverse=True)
flag = True
ans1 = ans2 = 0
for S,A,B in li:
  if flag:
    ans1 += A
  else:
    ans2 += B
  flag = not flag
  
print(ans1-ans2)

Solution (Python):
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB.sort(key=lambda x:sum(x), reverse=True)
tk = 0
ak = 0
for i, (a, b) in enumerate(AB):
    if i % 2 == 0:
        tk += a
    else:
        ak += b
print(tk-ak)

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

tans = 0
for i, _ab in enumerate(sorted(ab, key=lambda x: -x)):
  if i % 2 == 0:
    tans += _ab

print(tans - bsum)

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

Solution (Python):
n=int(input())
ans=0
l=[]
x=0
for i in range(n):
    a,b=map(int,input().split())
    l.append([a,b])
    x-=b

print(sum(map(sum,sorted(l,reverse=1,key=lambda x:sum(x))[::2]))+x)

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

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


if __name__ == "__main__":
    main()

Solution (Python):

import sys


def solve(N: int, A: "List[int]", B: "List[int]"):
    tmp = []
    for i in range(N):
        tmp.append([A[i], B[i], A[i] + B[i]])
    tmp.sort(reverse=True, key=lambda x: x[2])
    ret = 0
    for i in range(N):
        t = tmp[i][0] if i % 2 == 0 else -tmp[i][1]
        ret += t
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int()] * (N)  
    B = [int()] * (N)  
    for i in range(N):
        A[i] = int(next(tokens))
        B[i] = int(next(tokens))
    solve(N, A, B)

if __name__ == '__main__':
    main()

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

Solution (Python):
N = int(input())
ab = []
for i in range(N):
    a,b = map(int,input().split())
    c = a+b
    ab.append([c,a,b])
ab.sort(reverse=True)
t = 1
A,B = 0,0
for i in range(N):
    if t == 1:
        A += ab[i][1]
        t *= -1
    else:
        B += ab[i][2]
        t *= -1
print(A-B)

Solution (Python):
n = int(input())
listP = []
i=0
while i < n:
    a, b = map(int, input().split())
    listP.append([a+b, a, b])
    i+=1
listP.sort()
listP.reverse()

takaP=0
aokiP=0
index=0
while index < len(listP):
    if index%2==0:
        takaP+=listP[index][1]
    else:
        aokiP+=listP[index][2]
    index+=1
print(takaP-aokiP)

Solution (Python):
N=int(input())
Dinner=[[int(i) for i in input().split()] for i in range(N)]
C=[Dinner[i][0]+Dinner[i][1] for i in range(N)]
C.sort(reverse=True)
ans=0
for i in range(N):
  if i%2==0:
    ans+=C[i]
  ans-=Dinner[i][1]
print(ans)

Solution (Python):
s=[list(map(int,input().split()))for i in range(int(input()))];print(sum(sorted([x[1]+x[0] for x in s])[::-2])-sum([x[1]for x in s]))

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

Solution (Python):

n = int(input())
if n==1:
    a, b =map(int, input().split())
    print(a)
else:
    def return_a(n):
        return n[0]
    def return_b(n):
        return n[1]
    ab = [[0] * 3 for i in range(n)]
    for i in range(n):
        ab[i][0], ab[i][1] = map(int, input().split())
        ab[i][2] = ab[i][0] + ab[i][1]
    ab = sorted(ab, key=lambda x: x[2], reverse=True)
    print(sum(map(return_a, ab[0::2])) - sum(map(return_b, ab[1::2])))

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

n = int(input())
ab = []
for i in range(n):
    a = list(map(int, input().split()))
    ab.append([a[0]+a[1], a[0], a[1]])

ab = sorted(ab, reverse=True)

a = sum(list(map(lambda x: x[1], ab[::2])))
b = sum((list(map(lambda x: x[2], ab[1::2]))))

print(a-b)

Solution (Python):
from math import ceil
N = int(input())
D = [list(map(int, input().split())) for _ in range(N)]
D.sort(key=lambda x: sum(x), reverse=True)
ans = 0
for i in range(N):
    ans -= D[i][1]
    if i < ceil(N / 2):
        ans += D[i * 2][0] + D[i * 2][1]
print(ans)

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

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

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

print(T-A)

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

AB.sort(reverse=True)
for i in range(N):
    if i%2 == 1:
        ans -= AB[i]

print(ans)

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

ans = -sum([i[1] for i in ab])
sum_l = list(map(sum, ab))
sum_l.sort(reverse=True)

for i in sum_l[::2]:
    ans += i
print(ans)

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

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

ans = 0
for i, (a, b) in enumerate(X):
    if i % 2 == 0:
        ans += a
    else:
        ans -= b

print(ans)

Solution (Python):
n = int(input())
score = []
for i in range(n):
    a,b = map(int,input().split())
    score.append([a,b,a+b])
score.sort(key = lambda x: x[2])
score.reverse()

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

Solution (Python):
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)

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

Solution (Python):
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((abs(tmp[0] + tmp[1]), tmp[0], tmp[1]))

dishes = sorted(dishes, key=lambda x: x[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes) > 0:
    dish = dishes.pop(0)
    point[player] += dish[player + 1]
    player = int(not player)
print(point[0] - point[1])

Solution (Python):
N = int(input())
L = []
K = []
S = 0
for i in range(N):
  L.append(list(map(int,input().split())))
for i in range(N):
  S += -L[i][1]
for i in range(N):
  K.append(L[i][0]+L[i][1])
K.sort()
K.reverse()
if N%2 == 0:
  for i in range(N//2):
    S += K[i*2]
else:
  for i in range(N//2+1):
    S += K[i*2]
print(S)

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

Cs = [(A+B, i) for i, (A, B) in enumerate(zip(As, Bs))]
Cs.sort(reverse=True)

hA = sum([As[i] for C, i in Cs[::2]])
hB = sum([Bs[i] for C, i in Cs[1::2]])
print(hA - hB)

Solution (Python):

N=int(input())
A=[]
B=[]
C=[]
for i in range(0,N):
    a,b=map(int,input().split())
    A.append(a)
    B.append(b)
    C.append(a+b)
C.sort()
C.reverse()
point=-sum(B)

i=0
while i<N:
    point=point+C[i]
    i=i+2
print(point)

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)



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


def main():
    N = int(input())
    score = []
    for i in range(N):
        a, b = map(int, input().split())
        score.append((a + b, a, b))

    takahashi, aoki = 0, 0
    for i, (t, a, b) in enumerate(sorted(score, reverse=True)):
        if i % 2 == 0:
            takahashi += a
        else:
            aoki += b
    print(takahashi - aoki)


if __name__ == '__main__':
    main()

Solution (Python):


from collections import deque
import itertools as it
import sys
import math

sys.setrecursionlimit(1000000)

INF = 10 ** 18

N = input()
ls = []
for _ in range(N):
    A, B = map(int, raw_input().split())
    ls.append((A + B, A, B))
ls.sort(reverse = True)

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

print ans

Solution (Python):
N=int(input())
B=[0 for i in range(N)]
sum_AB=[0 for i in range(N)]
for i in range(N):
    A,B[i]=map(int,input().split())
    sum_AB[i]=A+B[i]
sum_AB.sort(reverse=True)
sum_B=sum(B)
sum_takahashi=-sum_B
i=0
while i<N:
    if i%2==0:
        sum_takahashi+=sum_AB[i]
    i+=1
print(sum_takahashi)

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

ab.sort(key=sum, reverse=True)

sol = int(0)

for i, x in enumerate(ab):
  if i % 2:
    sol -= ab[i][1]
  else:
    sol += ab[i][0]

print(sol)

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

ab.sort(key=sum, reverse=True)

sol = 0

for i, x in enumerate(ab):
  if i % 2:
    sol -= ab[i][1]
  else:
    sol += ab[i][0]

print(sol)

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,key=lambda x:x[0])
ans=0
for i in range(n):
    if i%2==0:
        ans+=AB[i][1]
    else:
        ans-=AB[i][2]
print(ans)

Solution (Python):
def get_ans(pairs):
    pairs = sorted(pairs, key=lambda x: -sum(x))
    score = 0
    flg = 0
    for a,b in pairs:
        score += a*(1-flg) - b*flg
        flg = 1- flg
    return score

if __name__ == '__main__':
    n = int(input())
    p = []
    for i in range(n):
        p.append(tuple(map(int, input().split())))

    print(get_ans(p))

Solution (Python):
N = int(input())
A = [[0 for i in range(2)] for j in range(N)]

for i in range(N):
    A[i] = [int(x) for x in input().split()]


sum = [[0 for i in range(2)]for j in range(N)]
for i in range(N):
    sum[i][0]=A[i][0]+A[i][1]
    sum[i][1] = i


sum = sorted(sum)
sum.reverse()
max = 0
for i in range(N):
    if(i%2==0):
        max = max + A[sum[i][1]][0]
    else:
        max = max - A[sum[i][1]][1]

print(max)

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

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

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

Solution (Python):
n = int(input())
B = []
total = []
count = 0

for i in range(n):
	a,b = map(int, input().split())
	B.append(b)
	total.append(a+b)

total_new = sorted(total, reverse=True)

for i in range(0, n, 2):
	count += total_new[i]

count -= sum(B)

print(count)

Solution (Python):
n=int(input())
a=[]
b=[]
c=[]
for i in range(n):
    ai,bi=map(int,input().split())
    a.append(ai)
    b.append(bi)
    c.append(ai+bi)
c=sorted(c,reverse=True)
print(sum(c[::2])-sum(b))

Solution (Python):


import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
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()
A, B = [0]*N, [0]*N
sm = [[0]*2 for i in range(N)]
for i in range(N):
    A[i], B[i] = MAP()
    sm[i][0] = A[i] + B[i]
    sm[i][1] = i

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

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

Solution (Python):
if __name__ == '__main__':
    N = int(input())
    B, AandB = [], []
    for n in range(N):
        a, b = map(int, input().split())
        B.append(b)
        AandB.append(a+b)

    AandB.sort(reverse=True)
    ans = -sum(B)

    for i in range(0, N, 2):
        ans += AandB[i]

    print(ans)

Solution (Python):
import sys
from collections import deque


n=int(sys.stdin.readline())
M = deque(maxlen=n)
for i in range(n):
    a,b = map(int,sys.stdin.readline().split())
    M.append([a,b])

M = sorted(M,key=lambda x:sum(x))
cnt = 0
for i in range(n):
    if i%2==0:
        cnt += M.pop()[0]
    else:
        cnt -= M.pop()[1]
print(cnt)

Solution (Python):
import sys

n=int(sys.stdin.readline())
M = []
for i in range(n):
    a,b = map(int,sys.stdin.readline().split())
    M.append([a,b])

M = sorted(M,key=lambda x:sum(x), reverse=True)
cnt = 0
for i in range(n):
    if i%2==0:
        cnt += M[i][0]
    else:
        cnt -= M[i][1]
print(cnt)

Solution (Python):
N = int(input())
total = []
a_list = []
b_list = []
for i in range(0,N):
  a,b = map(int,input().split())
  a_list += [a]
  b_list += [b]
  total += [a+b]

total.sort(reverse = True)

taka = 0

for j in range(0,N):
  if j % 2 == 0:
    taka += total[j]
  
print(-sum(b_list) + taka)

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

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

Solution (Python):
import numpy as np

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

D = sorted(C, reverse=True)

ans = 0

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

print(ans)

Solution (Python):
n = int(input())
c = []
bs = 0
for i in range(n):
    a,b = map(int,input().split())
    bs += b
    c.append(a+b)

c.sort()
c.reverse()

ans = -bs
for i in range(n):
    if i%2==0: ans += c[i]
print(ans)

Solution (Python):
N = int(input())
items = [list(map(int,input().split())) for i in range(N)]
items.sort(key=lambda x: x[0]+x[1], reverse=True)
taka = sum([items[i][0] for i in range(0,N,2)])
aoki = sum([items[i][1] for i in range(1,N,2)])
print(taka - aoki)

Solution (Python):
n = int(input())
a, b = zip(*sorted((tuple(map(int, input().split())) for _ in range(n)), key=sum))
print(sum(a[-1::-2]) - sum(b[-2::-2]))

Solution (Python):
n = int(input())
s = []
ans = 0
for i in range(n):
    a, b = map(int, input().split())
    s.append(a+b)
    ans -= b

s.sort(reverse=True)
for i in range(n):
    if i%2 == 0:
        ans += s[i]

print(ans)

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

Solution (Python):
n = int(input())
c = []
bs = 0
for i in range(n):
  a,b = map(int,input().split())
  bs += b
  c.append(a+b)

c.sort()

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

Solution (Python):
n = int(input())
c = []
bs = 0
for i in range(n):
  a,b = map(int,input().split())
  bs += b
  c.append(a+b)

c.sort()

ans = -bs
for i in reversed(range(n)):
  cnt = n-1-i
  if cnt%2==0: ans += c[i]
    
print(ans)

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

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

N = int(input())

arr = np.empty((N, 3), dtype='int64')
for i in range(N):
    arr[i, 0], arr[i, 1] = input().split()
    arr[i, 2] = arr[i, 0] + arr[i, 1]

arr = arr[np.argsort(arr[:, 2])][::-1]

print(np.sum(arr[::2, 0]) - np.sum(arr[1::2, 1]))

Solution (Python):
import numpy as np

N = int(input())

arr = np.empty((N, 3), dtype='int64')
for i in range(N):
    arr[i, 0], arr[i, 1] = input().split()
    arr[i, 2] = arr[i, 0] + arr[i, 1]

arr = arr[np.argsort(arr[:, 2])][::-1]

print(np.sum(arr[::2, 0]) - np.sum(arr[1::2, 1]))

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

N = int(input())

arr = np.array([input().split() + [0] for _ in range(N)], dtype='int64')
for i in range(N):
    arr[i, 2] = arr[i, 0] + arr[i, 1]

arr = arr[np.argsort(arr[:, 2])][::-1]

print(np.sum(arr[::2, 0]) - np.sum(arr[1::2, 1]))

Solution (Python):
import numpy as np

N = int(input())

arr = np.array([input().split() + [0] for _ in range(N)], dtype='int64')
for i in range(N):
    arr[i, 2] = arr[i, 0] + arr[i, 1]

arr = arr[np.argsort(arr[:, 2])][::-1]

print(np.sum(arr[::2, 0]) - np.sum(arr[1::2, 1]))

Solution (Python):
N = int(input())
A = [0] * N
B = [0] * N
Sum = [[0] * 2 for i in range(N)]

for i in range(N):
    A[i], B[i] = map(int, input().split())
    Sum[i][0] = i
    Sum[i][1] = A[i] + B[i]
    
a = 0
b = 0
turn = 0

Sum.sort(key=lambda x:x[1], reverse=True)
    
for i in range(N):
    if turn == 0:
        a += A[Sum[i][0]]
        turn = 1
    else:
        b += B[Sum[i][0]]
        turn = 0

print(a - b)

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

N = int(input())
A = [0] * N
B = [0] * N
Sum = [[0] * 2 for i in range(N)]

for i in range(N):
    A[i], B[i] = map(int, input().split())
    Sum[i][0] = i
    Sum[i][1] = A[i] + B[i]
    
a = 0
b = 0
turn = 0

Sum.sort(key=lambda x:x[1], reverse=True)
    
for i in range(N):
    if turn == 0:
        a += A[Sum[i][0]]
        turn = 1
    else:
        b += B[Sum[i][0]]
        turn = 0

print(a - b)

Solution (Python):
n=int(input())
C=[]

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

count_a=0
count_b=0

C.sort(reverse=True)

for j in range(n):
    if(j%2==0):
        count_a+=C[j][1]
    else:
        count_b+=C[j][2]

print(count_a-count_b)

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

X = []
for i in range(N):
    x, y = map(int, input().split())
    
    X.append([x+y,x,y])   


X.sort(reverse=True)

ansA = 0
ansB = 0

for index, i in enumerate(X):
    if index%2 == 0:
        ansA += i[1]
    else:
        ansB += i[2]

print(ansA - ansB)

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

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

C = []
for index, i in enumerate(range(N)):
    C.append([index, A[i] + B[i]])

C = sorted(C, key=lambda x:x[1], reverse=True)

ansA = 0
ansB = 0

for index, i in enumerate(C):
    if index%2 == 0:
        ansA += A[i[0]]
    else:
        ansB += B[i[0]]

print(ansA - ansB)

Solution (Python):


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

A = [ x[0] for x in inp_list]
B = [ x[1] for x in inp_list]

sum_list = [ A[i] + B[i] for i in range(N)] 

w_sum = sorted([ (sum_list[i], A[i], B[i]) for i in range(N)], reverse=True)

takahashi_sum = sum( [x[1] for x in w_sum[::2]] , 0)
aoki_sum =      sum( [x[2] for x in w_sum[1::2]], 0)

print(takahashi_sum - aoki_sum)

Solution (Python):


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


ans = 0
for e,t in enumerate(sorted(inp_list, key=lambda x : x[0] + x[1], reverse = True)):
    if e % 2 == 0:
        ans += t[0]
    else:
        ans -= t[1]
print(ans)