CodeEff/ECCO huggingface dataset:
# Original solution
import sys
input = sys.stdin.readline
mod = 998244353
n = int(eval(input()))
XY = sorted(tuple(map(int, input().split())) for _ in range(n))
X, Y = list(zip(*XY))
L = {y:i+1 for i, y in enumerate(sorted(Y))}
Y = tuple(L[y] for y in Y)
BIT = [0]*(n+1)
def add(i):
  while i<=n:
    BIT[i] += 1
    i += i&-i
def acc(i):
  res = 0
  while i:
    res += BIT[i]
    i -= i&-i
  return res
A = [0]*n
B = [0]*n
C = [0]*n
D = [0]*n
for i, y in enumerate(Y):
  A[i] = acc(y)
  B[i] = i - A[i]
  add(y)
BIT = [0]*(n+1)
for i in range(n-1, -1, -1):
  y = Y[i]
  C[i] = acc(y)
  D[i] = n-1-i - C[i]
  add(y)
ans = pow(2, n-1, mod) * n % mod
for a, b, c, d in zip(A, B, C, D):
  a = pow(2, a, mod)
  b = pow(2, b, mod)
  c = pow(2, c, mod)
  d = pow(2, d, mod)
  temp = (a-1)*b*c*(d-1) + a*(b-1)*(c-1)*d - (a-1)*(b-1)*(c-1)*(d-1)
  ans += temp
  ans %= mod
print(ans)

# Optimized solution
import sys
input = sys.stdin.readline
mod = 998244353
n = int(eval(input()))
XY = sorted(tuple(map(int, input().split())) for _ in range(n))
X, Y = list(zip(*XY))
L = {y:i+1 for i, y in enumerate(sorted(Y))}
Y = tuple(L[y] for y in Y)
BIT = [0]*(n+1)
def add(i):
  while i<=n:
    BIT[i] += 1
    i += i&-i
def acc(i):
  res = 0
  while i:
    res += BIT[i]
    i -= i&-i
  return res
A = [0]*n
B = [0]*n
C = [0]*n
D = [0]*n
for i, y in enumerate(Y):
  A[i] = acc(y)
  B[i] = i - A[i]
  add(y)
BIT = [0]*(n+1)
for i in range(n-1, -1, -1):
  y = Y[i]
  C[i] = acc(y)
  D[i] = n-1-i - C[i]
  add(y)
T = [1]*n
for i in range(n-1):
  T[i+1] = T[i]*2%mod
ans = T[n-1] * n % mod
for a, b, c, d in zip(A, B, C, D):
  a = T[a]
  b = T[b]
  c = T[c]
  d = T[d]
  temp = (a-1)*b*c*(d-1) + a*(b-1)*(c-1)*d - (a-1)*(b-1)*(c-1)*(d-1)
  ans += temp
  ans %= mod
print(ans)
# Original solution
from operator import itemgetter
mod=998244353

def bit_add(i):
    while i<=n:
        tree[i]+=1
        i+=i&(-i)

def bit_sum(i):
    s=0
    while i>0:
        s+=tree[i]
        i-=i&(-i)
    return s

n=int(eval(input()))
xy=[[i+1]+list(map(int,input().split())) for i in range(n)]
data=[[] for i in range(n+1)]
for i in [1,2]:
    xy.sort(key=itemgetter(i))
    for j in range(n):
        data[xy[j][0]].append(j+1)
        
lsls=[1]*(n+1)
for i in range(1,n+1):
    lsls[i]=lsls[i-1]*2%mod
for i in range(n+1):
    lsls[i]-=1

data=sorted(data[1:])
lst=[]
for i1,i2 in data:
    lst.append(i2)

s=pow(2,n,mod)-1
tree=[0]*(n+1)
ans=0
for i in range(n):
    y=lst[i]
    num=bit_sum(y)
    bit_add(y)
    a,b,c,d=i-num,num,y-1-num,n-y-i+num
    t=(lsls[i]+lsls[n-i-1]+lsls[n-y]+lsls[y-1]-(lsls[a]+lsls[b]+lsls[c]+lsls[d]))%mod
    ans=(ans+s-t)%mod
