Problem:
 Score : 400 points    Problem Statement There are N dishes of cuisine placed in front of Takahashi and Aoki.
For convenience, we call these dishes Dish 1 , Dish 2 , ..., Dish N .  When Takahashi eats Dish i , he earns A_i points of happiness ; when Aoki eats Dish i , she earns B_i points of happiness.  Starting from Takahashi, they alternately choose one dish and eat it, until there is no more dish to eat.
Here, both of them choose dishes so that the following value is maximized: "the sum of the happiness he/she will earn in the end" minus "the sum of the happiness the other person will earn in the end".  Find the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".      Constraints  1 \leq N \leq 10^5  1 \leq A_i \leq 10^9  1 \leq B_i \leq 10^9  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  A_1  B_1  :  A_N  B_N       Output Print the value: "the sum of the happiness Takahashi earns in the end" minus "the sum of the happiness Aoki earns in the end".        Sample Input 1 3
10 10
20 20
30 30      Sample Output 1 20  In this sample, both of them earns 10 points of happiness by eating Dish 1 , 20 points by eating Dish 2 , and 30 points by eating Dish 3 .  In this case, since Takahashi and Aoki have the same "taste", each time they will choose the dish with which they can earn the greatest happiness. Thus, first Takahashi will choose Dish 3 , then Aoki will choose Dish 2 , and finally Takahashi will choose Dish 1 , so the answer is (30 + 10) - 20 = 20 .       Sample Input 2 3
20 10
20 20
20 30      Sample Output 2 20  In this sample, Takahashi earns 20 points of happiness by eating any one of the dishes 1, 2 and 3 , but Aoki earns 10 points of happiness by eating Dish 1 , 20 points by eating Dish 2 , and 30 points by eating Dish 3 .  In this case, since only Aoki has likes and dislikes, each time they will choose the dish with which Aoki can earn the greatest happiness. Thus, first Takahashi will choose Dish 3 , then Aoki will choose Dish 2 , and finally Takahashi will choose Dish 1 , so the answer is (20 + 20) - 20 = 20 .       Sample Input 3 6
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000      Sample Output 3 -2999999997  Note that the answer may not fit into a 32 -bit integer.

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

N=int(input())
A=[0]*N
B=[0]*N
C=[0]*N

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

t=0
a=0

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


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

print(t-a)

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

Solution (Python):
import heapq

n = int(input())
happy = []
ans = 0
for i in range(n):
    a, b = tuple(map(int, input().split()))
    heapq.heappush(happy, - (a + b))
    ans += a
while len(happy) != 0:
    heapq.heappop(happy)
    if len(happy) != 0:
        h = heapq.heappop(happy)
        ans += h
    else:
        break
print(ans)

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

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

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

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

    prior = sorted(dish, key=lambda x: x[0] + x[1], reverse=True)
    pt_tak, pt_aok = 0, 0

    for i, (a, b) in enumerate(prior):
        if i%2 == 0:
            pt_tak += a
        else:
            pt_aok += b

    ans = pt_tak - pt_aok
    print(ans)

nikkei19q_c()

Solution (Python):
n = int(input())
atob = []
ans = 0
for i in range(n):
    x,y = map(int,input().split())
    ans += x
    atob.append(x+y)
    
atob.sort(reverse=True)

for i in range(n//2):
    ans -= atob[2*i+1]
    
print(ans)

Solution (Python):
import heapq
N = int(input())
AB = []
for i in range(N):
    ab = list(map(int, input().split()))
    AB.append([-ab[0] - ab[1], -ab[0], -ab[1]])

AB.sort(reverse=True)

heapq.heapify(AB)
ans = 0
for i in range(N):
    q = heapq.heappop(AB)
    if i % 2 == 0:
        ans += - q[1]
    else: ans += q[2]
print(ans)

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

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

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

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)
k=0
x=0
y=0
while k<n:
    if k%2==0:
        x+=l[k][1]
    else:
        y+=l[k][2]
    k+=1
