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):
n = int(input())
ab = []
bsum = 0
for i in range(n):
    a,b = map(int,input().split(' '))
    ab.append(a + b)
    bsum += b
ab.sort(reverse = True)
print(sum(ab[0::2]) - bsum)

Solution (Python):
n = int(input())
ab = []
bsum = 0
for i in range(n):
    a,b = map(int,input().split(' '))
    ab.append(a + b)
    bsum += b
ab.sort(reverse = True)
print(sum(ab[0::2]) - bsum)

Solution (Python):
n = int(input())
c = []
for i in range(n):
    c.append([int(m) for m in input().split()]+[i])
"""d = []
for i in range(n):
    d.append([c[i][1], c[i][0], i])"""
tans = 0
aans = 0
sumc = []

for i in range(n):
    sumc.append([c[i][0] + c[i][1], i])

sumc.sort(reverse=True)

for i in range(n):
    if i % 2 == 0:
        tans += c[sumc[i][1]][0]
    else:
        aans += c[sumc[i][1]][1]

print(tans -aans)

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

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

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

ans = 0
for j in range(n//2):
    ans += d[j*2][0]
    ans -= d[j*2+1][1]

if n % 2 == 1:
    ans += d[n-1][0]

print(ans)

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






sum_happiness = []
all_for_B = 0

for i in range(N):
    tmp1, tmp2 = list(map(int, input().split()))
    sum_happiness.append(tmp1 + tmp2)
    all_for_B += tmp2

sum_happiness.sort(reverse=True)


gain_A = 0
for i, h in enumerate(sum_happiness):
    if i % 2 == 0:
        gain_A += h
    


print(gain_A - all_for_B)

Solution (Python):
def dif(n,ab):
    c=[[sum(i),i] for i in ab]
    c.sort(reverse=True)

    a=[c[i][1][0] for i in range(n) if i%2==0]
    b=[c[i][1][1] for i in range(n) if i%2!=0]

    return sum(a)-sum(b)

n=int(input())
print(dif(n,[list(map(int,input().split())) for i in range(n)]))

Solution (Python):
n = int(input())
D = []
A = []
B = []
m = 1000000000
res = 0
for i in range(n):
    a,b = map(int,input().split())
    point = a+b
    D.append([point,i])
    A.append(a)
    B.append(b)
else:
    D.sort()
    D.reverse()

ans_a = 0
ans_c = 0
for i in range(n):
    if i%2 == 0:
        res += A[(D[i][1])]
        ans_a += A[(D[i][1])]
    else:
        res -= B[(D[i][1])]
        ans_c += B[(D[i][1])]
else:
    print(res)

Solution (Python):
def dif(n,ab):
    c=[[sum(i),i] for i in ab]
    c.sort(reverse=True)

    ap=0
    bp=0
    for i in range(n):
        if i%2==0:
            ap+=c[i][1][0]
        else:
            bp+=c[i][1][1]


    return ap-bp

n=int(input())
print(dif(n,[list(map(int,input().split())) for i in range(n)]))

Solution (Python):
n = int(input())
D = []
A = []
B = []
m = 1000000000
res = 0
for i in range(n):
    a,b = map(int,input().split())
    point = a+b
    D.append([point,i])
    A.append(a)
    B.append(b)
else:
    D.sort()
    D.reverse()

ans_a = 0
ans_c = 0
for i in range(n):
    if i%2 == 0:
        res += A[(D[i][1])]
        ans_a += A[(D[i][1])]
    else:
        res -= B[(D[i][1])]
        ans_c += B[(D[i][1])]
else:
    
    print(ans_a-ans_c)

Solution (Python):
N = int(raw_input())
L = []
for i in range(N):
  L.append(raw_input())
result = []
sumA = 0
sumB = 0
for i in range(N):
    L[i] = L[i].split()
    result.append([int(L[i][0]) + int(L[i][1]), i])
result.sort()
for i in range(N-1, -1, -2):
    index = result[i][1]
    sumA += int(L[index][0])
for i in range(N-2, -1, -2):
    index = result[i][1]
    sumB += int(L[index][1])
result_K = sumA - sumB
print(result_K)

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

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

Solution (Python):
from sys import stdin
 
def main():
    N = int(input())
    AB = [tuple(map(int, input().split())) for _ in [0] * N]
 
    dish = sorted(AB, reverse=1, key=lambda x: sum(x))
    taka, aoki = 0, 0
    for i in range(N):
        aoki += dish[i][1]
        if not i % 2:
            taka += sum(dish[i])
    print(taka - aoki)
 
input = lambda: stdin.readline()
main()

Solution (Python):

import sys

def io_generator():
	while True:
		yield raw_input()



def main(io):
	a=int(io.next())
	diff=[]
	for i in range(a):
		b,c= map(int, io.next().split())
		diff.append((b,c,b+c))
	diff = sorted(diff, key=lambda a:-a[2])
	
	ret= sum([x[i%2]*(1-2*(i%2)) for i,x in enumerate(diff)])
	
	return ret




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

Solution (Python):
n = input()
ans = 0
l = []
for i in xrange(n):
	a,b = map(int, raw_input().split())
	ans -= b
	l.append(a+b)
l.sort(reverse = True)
for i in xrange(0,n,2):
	ans += l[i]
print ans

Solution (Python):
import numpy as np

N = int(input())

A = [0 for i in range(N)]
B = [0 for i in range(N)]
C = [0 for i in range(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 = 0

for i in range(N):
    if i % 2 == 0:
        ans += C[i]

print(ans - sum(B))

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

Solution (Python):

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

H = sorted(H, reverse = True)
sum_c = 0
sum_a = 0

for i in range(n):
    if i % 2 == 0:
        sum_c += H[i][1]
    else:
        sum_a += H[i][2]

ans = sum_c - sum_a
print(ans)

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])
ans = 0
for i in range(n):
    ans += (1-i%2)*ab[i][0] - (i%2)*ab[i][1]
print(ans)

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

A.sort(reverse=True)
print(sum([ab for i, ab in enumerate(A) if i % 2 == 0]) - sum(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)
suma = 0
sumb = 0
for i in range(n):
    if i % 2 == 0:
        suma += ab[i][1]
    else:
        sumb += ab[i][2]
print(suma-sumb)

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

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

z = []
t = 0
for i in range(n):
    x, y = [int(x) for x in input().split()]
    t += y
    z.append(x + y)
z.sort(reverse=True)

s = 0
for i in range(n // 2):
    s += z[2 * i]
if n % 2 == 1:
    s += z[len(z) - 1]

print(s - t)

Solution (Python):
def main() -> None:
    n = int(input())
    menu = [[int(x) for x in input().split()] for _ in range(n)]

    for i, _ in enumerate(menu):
        menu[i] += [sum(menu[i])]

    menu.sort(key=lambda x: x[len(x) - 1], reverse=True)

    cnt = 0
    for i in range(n):
        if i % 2 == 0:
            cnt += menu[i][0]
        else:
            cnt -= menu[i][1]

    print(cnt)


if __name__ == "__main__":
    main()

Solution (Python):
def main() -> None:
    n = int(input())
    menu = [[int(x) for x in input().split()] for _ in range(n)]

    for i, _ in enumerate(menu):
        menu[i] += [sum(menu[i])]

    menu.sort(key=lambda x: x[len(x) - 1], reverse=True)

    cnt = 0
    for i in range(n):
        if i % 2 == 0:
            cnt += menu[i][0]
        else:
            cnt -= menu[i][1]

    print(cnt)


if __name__ == "__main__":
    main()

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

Solution (Python):
N=input()

L=[]
for i in range(N):
	a,b=map(int,raw_input().split())
	L.append( (a+b,a,b) ) 


L.sort(key=lambda x: -x[0])


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

print ans

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()
c=0
for k in range(n):
  if k%2==0:
    c+=l[L[k][1]][0]
  else:
    c-=l[L[k][1]][1]
print(c)

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

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

for _ in range(N):
  l = [int(i) for i in input().split()]
  lst.append([sum(l)] + l)

lst.sort()

result = 0
count = 0
for i in lst[::-1]:
  result += i[count + 1] * (-1) ** count
  count = (count + 1) % 2

print(result)

Solution (Python):
N = int(input())
sara = []
t_s = 0
a_s = 0
for i in range(N):
    A, B = map(int, input().split())
    sara.append([A, B])
sara.sort(key=lambda x:x[0]+x[1], reverse=True)
while True:
    if len(sara) == 0:
        break
    t_s += sara.pop(0)[0]
    if len(sara) == 0:
        break
    a_s += sara.pop(0)[1]
print(t_s - a_s)

Solution (Python):
import numpy as np

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

a = np.array(x, dtype='int').reshape((N, 2))
s = a[:,0:1] + a[:,1:2]
a = np.hstack((a, s))
a = a[np.argsort(a[:, 2])]
n = np.sum(a[(N + 1)%2::2, 0]) - np.sum(a[N % 2::2, 1])
print(n)

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

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

a = b = 0
for i,(x,y) in enumerate(reversed(src)):
    if i%2:
        b += y
    else:
        a += x
print(a-b)

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

Solution (Python):
import numpy as np

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

a = np.array(x, dtype='int').reshape((N, 2))
s = a[:,0:1] + a[:,1:2]
a = np.hstack((a, s))
a = a[np.argsort(a[:, 2])][::-1, :]
n = np.sum(a[0::2, 0]) - np.sum(a[1::2, 1])
print(n)

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([i for i in range(N)], key=lambda x: A[x] + B[x], reverse=True)
x, y = 0, 0
for (cnt, i) in enumerate(AB):
    if cnt % 2 == 0: 
        x += A[i]
    else:
        y += B[i]
print(x - y)

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()
l.reverse()
tak = 0
aok = 0


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

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(key=lambda x:x[2])
l.reverse()


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())
ps=[]
tp=[]
ap=[]
for i in range(N):
  p=input().split()
  ps.append([int(p[0])+int(p[1]),i])
  tp.append(int(p[0]))
  ap.append(int(p[1]))
    
def is_even(num):
  if num % 2 == 0:
    return True
  else:
    return False

T=0
A=0
calc=sorted(ps,reverse=True)

i=0
for p,j in calc:
  if is_even(i):
    T+=tp[j]
  else:
    A+=ap[j]
  i+=1
print(T-A)

Solution (Python):
d=sorted([list(map(int,input().split()))for _ in[0]*int(input())],key=sum);print(sum(t[0]for t in d[-1::-2])-sum(t[1]for t in d[-2::-2]))

Solution (Python):
N = int(input())
D=[]
b=0
for _ in range(N):
  A,B=map(int, input().split())
  D.append([A,B,A+B])
  b+=B
D.sort(reverse=True, key=lambda x:x[2])

ans=0
while D!=[]:
  ans+=D[0][2]
  D.pop(0)
  if D!=[]:
    D.pop(0)
  
print(ans-b)

Solution (Python):
n = int(input())
happiness_hash = {}
for i in range(n):
    a, b = tuple(map(int, input().split(' ')))
 
    happiness_hash[i] = (a, b)
 
sorted_happiness = sorted(happiness_hash.items(), key = lambda x : x[1][0] + x[1][1], reverse = True)
 
total = 0
i = 0
for k, v in sorted_happiness:
    happiness, selected = (0, k)
    if i % 2 == 0:
        happiness = v[0]
        total += happiness
    else:
        happiness = v[1]
        total -= happiness
    i += 1
 
print(total)

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

goukei=[]

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

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

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

Solution (Python):
n=int(input())
d=sorted([list(map(int,input().split()))for _ in[0]*n],key=lambda x:sum(x))[::-1]
t=d[::2]
a=d[1::2]
print(sum(v[0]for v in t)-sum(v[1]for v in a))

Solution (Python):
def main():
    N = int(input())
    ab = [[int(i) for i in input().split()] for _ in range(N)]
    ab = sorted(ab, 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)


main()

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

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

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

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

li = sorted(li)
li.reverse()
for i in range(n):
    if i%2 == 0:
        ans += li[i][1]
    else:
        ans -= li[i][2]

print(ans)

Solution (Python):
n = int(input())
l = [[] for i in range(n)]
A, B = 0, 0
for i in range(n):
    l[i] = list(map(int, input().split()))
    l[i].append(l[i][0]-l[i][1])
l.sort(key = lambda x: (x[0]+x[1]), reverse = True)

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

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

A = [None] * N
B = [None] * N
C = [None] * N

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

Z = zip(A, B, C)
Z = sorted(Z, key=lambda x: [x[2]], reverse=True)

A, B, C = map(list, zip(*Z))

T = True
R = 0

for i in range(N):
    if T:
        R += A[i]
        T  = False
    else:
        R -= B[i]
        T  = True

print(R)

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

Solution (Python):
import sys
sys.setrecursionlimit(10000000)

N = int(input())
A = {}
B = {}
AplusB =[]

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

AplusB.sort()
AplusB.reverse()


takahashi = 0
aoki = 0

for j in range(N):
	if(j%2 == 0):
		takahashi += A[AplusB[j][1]]
	else:
		aoki += B[AplusB[j][1]]

print(takahashi-aoki)

Solution (Python):
from sys import stderr, setrecursionlimit
setrecursionlimit(2147483647)
def getInt():
    return int(input())
def getInts():
    return [int(i) for i in input().split()]
def getIntLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInt())
    return res
def getIntsLines(n=1):
    res = []
    for _ in range(n):
        res.append(getInts())
    return res
def debug(*args, **kwargs):
    print(*args, file=stderr, **kwargs)
    
n = getInt()
dish = []
bsum = 0
for _ in range(n):
    a, b = getInts()
    bsum += b
    dish.append(a+b)
dish.sort(reverse=True)
print(sum(dish[::2]) - bsum)

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

Solution (Python):
from functools import reduce
from math import ceil

def solve(N, fortune):
  value = reduce(lambda a, b: a - b[1], fortune, 0)
  fortune.sort(key=lambda f: f[0] + f[1], reverse=True)
  for i in range(0, N, 2):
    value = value + fortune[i][0] + fortune[i][1]
  return value

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

print(solve(N, fortune))

Solution (Python):
n = int(input())
m = [[0] * 3 for i in range(n)]

for i in range(n):
    a, b = map(int, input().split())
    m[i][0] = a + b
    m[i][1] = a
    m[i][2] = b

m.sort(reverse=True)

takahashi = 0
aoki = 0

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

print(takahashi - aoki)

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

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

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

abd = sorted(dd, reverse=True)

res = 0
for i in range(n):
    d = abd.pop(0)
    if i % 2 == 0:
        res += d

print(res+sb)

Solution (Python):
N = int(input())
ABab = []
for i in range(N):
    a, b = list(map(int, input().split()))
    ABab.append([a+b, a, -1*b])
ABab.sort(reverse = True)
ans = 0
for i in range(N):
    ans += ABab[i][i%2 + 1]
print(ans)

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

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

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

A = []
b_sum = 0

for i in range(N):
    a,b = map(int,input().split())
    A.append((a+b, a, b))
    b_sum += b

A.sort(reverse=True)


count = 0


for i in range(0,N,2):
    count += A[i][0]

print(count-b_sum)

Solution (Python):
from operator import add


def read():
    N = int(input().strip())  
    A = []
    B = []
    for i in range(N):
        a, b = input().strip().split()
        A.append(int(a))
        B.append(int(b))
    return N, A, B


def solve(N, A, B):
    f = map(add, A, B)
    food = reversed(sorted(f))
    score = 0
    for i, f in enumerate(food):
        if i % 2 == 0:
            score += f
    return score - sum(B)


if __name__ == '__main__':
    inputs = read()
    print("%d" % solve(*inputs))

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

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

a = sorted(a)[::-1]

print(sum([a for i,a in enumerate(a) if i%2==0])-sum(b))

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

Solution (Python):
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

def akey(a):
    return a[0]+a[1]
list.sort(a,key=akey,reverse=True)


def func(a):
    pa,pb=0,0
    tag=True
    for idx in range(0,len(a)):
        if tag:
            pa+=a[idx][0]
        else:
            pb+=a[idx][1]
        tag=not tag
    return pa-pb
    
print(func(a))

Solution (Python):
import numpy as np
N = int(input())
A, B = [], []
Z = []
 
for i in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
 
    Z.append(-a - b)
 
indexes = np.argsort(Z)
ans = 0
for cnt, i in enumerate(indexes):
    if cnt % 2 == 0:
        ans += A[i]
    else:
        ans -= B[i]
 
print(ans)

Solution (Python):
def main():
    N = int(input())
    H = [0] * N
    retval = 0
    for i in range(N):
        a, b = tuple(map(int, input().split()))
        retval -= b
        key = a+b
        H[i] = key
    H.sort(reverse=True)
    retval += sum(H[::2])

    print(retval)


if __name__ == "__main__":
    main()

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

data = [[0 for i in range(3)] for j in range(base)]

for num in range(base):
    _num = input()
    _num = _num.split()
    data[num][0] = int(_num[0])+int(_num[1])
    data[num][1] = int(_num[0])
    data[num][2] = int(_num[1])

takahashi = 0
aoki = 0
data.sort()
data.reverse()

_num = 0
for num in range(base):
    if(_num == 0):
        takahashi += data[num][1]
        _num = 1

    elif(_num == 1):
        aoki += data[num][2]
        _num = 0

print(takahashi-aoki)

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

arr = sorted(arr,reverse=True)
ansa,ansb = 0 , 0
for i in range(N):
    if i % 2 == 0:
        ansa += arr[i][1]
    else:
        ansb += arr[i][2]
print(ansa - ansb)

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

AB = []
sum = 0
for i in range(N):
    a, b = [int(i) for i in input().split()]
    sum -= b
    AB.append(a+b)

AB.sort(reverse=True)

count = 0
for _ in range(N//2):
    count += AB.pop(0)
    AB.pop(0)
if N%2 == 1:
    count += AB.pop(0)

print(count + sum)

Solution (Python):
N = input()

data = []

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

data.sort()

ans = 0
flag = True

while N > 0:
    if flag:
        ans += data[N-1][1]
        flag = False
    else:
        ans -= data[N-1][2]
        flag = True
    N -= 1

print ans

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

for i in range(n):
    c=array1[i][0]+array1[i][1]
    array1[i].insert(0,c) 
array1.sort(key=lambda x: x[0],reverse=True)
sum1=0
sum2=0
for i in range(n):
    if(i%2==0):
        sum1+=array1[i][1]
    else:
        sum2+=array1[i][2]

print(sum1-sum2)

Solution (Python):


import os
import re
import sys
import math


n = int(input())

dishes = list()

for i in range(0, n):
    a, b = raw_input().split()
    a = int(a)
    b = int(b)
    sum = a + b
    dishes.append([a, b, sum])

takahashi = 0
aoki = 0
dishes.sort(key=lambda x: x[2], reverse=True)

for i in range(0, n):
    if i % 2 == 0:
        j = dishes[0]
        dishes.pop(0)
        takahashi = takahashi + j[0]
    else:
        j = dishes[0]
        dishes.pop(0)
        aoki = aoki + j[1]

print takahashi - aoki

Solution (Python):
n=int(input())
l=[[i]+list(map(int,input().split())) for i in range(n)]

l.sort(key=lambda x:-(x[1]+x[2]))
pa,pb=0,0
used=set()

v=0
while pa<n and pb<n:
  while pa<n and l[pa][0] in used:
    pa+=1
  if pa<n:
    used.add(l[pa][0])
    v+=l[pa][1]
  while pb<n and l[pb][0] in used:
    pb+=1
  if pb<n:
    used.add(l[pb][0])
    v-=l[pb][2]

print(v)

Solution (Python):
la=[]
lb=[]
n=int(input())
kari=[]
tak=0
ao=0
s=-1
for i in range(n):
    a,b=map(int,input().split())
    la.append(a)
    lb.append(b)
    kari.append(a+b)
    ao+=b
kari.sort()
if n%2==0:
    for v in range(int(n/2)):
        tak+=kari[s]
        s+=-2
else:
    for k in range(int(n/2)+1):
        tak+=kari[s]
        s+=-2
print(tak-ao)

Solution (Python):
import sys

import numpy as np

sys.setrecursionlimit(200000)


def input():
    return sys.stdin.readline()[:-1]


def ii(t: type = int):
    return t(input())


def il(t: type = int):
    return list(map(t, input().split()))


def imi(N: int, t: type = int):
    return [ii(t) for _ in range(N)]


def iml(N: int, t: type = int):
    return [il(t) for _ in range(N)]


def solve():
    N = ii()
    AB = iml(N)
    ll = []
    for a, b in AB:
        ll.append(a + b)
    ind = np.argsort(ll)[::-1]
    t = [AB[i][0] for i in ind[::2]]
    a = [AB[i][1] for i in ind[1::2]]
    return sum(t) - sum(a)


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

Solution (Python):
def cheat_solve(N, ABs):
    Ds = sorted([ab[0] + ab[1] for ab in ABs], reverse=True)
    bsum = sum([ab[1] for ab in ABs])
    dsum = sum(Ds[::2])
    return dsum - bsum

if __name__ == "__main__":
    N = int(input())
    ABs = [tuple(map(int, input().split(" "))) for _ in range(N)]
    print(cheat_solve(N, ABs))

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

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









l = sorted(dish, reverse=True)

t=a = 0
for i, (_, (a_i, b_i)) in enumerate(l):
    if i % 2 == 0:
        
        t += a_i
    else:
        a += b_i

print(t-a)

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

S=[]
bsum=0

for i in range(N):
    a,b = map(int,input().split())
    S.append(a+b)
    bsum+=b

S.sort(reverse=True)

ans=-bsum

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

Solution (Python):
n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
div = [[ab[i][1] + ab[i][0], ab[i][0], ab[i][1]] for i in range(n)]
div = sorted(div, key=lambda x: x[0], reverse=True)

counta = 0
countb = 0
for i in range(n):
    if i % 2 == 0:
        counta += div[i][1]
    else:
        countb += div[i][2]

print(counta - countb)

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

x = y = 0
for i in range(n):
    a, b, _ = dishes[i]
    if i % 2 == 0:
        x += a
    else:
        y += b

print(x - y)

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])
ans = 0
for i in range(n):
    ans += (1-i%2)*AB[i][0] - (i%2)*AB[i][1]
print(ans)

Solution (Python):
N = int( input())
A = [0]*N
B = [0]*N
S = [(0,0)]*N
for i in range(N):
    a, b = map( int, input().split())
    A[i] = a
    B[i] = b
    S[i] = (-a-b,i)
S.sort()
ansa = 0
ansb = 0
for i in range(N):
    _, j = S[i]
    if i%2 == 0:
        ansa += A[j]
    else:
        ansb += B[j]
print( ansa-ansb)

Solution (Python):
def inpl(): return list(map(int, input().split()))


N = int(input())
data = [[0, 0] for _ in range(N)]
wa = [[0, 0] for _ in range(N)]
for i in range(N):
    a, b = inpl()
    data[i][0] = a
    data[i][1] = b
    wa[i][0] = a+b
    wa[i][1] = i

wa.sort(reverse=True)

ans = 0
turn = "a"
for a, i in wa:
    if turn=="a":
        turn="b"
        ans += data[i][0]
    else:
        turn="a"
        ans -= data[i][1]
print(ans)

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