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())
apb = []
b_sum = 0
for i in range(N):
    A,B = map(int, input().split())
    apb += [A+B]
    b_sum += B





ans = sum(sorted(apb, reverse=True)[::2])-b_sum
print(ans)

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

dish = []
ans = 0
for i in range(n):
    a, b = map(int,input().split())
    ans -= b
    dish.append(a+b)
dish.sort(reverse=True)    

for i in range(n):
    if not i%2:
        ans += dish[i]
        
print(ans)

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

Solution (Python):
def main():
    N = int(input())
    A, B, C = [], [], []
    for _ in range(N):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        C.append(a+b)
    C.sort(reverse=True)
    ans = 0
    for i in range(N//2+N%2):
        ans += C[2*i]
    ans -= sum(B)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
d = {}
i = 0
x, s = [], []
for _ in range(n):
    a, b = map(int, input().split())
    k = a + b
    if not k in d:
        d[k] = i
        x.append([])
        s.append(k)
        i += 1
    x[d[k]].append([a, b])
t, a = 0, 0
s.sort(reverse = True)
l = len(x)
for i in range(l):
    x[i].sort(reverse = True)
now = 1
ans = 0
for i in s:
    y = x[d[i]]
    i, j = 0, len(y) - 1
    while i <= j:
        if now:
            ans += y[i][0]
            i += 1
        else:
            ans -= y[j][1]
            j -= 1
        now ^= 1
print(ans)

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

c = []
aok = 0
for i in range(n):
  a,b=map(int, input().split())
  cc  = a+b
  c.append(cc)
  aok += b
c.sort(reverse=True)

ans = sum(c[::2])-aok
print (ans)

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

Solution (Python):
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
AB = sorted(AB, key=lambda x:sum(x), reverse=True)

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

Solution (Python):
import sys
import collections

from operator import itemgetter

sys.setrecursionlimit(10 ** 8)

input = sys.stdin.readline


def main():
    N = int(input())
    AB = [[int(x) for x in input().split()] for _ in range(N)]

    C = []

    for i, (a, b) in enumerate(AB):
        C.append((a + b, i))

    C.sort(reverse=True)

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

    print(takahashi - aoki)


if __name__ == '__main__':
    main()

Solution (Python):

def resolve():
    N = int(input())

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

    P.sort(reverse=True)
    taka = 0
    aoki = 0
    for i, (diff, idx) in enumerate(P):
        if i % 2 == 0:
            taka += A[idx]
        else:
            aoki += B[idx]

    print(taka - aoki)


if __name__ == "__main__":
    resolve()

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

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

l=sorted([(a+b,a,b) for a,b in ab],reverse=True)

ans=sum([a for s,a,b in l[::2]])-sum([b for s,a,b in l[1::2]])

print(ans)

Solution (Python):
import sys
from sys import exit
from collections import deque
from copy import deepcopy
from bisect import bisect_left, bisect_right, insort_left, insort_right
from heapq import heapify, heappop, heappush
from itertools import product, permutations, combinations, combinations_with_replacement
from functools import reduce
from math import gcd, sin, cos, tan, asin, acos, atan, degrees, radians

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def lgcd(l):
    return reduce(gcd,l)
def llcm(l):
    return reduce(lcm,l)
def powmod(n,i,mod=MOD):
    return pow(n,mod-1+i,mod) if i<0 else pow(n,i,mod)
def div2(x):
    return x.bit_length()
def div10(x):
    return len(str(x))-(x==0)
def intput():
    return int(input())
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x,d=1):
        self.setdefault(x,0)
        self[x] += d
    def list(self):
        l = []
        for k in self:
            l.extend([k]*self[k])
        return l
