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.



Sample input:
3
10 10
20 20
30 30


Sample output:
20

Submission status: Runtime Error

Solution code:
n = int(input())
a, b, c = [], [], []
for _ in range(n):
    x, y = map(int, input().split())
    a.append(max(y-x, x))
    b.append(max(x-y, y))
    c.append([x, y])
num = [x for x in range(n)]
a, a0 = zip(*sorted(zip(a, num)))
b, b0 = zip(*sorted(zip(b, num)))
ans = 0
a, a0, b, b0 = list(a), list(a0), list(b), list(b0)
for i in range(n):
    if i%2 == 0:
       val = a0.pop()
       ans += c[val][0]
       a.pop()
       b.pop(val)
       b0.pop(val)
    else:
       val = b0.pop()
       ans -= c[val][1]
       b.pop()
       a.pop(val)
       a0.pop(val)
print(ans)

Submission status: Runtime Error

Solution code:
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()
    aa, bb = [], []        
    for i in range(n):
        a, b = mi()
        aa.append(a)
        bb.append(b)
    idxa = sorted(range(n), key=lambda x: aa[x])
    idxb = sorted(range(n), key=lambda x: bb[x])
    visted = [False]*n
    cura, curb = 0, 0
    t = 0
    ans = 0
    while cura < n-1 and curb < n-1:
        if t%2 == 0:
            while visted[idxb[curb]]:
                curb += 1
            ans += aa[idxb[curb]]
            visted[idxb[curb]]=True
        if t%2 == 1:
            while visted[idxa[cura]]:
                cura += 1
            ans -= bb[idxa[cura]]
            visted[idxa[cura]]=True
        t += 1
    print(ans)






if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from collections import deque
N = int(input())
lis = []

A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    lis.append((Ain+Bin,i))
lis.sort()
lis.reverse()
lis = deque(lis)

takacnt = 0
aocnt = 0

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        val = lis.popleft()
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        val = lis.popleft()
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)

Submission status: Runtime Error

Solution code:
from collections import deque
N = int(input())
lis = []

A = []
B = []
for i in range(N):
    Ain,Bin = map(int,input().split())
    A.append(Ain)
    B.append(Bin)
    lis.append((Ain+Bin,i))
lis.sort()
lis.reverse()
lis = deque(taka)

takacnt = 0
aocnt = 0
st = set()

# print(taka)
# print(ao)

for i in range(N):
    if i % 2 == 0:
        while True:
            val = lis.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        takacnt += A[val[1]]
    else:
        while True:
            val = lis.popleft()
            if not val[1] in st:
                break
        st.add(val[1])
        aocnt += B[val[1]]
print(takacnt-aocnt)

Submission status: Runtime Error

Solution code:
n = int(input())

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

ia.sort(key=lambda x:x[1])
ib.sort(key=lambda x:x[1])

ans = 0
for i in range(n):
    if i % 2 == 0:
        if ia[0][1] == ia[-1][1]:
            j, b = ib.pop()
            _, a = ia.pop(j)
        else:
            j, a = ia.pop()
            _, b = ib.pop(j)
        ans += a
    else:
        if ib[0][1] == ib[-1][1]:
            j, a = ia.pop()
            _, b = ib.pop(j)
        else:
            j, b = ib.pop()
            _, a = ia.pop(j)
        ans -= b
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import heapq

sys.setrecursionlimit(10 ** 6)

n = int(input())
a, b = [], []
used = [False] * (n + 1)
used[n] = True
for i in range(n):
    a_i, b_i = map(int, input().split())
    heapq.heappush(a, (-a_i, -b_i, i))
    heapq.heappush(b, (-b_i, -a_i, i))

flag = True
ans = 0
for _ in range(n):
    i, j = n, n
    while used[i]:
        a_i, b_i, i = heapq.heappop(a)
    while used[j]:
        b_j, a_j, j = heapq.heappop(b)
    if abs(a_i - a_j) > abs(b_i - b_j):
        if flag:
            ans -= a_i
        else:
            ans += b_i
        used[i] = True
        heapq.heappush(b, (b_j, a_j, j))
    else:
        if flag:
            ans -= a_j
        else:
            ans += b_j
        used[j] = True
        heapq.heappush(b, (b_i, a_i, i))
    flag = not flag
print(ans)

Submission status: Runtime Error

Solution code:
import heapq