print(x-y)

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


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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    AB = [list(map(int, input().split())) for _ in range(n)]
    for i in range(n):
        a, b = AB[i]
        AB[i] = [a + b, a, b]
    AB.sort(key=lambda x: x[0], reverse=True)

    score_t = sum(AB[i][1] for i in range(n) if i % 2 == 0)
    score_a = sum(AB[i][2] for i in range(n) if i % 2 != 0)

    print(score_t - score_a)


if __name__ == '__main__':
    resolve()

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    AB = [list(map(int, input().split())) for _ in range(n)]
    for i in range(n):
        a, b = AB[i]
        AB[i] = [a + b, a, b]
    AB.sort(key=lambda x: x[0], reverse=True)

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

    print(score_t - score_a)


if __name__ == '__main__':
    resolve()

Solution (Python):
def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    N = Z()
    A, B, C = [], [], []
    for i in range(N):
        a, b = ZZ()
        A.append(a)
        B.append(b)
        C.append([a+b, i])
    C.sort(reverse=True)
    output = 0
    for i in range(N):
        _, j = C[i]
        if i%2 == 0: output += A[j]
        else: output -= B[j]
    print(output)

    return

if __name__ == '__main__':
    main()

Solution (Python):
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))



N = I()
A,B = LIR(N,2)

from operator import itemgetter
def index_sort(A):
    A_sort = sorted(enumerate(A),key=itemgetter(1))
    index = [a[0] for a in A_sort]
    sorted_A = [a[1] for a in A_sort]
    return index, sorted_A

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

print(ans)

Solution (Python):
N = int(input())
t = []
for _ in range(N):
  a, b = map(int, input().split())
  t.append((a, b))
  
t.sort(key = lambda t: t[0] + t[1])
s = 0
while t:
  s += t.pop()[0]
  if t:
    s -= t.pop()[1]
    
print(s)

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()
    d = []
    for _ in range(n):
        a, b = ns()
        d.append((a + b, a, b))

    d.sort(reverse=True)
    turn = 1
    taka = 0
    ao = 0
    for i in range(n):
        if turn:
            taka += d[i][1]
        else:
            ao += d[i][2]
        turn ^= 1
    print(taka - ao)


if __name__ == '__main__':
    main()

Solution (Python):
import sys


import math
import collections

import bisect
import itertools
import fractions

import copy
import heapq
import decimal

import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))





def main():
    n = ni()
    d = []
    for _ in range(n):
        a, b = ns()
        d.append((a + b, a, b))

    d.sort(reverse=True)
    turn = 1
    taka = 0
    ao = 0
    for i in range(n):
        if turn:
            taka += d[i][1]
        else:
            ao += d[i][2]
        turn ^= 1
    print(taka - ao)


if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input():
    return sys.stdin.readline()[:-1]
N=int(input())
s=[None]*N
for i in range(N):
    A,B=map(int,input().split())
    s[i]=(A+B,A,B)
s.sort(reverse=1)
i=0
t=0
a=0
while i<N:
    if t:
        a-=s[i][2]
    else:
        a+=s[i][1]
    t=not t
    i+=1
print(a)

Solution (Python):
N = int(input())
l = []
for i in range(N):
    A, B = [int(_c) for _c in input().split(" ")]
    l.append({"A": A, "B": B, "sum": A + B})

l = sorted(l, key=lambda x: x["sum"], reverse=True)

a_total = 0
b_total = 0
for i, _l in enumerate(l):
    if i % 2 == 0:
        a_total += _l["A"]
    else:
        b_total += _l["B"]

print(a_total - b_total)

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 x: -x[0])

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

print(ans)

Solution (Python):
def main():
    N = int(input())
    info = [tuple(map(int, input().split())) for _ in range(N)]

    info.sort(key=lambda x: -(x[0]+x[1]))
    takahashi = sum([val for i, (val, _) in enumerate(info) if i % 2 == 0])
    aoki = sum([val for i, (_, val) in enumerate(info) if i % 2 == 1])
    print(takahashi-aoki)


if __name__ == "__main__":
    main()

Solution (Python):

N=int(input())
d=[]
for _ in range(N):
    x,y=map(int,input().split())
    d.append((x,y,x+y))
