Buggy python submission (verdict: Time Limit Exceeded):
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))
b=copy.deepcopy(a)

def akey(a):
    return a[0],a[1]
def bkey(a):
    return a[1],a[0]
list.sort(a,key=akey,reverse=True)
list.sort(b,key=bkey,reverse=True)

da=dict()
db=dict()
def f(a):

    return str(a[0]).zfill(20)+str(a[1]).zfill(10)
for idx in range(0,len(a)):
    if f(a[idx]) not in da:
        da[f(a[idx])]=1
    else:
        da[f(a[idx])]+=1
for idx in range(0,len(b)):
    if f(b[idx]) not in db:
        db[f(b[idx])]=1
    else:
        db[f(b[idx])]+=1

def func(a,b):
    pa,pb=0,0
    tag=True
    ida,idb=0,0
    while ida<len(a) and idb<len(b):
        if da[f(a[ida])]==0:
            ida+=1
            continue
        if db[f(b[idb])]==0:
            idb+=1
            continue
        if a[ida]==b[idb] :
            tmp=a[ida]
        else:
            v1=a[0][0]-b[0][1]
            v2=b[0][0]-b[1][1]
            if v1>v2:
                tmp=a[ida]
            else:
                tmp=b[idb]
        if tag:
            pa+=tmp[0]
        else:
            pb+=tmp[1]
        ida+=1
        idb+=1
        da[f(tmp)]-=1
        db[f(tmp)]-=1
        tag=not tag
        a,b,ida,idb=b,a,idb,ida
        
    return pa-pb
    
print(func(a,b)) 







Fixed submission:
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

def akey(a):
    return a[0]+a[1]
list.sort(a,key=akey,reverse=True)


def func(a):
    pa,pb=0,0
    tag=True
    for idx in range(0,len(a)):
        if tag:
            pa+=a[idx][0]
        else:
            pb+=a[idx][1]
        tag=not tag
    return pa-pb
    
print(func(a))

Buggy python submission (verdict: Time Limit Exceeded):
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))
b=copy.deepcopy(a)





def akey(a):
    return a[0],a[1]
def bkey(a):
    return a[1],a[0]
list.sort(a,key=akey,reverse=True)
list.sort(b,key=bkey,reverse=True)

def remove(a, data,tag):
    if tag:
        tag=0
    else:
        tag=1
    n = len(a)
    first = 0
    last = n - 1

    while first <= last:
        mid = int(first + ((last - first) / 2))

        if a[mid][tag] < data[tag] or (a[mid][tag] == data[tag] and a[mid][1-tag] < data[1-tag]):
            last = mid - 1
        elif a[mid][tag] > data[tag] or (a[mid][tag] == data[tag] and a[mid][1-tag] > data[1-tag]):
            first = mid + 1
        else:
            del a[mid]
            return

def func(a,b):
    pa,pb=0,0
    tag=True
    while len(a)!=0:
        if a[0]==b[0]:
            tmp=a[0]
        else:
            v1=a[0][0]-b[0][1]
            v2=b[0][0]-b[1][1]
            if v1>v2:
                tmp=a[0]
            else:
                tmp=b[0]
        if tag:
            pa+=tmp[0]
        else:
            pb+=tmp[1]
        remove(a,tmp,tag)
        remove(b,tmp,not tag)
        tag=not tag
        a,b=b,a

    return pa-pb
    
print(func(a,b)) 







Fixed submission:
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

def akey(a):
    return a[0]+a[1]
list.sort(a,key=akey,reverse=True)


def func(a):
    pa,pb=0,0
    tag=True
    for idx in range(0,len(a)):
        if tag:
            pa+=a[idx][0]
        else:
            pb+=a[idx][1]
        tag=not tag
    return pa-pb
    
print(func(a))

Buggy python submission (verdict: Time Limit Exceeded):
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))
b=copy.deepcopy(a)





def akey(a):
    return a[0],a[1]
def bkey(a):
    return a[1],a[0]
list.sort(a,key=akey,reverse=True)
list.sort(b,key=bkey,reverse=True)

def remove(a, data,tag):
    if tag:
        tag=0
    else:
        tag=1
    n = len(a)
    first = 0
    last = n - 1

    while first <= last:
        mid = int(first + ((last - first) / 2))

        if a[mid][tag] < data[tag] or (a[mid][tag] == data[tag] and a[mid][1-tag] < data[1-tag]):
            last = mid - 1
        elif a[mid][tag] > data[tag] or (a[mid][tag] == data[tag] and a[mid][1-tag] > data[1-tag]):
            first = mid + 1
        else:
            del a[mid]
            return

def func(a,b):
    pa,pb=0,0
    tag=True
    while len(a)!=0:

        if a[0]==b[0]:
            tmp=a[0]
        else:
            v1=a[0][0]-b[0][1]
            v2=b[0][0]-b[1][1]
            if v1>v2:
                tmp=a[0]
            else:
                tmp=b[0]
        if tag:
            pa+=tmp[0]
        else:
            pb+=tmp[1]
        remove(a,tmp,tag)
        remove(b,tmp,not tag)
        tag=not tag
        a,b=b,a

    return pa-pb
    
print(func(a,b)) 







Fixed submission:
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

def akey(a):
    return a[0]+a[1]
list.sort(a,key=akey,reverse=True)


def func(a):
    pa,pb=0,0
    tag=True
    for idx in range(0,len(a)):
        if tag:
            pa+=a[idx][0]
        else:
            pb+=a[idx][1]
        tag=not tag
    return pa-pb
    