n = int(input())
a, b = [], []
used = [False] * (n + 1)
used[n] = True
for i in range(n):
    a_i, b_i = map(int, input().split())
    heapq.heappush(a, (-a_i, -b_i, i))
    heapq.heappush(b, (-b_i, -a_i, i))

flag = True
ans = 0
for _ in range(n):
    i, j = n, n
    while used[i]:
        a_i, b_i, i = heapq.heappop(a)
    while used[j]:
        b_j, a_j, j = heapq.heappop(b)
    if abs(a_i - a_j) > abs(b_i - b_j):
        if flag:
            ans -= a_i
        else:
            ans += b_i
        used[i] = True
        heapq.heappush(b, (b_j, a_j, j))
    else:
        if flag:
            ans -= a_j
        else:
            ans += b_j
        used[j] = True
        heapq.heappush(b, (b_i, a_i, i))
    flag = not flag
print(ans)

Submission status: Runtime Error

Solution code:
ab=[sum(map(int, input().split())) for i in range(int(input()))]
ab.sort(reverse=True)
print(ab[::2]-ab[1::2])

Submission status: Runtime Error

Solution code:
ab=[sum(map(int, input().split())) for i in range(int(input()))]
ab.sort(reversed=1)
print(ab[::2]-ab[1::2])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
ABlist = sorted([a+b for a, b in [int(input()) for _ in range(N)]])[::-1]
ans = 0
for i in range(N):
    if i % 2 == 0:
        ans += ABlist[i]
    else:
        ans -= ABlist[i]