d.sort(key=lambda x:-x[2])
t=0
a=0
for i in range(N):
    if i%2==0:
        
        t+=d[i][0]
    else:
        a+=d[i][1]
print(t-a)

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

s = [(a+b, a, b) for a, b  in ab]
s.sort(reverse = True)


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

print(t-a)

Solution (Python):
import heapq

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

queue = []
for i in range(N):
    x, y = happiness[i]
    queue.append([-(x+y), x, y])

heapq.heapify(queue)
takahashi = 0
aoki = 0
for i in range(N):
    dish = heapq.heappop(queue)
    if i % 2 == 0:
        takahashi += dish[1]
    else:
        aoki += dish[2]

print(takahashi-aoki)

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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)
    x=sum([-b[2] for b in AB])
    sum_ab=sum([ab[0] for ab in AB[::2]])
    print(x+sum_ab)


if __name__=='__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
def main():
    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)
    x=sum([-b[2] for b in AB])
    sum_ab=sum([ab[0] for ab in AB[::2]])
    print(x+sum_ab)


if __name__=='__main__':
    main()

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

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

Solution (Python):
n = int(input())
b_sum = 0
c = []
for _ in range(n):
    a, b = map(int, input().split())
    b_sum += b
    c.append(a + b)
c.sort()
c = list(reversed(c))
print(sum(c[0::2]) - b_sum)

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    N = int(input())
    ans = 0
    AB = []
    for _ in range(N):
        a, b = map(int, input().split())
        ans -= b
        AB.append(a+b)
    AB.sort()

    for i in range(N):
        if i % 2 == 0:
            ans += AB.pop()
        else:
            AB.pop()
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):
n = int(input())
ab = [[int(i) for i in input().split()] for j in range(n)]

wa_a_b = []

for i in range(n):
    wa_a_b.append([ab[i][0]+ab[i][1],ab[i][0],ab[i][1]])
    
wa_a_b.sort(reverse=True)

ans = 0

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

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

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

ab.sort(reverse=True)

ans = 0

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

print(ans)

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

for i in range(N):
    ans += (-1)**(i%2) * AB[i][i%2 + 1]
print(ans)

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

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

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

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

abl = []

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

abl = sorted(abl, reverse=True)

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

print(ans)

Solution (Python):
n = int(input())
ab = []
for _ in range(n):
    a_, b_ = map(int, input().split())
    d = a_ + b_
    ab.append([a_, b_, d])
ab = sorted(ab, key=lambda x:x[2])[::-1]
print(sum([a[0] for a in ab[0::2]]) - sum([b[1] for b in ab[1::2]]))

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


def main():
    N = int(input())
    AB = [None] * N
    for i in range(N):
        A, B = map(int, input().split())
        AB[i] = (A, B, A + B)

    AB.sort(reverse=True, key=itemgetter(2))
    sum_A = 0
    sum_B = 0
    for i in range(N):
        if i % 2 == 0:
            sum_A += AB[i][0]
        else:
            sum_B += AB[i][1]

    ans = sum_A - sum_B
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
N = int(input())
AB = [list(map(int, input().split())) for _ in range(N)]
D = [[i, abs(a+b)] for i, (a, b) in enumerate(AB)]
D.sort(key=lambda x:x[1], reverse=True)
ta = [0, 0]
for j, (i, d) in enumerate(D):
  ta[j%2]+=AB[i][j%2]
print(ta[0]-ta[1])

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

from operator import itemgetter

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

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

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

takahashi = True
ans = 0

for i in range(N):
    if takahashi:
        ans += AB[i][0]
    else:
        ans -= AB[i][1]
    takahashi = not takahashi

print(ans)

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

c.sort(key=lambda x:x[1],reverse=True)

ans = 0
for i in range(n):
    if i%2==0:
        ans+=a[c[i][0]]
    else:
        ans-=b[c[i][0]]

print(ans)

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 5 + 10)


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