print(ans)

# Optimized solution
from operator import itemgetter
import sys
input=sys.stdin.readline
mod=998244353

def bit_add(i):
    while i<=n:
        tree[i]+=1
        i+=i&(-i)
        
def bit_sum(i):
    s=0
    while i>0:
        s+=tree[i]
        i-=i&(-i)
    return s

n=int(eval(input()))
xy=[[i+1]+list(map(int,input().split())) for i in range(n)]
data=[[] for i in range(n+1)]
for i in [1,2]:
    xy.sort(key=itemgetter(i))
    for j in range(n):
        data[xy[j][0]].append(j+1)
    
data=sorted(data[1:])
lst=[]
for i1,i2 in data:
    lst.append(i2)

lsls=[1]*(n+1)
for i in range(1,n+1):
    lsls[i]=lsls[i-1]*2%mod
for i in range(n+1):
    lsls[i]-=1
    
s=pow(2,n,mod)-1
tree=[0]*(n+1)
ans=0
for i in range(n):
    y=lst[i]
    num=bit_sum(y)
    bit_add(y)
    a,b,c,d=i-num,num,y-1-num,n-y-i+num
    zzz=lsls[i]+lsls[n-i-1]+lsls[n-y]+lsls[y-1]
    yyy=lsls[a]+lsls[b]+lsls[c]+lsls[d]
    t=(zzz%mod-yyy%mod)%mod
    ans=(ans+s-t)%mod
print(ans)
# Original solution
class Bit:
    def __init__(self, n):
        self.size = n
        self.tree = [0] * (n + 1)
    def sum(self, i):
        s = 0
        while i > 0:
            s += self.tree[i]
            i -= i & -i
        return s
    def add(self, i, x):
        while i <= self.size:
            self.tree[i] += x
            i += i & -i
import sys
input = sys.stdin.readline
mod = 998244353

def sub(a, b):
    return (a % mod + mod - b % mod) % mod


def main():
    n, = list(map(int, input().split()))
    t = 1
    dd = [t]
    for _ in range(n):
        t=2*t%mod
        dd.append(t)

    xs, ys = [], []
    for _ in range(n):
        x, y = list(map(int, input().split()))
        xs.append(x)
        ys.append(y)

    ini = sorted(list(range(n)), key=lambda x:xs[x])
    for i, yi in enumerate(sorted(list(range(n)), key=lambda x:ys[x])):
        ys[yi] = i 
    nys = [ys[i] for i in ini]

    ss1 = Bit(n)
    r = 0
    for i, y in enumerate(nys):
        ss1.add(y+1, 1)
        d = ss1.sum(y)
        c = i - d
        b = (n-1) - y - c
        a = (n-1) - b - c - d
        r = (r + sub(dd[b+c] + dd[c+d] + dd[d+a] + dd[a+b],
                dd[a] + dd[b] + dd[c] + dd[d])) % mod

    print((sub((dd[n] * n) % mod, (r+n)%mod)))
main()


# Optimized solution
import sys
input = sys.stdin.readline
mod = 998244353

def sub(a, b):
    return (a % mod + mod - b % mod) % mod


def main():
    n, = list(map(int, input().split()))
    t = 1
    dd = [t]
    for _ in range(n):
        t=2*t%mod
        dd.append(t)

    xs, ys = [], []
    for _ in range(n):
        x, y = list(map(int, input().split()))
        xs.append(x)
        ys.append(y)

    ini = sorted(list(range(n)), key=lambda x:xs[x])
    for i, yi in enumerate(sorted(list(range(n)), key=lambda x:ys[x])):
        ys[yi] = i 
    nys = [ys[i] for i in ini]

    tree = [0] * (n + 1)
    r = 0
    for i, y in enumerate(nys):
        j = y+1
        while j <= n:
            tree[j] += 1
            j += j & -j

        d = 0
        j = y
        while j > 0:
            d += tree[j]
            j -= j & -j

        c = i - d
        b = (n-1) - y - c
        a = (n-1) - b - c - d
        r = (r + sub(dd[b+c] + dd[c+d] + dd[d+a] + dd[a+b],
                dd[a] + dd[b] + dd[c] + dd[d])) % mod

    print((sub((dd[n] * n) % mod, (r+n)%mod)))
