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 numpy as np
N = int(input())

A = []
B = []
val = []

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

A = np.array(A)
B = np.array(B)
val = np.array(val)

sort_index = val.argsort()

A = (A[sort_index][::-1])
B = (B[sort_index][::-1])

taka = (A[0::2])
aoki = (B[1::2])

print(sum(taka) - sum(aoki))

Solution (Python):


from operator import itemgetter


n = int(input())
ablist = list()

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

ablist.sort(key=itemgetter(2), reverse=True)

tsum = 0
asum = 0


for idx in range(n):
    if idx % 2 == 0:
        
        tsum += ablist[idx][0]
    else:
        
        asum += ablist[idx][1]

ans1 = tsum - asum


print(ans1)

Solution (Python):
N = int(input())
D = [list(map(int,input().split()))+[k] for k in range(N)]

T = sorted(D, key = lambda x: x[0]+x[1], reverse = True)
A = sorted(D, key = lambda x: x[1]+x[0], reverse = True)
U = [1 for k in range(N)]

ans = 0
l = 0
m = 0
for k in range(N):
    if k%2 == 0:
        while U[T[l][2]] == 0:
            l += 1
        ans += T[l][0]
        U[T[l][2]] = 0
    else:
        while U[A[m][2]] == 0:
            m += 1
        ans -= A[m][1]
        U[A[m][2]] = 0

print(ans)

Solution (Python):
N = int(input().strip())
arr = []
for n in range(N):
  A, B = list(map(int, input().split()))
  arr.append([ A + B , A, B])

arr = sorted(arr, reverse=True)
ta = sum([a[1] for a in arr[::2]])
ao = sum([a[2] for a in arr[1::2]])
print(ta - ao)

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

Solution (Python):
N = int(input())
A = []
B = []
v = []
res = 0

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

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

for i in range(N):
    tmp=a.pop(0)[0]
    if i%2==0:
        res += A[tmp]
    else:
        res -= B[tmp]

print(res)

Solution (Python):
import numpy as np
N = int(input())
ApB = []

for i in range(N):
	temp1, temp2 = map(int, input().split())
	s = temp1 + temp2
	ApB.append([s, temp1, temp2, i])

ApB.sort()
score = 0
for i in range(N):
	if i % 2 == 0:
		score += ApB.pop()[1]
	else:
		score -= ApB.pop()[2]

print(score)

Solution (Python):
import numpy as np
N = int(input())
lst =  np.array([list(map(int,input().split())) for i in range(N)])
A = np.array([lst[i][0] for i in range(N)])
B = np.array([lst[i][1] for i in range(N)])
AB = np.array([A[i] + B[i] for i in range(N)])

loop = np.insert(lst,0,AB,axis=1)
loop = loop[loop[:,0].argsort()[::-1], :]


sumA = [i[1] for i in loop[0::2]]
sumB = [i[2] for i in loop[1::2]]









print(sum(sumA)-sum(sumB))

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

a = [0  for i in range(n)]
b = [0  for i in range(n)]
x = [[0,0,0]  for i in range(n)]

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

s=sorted(x,reverse=True)


nu=n//2
mod=n%2

count=0
for i in range(nu):
    count+=s[i*2][1]
  
    count-=s[i*2+1][2]
 

if mod==1:
    count+=s[2*nu][1]

    

    

print(count)

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

Solution (Python):
from operator import itemgetter

def main(N, A, B, C):
    a, b = 0, 0
    aindex = list(i[-1] for i in sorted(zip(C, A, B, range(N)), key=itemgetter(0, 1, 2), reverse=True))
    bindex = list(i[-1] for i in sorted(zip(C, B, A, range(N)), key=itemgetter(0, 1, 2), reverse=True))
    t = 0
    i = 0
    ai = 0
    bi = 0
    c = set()
    while i < N:
        if t == 0:
            while aindex[ai] in c:
                ai += 1
            a += A[aindex[ai]]
            c.add(aindex[ai])
        else:
            while bindex[bi] in c:
                bi += 1
            b += B[bindex[bi]]
            c.add(bindex[bi])
        i += 1
        t += 1
        t %= 2
    print(a - b)


