You are given an array $a$ of $n$ integers and an integer $s$. It is guaranteed that $n$ is odd.

In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to $s$.

The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array $6, 5, 8$ is equal to $6$, since if we sort this array we will get $5, 6, 8$, and $6$ is located on the middle position.


-----Input-----

The first line contains two integers $n$ and $s$ ($1\le n\le 2\cdot 10^5-1$, $1\le s\le 10^9$) — the length of the array and the required value of median.

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1\le a_i \le 10^9$) — the elements of the array $a$.

It is guaranteed that $n$ is odd.


-----Output-----

In a single line output the minimum number of operations to make the median being equal to $s$.


-----Examples-----
Input
3 8
6 5 8

Output
2
Input
7 20
21 15 12 11 20 19 12

Output
6


-----Note-----

In the first sample, $6$ can be increased twice. The array will transform to $8, 5, 8$, which becomes $5, 8, 8$ after sorting, hence the median is equal to $8$.

In the second sample, $19$ can be increased once and $15$ can be increased five times. The array will become equal to $21, 20, 12, 11, 20, 20, 12$. If we sort this array we get $11, 12, 12, 20, 20, 20, 21$, this way the median is $20$.

Difficulty: competition

Starter code:

Solutions:

import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline

n,s=list(map(int,input().split()))