main()
# Original solution
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(eval(input()))
mod=998244353
from collections import defaultdict
DX=defaultdict(int)
DY=defaultdict(int)
XY,X,Y=[],[],[]
for _ in range(n):
  x,y=list(map(int,input().split()))
  X.append(x)
  Y.append(y)
  XY.append((x,y))
X.sort()
Y.sort()
XY.sort(key=lambda x:x[0])
for i,x in enumerate(X):
  DX[x]=i+1
for i,y in enumerate(Y):
  DY[y]=i+1
XY2=[]
for x,y in XY:
  XY2.append((DX[x],DY[y]))
A=[[0]*4 for _ in range(n)]

n_max=2*10**5
nn=n_max.bit_length()+1
BIT=[0]*(2**nn)
BIT.insert(0,0)
def bitsum(BIT,i):
  s=0
  while i>0:
    s+=BIT[i]
    i-=i&(-i)
  return s
def bitadd(BIT,i,x):
  while i<=2**nn:
    BIT[i]+=x
    i+=i&(-i)
  return BIT

for i in range(n):
  x,y=XY2[i]
  ct=bitsum(BIT,y)
  A[i][2]+=ct
  A[i][1]+=i-ct
  bitadd(BIT,y,1)

BIT=[0]*(2**nn)
BIT.insert(0,0)
for i in range(n)[::-1]:
  x,y=XY2[i]
  ct=bitsum(BIT,y)
  A[i][3]+=ct
  A[i][0]+=(n-1-i)-ct
  bitadd(BIT,y,1)

def f(x):
  return pow(2,x,mod)

ans=0
for a,b,c,d in A:
  ans+=2*f(a+b+c+d)-f(a+b)-f(b+c)-f(c+d)-f(d+a)+f(a)+f(b)+f(c)+f(d)-1
  ans%=mod
print(ans)


# Optimized solution
import sys
input=lambda: sys.stdin.readline().rstrip()
n=int(eval(input()))
mod=998244353
from collections import defaultdict
DX=defaultdict(int)
DY=defaultdict(int)
XY,X,Y=[],[],[]
for _ in range(n):
  x,y=list(map(int,input().split()))
  X.append(x)
  Y.append(y)
  XY.append((x,y))
X.sort()
Y.sort()
XY.sort(key=lambda x:x[0])
for i,x in enumerate(X):
  DX[x]=i+1
for i,y in enumerate(Y):
  DY[y]=i+1
XY2=[]
for x,y in XY:
  XY2.append((DX[x],DY[y]))
A=[[0]*4 for _ in range(n)]

n_max=2*10**5
nn=n_max.bit_length()+1
BIT=[0]*(2**nn)
BIT.insert(0,0)
def bitsum(BIT,i):
  s=0
  while i>0:
    s+=BIT[i]
    i-=i&(-i)
  return s
def bitadd(BIT,i,x):
  while i<=2**nn:
    BIT[i]+=x
    i+=i&(-i)
  return BIT

for i in range(n):
  x,y=XY2[i]
  ct=bitsum(BIT,y)
  A[i][2]+=ct
  A[i][1]+=i-ct
  bitadd(BIT,y,1)

BIT=[0]*(2**nn)
BIT.insert(0,0)
for i in range(n)[::-1]:
  x,y=XY2[i]
  ct=bitsum(BIT,y)
  A[i][3]+=ct
  A[i][0]+=(n-1-i)-ct
  bitadd(BIT,y,1)

P=[0]*n
P[0]=1
for i in range(1,n):
  P[i]=(P[i-1]*2)%mod
def f(x):
  return P[x]

ans=0
for a,b,c,d in A:
  ans+=2*f(a+b+c+d)-f(a+b)-f(b+c)-f(c+d)-f(d+a)+f(a)+f(b)+f(c)+f(d)-1
  ans%=mod