if __name__ == "__main__":
    N = int(input())
    A, B = [], []
    C = []
    for _ in range(N):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        C.append(a+b)
    main(N, A, B, C)

Solution (Python):
import math
n = int(input())
s = 0
t = 0
x = []
for I in range(n):
 a,b = map(int,input().split())
 x.append(a+b)
 s += b
x.sort(reverse = True)
for I in range(math.ceil(n/2)):
 t += x[2*I]
print(t-s)

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

il = sorted(range(n), key=lambda k: apb[k], reverse=True)
at = 0
bt = 0
for i in range(len(il)):
    selected = il[i]
    if i % 2 == 0:
        at += a[selected]
    else:
        bt += b[selected]
print(at - bt)

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

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


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


a, b =0, 0
turn = 1
for i in range(n):
    if turn ==1:
        a+=dish_list[i][0]
    else:
        b+=dish_list[i][1]
    turn*=-1



































print(a-b)

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

res = 0
for i, (v, a, b) in enumerate(val):
    res += a if i % 2 == 0 else -b
print res

Solution (Python):
data = input().split()

n = int(data[0])
a=[]
for i in range(n):
    line = input().split()
    tmp=[]
    tmp.append(int(line[1]) + int(line[0]))
    tmp.append(int(line[0]))
    tmp.append(int(line[1]))
    a.append(tmp)

res=0
a.sort(key=lambda x: x[0])
a.reverse()

flg=True

for e in a:
    if(flg):
        res +=e[1]
    else:
        res -=e[2]
    flg=not(flg)
    

print(res)

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

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

my_list = [[dif, a, b] for dif, a, b in zip(dif_list, A_list, B_list)]
my_list.sort(reverse=True)

takahashi_score = 0
aoki_score = 0

for i, list_items in enumerate(my_list):
    a = list_items[1]
    b = list_items[2]
    if i % 2 == 0:
        takahashi_score += a
    else:
        aoki_score += b

print(takahashi_score - aoki_score)

Solution (Python):
n = int(input())
a = []
b = []
for i in range(n):
    ta, tb = map(int, input().split())
    a.append(ta)
    b.append(tb)
    
happya = 0
happyb = 0

def wa(a,b):
    return a+b

c = list(map(wa, a, b))
for i in range(n):
    c[i] = [c[i], i]
c.sort()
c.reverse()

d = []
for i in range(n):
    d.append(c[i][1])

for i in range(n):
    if(i % 2 == 0):
        happya += a[d[i]]
    else:
        happyb += b[d[i]]
        
print(happya-happyb)

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
ab=[]
for _ in range(n):
    t,a=map(int,input().split())
    ab.append([t,a,t+a])
sorted_items = sorted(
  ab,
  key = lambda x: x[2],
  reverse=True
)
t=0
a=0
for i in range(n):
    if i%2==0:
        t+=sorted_items[i][0]
    else:
        a+=sorted_items[i][1]
print(t-a)

Solution (Python):

n = int(input())
a, b = list(), list()
ab = list()
for i in range(n):
    a_, b_ = map(int, input().split())
    a.append(a_)
    b.append(b_)
    ab.append((a_, b_))
ans = 0
ab.sort(key=(lambda x: sum(x)), reverse=True)
for i, ab_ in enumerate(ab):
    if i % 2 == 0:
        ans += ab_[0]
    else:
        ans -= ab_[1]
print(ans)

Solution (Python):
import numpy as np

N = int(input())
x = []
y = []
for i in range(N):
    a, b = [int(_) for _ in input().split()]
    x.append(a)
    y.append(b)