def resolve():
    N = int(input())
    LL = []
    for i in range(N):
        L = list(map(int, input().split()))
        LL.append(L + [sum(L)])

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

    cntA = 0
    cntT = 0
    for i in range(len(LL)):
        if i % 2 == 0:
            cntT += LL[i][0]
        else:
            cntA += LL[i][1]
    print(cntT - cntA)


resolve()

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

cnt,A=0,[]
for a,b in AB:
    cnt -=b
    A.append(a+b)

A.sort(reverse=True)
for i in range(0,n,2):
    cnt +=A[i]
print(cnt)

Solution (Python):

"""
問題を言い換えた時に、
高橋くんがa+bの幸福度を得られる時に、
青木さんが-a-bの妨害をできる
と言い換えても、最適な行動が取れる。
よって、a+bの降順にソートして、
高橋くんの番なら+a
青木さんの番なら-b
することで答えが得られる
"""
import sys
from operator import itemgetter
readline = sys.stdin.buffer.readline
def even(n): return 1 if n%2==0 else 0

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

AB.sort(reverse=True)

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

print(ans)

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

Solution (Python):
from collections import deque
from collections import OrderedDict

def main():
    N, *AB = map(int, open(0).read().split())
    C = [0]*N
    ans = 0
    for i in range(N):
        a = AB[i * 2 + 0]
        b = AB[i * 2 + 1]
        C[i] = a + b
        ans -= b
    C.sort(reverse=True)
    eaten = (N + 1) // 2
    for i in range(eaten):
        ans += C[2*i]
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
from operator import itemgetter
n, *AB = map(int, open(0).read().split())
AB = sorted(zip(AB[::2], AB[1::2]), key=sum, reverse=1)
print(sum(map(itemgetter(0), AB[::2])) - sum(map(itemgetter(1), AB[1::2])))

Solution (Python):
from operator import itemgetter
n, *AB = map(int, open(0).read().split())
A, B = AB[::2], AB[1::2]
AB = sorted([(a, b) for a, b in zip(A, B)], key=sum, reverse=1)
print(sum(map(itemgetter(0), AB[::2])) - sum(map(itemgetter(1), AB[1::2])))

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

Solution (Python):
from collections import deque

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

dif.sort(key=lambda x: x[0])
Takahashi = 0
Aoki = 0
while dif:
    Takahashi += dif.pop()[1]
    if not dif:
        break
    Aoki += dif.pop()[2]

print(Takahashi-Aoki)

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

Solution (Python):
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N = int(rl())
    A, B = [0] * N, [0] * N
    for i in range(N):
        A[i], B[i] = map(int, rl().split())
    
    d = [0] * N
    for i in range(N):
        d[i] = A[i] + B[i]
    d.sort(reverse=True)
    
    ans = sum(d[::2]) - sum(B)
    print(ans)


if __name__ == '__main__':
    solve()

Solution (Python):
import sys
import math  
import bisect  
import queue  


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


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

    V = []
    for a, b in zip(A, B):
        V.append((a + b, a, b))

    V.sort(reverse=True)
    takahashi = 0
    aoki = 0
    for i in range(N):
        if i % 2 == 0:
            takahashi += V[i][1]
        else:
            aoki += V[i][2]

    print(takahashi - aoki)


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=sorted(L, reverse=True, key=lambda x: x[2])
taka=0
ao=0
for i in range(N):
    l=L[i]
    a,b,_=l
    if i%2==0:
        taka+=a
    else:
        ao+=b
print(taka-ao)

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

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)

ta,ao = 0,0
for i in range(n):
    if i % 2 == 0:
        ta += d[i][1]
    else:
        ao += d[i][2]
        
print(ta-ao)

Solution (Python):
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tup(t=int):return tuple(pin(t))

def resolve():
    N=int(input())
    AB=[tup()for i in range(N)]
    AB.sort(key=lambda x:sum(x),reverse=True)
    

    n=N
    turn=0
    his=0
    her=0
    for i in range(N):
        if i%2==0:
            his+=AB[i][0]
        else:her+=AB[i][1]
    print((his-her))
            

resolve()

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

