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):



def main():
    n = int(input())
    dishes = list()
    ans = 0

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

    for index, dish in enumerate(sorted(dishes, key=lambda x: x[0] + x[1], reverse=True)):
        if index % 2 == 0:
            ans += dish[0]
        else:
            ans -= dish[1]

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
ls=[list(map(int,input().split())) for i in range(n)]
ls=sorted(ls,key=lambda x:sum(x),reverse=True)
taka=sum([ls[i][0] for i in range(0,len(ls),2)])
aoki=sum([ls[i][1] for i in range(1,len(ls),2)])

print(taka-aoki)

Solution (Python):



def main():
    n = int(input())
    dishes = list()
    ans = 0

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

    for index, dish in enumerate(sorted(dishes, reverse=True)):
        if index % 2 == 0:
            ans += dish[1]
        else:
            ans -= dish[2]

    print(ans)


if __name__ == '__main__':
    main()

Solution (Python):
n=int(input())
a_=[]
b_=[]

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

sa_ = sorted(
  a_,
  key = lambda x: (x[0], x[1]),
)
sb_ = sorted(
  b_,
  key = lambda x: (x[0], x[1]),
)

i_={}
res=0

for i in range(n):
    if i % 2 :
        item = sb_.pop()
        while ( item[2] in i_ ) :
            item = sb_.pop()
        res -= item[1]
        i_[item[2]]=1
    else :
        item = sa_.pop()
        while ( item[2] in i_ ) :
            item = sa_.pop()
        res += item[1]
        i_[item[2]]=1

print(res)

Solution (Python):
from operator import itemgetter
N = int(input())
A = []
for i in range(N):
  a,b = map(int, input().split())
  A.append([a+b,a,b])
  
A.sort(key=itemgetter(0),reverse=True)

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

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

Solution (Python):

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

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

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

print(t-a)

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

N = int(input())
IN = []
for _ in range(N):
    s = input().split()
    A = int(s[0])
    B = int(s[1])
    R = A + B
    IN.append((A,B,R))

sortedIN = sorted(IN, key=itemgetter(2), reverse=True)
sortedIN.append((0,0,0))

sum_A = 0
sum_B = 0

for i in range(0, N, 2):
    sum_A += sortedIN[i][0]
    sum_B += sortedIN[i+1][1]

print(sum_A - sum_B)

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

Solution (Python):
import sys

N = int(input())
aAB = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]
aAB = sorted([a+b,a,b] for a,b in aAB)[::-1]
iA = 0
iB = 0
for i in range(N):
    if i % 2:
        iB+=aAB[i][2]
    else:
        iA+=aAB[i][1]
print(iA-iB)

Solution (Python):
def main():
    n = int(input())
    A = []
    B = []
    C = {}
    for i in range(n):
        a, b = map(int, input().split())
        A.append(a)
        B.append(b)
        C[str(i)] = a + b
    ans = 0
    isA = True
    for k, v in sorted(C.items(), key=lambda x: -x[1]):
        if isA:
            ans += A[int(k)]
        else:
            ans -= B[int(k)]
        isA = not isA
    print(ans)


if __name__ == "__main__":
    main()

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

dicts = {}
for i in range(N):
    dicts[i] = sum(inputs[i])

ans = 0
count = 0
for key, value in sorted(dicts.items(), key=lambda x: -x[1]):
    if count % 2 == 0:
        ans += inputs[key][0]
    else:
        ans -= inputs[key][1]
    count += 1

print(ans)

Solution (Python):
N =int(input())
l=[[int(i)for i in input().split()]for j in range(N)]
l =sorted(l,key=lambda x:sum(x),reverse=True)
ans =[0,0]
nu = 0
for i in l:
    ans[nu] += i[nu]
    if nu == 0:
        nu = 1
    else:
        nu = 0
print(ans[0]-ans[1])

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+1+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 = int(input())

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

gou.sort()
gou.reverse()

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

print(ans)

Solution (Python):
from collections import deque
n =int(input())
takahashi = 0
aoki = 0
ab = []
a = []
for i in range(n):
 tmp1,tmp2 = (int(i) for i in input().split())
 a.append([tmp1,tmp2])
 ab.append(tmp1+tmp2)
 aoki += tmp2


ab = sorted(ab,reverse = True)
start = 0
for i in range(n):
  if i%2 == 0:
    takahashi += ab[i]
  else:
    continue


print(takahashi-aoki)

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

Solution (Python):
import sys
n = int(input())
T = [line.split() for line in sys.stdin.readlines()]
res = 0
for i, t in enumerate(sorted([(-int(a) - int(b), int(b)) for a, b in T])):
	if i % 2 == 0:
		res -= t[0]
	res -= t[1]

print(res)

Solution (Python):
N=int(input())
sub=[]
AB=[]
for _ in range(N):
    a,b=map(int,input().split())
    AB.append((a,b,a+b))
    sub.append(a+b)
ta=0
ao=0
AB.sort(key=lambda x:-x[2])
for i in range(N):
    if i%2==0: ta+=AB[i][0]
    else: ao+=AB[i][1]
print(ta-ao)

Solution (Python):
import math
import sys
from operator import itemgetter





N = int(input())
r = [[0 for i in range(3)] for j in range(N)]
rsorted = [[0 for i in range(3)] for j in range(N)]

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

rsorted = sorted(r, key = itemgetter(2), reverse=True)

a = 0
b = 0
turn = True

for i in range(N):
	if turn:
		a += rsorted[i][0]
	else:
		b += rsorted[i][1]
	turn = not(turn)
print(a-b)