print(ans)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True) # 降順
alice, bob = a[0::2], a[1::2]
print((sum(alice) - sum(bob)))

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = 0
for i,ai in enumerate(a):
    if i%2==0:
        ans += ai
    else:
        ans -= ai
print(ans)
# Original solution
eval(input());a,b,c=0,0,sorted(map(int,input().split()))
while c:
  a+=c.pop()
  b+=c.pop() if c else 0
print((a-b))

# Optimized solution
eval(input());a=sorted(map(int,input().split()))[::-1];print((sum(a[::2])-sum(a[1::2])))
# Original solution
Num = int(eval(input()))
Num_Array = list(map(int,input().split()))
Alice,Bob = 0,0

for i in range ( Num ):
    Check_Max = -1

    for x in range(len(Num_Array)):
        if Num_Array[x] > Check_Max :
            Check_Max = Num_Array[x]
            check = x

    Num_Array.pop(check)

    if i % 2 == 0 :
        Alice += Check_Max
    else:
        Bob += Check_Max

print((Alice - Bob))

# Optimized solution
Num = int(eval(input()))
Num_Array = sorted(list(map(int,input().split())),reverse=True)
Alice,Bob = 0,0

for i in range(Num):

    if i % 2 == 0 :
        Alice += Num_Array[i]
    else:
        Bob   += Num_Array[i]

print((Alice - Bob))
# Original solution
n = int(eval(input()))
cards = [i for i in map(int, input().split())]
alice = []
bob = []
for i in range(n):
    if i % 2 == 0:
        alice.append(max(cards))
        cards.pop(cards.index(max(cards)))
    else:
        bob.append(max(cards))
        cards.pop(cards.index(max(cards)))
print((sum(alice) - sum(bob)))

# Optimized solution
n = int(eval(input()))
cards = sorted(list(map(int, input().split())), reverse=True)
alice = []
bob = []
for i in range(0, n, 2):
    alice.append(cards[i])
    try:
        bob.append(cards[i+1])
    except:
        break
print((sum(alice) - sum(bob)))
# Original solution
num = int(eval(input()))
cards = sorted(list(map(int, input().split())), reverse = True)
alice = 0
bob = 0

for i in range(num):
  if i//2*2 == i:
    alice += cards[i]
  else:
    bob += cards[i]

print((alice - bob))

# Optimized solution
N = int(eval(input()))
A = list(map(int, input().split()))
A = sorted(A, reverse = True)
dif = sum(A[0::2]) - sum(A[1::2])
print(dif)
# Original solution
# ABC088B - Card Game for Two
n = int(eval(input()))
lst = sorted(list(map(int, input().rstrip().split())), reverse=True)
total = 0
for i in range(n):
    if i % 2 == 0:
        total += lst[i]
    else:
        total -= lst[i]
print(total)

# Optimized solution
# ABC088B - Card Game for Two
import sys
input = sys.stdin.readline

n = int(eval(input()))
lst = sorted(list(map(int, input().rstrip().split())), reverse=True)
total = 0
for i in range(n):
    if i % 2 == 0:
        total += lst[i]
    else:
        total -= lst[i]
print(total)
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
a_min = min(a)
alice = 0
bob = 0
while max(a) != 0:
    alice += max(a)
    for i in range(len(a)):
        if a[i] == max(a):
            a[i] = 0
            break
    bob += max(a)
    for i in range(len(a)):
        if a[i] == max(a):
            a[i] = 0
            break
if alice > bob:
    print((alice-bob))
else:
    print((bob-alice))

# Optimized solution
n = int(eval(input()))
a = sorted(list(map(int,input().split())), reverse=True)
print((sum(a[::2]) - sum(a[1::2])))
# Original solution
eval(input())
l=sorted(map(int,input().split()))[::-1]
print((sum(l[::2])-sum(l[1::2])))

# Optimized solution
n = int(eval(input()))
a=list(map(int,input().split()))
aa =sorted(a, reverse=True)
alice=sum(aa[0::2])
bob=sum(aa[1::2])
print((alice-bob))
# Original solution
N = int(eval(input()))
a_input = list(map(int, input().split()))
a = list(a_input)
alice = 0
bob = 0
for i in range(len(a)):
    max_i = 0
    max_a = 0
    for j in range(N):
        if a[j] > max_a:
            max_a = a[j]
            max_i = j
    if i%2 == 0:
        alice = alice + max_a
    else:
        bob = bob + max_a
    a[max_i] = 0