ab.sort(key=lambda p: - p[0] - p[1])
print(sum(p[0] for p in ab[::2]) - sum(p[1] for p in ab[1::2]))

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

Solution (Python):
print(sum(p[1+i%2]for i,p in enumerate(sorted([(lambda a,b:(-a-b,a,-b))(*map(int,input().split()))for i in range(int(input()))]))))

Solution (Python):
print(sum(-b if i%2 else a for i,(p,a,b)in enumerate(sorted([(lambda a,b:(-a-b,a,b))(*map(int,input().split()))for i in range(int(input()))]))))

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

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)

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

print(ans)

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=a+b
    C.append(c)

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

bs=sum(B)
ans-=bs
print(ans)

Solution (Python):
printn = lambda x: print(x,end='')
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True 
BIG = 10**18
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
ab = []
for i in range(n):
    a,b = inm()
    ab.append((a+b,a,b))
ab.sort(reverse=True)
sm = 0
for i in range(n):
    if i%2==0:
        sm += ab[i][1]
    else:
        sm -= ab[i][2]
print(sm)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
ab = [list(map(int, readline().split())) for i in range(n)]
memo = [0] * n
ans = 0
for i, ab_ in enumerate(ab):
    memo[i] = ab_[0] + ab_[1]
    ans -= ab_[1]
memo.sort(reverse=True)
for i in range(n):
    if i % 2 == 0:
        ans += memo[i]
print(ans)

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

c = sorted(c, key=lambda x: x[1], reverse=True)
takahaship, aokip = 0, 0
i = 0
for _ in c:
    if i % 2 == 0:
        takahaship += a[c[i][0]]
    else:
        aokip += b[c[i][0]]
    i += 1
print(takahaship - aokip)

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

print(sum(sorted([d[0] + d[1] for d in D], reverse=True)[::2])
      - sum([d[1] for d in D]))

Solution (Python):
import sys
input = sys.stdin.readline
n=int(input())
a=[list(map(int,input().split())) for i in range(n)]
b=sorted([v[0]+v[1] for v in a],reverse=1)
ans=0
for i in a:
    ans-=i[1]
for i in range(n):
    if i%2==0:
        ans+=b[i]
print(ans)

Solution (Python):
import sys

readline = sys.stdin.readline
n = int(readline())
A = []
B = []
AB = []
for i in range(n):
    a, b = map(int, readline().split())
    A.append(a)
    B.append(b)
    AB.append(a+b)
AB.sort()
ans = -sum(B) + sum(AB[::-2])
print(ans)

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

AB = sorted(AB, key = lambda el:sum(el), reverse = True)


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

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, i])
C = sorted(C, reverse=True)

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

Solution (Python):
MOD = 10 ** 9 + 7
INF = 10 ** 10
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000000)
dy = (-1,0,1,0)
dx = (0,1,0,-1)
from bisect import bisect_left,bisect_right
from collections import deque

def main():
    n = int(input())
    food = []
    ans = 0
    for _ in range(n):
        a,b = map(int,input().split())
        ans -= b
        food.append(a + b)
    
    food.sort(reverse = True)
    for i in range(n):
        if i%2 == 0:
            ans += food[i]
    print(ans)
if __name__ =='__main__':
    main()

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

a_b=[]
x=0
for a,b in ab:
    a_b.append(a+b)
    x-=b
a_b.sort(reverse=True)
ans=0
for i in range(0,n,2):
    ans+=a_b[i]

print(ans+x)

Solution (Python):
def main():
    
    N = int(input())
    AB = [[int(i) for i in input().split()] for j in range(N)]
    AB.sort(reverse=True, key=lambda p: p[0]+p[1])
    X = sum(-b for a, b in AB)
    for i in range(0, N, 2):
        X += sum(AB[i])
    print(X)


if __name__ == '__main__':
    main()

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

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

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

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

ans = 0
for i in range(n):
    a,b = map(int,input().split())
    res.append(a+b)
    ans-=b

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

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])[::-1]
res = 0
for idx, i in enumerate(l):
    if idx % 2 == 0:
        res += i[1]
    else:
        res -= i[2]
print(res)