nx = np.array(x)
ny = np.array(y)
ns = nx + ny
arr = np.array([nx, ny, ns]).T
arr = arr[np.argsort(arr[:, 2])][::-1, :]
n = np.sum(arr[0::2, 0]) - np.sum(arr[1::2, 1])
print(n)

Solution (Python):
import numpy as np


def main():
    N = int(input())
    A = []
    B = []
    for i in range(0, N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
    
    takahashi = 0
    aoki = 0
    
    A = np.array(A)
    B = np.array(B)
    sum_AB = A + B
    l = sum_AB.argsort()[::-1]
    takahashi = sum([A[i] for i in [j for idx, j in enumerate(l) if idx % 2 == 0]])
    aoki = sum([B[i] for i in [j for idx, j in enumerate(l) if idx % 2 != 0]])

    print(int(takahashi - aoki))


main()

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

Solution (Python):
import numpy as np
import sys
from operator import itemgetter
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
l = []
for i in range(N):
    a,b = IL()
    l.append([a,b,a+b])

l.sort(key=itemgetter(2),reverse=True)

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

print(chokudai-aoki)

Solution (Python):
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_int_list():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


def main():
    n = get_int()
    A = []
    B = []
    for _ in range(n):
        a, b = get_int_list()
        A.append(a)
        B.append(b)

    sums = [(i, a + b) for i, (a, b) in enumerate(zip(A, B))]
    sums.sort(key=lambda x: x[1], reverse=True)
    takahashi = [A[i] for i, _ in sums[0::2]]
    aoki = [B[i] for i, _ in sums[1::2]]
    print(sum(takahashi) - sum(aoki))


if __name__ == '__main__':
    main()

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

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


all_list.sort()
all_list.reverse()


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

Solution (Python):
n = int(input())
c = []
d = []
e = []

for i in range(0, n):
    a, b = map(int, input().split())
    c.append(a)
    d.append(b)
    e.append(a + b)

li1, li2 = sorted(e), sorted(range(len(e)), key=lambda k: e[k])

turn = 0
happy = 0

for i in range(n - 1, -1, -1):
    now = li1[i]
    if (turn == 0):
        max = 0
        maxKey = 0
        for j in range(i, -1, -1):
            if (now == li1[j] and max < c[li2[j]]):
                max = c[li2[j]]
                maxKey = j
            else:
                li2[i], li2[maxKey] = li2[maxKey], li2[i]
                break
        happy += c[li2[i]]
    else:

        max = 0
        maxKey = 0
        for j in range(i, -1, -1):
            if (now == li1[j] and max < d[li2[j]]):
                max = d[li2[j]]
                maxKey = j
            else:
                li2[i], li2[maxKey] = li2[maxKey], li2[i]
                break

        happy -= d[li2[i]]
    turn = (turn + 1) % 2
print(happy)

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

a = sorted(a, key=lambda x: -x[0])
taka = 0
aoki = 0
for i in range(n):
  if i % 2 == 0:
    taka += a[i][1]
  else:
    aoki += a[i][2]

print(taka - aoki)

Solution (Python):
import heapq

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

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

print(ans)

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

sum_list = []
for i in range(N):
    _, a, b = ab[i]
    sum_list.append((a + b, i))
sum_list = sorted(sum_list, key=lambda x:-x[0])

ans = 0

for k in range(N):
    if k % 2 == 0:
        su = sum_list[k]
        ans += ab[su[1]][1]
    else:
        su = sum_list[k]
        ans -= ab[su[1]][2]
print(ans)

Solution (Python):


import numpy as np
n = int(input())

a = np.array([list(map(int,input().split())) for _ in range(n)])
t = np.argsort(a[:,0]+a[:,1])[::-1]
ans = 0

for i,j in zip(t,range(n)):
    if j%2 == 0:
        ans+=a[i][0]
    else:
        ans-=a[i][1]

print(ans)

Solution (Python):
n = int(input())
a = [list(map(int, input().split())) for i in range(n)]
b = sorted([[a[i][0] + a[i][1], a[i][0]] for i in range(n)])
taka = 0
aoki = 0

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

print(taka - aoki)

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

for i in range(0,N):
    t,a=map(int,input().split(" "))
    d=t+a
    flist.append([d,t,a])


count=0
score=0
number=0
flist.sort(reverse=True)


for count in range(0,N):
    if count%2==0:
        score+=flist[count][1]
    else:
        score-=flist[count][2]

    
print(score)

Solution (Python):
n=int(input())
a=[0]*n
b=[0]*n
c=[]
for i in range(n):
	a[i],b[i]=map(int,input().split())
	c.append((a[i]+b[i],i))
d=sorted(c,reverse=True)
ta=0
ao=0
turn=0
for i in range(n):
	if turn==0:
		ta+=a[d[i][1]]
		turn=1
	else:
		ao+=b[d[i][1]]
		turn=0
print(ta-ao)

Solution (Python):
n=int(input())
s=[list(map(int,input().split(" "))) for k in range(n)]
aa=sorted(s,key=lambda x:x[0]+x[1],reverse=True)
c=0
for l in range(n):
  if l%2==0:
    c+=aa[l][0]
  else:
    c-=aa[l][1]
print(c)

Solution (Python):


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

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

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


count = 1
Takahashi = 0
Aoki = 0
for i in lst:
    if count % 2 == 1:
        Takahashi += i[0]
    else:
        Aoki += i[1]
    count+=1
print(Takahashi-Aoki)

Solution (Python):
n = int(input())
ab = [[int(_) for _ in input().split()] for __ in range(n)]
s = [[sum(e), i] for i, e in enumerate(ab)]
s.sort(reverse=True)
t = 0

for j, x in enumerate(s):
    t += ab[x[1]][0] if j % 2 == 0 else -ab[x[1]][1]
print(t)

Solution (Python):

import numpy as np

def solve():
    N = int(input())
    A, B = np.vstack([np.array(list(map(int, input().split()))) for _ in range(N)]).T
    C = A+B
    C.sort()
    res = (C[-1::-2]).sum() - B.sum()
    return str(res)
if __name__ == '__main__':
    print(solve())

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

points = []
for i in range(n):
	temp =  list(map(int, input().split()))
	points.append(temp)

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

print(
	sum([x[0] for x in points[0::2]] )
	-
	sum([x[1] for x in points[1::2]] )
	)

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

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

if n % 2 == 1:
    nums.append([0, 0, 0])
    
A = 0
B = 0
for i in range(0, n, 2):
    A += nums[i][1]
    B += nums[i+1][2]
    
print(A - B)

Solution (Python):
import numpy as np

N = int(input())
Alist = []
Blist = []
sumlist = []

for i in range(N):
    a,b = map(int,input().split())
    Alist.append(a)
    Blist.append(b)
    sumlist.append(a+b)

index = np.argsort(sumlist)

sumlist = np.sort(sumlist)




counter = 0
takahasi = 0
aoki = 0

for i in range(N)[::-1]:
    if counter == 0:
        takahasi += Alist[index[i]]
        counter = 1
        continue
    if counter == 1:
        aoki += Blist[index[i]]
        counter = 0
        continue

print(takahasi-aoki)

Solution (Python):
import math
from operator import itemgetter

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

C = [(A[i], B[i], A[i] + B[i]) for i in range(N)]
C = sorted(C, key=itemgetter(2), reverse=True)

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

print(ans)

Solution (Python):



import array
from bisect import *
from collections import *
import fractions
import heapq 
from itertools import *
import math
import random
import re
import string
import sys

def solve(N, ABs):
    Cs = []
    for n in range(N):
        a, b = ABs[n]
        Cs.append((a + b, a, b))
    Cs.sort()
    Cs.reverse()
    
    taka = 0
    aoki = 0
    for i, c in enumerate(Cs):
        if i % 2 == 0:
            taka += Cs[i][1]
        else:
            aoki += Cs[i][2]
    return taka - aoki

def main():
    N = int(input())
    ABs = []
    for n in range(N):
        a, b = map(int, input().split())
        ABs.append((a, b))
    print(solve(N, ABs))
main()

Solution (Python):
import numpy as np

N = int(input())
AB = np.zeros((3, N))

for i in range(N):
    tmpA, tmpB = map(int, input().split())
    AB[0, i] = tmpA + tmpB
    AB[1, i] = tmpA
    AB[2, i] = tmpB

AB = AB[:, np.argsort(AB[0, :])][:, ::-1]

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

Solution (Python):
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [long(input_raw[0])]
    A_list=[]
    B_list=[]
    All_list = []
    sum_list = []
    abs_list = []

    eated_set = set([])
    for i in range(N):
        input_raw = read_func().strip().split()
        [A, B] = [long(input_raw[0]), long(input_raw[1])]
        A_list.append(A)
        B_list.append(B)
        All_list.append((A, i))
        All_list.append((B, i))
        sum_list.append((A + B, i))
        abs_list.append((abs(A - B), i))

    All_list.sort(reverse = True)





















    is_t_turn = True
    t_sum = 0L
    a_sum = 0L
    eated_set = set([])
    sum_list.sort(reverse=True)
    for i in range(len(sum_list)):

        if is_t_turn == True:
            t_sum += A_list[sum_list[i][1]]

        else:
            a_sum += B_list[sum_list[i][1]]

        if is_t_turn == True:
            is_t_turn = False
        else:
            is_t_turn = True
    sum2 =  t_sum - a_sum



















    print sum2


if __name__ == '__main__':
    main()

Solution (Python):
def C2():
    N = int(input())
    AB = []
    for i in range(N):
        a, b = map(int, input().split())
        AB.append([a + b, a, b])
    AB.sort()
    AB = AB[::-1]
    i = 0
    ans = 0
    while i < N:
        ans += AB[i][1]
        i += 1
        if i >= N:
            break
        ans -= AB[i][2]
        i += 1
    print(ans)
C2()

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

li2 = sorted(li, key=lambda x: (x[0] + x[1]), reverse=True)
v = 0
for i, (a, b) in enumerate(li2):
    if i % 2 == 0:
        v += a
    else:
        v -= b

print(v)

Solution (Python):
import numpy as np
N=int(input())
AB=np.empty((N,2))
sum=np.empty(N)

for i in range(N):
    AB[i]=list(map(int,input().split()))
    sum[i]=AB[i][0]+AB[i][1]
lis = np.argsort(sum)
taka=0
aoki=0
for i in lis:
    if N%2==0:
        if i%2!=0:
            taka+=AB[lis[i]][0]
        else:
            aoki+=AB[lis[i]][1]
    else:
        if i%2==0:
            taka+=AB[lis[i]][0]
        else:
            aoki+=AB[lis[i]][1]

print(int(taka-aoki))

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

check = []
for i in range(N):
    inp = input().split()
    check.append([i, int(inp[0]), int(inp[1]), int(inp[0])+int(inp[1])])

check = sorted(check, key=lambda x:x[3])
check.reverse()


count = 0
ans = 0
while(count+1 < N):
    ans += check[count][1]
    ans -= check[count+1][2]
    count += 2

if count+1==N:
    ans += check[count][1]

print(ans)

Solution (Python):
n=int(input())
a=[]
b=[]
c=[]
for i in range(n):
    s=input().split()
    A,B=int(s[0]),int(s[1])
    a.append(A)
    b.append(B)
    c.append(A+B)
c.sort(reverse=True)
s1=0
s2=0
for i in range(n):
    s1+=a[i]
    if i%2:
        s2+=c[i]
print(s1-s2)

Solution (Python):
n = int(input())
x = [[0]*3 for i in range(n)]
for i in range(n):
    a,b = map(int,input().split())	
    x[i] = [a+b,a,b]
x.sort()
C = [[0]*3 for i in range(n)]
for i in range(n):
    C[i]=x[n-1-i]
x = C

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

Solution (Python):
N = int(input())
dish = [[0 for _ in range(3)] for _ in range(N)]
Takahashi = []
Aoki = []
for i in range(N):
    dish[i][0],dish[i][1] = [int(x) for x in input().split()]
    dish[i][2] = dish[i][0]+dish[i][1]
dish.sort(key=lambda x:(x[2],x[0],x[1]),reverse=True)
for i in range(N):
    if(i%2==0):
        Takahashi.append(dish[i][0])
    else:
        Aoki.append(dish[i][1])

print(sum(Takahashi)-sum(Aoki))

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

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

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


print(sum([a[0] for a in A[0::2]]) - sum([a[1] for a in A[1::2]]))

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

for i in range(n):
    ab[i].append(ab[i][0] + ab[i][1])
ab.sort(key=lambda x: x[2], reverse = True)
takahashi = 0
aoki = 0
for i in range(n):
    if i % 2 == 0:
        takahashi += ab[i][0]
    else:
        aoki += ab[i][1]
print(takahashi - aoki)

Solution (Python):
from operator import itemgetter
n=int(input())
li=[]
x=[0,0]
for i in range(n):
  a, b = list(map(int, input().split()))
  li.append([a,b,a+b])

li.sort(reverse=True, key=itemgetter(2))
for i in range(n):
  x[i % 2] += li[i][i % 2]

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

Solution (Python):
import math
from operator import itemgetter
n = int(input())
m =[]
l1 =[]
l2 =[]
for i in range(n):
    m.append(input().split())
    l1.append([int(m[i][0])+int(m[i][1]),int(m[i][0]),int(m[i][1])])
l1.sort(key=itemgetter(0),reverse=True)
ans = 0
if n%2 == 0:
    m = math.floor(n/2)
    for i in range(m):
        ans += l1[2*i][1]
        ans -= l1[(2*i)+1][2]
else:
    ans += l1[0][1]
    m = math.floor((n-1)/2)
    for i in range(1,m+1):
        ans -= l1[(2*i)-1][2]
        ans += l1[(2*i)][1]

print(ans)

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

rec = sorted(rec, reverse=True)
for i in range(N):
    if i % 2 == 0:
        num += rec[i]
print(num)

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

print(ans)

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

li = list(sorted(box, key=lambda x: sum(x), reverse = True))

taka = []
aoki = []

for i in range(len(li)):
    taka.append(li[0][0])
    del li[0]
    if li == []:
        print(sum(taka) - sum(aoki))
        quit()
    aoki.append(li[0][1])
    del li[0]
    if li ==[]:
        print(sum(taka) - sum(aoki))
        quit()

Solution (Python):


n = int(input())
A = [tuple(int(x) for x in input().split()) for i in range(n)]
A.sort(key=lambda ab: -(ab[0] + ab[1]))
print(sum(a for a, _ in A[::2]) - sum(b for _, b in A[1::2]))

Solution (Python):
import sys
def input(): return sys.stdin.readline()
def inpl(): return [int(i) for i in input().split()]

N = int(input())
AB = [inpl() for _ in range(N)]
ABS = [(i+j, num) for num, (i, j) in enumerate(AB)]
ABS.sort(reverse = True)
ans = 0
ctr = True
for _, i in ABS:
    ans += (2*ctr -1)*AB[i][not ctr]
    ctr = not ctr
print(ans)

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

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

diff = []
for _ in range(N):
    diff.append(B[_] + A[_])

diff = np.array(diff)
A = np.array(A)
B = np.array(B)

sort_index = diff.argsort()

A = (A[sort_index][::-1])
B = (B[sort_index][::-1])

taka = (A[0::2])
aoki = (B[1::2])

print(sum(taka) - sum(aoki))

Solution (Python):
N = int(input())
A = []
B = []
su = []
for i in range(N):
    a, b = (int(i) for i in input().split())
    A.append(a)
    B.append(b)
    su.append( (a + b, a - b, a, b) )
su.sort()
su.reverse()

cc = 0
for i in range(N):
    if i < N-1 and su[i][0] == su[i+1][0]:
        cc += 1
    else:
        if cc:
            temp = []
            for j in range(i-cc, i+1):
                temp.append(su[j])
            temp2 = []
            for j in range(i-cc, i+1):
                if j % 2 == 0:
                    temp2.append(temp.pop(0))
                else:
                    temp2.append(temp.pop())
            for j in range(i-cc, i+1):
                su[j] = temp2[j-(i-cc)]
            cc = 0
ans = 0
for i in range(N):
    if i%2 == 0:
        ans += su[i][2]
    else:
        ans -= su[i][3]

print(ans)

Solution (Python):
def run(N, A, B):
    sum_AB = {}
    for i in range(N):
        sum_AB[i] = A[i] + B[i]
    sum_AB = sorted(sum_AB.items(), key=lambda x: x[1], reverse=True)
    turn_A = True
    sum_A = 0
    sum_B = 0
    for tmp in sum_AB:
        if turn_A:
            sum_A += A[tmp[0]]
        else:
            sum_B += B[tmp[0]]
        turn_A = not turn_A
    return sum_A - sum_B
    '''
    diff = {}
    for i in range(N):
        diff[i] = A[i] - B[i]
    diff = sorted(diff.items(), key=lambda x: x[1])
    print(diff)
    li = 0
    ri = N - 1
    sum_A = 0
    sum_B = 0
    turn_A = True
    for _ in range(N):
        if -diff[li][1] >= diff[ri][1]:
            if turn_A:
                sum_A += A[li]
            else:
                sum_B += B[li]
            li += 1
        else:
            if turn_A:
                sum_A += A[ri]
            else:
                sum_B += B[ri]
            ri -= 1
        turn_A = not turn_A
    return sum_A - sum_B
    '''


def main():
    N = int(input())
    A = []
    B = []
    for _ in range(N):
        tmp = list(map(int, input().split()))
        A.append(tmp[0])
        B.append(tmp[1])
    print(run(N, A, B))


if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
C = [-1] * N
for i in range(N):
    ai, bi = [int(_) for _ in input().split()]
    C[i] = (ai + bi, ai, bi)

C.sort(reverse=True)

result = 0
for i, ci in enumerate(C):
    if i % 2 == 0:
        result += ci[1]
    else:
        result -= ci[2]

print(result)

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[2])


    



takahashi = 0
for i in ab[0::2]:
    takahashi += i[0]

aoki = 0
for i in ab[1::2]:
    aoki += i[1]


print(takahashi - aoki)

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

Solution (Python):

def select(list_, selected_set):
    while True:
        s = list_.pop()
        if not s[0] in selected_set:
            return s


n = int(input())
ab = []

for i in range(n):
    ai, bi = map(int, input().split())
    ab.append((i, ai, bi))

flag = True
list_a = sorted(ab, key=lambda x: (x[1] + x[2]))
list_b = sorted(ab, key=lambda x: (x[2] + x[1]))
a = 0
b = 0
selected = set()
for _ in range(n):
    s = None
    if flag:
        s = select(list_a, selected)
        a += s[1]
    else:
        s = select(list_b, selected)
        b += s[2]
    selected.add(s[0])

    flag = not(flag)

print(a - b)

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

Solution (Python):
N = int(input())
ABC = [[0] * 3 for i in range(N)]
for i in range(N):
    ABC[i][0], ABC[i][1] = list(map(int, input().split()))
    ABC[i][2] = - (ABC[i][0] + ABC[i][1])

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

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

print(taka - aoki)