print((alice-bob))

# Optimized solution
# B - Card Game for Two
#25min
N = int(eval(input()))
a_input = list(map(int, input().split()))
a = list(a_input)
alice = 0
bob = 0
a.sort(reverse=True)
for i in range(N):
    if i%2 == 0:
        alice = alice + a[i]
    else:
        bob = bob + a[i]
print((alice-bob))
# Original solution
N = int(eval(input()))
l = list(map(int, input().split()))
l.sort(reverse=True)
print((sum([l[i] for i in range(0, len(l), 2)]) - sum([l[i] for i in range(1, len(l), 2)])))

# Optimized solution
N = int(eval(input()))
l = list(map(int, input().split()))
l.sort(reverse=True)
print((sum(l[0::2]) - sum(l[1::2])))
# Original solution
N = int(eval(input()))
a = sorted([int(x) for x in input().split()], reverse=True)

alice = sum(a[0::2])
bob = sum(a[1::2])
print((alice-bob))

# Optimized solution
N = int(eval(input()))
a = sorted([int(x) for x in input().split()], reverse=True)

print((sum(a[0::2])-sum(a[1::2])))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))

A = 0
B = 0
while(True):
 mx = max(a)
 if mx == -1: break
 mx_idx = a.index(mx)
 a[mx_idx] = -1
 A += mx
 
 mx = max(a)
 if mx == -1: break
 mx_idx = a.index(mx)
 a[mx_idx] = -1
 B += mx

print((A-B))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort()
a.reverse()

A = 0
B = 0
i = 0
while(True):
 A += a[i]
 i += 1
 if i==n: break
 B += a[i]
 i += 1
 if i==n: break

print((A-B))
# Original solution
N=int(eval(input()))
L=list(map(int,input().split()))
L.sort(reverse=True)
Bob, Alice=0,0
for i in range(0,N,2):
  Alice=Alice+L[i]
for i in range(1,N,2):
  Bob=Bob+L[i]
print((Alice-Bob))

# Optimized solution
N=int(eval(input()))
A=list(map(int,input().split()))
A.sort(reverse=True)
Alice=0
Bob=0
for i in range(N):
  if i%2==0:
    Alice += A[i]
  else:
    Bob += A[i]
print((Alice-Bob))
# Original solution
n=int(eval(input()))
a=[int(i)for i in input().split()]
a.sort()
alice=0
bob=0
for i in range(n):
    if i%2==0:
        alice+=a.pop(-1)
    else:
        bob+=a.pop(-1)
print((alice-bob))

# Optimized solution
n=int(eval(input()))
a=sorted([int(i)for i in input().split()])
res=0
for i in range(n):
    tmp=a.pop(-1)
    if i%2==0:
        res+=tmp
    else:
        res-=tmp
print(res)
# Original solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort(reverse =True)
a = 0
b = 0
for i in range(len(A)):
    if i%2==0:
        a += A[i]
    else:
        b += A[i]
print((a-b))

# Optimized solution
N = int(eval(input()))
A = list(map(int,input().split()))
A.sort(reverse =True)
a = sum(A[::2])
b = sum(A[1::2])
print((a-b))
# Original solution
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort(reverse=True)

a = 0
b = 0

for i, num in enumerate(l):
    if i % 2 == 0:
        a += num
    else:
        b += num

print((a-b))


# Optimized solution
n = int(eval(input()))
l = list(map(int, input().split()))
l.sort(reverse=True)

a = sum(l[::2])
b = sum(l[1::2])
print((a-b))
# Original solution
n = int(eval(input()))
nums = [int(x) for x in input().split()]
nums.sort(reverse=True)
print((sum(nums[::2]) - sum(nums[1::2])))

# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
a.sort(reverse=True)
alice = 0
bob = 0
turn = 0
for i in range(n):
    if turn % 2 == 0:
        alice += a[i]
        turn += 1
    else:
        bob += a[i]
        turn += 1