Solution (Python):
n = int(input())
a_b = []
b_sum = 0
for i in range(n):
    ai, bi = map(int, input().split())
    a_b.append(ai+bi)
    b_sum += bi
a_b.sort(reverse=True)
ans = 0
for i in range(len(a_b)):
    if i%2==0:
        ans += a_b[i]
print(ans-b_sum)

Solution (Python):
def main():
    n = int(input())
    vals = []
    scores = []

    for i in range(n):
        a, b = [int(strn) for strn in input().split()]
        vals.append([a, b, True])
        scores.append([a + b, i])

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

    total = 0
    count = 0
    while True:
        
        candidate = scores[-1][1]
        total += int(vals[candidate][count % 2] * (count % 2 - 0.5) * -2)
        count += 1
        vals[candidate][2] = False
        del scores[-1]
        if count == len(vals):
            break

    print(total)


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n = int(input())
    vals = []
    scores_a = []
    scores_b = []

    for i in range(n):
        a, b = [int(strn) for strn in input().split()]
        vals.append([a, b, True])
        scores_a.append((a + b, i))
        scores_b.append((a + b, i))

    scores_a.sort(key=lambda x: x[0])
    scores_b.sort(key=lambda x: x[0])

    
    

    total = 0
    count = 0
    while True:
        
        candidate = scores_a[-1][1]
        candidate_live = vals[candidate][2]
        
        while not candidate_live:
            
            del scores_a[-1]
            
            candidate = scores_a[-1][1]
            candidate_live = vals[candidate][2]

        total += vals[candidate][0]
        count += 1
        vals[candidate][2] = False
        del scores_a[-1]

        if count == len(vals):
            break

        
        candidate = scores_b[-1][1]
        candidate_live = vals[candidate][2]
        while not candidate_live:
            
            del scores_b[-1]
            
            candidate = scores_b[-1][1]
            candidate_live = vals[candidate][2]

        total -= vals[candidate][1]
        count += 1
        vals[candidate][2] = False

        if count == len(vals):
            break

    print(total)


if __name__ == "__main__":
    main()

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

ab = sorted([x[0]+x[1] for x in AB], reverse=True)
ans = 0
for i in range(N):
    ans -= AB[i][1]

if N % 2 == 0:
    K = N // 2
else:
    K = N // 2 + 1
for i in range(K):
    ans += ab[2*i]


print(ans)

Solution (Python):


n = int(input())
a = [0 for i in range(n)]
b = [0 for i in range(n)]
s = []

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

s.sort(key=lambda e: e[1], reverse=True)

turn = True
taka, aoki = 0, 0
for subs in s:
    if turn:
        taka += a[subs[0]]
    else:
        aoki += b[subs[0]]
    turn = not turn

print(taka - aoki)

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

X = []
for (a,b) in AB:
    X.append((a+b,b))

X.sort(reverse=True)
pa,pb = 0,0
for i in range(N):
    ab,b = X[i]
    pb += b
    if i%2==0:
        pa += ab

print(pa-pb)

Solution (Python):

import sys





"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    s = [[a, b, a + b] for a, b in ip.SILS(n)]

    id.S(s, 1, 2)

    ap = bp = 0
    for i, t in e(s):
        if i % 2 == 0:
            ap += t[0]
        else:
            bp += t[1]

    print(ap - bp)


main()

Solution (Python):

import sys





"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    s = ip.SILS(n)

    for i in r(n):
        s[i].append(s[i][0] + s[i][1])

    id.S(s, 1, 2)

    ap = bp = 0
    for i, t in e(s):
        if i % 2 == 0:
            ap += t[0]
        else:
            bp += t[1]

    print(ap - bp)


main()

Solution (Python):

import sys





"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    s = ip.SILS(n)

    for i in r(n):
        s[i].append(s[i][0] + s[i][1])

    id.S(s, 1, 2)

    print(sum(s[i][0] for i in r(0, n, 2)) - sum(s[i][1] for i in r(1, n, 2)))


main()

Solution (Python):

import sys





"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()

    s = ip.SILS(n)

    for i in r(n):
        s[i].append(s[i][0] + s[i][1])

    id.S(s, 1, 2)

    ap = sum(s[i][0] for i in r(0, n, 2))
    bp = sum(s[i][1] for i in r(1, n, 2))

    print(ap - bp)


main()

Solution (Python):

import sys





"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()

    s = ip.SILS(n)

    for i in r(n):
        s[i].append(s[i][0] + s[i][1])

    id.S(s, 1, 2)

    ap = bp = 0

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

    print(ap - bp)


main()

Solution (Python):
print(-sum([v[k%2]*(k%2*2-1)for k,v in enumerate(sorted([list(map(int,input().split())) for _ in range(int(input()))],key=sum)[::-1])]))

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

sum_list = []
for a, b in items:
    sum_list.append((a + b, a, b))

sum_list = sorted(sum_list, key=lambda x: -x[0])

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

Solution (Python):
print(-sum([v[k%2]*(k%2*2-1)for k,v in enumerate(sorted([[int(j) for j in input().split()] for i in range(int(input()))],key=lambda x:-x[0]-x[1]))]))

Solution (Python):
import sys
from operator import itemgetter


def r(n, ab):

    ss = [x + [x[0] + x[1]] for x in ab]
    ss.sort(key=itemgetter(2), reverse=True)
    
    scr = 0
    sente = True
    for s in ss:
        if sente:
            scr += s[0]
        else:
            scr -= s[1]
        sente = not sente

    return scr

def main():
    input = sys.stdin.readline
    n = int(input())
    ab = [list(map(int, input().split())) for _ in range(n)]
    print(r(n, ab))


if __name__ == '__main__':
    main()