print(func(a))

Buggy python submission (verdict: Runtime Error):
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))
b=copy.deepcopy(a)





def akey(a):
    return a[0],a[1]
def bkey(a):
    return a[1],a[0]
list.sort(a,key=akey,reverse=True)
list.sort(b,key=bkey,reverse=True)

def remove(a, data,tag):
    if tag:
        tag=0
    else:
        tag=1
    n = len(a)
    first = 0
    last = n - 1

    while first <= last:
        mid = int(first + ((last - first) / 2))

        if a[mid][tag] < data[tag]:
            last = mid - 1
        elif a[mid][tag] > data[tag]:
            first = mid + 1
        else:
            del a[mid]
            return

def func(a,b):
    pa,pb=0,0
    tag=True
    while len(a)!=0:
        if a[0]==b[0]:
            tmp=a[0]
        else:
            v1=a[0][0]-b[0][1]
            v2=b[0][0]-b[1][1]
            if v1>v2:
                tmp=a[0]
            else:
                tmp=b[0]
        if tag:
            pa+=tmp[0]
        else:
            pb+=tmp[1]

        remove(a,tmp,tag)
        remove(b,tmp,not tag)
        tag=not tag
        a,b=b,a

    return pa-pb
    
print(func(a,b)) 







Fixed submission:
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

def akey(a):
    return a[0]+a[1]
list.sort(a,key=akey,reverse=True)


def func(a):
    pa,pb=0,0
    tag=True
    for idx in range(0,len(a)):
        if tag:
            pa+=a[idx][0]
        else:
            pb+=a[idx][1]
        tag=not tag
    return pa-pb
    
print(func(a))

Buggy python submission (verdict: Time Limit Exceeded):
import math
import copy


def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

b=copy.deepcopy(a)


def akey(a):
    return a[0],a[1]
def bkey(a):
    return a[1],a[0]
list.sort(a,key=akey,reverse=True)
list.sort(b,key=bkey,reverse=True)


def func(a,b):
    pa,pb=0,0
    tag=True
    while len(a)!=0:
        if a[0]==b[0]:
            tmp=a[0]
        else:
            v1=a[0][0]-b[0][1]
            v2=b[0][0]-b[1][1]
            if v1>v2:
                tmp=a[0]
            else:
                tmp=b[0]
        if tag:
            pa+=tmp[0]
        else:
            pb+=tmp[1]
        tag=not tag
        a,b=b,a
        a.remove(tmp)
        b.remove(tmp)
    return pa-pb
    
print(func(a,b)) 







Fixed submission:
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

def akey(a):
    return a[0]+a[1]
list.sort(a,key=akey,reverse=True)


def func(a):
    pa,pb=0,0
    tag=True
    for idx in range(0,len(a)):
        if tag:
            pa+=a[idx][0]
        else:
            pb+=a[idx][1]
        tag=not tag
    return pa-pb
    
print(func(a))

Buggy python submission (verdict: Runtime Error):
import math
import copy
from dask.dataframe.tests.test_rolling import idx


def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

b=copy.deepcopy(a)


def akey(a):
    return a[0],a[1]
def bkey(a):
    return a[1],a[0]
list.sort(a,key=akey,reverse=True)
list.sort(b,key=bkey,reverse=True)


def func(a,b):
    pa,pb=0,0
    tag=True
    while len(a)!=0:
        if a[0]==b[0]:
            tmp=a[0]
        else:
            v1=a[0][0]-b[0][1]
            v2=b[0][0]-b[1][1]
            if v1>v2:
                tmp=a[0]
            else:
                tmp=b[0]
        if tag:
            pa+=tmp[0]
        else:
            pb+=tmp[1]
        tag=not tag
        a,b=b,a
        a.remove(tmp)
        b.remove(tmp)
    return pa-pb
    
print(func(a,b)) 







Fixed submission:
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

def akey(a):
    return a[0]+a[1]
list.sort(a,key=akey,reverse=True)


def func(a):
    pa,pb=0,0
    tag=True
    for idx in range(0,len(a)):
        if tag:
            pa+=a[idx][0]
        else:
            pb+=a[idx][1]
        tag=not tag
    return pa-pb
    
print(func(a))

Buggy python submission (verdict: Runtime Error):
import math
import copy
from dask.dataframe.tests.test_rolling import idx


def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

b=copy.deepcopy(a)


def akey(a):
    return a[0],a[1]
def bkey(a):
    return a[1],a[0]
list.sort(a,key=akey,reverse=True)
list.sort(b,key=bkey,reverse=True)


def func(a,b):
    pa,pb=0,0
    tag=True
    while len(a)!=0:
        if a[0]==b[0]:
            tmp=a[0]
        else:
            v1=a[0][0]-b[0][1]
            v2=b[0][0]-b[1][1]
            if v1>v2:
                tmp=a[0]
            else:
                tmp=b[0]
        if tag:
            pa+=tmp[0]
        else:
            pb+=tmp[1]
        tag=not tag
        a,b=b,a
        a.remove(tmp)
        b.remove(tmp)
    return pa-pb
    
print(func(a,b)) 







Fixed submission:
import math
import copy

def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
a=nCast(inputArr1(n))

def akey(a):
    return a[0]+a[1]
list.sort(a,key=akey,reverse=True)


def func(a):
    pa,pb=0,0
    tag=True
    for idx in range(0,len(a)):
        if tag:
            pa+=a[idx][0]
        else:
            pb+=a[idx][1]
        tag=not tag
    return pa-pb
    
print(func(a))