print((alice - bob))
# Original solution
n = int(eval(input()))
a = list(map(int, input().split()))
al, bo = [], []
for i in range(n):
	if i % 2 == 0:
		al.append(max(a))
		a.remove(max(a))
	elif i % 2 == 1:
		bo.append(max(a))
		a.remove(max(a))
print((sum(al)-sum(bo)))


# Optimized solution
n = int(eval(input()))
a = list(map(int, input().split()))
al, bo = [], []
for i in range(n):
	if i % 2 == 0:
		al.append(max(a))
		a.remove(max(a))
	else:
		bo.append(max(a))
		a.remove(max(a))
print((sum(al)-sum(bo)))
# Original solution
n=int(eval(input()))
a=sorted(list(map(int,input().split())),reverse=True)
ans=0
for i in range(n):
  if i%2==0:
    ans+=a[i]
  else:
    ans-=a[i]
print(ans)

# Optimized solution
N=eval(input())
a=list(map(int,input().split()))
alice=0
bob=0
a=sorted(a,reverse=True)
for i in range(int(N)):
    if i%2==0:
        alice+=a[i]
    else:
        bob+=a[i]
print((alice-bob))
# Original solution
n = int(eval(input()))
c = list(map(int,input().split()))
c.sort(reverse = True)
a = 0
b = 0
if n % 2 == 0:
    for i in range(n // 2 ):
        a += c[i * 2]
        b += c[i * 2 + 1]
else:
    for i in range(n // 2 ):
        a += c[i * 2]
        b += c[i * 2 + 1]
    a += c[n - 1]

print((a - b))

# Optimized solution
n = int(eval(input()))
data = list(map(int,input().split()))
data.sort(reverse = True)
print((sum(data[::2]) - sum(data[1::2])))
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))
Alice = []
Bob = []
while a != []:
    get = max(a)
    Alice.append(get)
    a.remove(get)
    if a != []:
        get = max(a)
        Bob.append(get)
        a.remove(get)
print((sum(Alice) - sum(Bob)))

# Optimized solution
N = int(eval(input()))
a = sorted(list(map(int, input().split())), reverse=True)
print((sum(a[0::2]) - sum(a[1::2])))
# Original solution
num = int(eval(input()))

alice = 0
bob = 0
cards = list(map(int,input().split()))
for i in range(1,num+1):
    
    if i % 2 == 1:
        alice += max(cards)
        cards.remove(max(cards))
    else:
        bob += max(cards)
        cards.remove(max(cards))

ans = alice - bob
print(ans)
        

# Optimized solution
n = int(eval(input()))
a = sorted(list(map(int, input().split())), reverse=True)
print((sum(a[::2]) - sum(a[1::2])))
# Original solution
import sys
from collections import deque

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()
a = LI()
a = sorted(a)

d = a

x = 0
y = 0
flag = 0
while len(d) != 0:
    if flag == 0:
        x += d.pop()
        flag = 1
    elif flag == 1:
        y += d.pop()
        flag = 0
print((x-y))

# Optimized solution
import sys
from itertools import combinations
import math


def I(): return int(sys.stdin.readline().rstrip())


def LI(): return list(map(int, sys.stdin.readline().rstrip().split()))


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


def LS(): return list(sys.stdin.readline().rstrip().split())


N = I()
A = LI()

A.sort()
A = A[::-1]
alice = 0
bob = 0
flag = 0
for i in A:

    if flag % 2 == 0:
        alice += i
    else:
        bob += i
    flag += 1
print((alice-bob))
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort(reverse=True)
a.append(0)
Ali,Bob=0,0
for i in range(0,n,2):
    Ali +=a[i]
    Bob +=a[i+1]
print((Ali-Bob))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
a.sort(reverse=True)
Ali,Bob=0,0
for i in range(n):
    if i%2==0:
        Ali +=a[i]
    else:
        Bob +=a[i]
print((Ali-Bob))
# Original solution
N = int(eval(input()))
card = list(map(int,input().split()))
A = 0
B = 0
card.sort(reverse = True)
while True:
    A += card[0]
    card.pop(0)
    if not card:
        break
    B += card[0]
    card.pop(0)
    if not card:
        break