a=list(map(int,input().split()))
a.sort()
med=a[n//2]

ans=0
if med>s:
    for i in range(n//2+1):
        if a[i]>s:
            ans+=a[i]-s
elif med<s:
    for i in range(n//2,n):
        if s>a[i]:
            ans+=s-a[i]
print(ans)



#      
import collections, atexit, math, sys, bisect 

sys.setrecursionlimit(1000000)
def getIntList():
    return list(map(int, input().split()))    

try :
    #raise ModuleNotFoundError
    import numpy
    def dprint(*args, **kwargs):
        print(*args, **kwargs, file=sys.stderr)
    dprint('debug mode')
except ModuleNotFoundError:
    def dprint(*args, **kwargs):
        pass



inId = 0
outId = 0
if inId>0:
    dprint('use input', inId)
    sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
    dprint('use output', outId)
    sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
    atexit.register(lambda :sys.stdout.close())     #idle 中不会执行 atexit
    
N, S = getIntList()

za = getIntList()

za.sort()

mid = N//2
res = 0
for i in range(N):
    if i<mid:
        if za[i]>S:
            res += za[i]-S
    elif i>mid:
        if za[i]<S:
            res += S-za[i]
    else:
        res += abs(S-za[i])
print(res)








n, s = list(map(int, input().split()))

a = list(map(int, input().split()))

a.sort()

m = n // 2

ans = 0

if a[m] > s:
    ans = sum([max(x - s, 0) for x in a[:m+1]])
if a[m] < s:
    ans = sum([max(s - x, 0) for x in a[m:]])

print(ans)


def __starting_point():
    n, s = list(map(int, input().split()))
    a = list(map(int, input().split()))
    a.sort()
    i = n // 2
    median = a[i]
    result = 0
    if median > s:
        for j in range(i + 1):
            result += max(0, a[j] - s)
    elif median < s:
        for j in range(i, n):
            result += max(0, s - a[j])
    print(result)

__starting_point()

n, s = list(map(int, input().split(' ')))
aa = sorted(list(map(int, input().split(' '))))

res = 0
m = n // 2
for i in range(m):
    if aa[i] > s:
        res += aa[i] - s
res += abs(aa[m] - s)
for i in range(m+1, n):
    if aa[i] < s:
        res += s - aa[i]

print(res)



n, s = list(map(int, input().split()))

a = sorted(list(map(int, input().split())))

ans = abs(a[n // 2] - s)

for i in range(n // 2):
    if a[i] > s:
        ans += a[i] - s

for i in range(n // 2 + 1, n):
    if a[i] < s:
        ans += s - a[i]

print(ans)


n, s  = list(map(int, input().split()))
a  = list(map(int, input().split()))

mid  = n//2

a.sort()
res = 0
median = a[mid]

j = mid

if median<s:
    while j<n and a[j]<s:
        res += s - a[j]
        j += 1
elif median>s:
    while j>=0 and a[j]>s:
        res += a[j] - s
        j -= 1





print(res)

def __starting_point():
    n, s = [int(__) for __ in input().strip().split()]
    arr = [int(__) for __ in input().strip().split()]
    arr.sort()
    mid = n // 2
    ans = 0
    if s == arr[mid]:
        print(ans)
    elif s > arr[mid]:
        while mid < n and arr[mid] < s:
            ans += s - arr[mid]
            mid += 1
        print(ans)
    else:
        while mid >= 0 and arr[mid] > s:
            ans += arr[mid] - s
            mid -= 1
        print(ans)
__starting_point()

n,s = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a = sorted(a)
m = n//2
ans = 0
if a[m]>s:
    while(m>=0 and a[m]>s):
        ans+= a[m]-s
        m = m-1
else:
    while(m<n and a[m]<s):
        ans+= s-a[m]
        m+=1
print(ans)

n,s=list(map(int,input().split()))

a=list(map(int,input().split()))

a.sort()
if(s>a[n//2]):
    fir=n
    for i in range(n//2,n):
        if(a[i]>=s):
            fir=i
            break
    sum1=sum(a[n//2:fir])
    fin=s*(fir-n//2)
    print(fin-sum1)
elif(s<a[n//2]):
    fir=n//2
    for i in range(n//2):
        if(a[i]>=s):
            fir=i
            break
    sum1=sum(a[fir:n//2+1])
    fin=s*(n//2-fir+1)
    print(sum1-fin)
else:
    print(0)



from sys import stdin, stdout 
from bisect import bisect_left, bisect_right
from collections import defaultdict
import math
from fractions import Fraction as frac
from random import random
cin = stdin.readline
def cout(x):
	stdout.write(str(x)+'\n')
def var(type = int):
    return type(stdin.readline())
def readline(type = int):
    return list(map(type,stdin.readline().split()))
def readlist(type = int):
    return list(map(type,stdin.readline().split()))
def sorted_indexes(arr):
    return sorted(list(range(len(arr))),key=arr.__getitem__)
def printr(arr):
    [stdout.write(str(x)+' ')   for x in arr]
    cout('')
def find_lt(a, x):#'Find rightmost value less than x'
    i = bisect_left(a, x)
    if i:
        return a[i-1]
    raise ValueError
def find_gt(a, x):#'Find leftmost value greater than x'
    i = bisect_right(a, x)
    if i != len(a):
        return a[i]
    raise ValueError
def dist(x,y):
    return math.sqrt(x*x + y*y)
def binary_search(arr, x):
    i = bisect_left(arr, x)
    if i == len(arr) or arr[i] != x:
        return -1
    return i

# ---------------------Template ends-------------sdpt,sdpt131[Sudipta Banik]---------------------

# mp = [0]*201
# ops = [0]*201
# def go(arr,i,j ,dp):
#     if i==j and ops[i] is None:
#         return [mp[i],mp[i]]
#     if i>j:
#         return [0,0]
#     if dp[i][j]:
#         return dp[i][j]
#     mx = -1000000000
#     mn = 1000000000
#     for k in range(i+1,j,2):
#         if ops[k]:
#             left = go(arr,i,k-1,dp)
#             right = go(arr,k+1,j,dp)
#             mx = max(mx,left[0] + right[0])
#             mn = min(mn,left[1] + right[1])
#         else:
#             left = go(arr,i,k-1,dp)
#             right = go(arr,k+1,j,dp)
#             mx = max(mx,left[0] - right[1])
#             mn = min(mn,left[1] - right[0])
#     dp[i][j] = [mx,mn]
#     return [mx,mn]

    

n , s = readline(int)

arr = readlist(int)

arr.sort()

count = 0

j = n//2

if arr[j] < s:
    for i in range(j,n):
        if arr[i] < s:
            count += (s-arr[i])
        else:
            break

    print(count)

else:
    for i in range(j,-1,-1):
        if arr[i] > s:
            count += arr[i]-s
        else:
            break
    print(count)




    









# # def tobit(s):
# #     x = []
# #     for _ in range(3):
# #         x.append(s%2)
# #         s//=2
# #     return x

# def power(x, y, p) :
#     res = 1
#     x = x % p 
#     while (y > 0) :
#         if ((y & 1) == 1) :
#             res = (res * x) % p
#         y = y >> 1
#         x = (x * x) % p
#     return res




# def setCount(x):
#     return bin(x).count('1')

# for _ in range(var()):
    
#     a,b,n = readline()
#     p = 1000000007  
#     diff = abs(a-b)
#     mod  = power(a,n,p)
#     mod += power(b,n,p)
#     print(math.gcd(mod,diff)%p)
    
    
#     # n = var()
#     # # print(bin(n))
#     # if setCount(n)==2:
#     #     print(0)
#     # elif setCount(n)==1:
#     #     if n == 1:
#     #         print(2)
#     #     else:
#     #         print(1)
#     # elif setCount(n)==0:
#     #     print(3)
#     # else:
#     #     lo = n-1
#     #     hi = n+1
#     #     while(lo >= 3):
#     #         if(setCount(lo)==2):
#     #             break
#     #         lo -=1
#     #     while(hi <= 1000):
#     #         if(setCount(hi)==2):
#     #             break
#     #         hi +=1
        
#     #     if (hi - n) < (n - lo):
#     #         print(hi-n)
#     #     else:
#     #         print(n-lo)
        
    





# #     s = cin()
# #     t = cin()
# #     flg = False
# #     for el in range(8):
# #         bits = tobit(el)
# #         ch = []
# #         # printr(bits)
# #         for i in range(3):
# #             if bits[i]==0:
# #                 ch.append(s[i])
# #             else:
# #                 ch.append(t[i])
# #         ch.sort()
# #         if (''.join(ch) == 'bbo'):
# #             flg = True
# #             break
# #     if flg:
# #         print("yes")
# #     else:
# #         print("no")


n,s=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
x=n//2
c=0
if a[x]==s:
    print(c)
    return
if a[x]<s:
    for i in range(x,n):
        if a[i]<s:
            c+=s-a[i]
else:
    for i in range(0,x+1):
        if a[i]>s:
            c+=a[i]-s
print(c)            


a,b=map(int,input().split())
t=[int(i) for i in input().split()]
t=sorted(t)
d1=t[int((a-1)/2):a:1]
d2=t[0:int((a+1)/2):1]
s1=0
for i in d1:
    if(i<b):
        s1+=(b-i)
s2=0
for i in d2:
    if(i>b):
        s2+=(i-b)
print(max(s1,s2))

n, s = list(map(int, input().split()))
a = list(map(int, input().split()))

a.sort()
ans = abs(a[n // 2] - s)
a[n // 2] = s
for i in range(n // 2, n - 1):
    if a[i] > a[i + 1]:
        ans += a[i] - a[i + 1]
        a[i + 1] = a[i]
for i in range(n // 2, 0, -1):
    if a[i] < a[i - 1]:
        ans += a[i - 1] - a[i]
        a[i - 1] = a[i]
print(ans)


#!/usr/bin/env python3
n, s = list(map(int, input().split()))
xs = [int(x) for x in input().split()]
xs.sort()
c = 0
if xs[n//2] < s:
  for i in range(n//2, n): c += max(0, s - xs[i])
elif xs[n//2] > s:
  for i in range(0, n//2+1): c += max(0, xs[i] - s)

print(c)


c = 0
n, s = list(map(int, input().split()))
arr = sorted([int(i) for i in input().split()])
if arr[n//2] < s:
   for i in range(n//2, n): c += (s - arr[i])*(arr[i] < s)
else:
   for i in range(n//2+1): c -= (s - arr[i])*(arr[i] > s)
print(c)


n,s=map(int,input().split())
z=list(map(int,input().split()))
z.sort()
y=n//2
c=0
if z[y]==s:
    print(c)
    return
if z[y]<s:
    for i in range(y,n):
        if z[i]<s:
            c+=s-z[i]
else:
    for i in range(0,y+1):
        if z[i]>s:
            c+=z[i]-s
print(c) 

n, s = (int(x) for x in input().split())

arr = [int(x) for x in input().split()]

less = sorted([x for x in arr if x < s], reverse=True)
more = sorted([x for x in arr if x > s])
if len(less) == len(more):
    print(0)
    quit()

eq_nr = len(arr) - len(less) - len(more)

target = []
count = eq_nr
idx = 0

operations = 0
if len(less) > len(more):
    target = less
    count += len(more)
else:
    target = more
    count += len(less)

while count < (n + 1) // 2:
    operations += abs(target[idx] - s)
    count += 1
    idx += 1

print(operations)


import sys
f=sys.stdin
out=sys.stdout

def findOperations(s,ind,mid):
	return prefix[mid]-prefix[ind]+abs(s-arr[ind])


n,s=map(int,input().split())
arr=list(map(int,input().split()))

cnt=0
arr.sort()
mid=n//2


for i in range(mid):
	if (arr[i]>s):
		cnt+=(abs(s-arr[i]))
for i in range(mid+1,n):
	if (arr[i]<s):
		cnt+=(abs(s-arr[i]))
cnt+=(abs(s-arr[mid]))
print(cnt)

n,s=map(int,input().split())
a=sorted(list(map(int,input().split())))
ans=0
if s>=a[n//2]:
    for i in range(n//2,n):
        if a[i]>=s:
            break
        ans+=(s-a[i])
else:
    for i in range(n//2,-1,-1):
        if a[i]<=s:
            break
        ans+=(a[i]-s)
print(ans)

n,s=[int(i) for i in input().split()]
arr=[int(i) for i in input().split()]
arr.sort()
if (n==1):
    print (abs(arr[0]-s))
else:
    if (arr[n//2]==s):
        print (0)
    else:
        count=abs(s-arr[n//2])
        arr[n//2]=s
        for i in range(n//2 + 1, n):
            if (arr[i]<arr[i-1]):
                count+=arr[i-1]-arr[i]
                arr[i]=arr[i-1]
        for i in range(n//2 - 1, -1,-1):
            if (arr[i]>arr[i+1]):
                count+=arr[i]-arr[i+1]
                arr[i]=arr[i+1]
        print (count)

nip,s=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort()
x=nip//2
c=0
if a[x]==s:
    print(c)
    return
if a[x]<s:
    for i in range(x,nip):
        if a[i]<s:
            c+=s-a[i]
else:
    for i in range(0,x+1):
        if a[i]>s:
            c+=a[i]-s
print(c)            


n,s=map(int,input().split())
a=list(map(int,input().split()))
a=sorted(a)
ans=0
for i in range(len(a)//2):
    if a[i]>s:
        ans+=(a[i]-s)
ans+=abs(a[len(a)//2]-s)
for i in range(len(a)//2+1,len(a)):
    if s>a[i]:
        ans+=(s-a[i])
print(ans)

n,s=map(int, input().split())
ar=list(map(int, input().split()))
ar.sort()
z=(n//2)
q=0
if ar[z]<s:
    for i in range(z,n):
        if ar[i]<s:
            q+=s-ar[i]
        else:
            break
else:
    for i in range(z,-1,-1):
        if ar[i]>s:
            q+=ar[i]-s
        else:
            break
print(q)

n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
a.sort()
s = abs(m - a[n//2])
for i in range(n//2):
    if a[i] > m:
        s += a[i] - m
for i in range(n//2 + 1, n):
    if a[i] < m:
        s += m - a[i]
print(s)