class comb():
    def __init__(self, n, mod=None):
        self.l = [1]
        self.n = n
        self.mod = mod
    def get(self,k):
        l,n,mod = self.l, self.n, self.mod
        k = n-k if k>n//2 else k
        while len(l)<=k:
            i = len(l)
            l.append(l[i-1]*(n+1-i)//i if mod==None else (l[i-1]*(n+1-i)*powmod(i,-1,mod))%mod)
        return l[k]
def pf(x,mode='counter'):
    C = counter()
    p = 2
    while x>1:
        k = 0
        while x%p==0:
            x //= p
            k += 1
        if k>0:
            C.add(p,k)
        p = p+2-(p==2) if p*p<x else x
    if mode=='counter':
        return C
    S = set([1])
    for k in C:
        T = deepcopy(S)
        for x in T:
            for i in range(1,C[k]+1):
                S.add(x*(k**i))
    if mode=='set':
        return S
    if mode=='list':
        return sorted(list(S))



N=intput()
C=[]
ans=0
for _ in range(N):
    C.append(lint())
C.sort(reverse=True,key=sum)
for i in range(N):
    ans+=((-1)**(i%2))*C[i][i%2]
print(ans)

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

ab.sort()
ab=ab[::-1]

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

Solution (Python):
import sys, math
from functools import lru_cache
import heapq
sys.setrecursionlimit(10**9)
MOD = 10**9+7

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

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

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

def main():
    N = ii()
    A, B = i2(N)
    ans = 0

    C = [(a + b, i) for a, b, i in zip(A, B, range(N))]
    C.sort(reverse=True)

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

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
ans, a, b = 0, [], []
for _ in range(n):
    x, y = map(int, input().split())
    a.append(x+y)
    b.append([x, y])
num = [x for x in range(n)]
a, a0 = zip(*sorted(zip(a, num)))
a, a0 = list(a), list(a0)

for i in range(n):
    val = a0.pop()
    a.pop()
    if i%2 == 0:
       ans += b[val][0]
    else:
       ans -= b[val][1]
print(ans)

Solution (Python):
import sys



def input():
    return sys.stdin.readline().strip()


def input_int():
    return int(input())


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


def main():
    n = input_int()
    dishes = []
    for i in range(n):
        a, b = input_int_list()
        dishes.append((a, b, a + b))
    
    dishes = sorted(dishes, key=lambda x: x[2])
    t_sum = 0
    a_sum = 0
    is_takahashi = True  
    while dishes:
        a, b, _ = dishes.pop()
        if is_takahashi:
            t_sum += a
        else:
            a_sum += b
        is_takahashi = not is_takahashi
    print(t_sum - a_sum)

    return


if __name__ == "__main__":
    main()

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

l.sort()
l.reverse()
s=0
for i in range(0,n,2):
  s+=l[i][1]
for i in range(1,n,2):
  s-=l[i][2]
print(s)

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

AB_list = [[0,0,0] for i in range(N)]

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

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

print(total)

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

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

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

ans = 0
for i in range(N//2):
  ans += l[2*i]
if N % 2 == 1:
  ans += l[-1]
ans -= sum(B)
print(ans)

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

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

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

aoki = 0
for _ in range(N):
    a, b = map(int, input().split())
    cooking.append([a + b, a, b])
chokudai = 0
cooking.sort(reverse=True)
for i in range(0, N):
    if i % 2 == 0:
        chokudai += cooking[i][1]
    else:
        aoki += cooking[i][2]
ans = chokudai - aoki

print(ans)

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

aoki = 0
for _ in range(N):
    a, b = map(int, input().split())
    cooking.append([a + b, a, b])
    aoki += b
chokudai = 0
cooking.sort(reverse=True)
for i in range(0, N , 2):
    chokudai += cooking[i][1]
    aoki -= cooking[i][2]
ans = chokudai - aoki

print(ans)

Solution (Python):
N = int(input())
l=[list(map(int,input().split())) for i in range(N)]
l_after=sorted(((i+j,i,j) for i,j in l),reverse=True)
print(sum(b for a,b,c in l_after[::2])-sum(c for a,b,c in l_after[1::2]))

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

Solution (Python):

N = int(input())

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

diff = sorted(((a+b,a,b) for a,b in ab), reverse=True)

print(sum(a for _,a,b in diff[::2]) - sum(b for _,a,b in diff[1::2]))

Solution (Python):
n = int(input())
a, b = [0]*n, [0]*n
for i in range(n):
  x, y = map(int, input().split())
  a[i], b[i] = x+y, y
ans = sum(sorted(a, reverse=True)[::2])-sum(b)
print(ans)

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

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


tak_score=0
aok_score=0
turn=0
while pablist:
  p,a,b=pablist.pop()
  if turn&1==0:
    tak_score+=a
  else:
    aok_score+=b
  turn+=1
  
print(tak_score-aok_score)

Solution (Python):
ma = lambda :map(int,input().split())
lma = lambda :list(map(int,input().split()))
tma = lambda :tuple(map(int,input().split()))
ni = lambda:int(input())
yn = lambda fl:print("Yes") if fl else print("No")
import collections
import math
import itertools
import heapq as hq
n= ni()
ab = []
dif = []
for i in range(n):
    a,b = ma()
    ab.append((a,b))
    dif.append((a+b,i))
dif.sort(reverse=True)
tak = 0
ao = 0
for i in range(n):
    d,idx = dif[i]
    if i%2==0:
        tak+=ab[idx][0]
    else:
        ao+=ab[idx][1]
print(tak-ao)

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

Solution (Python):
N = int(input())
ABs = []
As = []
Bs = []

tk = 0
ao = 0

for i in range(N):
  a,b = map(int, input().split())
  As.append(a)
  Bs.append(b)
  ABs.append((a+b, i))
  
ABs.sort(key=lambda x:x[0], reverse=True)

for i in range(N):
  if i%2 == 0:
    tk += As[ABs[i][1]]
  else:
    ao += Bs[ABs[i][1]]
    
print(tk-ao)

Solution (Python):
n=int(input())
a,b=[],0
for i in range(n):
  p,q=map(int,input().split())
  a+=[p+q]
  b-=q
print(sum(sorted(a)[::-2])+b)

Solution (Python):
from collections import deque
n = int(input())
li = []
l = []
di = {}
for i in range(n):
    a, b = map(int, input().split())
    li.append((a+b, -a, i))
    l.append((b+a, -b, i))
    di[i] = False
li.sort(reverse=True)
l.sort(reverse=True)
li = deque(li)
l = deque(l)
left, right = 0, 0
while li:
    while True and li:
        p = li.popleft()
        if di[p[2]]:
            continue
        di[p[2]] = True
        left += -p[1]
        break
    if len(l) != 0:
        while True and l:
            q = l.popleft()
            if di[q[2]]:
                continue
            di[q[2]] = True
            right += -q[1]
            break
print(left-right)

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

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

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

ans = 0
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a + b
    ans -= b
A = sorted(A, reverse=True)
for i in range(N):
    if i % 2 == 0:
        ans += A[i]
print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
lis=[]
for i in range(n):
    a,b=MI()
    lis.append([a,b,a+b])
lis.sort(key=lambda x:x[2],reverse=True)
ans=0
for i in range(n):
    if i%2==0:
        ans+=lis[i][0]
    else:
        ans-=lis[i][1]
print(ans)

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

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

ans = 0
for i in range(N):
    a, b = map(int, input().split())
    A[i] = a + b
    ans -= b
A = sorted(A, reverse=True)
for i in range(N):
    if i % 2 == 0:
        ans += A[i]
print(ans)

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

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

c1 = 0
c2 = 0
for i,[X,Y,Z] in enumerate(x):
    if i%2 == 0:
        c1 += X
    else:
        c2 += Y
print(c1-c2)

Solution (Python):
import sys
import numpy as np
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    n = ii()
    x = []  
    ans = 0     
    for i in range(n):
        a, b = mi()
        x.append(a+b)
        ans -= b
    x.sort(reverse=True)
    ans += sum(x[::2])    
    print(ans)






if __name__ == '__main__':
    main()

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

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

score=[]
bsum=0

for _ in range(n):
    a,b=map(int,input().split())
    score.append(a+b)
    bsum-=b

score.sort(reverse=True)

for i,v in enumerate(score):
    if i%2==0:
        bsum+=v

print(bsum)

Solution (Python):
import sys

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

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N = int(readline())
    X = 0
    AB = []
    for _ in range(N):
        A, B = map(int, readline().split())
        X -= B
        AB.append(A + B)
    AB.sort(reverse=True)
    for ab in AB[::2]:
        X += ab
    print(X)


if __name__ == '__main__':
    main()

Solution (Python):
import sys,math,collections,itertools
input = sys.stdin.readline

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

taka = 0
aoki = 0
ABC.sort(key=lambda x:x[2])
while ABC:
    
    taka += ABC.pop()[0]
    if len(ABC)==0:
        break
    aoki += ABC.pop()[1]
print(taka-aoki)

Solution (Python):
import bisect, collections, copy, heapq, itertools, math, string, sys
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = float('inf')
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    N = I()
    AB = [LI() for _ in range(N)]
    
    AB.sort(key=lambda x: x[0] + x[1], reverse=True)

    score_t = 0
    score_a = 0
    for i in range(N):
        a, b = AB[i]
        if i % 2 == 0:
            score_t += a
        else:
            score_a += b

    print(score_t - score_a)

if __name__ == '__main__':
    resolve()

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

Solution (Python):


def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    N = read_int()
    AB = []
    for _ in range(N):
        A, B = read_ints()
        AB.append((A+B, A, B))
    AB.sort()
    scores = [0, 0]
    p = 0
    while AB:
        _, *s = AB.pop()
        scores[p] += s[p]
        p ^= 1
    return scores[0]-scores[1]


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

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

Solution (Python):
n = int(input())
l = []
for i in range(n):
  a,b = map(int,input().split())
  l.append([a+b,a,b])
l1 = sorted(l)[::-1]
bit = 0
ans = 0
for i,j,k in l1:
  if bit==0:
    ans += j
    bit = 1
  else:
    ans -= k
    bit = 0
print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n = int(readline())
    mat = []
    for _ in range(n):
        a, b = map(int, readline().split())
        c = a + b
        mat.append([c, a, b])

    mat.sort(reverse=True)

    a_sum, b_sum = 0, 0

    for i in range(n):
        if i % 2 == 0:
            a_sum += mat[i][1]
        else:
            b_sum += mat[i][2]

    print(a_sum - b_sum)


if __name__ == '__main__':
    main()

Solution (Python):





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

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

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


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

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

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

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

    return arr



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



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


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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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


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

    divisors.sort()
    return divisors


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

n = ir()
ab = []
for i in range(n):
    a,b = lr()
    ab.append([a,b])
ab.sort(key=lambda x:x[0]+x[1], reverse=True)
ans = 0
for i,num in enumerate(ab):
    if i%2 == 0:
        ans+=num[0]
    else:
        ans-=num[1]
print(ans)

Solution (Python):


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


SUM.sort(reverse=True)

sumA = 0
sumB = 0
for i in range(N):
    idx = SUM[i][1]
    if i % 2 == 0:
        sumA += A[idx]
    else:
        sumB += B[idx]

print(sumA - sumB)

Solution (Python):
def main():
  N = int(input())
  cuisine =  []
  for i in range(N):
    a,b = map(int, input().split())
    cuisine.append([a+b, a, b])
  cuisine.sort(key = lambda x:x[0], reverse = True)
  happy_t = 0
  happy_a = 0
  for i in range(N):
    if i % 2 == 0:
      happy_t += cuisine[i][1]
    else:
      happy_a += cuisine[i][2]
  print(happy_t-happy_a)
  
if __name__ == "__main__":
  main()

Solution (Python):
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = []
for i in range(n):
    A, B = MAP()
    a.append([A+B, A, B])

a.sort(reverse=True)
tmp_a = 0
tmp_b = 0

for i in range(n):
    if i % 2 == 0:
        tmp_a += a[i][1]
    else:
        tmp_b += a[i][2]

ans = tmp_a - tmp_b
print(ans)

Solution (Python):
def main():
    N = int(input())
    input_list = [list(map(int, input().split())) for _ in range(N)]
    dish_list = [(sum(row), row[0], row[1], n) for n, row in enumerate(input_list)]
    dish_list.sort(reverse=True)
    ans = sum([((- 1)**(n % 2)) * dish[1 + n % 2] for n, dish in enumerate(dish_list)])
    print(ans)


if __name__ == '__main__':
    main()

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

AB.sort()
ans = 0
for i in range(n):
    if i%2 == 0:
        ans += AB.pop()
    else:
        AB.pop()
ans -= Sb
print(ans)

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

Solution (Python):
import numpy as np
n = int(input())
A,B = np.array([input().split() for _ in range(n)], dtype=np.int64).T

ans = A.sum() 
improve = A+B 
improve.sort()
ans -= improve[::-1][1::2].sum()
print(ans)

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

x = y = 0
i = 0
while AB:
    a,b = AB.pop()
    if i%2:
        y += b
    else:
        x += a
    i += 1
print(x-y)

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

c = [i+j for i, j in AB]
c.sort(reverse = True)

ans = sum(c[::2]) - sum([j for i, j in AB])
print(ans)

Solution (Python):
def solve(n, a, b):
    v = sorted(zip(a, b), key=lambda x:x[0]+x[1], reverse=True)
    return sum(x+y for x, y in v[::2]) - sum(b)

n = int(input())
a = [0]*n
b = [0]*n
for i in range(n):
    a[i], b[i] = map(int, input().split())
print(solve(n, a, b))

Solution (Python):
from collections import deque

n = int(input())
ab = [list(map(int, input().split())) for i in range(n)]
ab = list(map(lambda x: [x[0], x[1], x[0]+x[1]], ab))
ab.sort(key=lambda x:x[2], reverse=True)
ab=deque(ab)
count = 0
ans=0
while len(ab)>0:
  a, b, dif = ab.popleft()
  if count%2==0:
    ans+=a
  else:
    ans-=b
  count+=1
print(ans)

Solution (Python):
from collections import deque

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

for i in range(n):
  a, b=ab[i]
  ab[i].append(a+b)
ab.sort(key=lambda x:x[2], reverse=True)
ab=deque(ab)
count = 0
ans=0
while len(ab)>0:
  a, b, dif = ab.popleft()
  if count%2==0:
    ans+=a
  else:
    ans-=b
  count+=1
print(ans)

Solution (Python):
from collections import deque

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

suml.sort(reverse=True)
q = deque(suml)

asum = 0
bsum = 0
a_turn = True
while q:
    if a_turn:
        _, poped, _ = q.popleft()
        asum += poped
    else:
        _, _, poped = q.popleft()
        bsum += poped
    a_turn = not a_turn

print(asum-bsum)

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

C.sort(reverse=True)
print(sum(C[::2])-sum(B))

Solution (Python):
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**8)
mod = 10**9+7

INF = 10**18
eps = 10**-7

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

Solution (Python):
n,*ab = map(int,open(0).read().split())
abc = [(ab[i*2],ab[i*2+1],ab[i*2]+ab[i*2+1]) for i in range(n)]
abc.sort(key=lambda x:x[2],reverse = True)
print(sum([abc[i][0] if i%2==0 else -abc[i][1] for i in range(n)]))

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

dish = []
ans = 0
for _ in range(n):
    a, b = map(int, input().split())
    dish.append(a + b)
    ans += -1 * b

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