print((A - B))

# Optimized solution
N = int(eval(input()))
Li = list(map(int,input().split()))
Li = sorted(Li)
a = 0
b = 0
while True:
    a += Li.pop()
    if not Li:
        break
        
    b += Li.pop()
    if not Li:
        break

print((a - b))
# Original solution
#B
n = int(eval(input()))
a = list(map(int, input().split()))
a_1 =  sorted(a, reverse=True)
alice = 0
bob = 0

for i in range(0, len(a)):
    if i % 2 != 0:
        bob += a_1[i]
    if i % 2 == 0:
        alice += a_1[i]
        
print((alice - bob))

# Optimized solution
#B
n = int(eval(input()))
a = list(map(int, input().split()))
a_1 =  sorted(a, reverse=True)

alice = sum(a_1[::2])
bob = sum(a_1[1::2])
        
print((alice - bob))
# Original solution
import sys
import subprocess
import re
import datetime
import os

N = int(eval(input()))
A = list(map(int,input().split()))

A.sort(reverse=True)

Alice = 0
Bob = 0

for i in range(N):
    if i%2 == 0:
        Alice = Alice + A[i]
    else:
        Bob = Bob + A[i]

ans = (Alice - Bob)

print(ans)

# Optimized solution

N = int(eval(input()))
A = list(map(int,input().split()))

A.sort(reverse=True)

Alice = 0
Bob = 0

for i in range(N):
    if i%2 == 0:
        Alice = Alice + A[i]
    else:
        Bob = Bob + A[i]

ans = (Alice - Bob)

print(ans)
# Original solution
n=int(eval(input()))
a=list(map(int,input().split()))
s=0
a.sort()
s=sum(a[:n:2])-sum(a[1:n:2])
if s>0:
    print(s)
else:
    print((-s))

# Optimized solution
n=int(eval(input()))
a=list(map(int,input().split()))
s=0
a.sort()
s=sum(a[:n:2])-sum(a[1:n:2])

print((abs(s)))
# Original solution
N = int(eval(input()))
a = list(map(int, input().split()))

a = sorted(a, reverse=True)

alice = sum(a[::2])
bob = sum(a[1::2])

print((alice - bob))

# Optimized solution
N = int(eval(input()))
a = list(map(int, input().split()))

a = sorted(a)[::-1]

alice = a[0::2]
bob = a[1::2]

print((sum(alice) - sum(bob)))
# Original solution
import sys
input = sys.stdin.readline

INF = float('inf')


def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))

    alice = 0
    bob = 0

    for _ in range(N):
        if len(A) != 0:
            alice += A.pop(A.index(max(A)))
        if len(A) != 0:
            bob += A.pop(A.index(max(A)))

    print((alice - bob))


if __name__ == '__main__':
    main()


# Optimized solution
import sys
input = sys.stdin.readline

INF = float('inf')


def main():
    N = int(eval(input()))
    A = list(map(int, input().split()))

    alice = 0
    bob = 0

    A = sorted(A, reverse=True)

    for _ in range(N):
        if len(A) != 0:
            alice += A.pop(0)
        if len(A) != 0:
            bob += A.pop(0)

    print((alice - bob))


if __name__ == '__main__':
    main()
# Original solution
n = int(eval(input()))
x = list(map(int, input().split()))
a=0
b=0
def max():
    m = 0
    j = 0
    for i in range(len(x)):
        if x[i]>m:
            m=x[i]
            j=i
    x.pop(j)
    return m
if n%2 == 0:
    i=0
    while i<n:
        a += max()
        b += max()
        i += 2
else:
    i=0
    while i<n-1:
        a += max()
        b += max()
        i += 2
    a+=max()
print((a-b))

# Optimized solution
n = int(eval(input()))
x = list(map(int, input().split()))
a=0
b=0
x.sort(reverse=True)
for i in range(int(n/2)):
    a += x[i*2]
    b += x[i*2+1]
if n%2==1:
    a+=x[n-1]
print((a-b))