print(ans // 2)

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF INT_MAX
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define sec second
#define fir first
typedef long long ll;
typedef pair<int, int> P;
typedef priority_queue<int> pque;
typedef vector<int> Vec;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    int v[n][3];
    rep(i, n) {
        cin >> v[i][1] >> v[i][2];
        v[i][0] = v[i][1] + v[i][2];
    }
    sort(v, v + n, greater<>());
    int ans = 0;
    rep(i, n) {
        if(i % 2 == 0) ans += v[i][1];
        else ans -= v[i][2];
    }
    cout << ans << endl;
    return 0;
}

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(N)]
    ans = 0
    for i in range(N):
        ls[i].append(ls[i][0]+ls[i][1])
    ls = sorted(ls,key=lambda x:-x[2])
    if N==1:
        print(ls[0][1])
    for i in range(N):
        ans -= ls[i][1]

    for i in range(N//2):
        ans += ls[2*i][2]

    if N%2==1:
        ans += ls[2*i+2][2]
    
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
def main():
    N = int(input())
    ls = [[int(x) for x in input().split()] for _ in range(N)]
    ans = 0
    for i in range(N):
        ls[i].append(ls[i][0]+ls[i][1])
    ls = sorted(ls,key=lambda x:-x[2])
    
    for i in range(N):
        ans -= ls[i][1]
    for i in range(N//2):
        ans += ls[2*i][2]

    if N%2==1:
        ans += ls[2*i+2][2]
    
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import heapq

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

flags = [1 for _ in range(N)]
Asum, Bsum = 0, 0
ans = 0
for i in range(N):
  if i%2==0:
    flag = 0
    while flag == 0:
      neg_a, ii = heapq.heappop(A)
      flag = flags[ii]
      flags[ii] = 0
    Asum += -neg_a
  else:
    neg_b, ii = heapq.heappop(B)
    flag = 0
    while flag == 0:
      neg_b, ii = heapq.heappop(B)
      flag = flags[ii]
      flags[ii] = 0
    Bsum += -neg_b  
print(Asum-Bsum)

Submission status: Runtime Error

Solution code:
import heapq

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

flags = [1 for _ in range(N)]
Asum, Bsum = 0, 0
ans = 0
for i in range(N):
  if i%2==0:
    flag = 0
    while flag == 0:
      neg_a, i = heapq.heappop(A)
      flag = flags[i]
      flags[i] = 0
    Asum += -neg_a
  else:
    neg_b, i = heapq.heappop(B)
    flag = 0
    while flag == 0:
      neg_b, i = heapq.heappop(B)
      flag = flags[i]
      flags[i] = 0
    Bsum += -neg_b  
print(Asum-Bsum)

Submission status: Runtime Error

Solution code:
N, M = map(int, input().split())
S = input()
T = input()

S_cnt = [0] * 27
T_cnt = [0] * 27

for s in S:
  S_cnt[ord(s) - ord("A")] += 1
for t in T:
  T_cnt[ord(t) - ord("A")] += 1
#print("S_cnt", *S_cnt)
#print("T_cnt", *T_cnt)

answer = 0
for i in range(27):
  if S_cnt[i]:
    if T_cnt[i] == 0:
      print(-1)
      exit()
    else:
      answer = max(answer, -(-S_cnt[i] // T_cnt[i]))
print(answer)

Submission status: Runtime Error

Solution code:
=int(input())
c=[]
a=[]
b=[]
for i in range(n):
	x,y=map(int,input().split())
	a.append(x)
	b.append(y)
	c.append([x-y,i])
c.sort()
c.reverse()
q=[]
qq=[]
for i in range(n):
	if i%2==0:
		q.append(c[i][1])
	else:
		qq.append(c[i][1])
ans=0
for i in range(len(q)):
	ans+=a[q[i]]
for i in range(len(qq)):
	ans-=b[qq[i]]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

d=[[a[i],b[i],a[i]+b[i]] for i in range(n)]
d.sort(reverse=True,key=lambda x:x[2])
print( sum( d[i][0] for i in range((m+1)//2) ) - sum( d[i][1] for i in range((m+1)//2,m))  )

Submission status: Runtime Error

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

AB.sort(key=lambda x:(x[0]+x[1]),reverse=True)
print(sum([x for x in zip(*AB[::2])][0])-sum([x for x in zip(*AB[1::2])][1]))

Submission status: Runtime Error

Solution code:
import heapq
import numpy as np 
n=int(input())
l=[list(map(int,input().split())) for i in range(n)]
for i in range(n):
    l[i][0],l[i][1]=-l[i][0],-l[i][1]
heapq.heapify(l)
ans=0
for i in range(n):
    ans-=l[0][0]*((-1)**i)
    minimum=heapq.heappop(l)
    for j in range(n-i-1):
        l[j][0],l[j][1]=l[j][1],l[j][0]
    #print(l)
print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
lists=[]
lists1=[]
for i in range(n):
    a,b=map(int,input().split())
    lists.append((a+b,a,b))
listed=sorted(lists,key=lambda x:x[0],reverse=True)

ans=0
for n in range(n):
if n%2==0:
    ans+=listed[n][1]
    
elif n%2!=0:
    ans-=listed[n][2]
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,copy,time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

N = inp()
ABs = []
for _ in range(N):
    A,B = inpl()
    ABs.append([A+B,A,B])

ABs.sort(reversed=True)
t = a = 0

for i,[AB,A,B] in enumerate(ABs):
    if i%2 == 0:
        t += A
    else:
        a += B

print(t-a)

Submission status: Runtime Error

Solution code:
import numpy as np
 
N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = []
aoki = []
 
for i in range(N):
  A[i], B[i] = map(int,input().split())
 
D = np.array(A) + np.array(B)

for i in range(N):
  C[i] = [i, D[i]]
  
C = sorted(C, key=lambda x:x[1])
 
while len(C) > 0:
  tmp_max = C[-1][0]
  takahashi.append(A[tmp_max])
  A.pop(tmp_max)
  B.pop(tmp_max)
  C.pop(tmp_max)
 
  if len(C)>0 :
    tmp_max = C[-1][0]
    aoki.append(B[tmp_max])
    A.pop(tmp_max)
    B.pop(tmp_max)
    C.pop(tmp_max)
 
print(sum(takahashi)-sum(aoki))

Submission status: Runtime Error

Solution code:

import numpy as np

N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = []
aoki = []


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


D = np.array(A) + np.array(B)
for i in range(N):
  C[i] = [i, D[i]]


C = sorted(C, key=lambda x:x[1])



while len(C) > 0:
  tmp_max = C[-1][0]
  takahashi.append(A[tmp_max])
  A.pop(tmp_max)
  B.pop(tmp_max)
  C.pop(tmp_max)

  if len(C)>0 :
    tmp_max = C[-1][0]
    aoki.append(B[tmp_max])
    A.pop(tmp_max)
    B.pop(tmp_max)
    C.pop(tmp_max)

print(sum(takahashi)-sum(aoki))

Submission status: Runtime Error

Solution code:

import numpy as np

N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = 0
aoki = 0



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


D = list(np.array(A) + np.array(B))
for i in range(N):
  C[i] = [i, D[i]]




C = sorted(C, key=lambda x:x[1])



while len(C) > 0:
  tmp_max = C[-1][0]
  takahashi += A[tmp_max]
  A.pop(tmp_max)
  B.pop(tmp_max)
  C.pop(tmp_max)

  if len(C)>0 :
    tmp_max = C[-1][0]
    aoki += B[tmp_max]
    A.pop(tmp_max)
    B.pop(tmp_max)
    C.pop(tmp_max)

print(takahashi-aoki)

Submission status: Runtime Error

Solution code:
#%%
import time



import numpy as np

N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = 0
aoki = 0
for i in range(N):
  A[i], B[i] = map(int,input().split())
  C[i].append(i)
  C[i].append((np.array(A)[1] + np.array(B)[1]))



C = sorted(C, key=lambda x:x[1])




while len(C) > 0:
  tmp_max = C[-1][0]
  takahashi += A[tmp_max]
  A.pop(tmp_max)
  B.pop(tmp_max)
  C.pop(tmp_max)

  if len(C)>0 :
    tmp_max = C[-1][0]
    aoki += B[tmp_max]
    A.pop(tmp_max)
    B.pop(tmp_max)
    C.pop(tmp_max)

print(takahashi-aoki)

Submission status: Runtime Error

Solution code:
import numpy as np

N = int(input())
A = [0] * N
B = [0] * N
C = [[] for _ in range(N) ]
takahashi = 0
aoki = 0
for i in range(N):
  A[i], B[i] = map(int,input().split())
  C[i].append(i)
  C[i].append(A[i]+B[i])

C = sorted(C, key=lambda x:x[1])

while len(C) > 0:
  tmp_max = C[-1][0]
  takahashi += A[tmp_max]
  A.pop(tmp_max)
  B.pop(tmp_max)
  C.pop(tmp_max)

  if len(C)>0 :
    tmp_max = C[-1][0]
    aoki += B[tmp_max]
    A.pop(tmp_max)
    B.pop(tmp_max)
    C.pop(tmp_max)

print(takahashi-aoki)

Submission status: Runtime Error

Solution code:
N = int(input())
ABs = [list(map(int,input.split())) for i in rane(N)]
li = []
for A,B in ABs:
  li.append([A+B,A,B])
  
li.sort(reverse=True)
flag = True
ans1 = ans2 = 0
for S,A,B in li:
  if flag:
    ans1 += A
  else:
    ans2 += B
  flag = not flag
  
print(ans1-ans2)

Submission status: Runtime Error

Solution code:
input()
s=[list(map(int,input().split()))for i in range(n)]
print(sum(sorted([x[1]+x[0] for x in s])[::-2])-sum([x[1]for x in s]))

Submission status: Runtime Error

Solution code:
n = int(input())
if n==1:
  print(int(input()))
else:
  ab = [[0] * n for i in range(3)]
  for i in range(n):
    ab[0][i], ab[1][i] = map(int, input().split())
    ab[2][i] = ab[0][i] + ab[1][i]
  sorted(ab, key=lambda x: x[2])
  print(sum(ab[0][0::2])-sum(ab[1][1::2]))

Submission status: Runtime Error

Solution code:
n = int(input())
if n==1:
  print(int(input())
else:
  ab = [[0] * n for i in range(3)]
  for i in range(n):
    ab[0][i], ab[1][i] = map(int, input().split())
    ab[2][i] = ab[0][i] + ab[1][i]
  sorted(ab, key=lambda x: x[2])
  print(sum(ab[0][0::2])-sum(ab[1][1::2]))

Submission status: Runtime Error

Solution code:
n = int(input())
ab = [[0] * n for i in range(3)]
for i in range(n):
  ab[0][i], ab[1][i] = map(int, input().split())
  ab[2][i] = ab[0][i] + ab[1][i]
sorted(ab, key=lambda x: x[2])
print(sum(ab[0][0::2])-sum(ab[1][1::2]))

Submission status: Runtime Error

Solution code:
n = int(input())
ab = [[0] * 3 for i in range(n)]
for i in range(n):
  ab[i][0], ab[i][1] = map(int, input().split())
  ab[i][2] = ab[i][0] + ab[i][1]
sorted(ab, key=lambda x: x[2])
print(sum(ab[0::2][0])-sum(ab[1::2][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
for i in range(n):
  ab[i][0], ab[i][1] = map(int, input().split())
  ab[i][2] = ab[i][0] + ab[i][1]
sorted(ab, key=lambda x: x[2])
print(sum(ab[0::2][0])-sum(ab[1::2][1]))

Submission status: Runtime Error

Solution code:
n = int(input())
AB = [list(map(int, input().split())) for _ in range(n)]
AB.sort(reverse = True, key = lambda x:x[0]+x[1])
ans = sum(AB[0::2][0]) - sum(AB[1::2][1])
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
Ahap=0
Bhap=0
ListAi=[] #高橋君の食べた幸福度
ListBi=[] #青木さんの食べた幸福度
ListEi=[] #i番目に食べるもののPointを格納し、この中で大きい数値の順に食べる
for i in range(0,N,1): #N回の食事をする
  ABi=input()
  ListABi=ABi.split()
  Ai=int(ListABi[0])
  Bi=int(ListABi[1])
  Point=Ai+Bi
  ListAi.append(Ai)
  ListBi.append(Bi)
  ListEi.append(Point)

for j in range(0,N,1):
  maxi=ListEi(max)
  poji=ListEi.index(maxi)
  a=ListAi.pop(poji)
  b=ListBi.pop(poji)
  if j%2==1:
    Ahap+=a
  elif j%2==1:
    Bhap+=b
  
S=Ahap-Bhap
print(S)

Submission status: Runtime Error

Solution code:
N=int(input())
Ahap=0
Bhap=0
ListAi=[] #高橋君の食べた幸福度
ListBi=[] #青木さんの食べた幸福度
ListEi=[] #i番目に食べるもののPointを格納し、この中で大きい数値の順に食べる
for i in range(0,N,1): #N回の食事をする
  ABi=input()
  ListABi=ABi.split()
  Ai=ListABi[0]
  Bi=ListABi[1]
  Point=Ai+Bi
  ListAi.append(Ai)
  ListBi.append(Bi)
  ListEi.append(Point)

for j in range(0,N,1):
  maxi=ListEi(max)
  poji=ListEi.index(maxi)
  a=ListAi.pop(poji)
  b=ListBi.pop(poji)
  if j%2==1:
    Ahap+=a
  elif j%2==1:
    Bhap+=b
  
S=Ahap-Bhap
print(S)

Submission status: Runtime Error

Solution code:
N=int(input())
Ahap=0
Bhap=0
ListAi=[] #高橋君の食べた幸福度
ListBi=[] #青木さんの食べた幸福度
ListEi=[] #i番目に食べるもののPointを格納し、この中で大きい数値の順に食べる
for i in range(0,N,1): #N回の食事をする
  Ai=int(input())
  Bi=int(input())
  Point=Ai+Bi
  ListAi.append(Ai)
  ListBi.append(Bi)
  ListEi.append(Point)

for j in range(0,N,1):
  maxi=ListEi(max)
  poji=ListEi.index(maxi)
  a=ListAi.pop(poji)
  b=ListBi.pop(poji)
  if j%2==1:
    Ahap+=a
  elif j%2==1:
    Bhap+=b
  
S=Ahap-Bhap
print(S)

Submission status: Runtime Error

Solution code:
from operator import itemgetter
N = int(input())
A = []
B = []
for i in range(N):
    Ai, Bi = map(int, input().split())
    A.append(Ai)
    B.append(Bi)
C = []
for i in range(N):
    C.append([i,A[i]-B[i]])

C.sort(key=itemgetter(1),reverse=True)
print(C)
m = 0
w = 0
for i in range(N//2):
	m += A[C[i][0]]
	w += B[C[N-1-i][0]]
if N % 2 == 1:
  	m += A[C[N//2+1][0]]
print(m-w)

Submission status: Runtime Error

Solution code:
n = input()
dishes = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dishes.append((tmp[0] - tmp[1], tmp[0], tmp[1]))

sorted(dishes, key=lambda v: v[0], reverse=True)

point = [0, 0]
player = 0
while len(dishes[0]) > 0:
    if player == 0:
        dish = dishes.pop(0)
    else:
        dish = dishes.pop(len(dishes) - 1)

    # remove dish
    dishes.remove(dish)

    point[player] += dish[player + 2]
    player = int(not player)
print(point[0] - point[1])

Submission status: Runtime Error

Solution code:
n = input()
dish = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dish.append((tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1]))

point = [0, 0]

player = 0
while len(dish) > 0:
    # print(player.__str__(), player)

    sorted(dish, key=lambda v: dish[player], reverse=True)
    # print(dish[0])
    point[player] += dish.pop(0)[player + 2]
    player = int(not player)
    # print('point', point)

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

Submission status: Runtime Error

Solution code:
n = input()
dish = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dish.append((tmp[0] - tmp[1], tmp[1] - tmp[0], tmp[0], tmp[1]))

point = [0, 0]

player = 0
while len(dish) > 0:

    sorted(dish, key=lambda v: dish[player], reverse=True)
    point[player] = dish.pop(0)[player + 2]
    player = int(not player)


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

Submission status: Runtime Error

Solution code:
n = input()
dish = []
for i in range(int(n)):
    tmp = [int(each) for each in input().split()]
    dish.append((tmp[0] - tmp[1], tmp[1] - tmp[0]))

point = [0, 0]

player = 0
while len(dish) > 0:

    sorted(dish, key=lambda v: dish[player], reverse=True)
    point[player] += point[player]
    player = int(not player)
print(point[0] - point[1])

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())
A, B, C = np.zeros((3, N))
for num in range(N):
    A[num], B[num] = map(int, input().split())

SUM = 0
if N % 2 == 0 :
    R = N / 2
else :
    R = N / 2 + 1

for num in range(R) :
    max_index = A.argmax() + B[np.where(A == A.max())].argmax()
    SUM += A[max_index]
    A = np.delete(A, max_index)
    B = np.delete(B, max_index)
    if len(A) == 0 :
        break
    
    max_index = B.argmax() + A[np.where(B == B.max())].argmax()
    SUM -= B[max_index]
    A = np.delete(A, max_index)
    B = np.delete(B, max_index)
print(int(SUM))

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())
A, B, C = np.zeros((3, N))
for num in range(N):
    A[num], B[num] = map(int, input().split())
    
SUM = 0
round=lambda x:(x*2+1)//2
for num in range(round(N/2)) :
    max_index = A.argmax() + B[np.where(A == A.max())].argmax()
    SUM += A[max_index]
    A = np.delete(A, max_index)
    B = np.delete(B, max_index)
    if len(A) == 0 :
        break
    
    max_index = B.argmax() + A[np.where(B == B.max())].argmax()
    SUM -= B[max_index]
    A = np.delete(A, max_index)
    B = np.delete(B, max_index)

print(int(SUM))

Submission status: Runtime Error

Solution code:
import numpy as np

N=int(input())
A, B, C = np.zeros((3, N))
for num in range(N):
    A[num], B[num] = map(int, input().split())
SUM = 0

for num in range(round(N/2)+1) :
    max_index = A.argmax() + B[np.where(A == A.max())].argmax()
    SUM += A[max_index]
    A = np.delete(A, max_index)
    B = np.delete(B, max_index)
    if len(A) == 0 :
        break
    
    max_index = B.argmax() + A[np.where(B == B.max())].argmax()
    SUM -= B[max_index]
    A = np.delete(A, max_index)
    B = np.delete(B, max_index)
print(int(SUM))

Submission status: Runtime Error

Solution code:
n = int(input())
a = []
for i in range(n):
  ai, bi = list(map(int, input()))
  a.append((ai, bi, ai+bi))
a.sort(key = lambda x: x[2], reverse=True)
tak = 0
aok = 0
for i in range(n):
  if i%2 == 0:
    tak += a[i][0]
  else:
    aok += a[i][1]
print(tak - aok)

Submission status: Runtime Error

Solution code:
N = int(input())
l = []
sumB = 0
for i in range(N):
    tmp = map(int, input().split())
    l.append(tmp[0] + tmp[1])
    sumB += tmp[1]
l.sort(reverse=True)
A = 0
for i in range(0, N, 2):
        A += l[i]
print(A - sumB)

Submission status: Runtime Error

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

c.sort()

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

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
L = [[0] * 3 for _ in range(N)]

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

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

print(sum(L[::2][0]) - sum(L[1::2][1]))

Submission status: Runtime Error

Solution code:
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 = ~
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)

Submission status: Runtime Error

Solution code:
from sys import stdin
import pandas as pd

N = stdin.readline().rstrip()
a = []
for line in stdin:
    a.append(line.rstrip().split())


def findMax(df, col, sort):
    df = df.sort_values(by=sort,
                        ascending=False).reset_index(drop=True)
    res = df.head(1)[col].values[0]
    df = df.drop(0)
    return res, df


print(N)

df = pd.DataFrame(a)
df.columns = ["expA", "expB"]
df = df.assign(expA=pd.to_numeric(df.expA))
df = df.assign(expB=pd.to_numeric(df.expB))

resA = 0
resB = 0
for i in range(0, int(N)):
    if(i % 2 == 0):
        res, df = findMax(df, "expA", ["expA", "expB"])
        resA += res
    else:
        res, df = findMax(df, "expB", ["expB", "expA"])
        resB += res

print(resA-resB)