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: EASY
Tags: Greedy algorithms
Skill types: Greedy algorithms

Starter code:

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


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


import math
from decimal import Decimal
import heapq

def na():
	n = int(input())
	b = [int(x) for x in input().split()]
	return (n, b)

def nab():
	n = int(input())
	b = [int(x) for x in input().split()]
	c = [int(x) for x in input().split()]
	return (n, b, c)

def dv():
	(n, m) = map(int, input().split())
	return (n, m)

def dva():
	(n, m) = map(int, input().split())
	a = [int(x) for x in input().split()]
	b = [int(x) for x in input().split()]
	return (n, m, b)

def eratosthenes(n):
	sieve = list(range(n + 1))
	for i in sieve:
		if i > 1:
			for j in range(i + i, len(sieve), i):
				sieve[j] = 0
	return sorted(set(sieve))

def nm():
	n = int(input())
	b = [int(x) for x in input().split()]
	m = int(input())
	c = [int(x) for x in input().split()]
	return (n, b, m, c)

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


(array_length, desired_median) = map(int, input().split())
array = list(map(int, input().split()))
array.sort()
solution = 0
median_pos = array_length // 2
for pos in range(median_pos - 1, -1, -1):
	if array[pos] > desired_median:
		solution += array[pos] - desired_median
	else:
		break
solution += abs(desired_median - array[median_pos])
for pos in range(median_pos + 1, array_length):
	if array[pos] < desired_median:
		solution += desired_median - array[pos]
	else:
		break
print(solution)


a = [int(x) for x in input().split(' ')]
n = a[0]
s = a[1]
a = [int(x) for x in input().split(' ')]
mid = n // 2
a = sorted(a)
if a[mid] == s:
	print(0)
if a[mid] < s:
	Sum = 0
	for i in range(mid, n):
		Sum = Sum + max(s - a[i], 0)
	print(Sum)
if a[mid] > s:
	Sum = 0
	for i in range(0, mid + 1):
		Sum = Sum + max(a[i] - s, 0)
	print(Sum)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
x = n // 2
c = 0
if a[x] == s:
	print(c)
	exit(0)
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)


(n, s) = map(int, input().split())
l = sorted([int(x) for x in input().split()])
m = n // 2
res = 0
if l[m] < s:
	for e in l[m:]:
		if e >= s:
			break
		res += s - e
elif l[m] > s:
	for e in l[m::-1]:
		if e <= s:
			break
		res += e - s
print(res)


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


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


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
from collections import deque

def bfs(graph, alpha=0):
	n = len(graph)
	order = []
	q = deque([alpha])
	used = [False] * n
	used[alpha] = True
	(dist, parents) = ([0] * n, [-1] * n)
	while q:
		v = q.popleft()
		order += [v]
		for u in graph[v]:
			if not used[u]:
				used[u] = True
				q.append(u)
				dist[u] = dist[v] + 1
				parents[u] = v
	return (used, dist, parents, order)

def shortest_path(graph, alpha, omega):
	(used, dist, parents) = bfs(graph, alpha)
	if not used[omega]:
		return []
	path = [omega]
	v = omega
	while parents[v] != -1:
		path += [parents[v]]
		v = parents[v]
	return path[::-1]
for _ in range(int(input()) if not True else 1):
	(n, s) = map(int, input().split())
	a = sorted(list(map(int, input().split())))
	ans = 0
	for i in range(n // 2):
		if a[i] <= s:
			continue
		ans += a[i] - s
	for i in range(n // 2):
		ind = n - 1 - i
		if a[ind] >= s:
			continue
		ans += s - a[ind]
	ans += abs(s - a[n // 2])
	print(ans)


def solve():
	(n, s) = list(map(int, input().split()))
	arr = list(map(int, input().split()))
	arr.sort()
	middle = n // 2
	if arr[middle] == s:
		print(0)
	elif arr[middle] > s:
		decrease = 0
		for i in range(middle, n):
			if arr[i] > s:
				decrease += arr[i] - s
		decrease_t = 0
		for i in range(0, middle + 1):
			if arr[i] > s:
				decrease_t += arr[i] - s
		print(min(decrease, decrease_t))
	else:
		increase = 0
		for i in range(middle, n):
			if arr[i] < s:
				increase += s - arr[i]
		increase_t = 0
		for i in range(0, middle + 1):
			if arr[i] < s:
				increase_t += s - arr[i]
		print(min(increase, increase_t))
solve()


(n, s) = map(int, input().split(' '))
elements = list(map(int, input().split(' ')))
elements.sort()
index = (n + 1) // 2 - 1
median = elements[index]
moves = 0

def greater(elements, s, index):
	answer = 0
	while index != -1:
		toAdd = elements[index] - s
		if toAdd <= 0:
			return answer
		answer += toAdd
		index -= 1
	return answer

def smaller(elements, s, index, n):
	answer = 0
	while index != n:
		toAdd = s - elements[index]
		if toAdd <= 0:
			return answer
		answer += toAdd
		index += 1
	return answer
if median == s:
	print(0)
	exit()
if median > s:
	print(greater(elements, s, index))
	exit()
print(smaller(elements, s, index, n))


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


(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))
elif 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)


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


a = input().split()
n = int(a[0])
s = int(a[1])
A = input().split()
for i in range(n):
	A[i] = int(A[i])
A.sort()
(men, rav, bol, result) = (0, 0, 0, 0)
for i in range(n):
	if int(A[i]) < s:
		men += 1
	elif int(A[i]) == s:
		rav += 1
	else:
		bol += 1
if s < int(A[0]):
	for i in range((n + 1) // 2):
		result += int(A[i]) - s
elif s > int(A[-1]):
	for i in range((n + 1) // 2 - 1, n):
		result += s - int(A[i])
elif men >= (n + 1) // 2:
	for i in range((n + 1) // 2, men + 1):
		result += s - int(A[i - 1])
elif bol >= (n + 1) // 2:
	for i in range(men + rav + 1, (n + 1) // 2 + 1):
		result += int(A[i - 1]) - s
print(result)


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


from collections import deque as de
import math
from sys import stdin, stdout
import re
from collections import Counter as cnt
from functools import reduce
from itertools import groupby as gb
from bisect import bisect_left as bl, bisect_right as br

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

class My_stack:

	def __init__(self):
		self.data = []

	def my_push(self, x):
		return self.data.append(x)

	def my_pop(self):
		return self.data.pop()

	def my_peak(self):
		return self.data[-1]

	def my_contains(self, x):
		return self.data.count(x)

	def my_show_all(self):
		return self.data

	def isEmpty(self):
		return len(self.data) == 0
arrStack = My_stack()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binarytodecimal(n):
	return int(n, 2)

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def get_prime_factors(number):
	prime_factors = []
	while number % 2 == 0:
		prime_factors.append(2)
		number = number / 2
	for i in range(3, int(math.sqrt(number)) + 1, 2):
		while number % i == 0:
			prime_factors.append(int(i))
			number = number / i
	if number > 2:
		prime_factors.append(int(number))
	return prime_factors

def get_frequency(list):
	dic = {}
	for ele in list:
		if ele in dic:
			dic[ele] += 1
		else:
			dic[ele] = 1
	return dic

def Log2(x):
	return math.log10(x) / math.log10(2)

def getProduct(n):
	product = 1
	while n != 0:
		product = product * (n % 10)
		n = n // 10
	return product

def lcm(x, y):
	lcm = x * y // math.gcd(x, y)
	return lcm

def isPowerOfTwo(n):
	return math.ceil(Log2(n)) == math.floor(Log2(n))

def checkisap(list):
	d = list[1] - list[0]
	for i in range(2, len(list)):
		temp = list[i] - list[i - 1]
		if temp != d:
			return False
	return True

def ceildiv(x, y):
	return (x + y - 1) // y

def di():
	return map(int, input().split())

def ii():
	return int(input())

def li():
	return list(map(int, input().split()))

def si():
	return list(map(int, input()))

def indict():
	dic = {}
	for (index, value) in enumerate(input().split()):
		dic[int(value)] = int(index) + 1
	return dic

def frqdict():
	dic = {}
	for (index, value) in enumerate(input().split()):
		if int(value) not in dic:
			dic[int(value)] = 1
		else:
			dic[int(value)] += 1
	return dic
(n, s) = di()
a = sorted(li())
md = a[n // 2]
if md == s:
	print(0)
else:
	if md > s:
		ans = md - s
		a[n // 2] = s
		for i in range(n // 2 - 1, -1, -1):
			if a[i] > s:
				ans += a[i] - s
			else:
				break
	else:
		ans = s - md
		a[n // 2] = s
		for i in range(n // 2 + 1, n):
			if a[i] < s:
				ans += s - a[i]
			else:
				break
	print(ans)


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


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) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
median = n // 2
if s > arr[median]:
	ans = abs(s - arr[median])
	i = median + 1
	while i < n:
		if arr[i] < s:
			ans += s - arr[i]
			i += 1
		else:
			break
	print(ans)
else:
	ans = abs(s - arr[median])
	i = median - 1
	while i >= 0:
		if arr[i] > s:
			ans += arr[i] - s
			i -= 1
		else:
			break
	print(ans)


(n, s) = map(int, input().split())
l = map(int, input().split())
(less, higher, eq) = ([], [], 0)
for x in l:
	if x < s:
		less.append(s - x)
	elif x > s:
		higher.append(x - s)
	else:
		eq += 1
cost = 0
if len(less) > n // 2:
	less.sort()
	cost += sum(less[:len(less) - n // 2])
if len(higher) > n // 2:
	higher.sort()
	cost += sum(higher[:len(higher) - n // 2])
print(cost)


(n, s) = 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)


def find(fin, s):
	if s < fin[0]:
		return -1
	if s > fin[-1]:
		return len(fin) - 1
	i = 0
	while s > fin[i]:
		i += 1
	return i - 1
(n, s) = input().split()
n = int(n)
s = int(s)
array = input().split()
fin = []
for i in array:
	fin.append(int(i))
fin.sort()
if s not in fin:
	mids = n // 2
	ind = find(fin, s)
	if ind < mids:
		ind = ind + 1
	if ind < mids:
		sums = 0
		while ind <= mids:
			sums += abs(fin[ind] - s)
			ind += 1
	else:
		sums = 0
		while ind >= mids:
			sums += abs(fin[ind] - s)
			ind -= 1
else:
	ind = fin.index(s) + 1
	remele = ind - (n + 1) // 2
	if remele > 0:
		sums = 0
		i = 1
		while i <= remele:
			sums += s - fin[ind - i - 1]
			i += 1
	else:
		remele = -1 * remele
		sums = 0
		i = 1
		while i <= remele:
			sums += fin[ind + i - 1] - s
			i += 1
print(sums)


def exe(arr, n, m):
	mid = int(n / 2)
	s = 0
	if m > arr[mid]:
		while mid < n and arr[mid] < m:
			s = s + m - arr[mid]
			mid = mid + 1
		return s
	elif m < arr[mid]:
		while mid >= 0 and arr[mid] > m:
			s = s + arr[mid] - m
			mid = mid - 1
		return s
	else:
		return 0

def main():
	s = input().split(' ')
	n = int(s[0])
	m = int(s[1])
	arr = list(map(int, input().split(' ')))
	arr.sort()
	res = exe(arr, n, m)
	print(res)
main()


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


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


(a, b) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
low = []
eq = []
high = []
flag = True
num = int((a - 1) / 2)
for i in l:
	if i < b:
		low.append(i)
	elif i > b:
		high.append(i)
	elif flag:
		eq.append(i)
		flag = False
	else:
		high.append(i)
if len(low) == len(high):
	print(0)
elif len(low) > len(high):
	k = b
	t = len(low) - num
	r = 0
	n = -1
	for _ in range(t):
		r += k - low[n]
		n -= 1
	print(r)
else:
	k = b
	t = len(high) - num
	r = 0
	n = 0
	for _ in range(t):
		r += high[n] - k
		n += 1
	print(r)


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


(n, m) = map(int, input().split())
arr = [int(x) for x in input().split()]
arr.sort()
moves = 0
for i in range(len(arr)):
	if i < len(arr) // 2:
		moves += max(0, arr[i] - m)
	elif i == len(arr) // 2:
		moves += max(0, arr[i] - m)
		moves += max(0, m - arr[i])
	else:
		moves += max(0, m - arr[i])
print(moves)


(n, s) = [int(i) for i in input().split()]
middle_number = int((n - 1) / 2)
mylist = [int(i) for i in input().split()]
mylist.sort()
if mylist[middle_number] == s:
	print(0)
elif mylist[middle_number] < s:
	counter = 0
	for i in range(middle_number, len(mylist)):
		if mylist[i] < s:
			counter += s - mylist[i]
		else:
			break
	print(counter)
else:
	counter = 0
	for i in range(middle_number, -1, -1):
		if mylist[i] > s:
			counter += mylist[i] - s
		else:
			break
	print(counter)


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


def mp():
	return map(int, input().split())
(n, m) = mp()
a = list(mp())
a.sort()
if a[n // 2] < m:
	s = 0
	i = n // 2
	while i < n and a[i] < m:
		s += m - a[i]
		i += 1
	print(s)
else:
	s = 0
	i = 0
	while i <= n // 2:
		s += max(0, a[i] - m)
		i += 1
	print(s)


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


from collections import deque, Counter, OrderedDict
from heapq import nsmallest, nlargest
from math import ceil, floor, log, log2, sqrt, gcd, factorial

def binNumber(n, size=1):
	return bin(n)[2:].zfill(size)

def iar():
	return list(map(int, input().split()))

def ini():
	return int(input())

def isp():
	return map(int, input().split())

def sti():
	return str(input())
(n, s) = isp()
a = iar()
a.sort()
d = 0
for i in range(n // 2):
	if a[i] > s:
		d += a[i] - s
	elif a[n - 1 - i] < s:
		d += s - a[n - 1 - i]
d += abs(a[n // 2] - s)
print(d)


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


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


(n, s) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
mid = l[n // 2]
if n == 1:
	print(abs(l[0] - s))
elif s == mid:
	print(0)
elif s > mid:
	ans = 0
	i = n // 2
	while i < n and l[i] < s:
		ans += s - l[i]
		i += 1
	print(ans)
else:
	ans = 0
	i = n // 2
	while i >= 0 and l[i] > s:
		ans += l[i] - s
		i -= 1
	print(ans)


read = lambda : map(int, input().split())
(n, s) = read()
a = list(read())
a.sort()
m = n // 2
ans = abs(a[m] - s)
ans += sum((max(0, x - s) for x in a[:m]))
ans += sum((max(0, s - x) for x in a[m + 1:]))
print(ans)


(n, s) = map(int, input().split())
arr = list(map(int, input().split()))
count = 0
arr = sorted(arr)
index = int(n / 2)
count = 0
while arr[index] < s:
	count += s - arr[index]
	arr[index] = s
	index += 1
	if index == n:
		break
index = int(n / 2)
while arr[index] > s:
	count += arr[index] - s
	arr[index] = s
	index -= 1
	if index == -1:
		break
print(count)


(count, target_median) = input().split(' ')
count = int(count)
mid = count // 2
median = int(target_median)
line = input()
numbers = [int(x) for x in line.split(' ')]
numbers.sort()
ops = 0
if numbers[mid] == median:
	pass
elif numbers[mid] > median:
	i = mid
	while i >= 0 and numbers[i] > median:
		ops += numbers[i] - median
		i -= 1
else:
	i = mid
	while i < count and numbers[i] < median:
		ops += median - numbers[i]
		i += 1
print(ops)


read = lambda : map(int, input().split())
(n, s) = read()
a = sorted(read())
m = n // 2
print(abs(a[m] - s) + sum((max(0, i - s) for i in a[:m])) + sum((max(0, s - i) for i in a[m + 1:])))


(n, s) = map(int, input().split())
l = sorted(list(map(int, input().split())))
import bisect
if s == l[n // 2]:
	print(0)
elif s > l[n // 2]:
	a = 0
	ind = bisect.bisect_left(l, s)
	for i in range(n // 2, ind):
		a += s - l[i]
	print(a)
else:
	a = 0
	ind = bisect.bisect(l, s)
	for i in range(ind, n // 2 + 1):
		a += l[i] - s
	print(a)


from sys import stdin, stdout
(a, b) = map(int, stdin.readline().split())
z = sorted(map(int, stdin.readline().split()))
k = a // 2
s = 0
if z[k] < b:
	while k < a and z[k] < b:
		s += b - z[k]
		k += 1
elif z[k] > b:
	while k > -1 and z[k] > b:
		s += z[k] - b
		k -= 1
stdout.write(str(s))


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


def main():
	(n, s) = map(int, input().split())
	arr = list(map(int, input().split()))
	arr.sort()
	med = n // 2
	ops = 0
	idx = med
	if arr[med] < s:
		while idx < n and arr[idx] < s:
			ops += s - arr[idx]
			idx += 1
	elif arr[med] > s:
		while idx >= 0 and arr[idx] > s:
			ops += arr[idx] - s
			idx -= 1
	print(ops)
main()


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
(l, h) = (0, n - 1)
indx = n
while l <= h:
	m = (l + h) // 2
	if s <= a[m]:
		indx = m
		h = m - 1
	else:
		l = m + 1
ans = 0
for i in range(indx, n // 2 + 1):
	ans += a[i] - s
for i in range(n // 2, indx):
	ans += s - a[i]
print(ans)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
(n, k) = f()
l = sorted(il())
sm = 0
for i in range(n // 2):
	sm = sm + abs(k - l[i]) if l[i] > k else sm + 0
for i in range(n // 2 + 1, n):
	sm = sm + abs(k - l[i]) if l[i] < k else sm + 0
print(sm + abs(l[n // 2] - k))


(n, m) = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
a = sorted(a)
res = 0
i = int(n / 2)
if a[int(n / 2)] > m:
	while a[i] > m:
		res += a[i] - m
		i -= 1
		if i < 0:
			break
else:
	while a[i] < m:
		res += m - a[i]
		i += 1
		if i == n:
			break
print(res)


(n, s) = input().split()
n = int(n)
s = int(s)
l = list(map(int, input().split()))
import math
l.sort()
ind = int((len(l) + 1) / 2) - 1
if l[ind] == s:
	print(0)
else:
	c = 0
	if l[ind] == s:
		print(0)
	elif s > l[ind]:
		for i in range(ind, len(l)):
			if s > l[i]:
				c = c + s - l[i]
		print(c)
	else:
		for i in range(ind + 1):
			if l[i] > s:
				c = c + l[i] - s
		print(c)


(n, s) = map(int, input().split())
arr = list(map(int, input().split()))
arr = sorted(arr)
result = 0
med = (n - 1) // 2
while med in range(n) and arr[med] < s:
	result += s - arr[med]
	med = med + 1
med = (n - 1) // 2
while med in range(n) and arr[med] > s:
	result += arr[med] - s
	med = med - 1
print(result)


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


(n, s) = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
i = n // 2
c = 0
if a[i] < s:
	while i < n and a[i] < s:
		c += s - a[i]
		i += 1
elif a[i] > s:
	while i > -1 and a[i] > s:
		c += a[i] - s
		i -= 1
print(c)


from sys import stdin, stdout
import cProfile
printHeap = str()
test = False
memory_constrained = False

def display(string_to_print):
	stdout.write(str(string_to_print) + '\n')

def test_print(output):
	if test:
		stdout.write(str(output) + '\n')

def display_list(list1, sep=' '):
	stdout.write(sep.join(map(str, list1)) + '\n')

def get_int():
	return int(stdin.readline())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))
memory = dict()

def clear_cache():
	global memory
	memory = dict()

def cached_fn(fn, *args):
	global memory
	if args in memory:
		return memory[args]
	else:
		result = fn(*args)
		memory[args] = result
		return result

def main():
	(n, ele) = get_tuple()
	li = get_list()
	li.sort()
	mid = n // 2
	for i in range(n):
		if li[i] >= ele:
			break
	sm = 0
	if mid < i:
		for k in range(mid, i):
			sm += abs(li[k] - ele)
		if i == n - 1 and li[i] < ele:
			sm += abs(li[i] - ele)
	elif mid >= i:
		for k in range(i, mid + 1):
			sm += abs(li[k] - ele)
	print(sm)
cProfile.run('main()') if test else main()


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


I = lambda : int(input())
ID = lambda : map(int, input().split())
IL = lambda : list(ID())
(n, s) = ID()
a = IL()
a.sort()
ans = 0
for i in range(n // 2 + 1):
	if a[i] > s:
		ans += a[i] - s
for i in range(n // 2, n):
	if a[i] < s:
		ans += s - a[i]
print(ans)


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


(n, median) = list(map(int, input().split(' ')))
l = list(map(int, input().split(' ')))
count = 0
l.sort()
i = n // 2
if l[i] < median:
	while i < n and l[i] < median:
		count += median - l[i]
		i += 1
else:
	while i >= 0 and l[i] > median:
		count += l[i] - median
		i -= 1
print(count)


from sys import stdin
ns = [int(x) for x in stdin.readline().split()]
a = [int(x) for x in stdin.readline().split()]
n = ns[0]
s = ns[1]
midpoint = n // 2
a.sort()
w = 0
while w < n and s > a[w]:
	w += 1
op = 0
if w <= midpoint:
	for i in range(w, midpoint + 1):
		op += a[i] - s
if w > midpoint:
	for i in range(midpoint, w):
		op += s - a[i]
print(op)


(n, s) = input().split()
n = int(n)
s = int(s)
arr = [0 for i in range(n)]
arr = input().split(' ')
for i in range(n):
	arr[i] = int(arr[i])
arr.sort()
l = n // 2
s1 = s - arr[l]
if s1 < 0:
	s1 = -1 * s1
sum = 0
for i in range(l):
	if arr[i] > s:
		a = arr[i] - s
		sum = sum + a
for i in range(l + 1, n):
	if arr[i] < s:
		a = s - arr[i]
		sum = sum + a
print(sum + s1)


t = list(map(int, input().rstrip().split()))
m = list(map(int, input().rstrip().split()))
s = sorted(m)
j = int((len(s) - 1) / 2)
k = 0
if s[j] < t[1]:
	k += t[1] - s[j]
if s[j] > t[1]:
	k += s[j] - t[1]
for i in s:
	s[j] = t[1]
for i in range(0, j):
	if s[j] <= s[i]:
		k += s[i] - s[j]
for i in range(j + 1, len(s)):
	if s[j] >= s[i]:
		k += s[j] - s[i]
print(k)


def solve(s, arr):
	arr.sort()
	ans = 0
	i = len(arr) // 2
	if arr[i] < s:
		ans += s - arr[i]
		i += 1
		while i < len(arr) and arr[i] < s:
			ans += s - arr[i]
			i += 1
	else:
		ans += arr[i] - s
		i -= 1
		while i > -1 and arr[i] > s:
			ans += arr[i] - s
			i -= 1
	return ans

def main():
	(n, s) = map(int, input().split())
	arr = list(map(int, input().split()))
	print(solve(s, arr))
main()


(n, s) = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
(a, m, k) = (sorted(a), n // 2, 0)
if a[m] > s:
	for i in range(n):
		if a[i] >= s:
			break
	for j in range(i, m + 1):
		k += a[j] - s
elif a[m] < s:
	for i in range(m, n):
		if a[i] >= s:
			break
		k += s - a[i]
		a[i] = s
print(k)


import math

def main():
	(n, s) = map(int, input().split(' '))
	ip = [int(item) for item in input().split(' ')]
	ip.sort()
	med = math.floor(n / 2)
	moves = abs(ip[med] - s)
	for i in range(n):
		if i < med:
			if ip[i] > s:
				moves += ip[i] - s
		elif i > med:
			if ip[i] < s:
				moves += s - ip[i]
	print(moves)
main()


(n, s) = map(int, input().split())
A = map(int, input().split())
A = sorted(A)
m = A[n // 2]
if m < s:
	ans = s - m + sum((max(0, s - a) for a in A[n // 2 + 1:]))
elif m > s:
	ans = m - s + sum((max(0, a - s) for a in A[:n // 2]))
else:
	ans = 0
print(ans)


def main():
	(n, k) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a.sort()
	if a[n // 2] == k:
		return 0
	if n == 1:
		return abs(a[0] - k)
	c = abs(a[n // 2] - k)
	i = 1
	while i <= n // 2 and k > a[n // 2 + i]:
		c = c + abs(a[n // 2 + i] - k)
		i = i + 1
	i = 1
	while i <= n // 2 and k < a[n // 2 - i]:
		c = c + abs(a[n // 2 - i] - k)
		i += 1
	return c
print(main())


inp = lambda : [*map(int, input().split())]
(n, s) = inp()
a = sorted(inp())
i = n // 2
ans = 0
if s == a[i]:
	print(0)
	quit()
if s > a[i]:
	while i < n and a[i] < s:
		ans += s - a[i]
		i += 1
else:
	while i >= 0 and a[i] > s:
		ans += a[i] - s
		i -= 1
print(ans)


from sys import stdin
from collections import deque, Counter
import sys
import math
import operator
import random
from fractions import Fraction
import functools
(n, s) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
num = arr[n // 2]
ind = n // 2
ans = 0
for i in range(0, ind + 1):
	if arr[i] > s:
		ans += arr[i] - s
for i in range(ind, n):
	if arr[i] < s:
		ans += s - arr[i]
print(ans)


def findmedium(s, n):
	global arr
	mid = int(n / 2)
	step = 0
	if arr[mid] > s:
		step += arr[mid] - s
		arr[mid] = s
		for i in range(mid - 1, -1, -1):
			if arr[i] > s:
				step += arr[i] - s
				arr[i] = s
			else:
				break
	elif arr[mid] < s:
		step += s - arr[mid]
		arr[mid] = s
		for i in range(mid + 1, n):
			if arr[i] < s:
				step += s - arr[i]
				arr[i] = s
			else:
				break
	print(step)
arr = []
(n, s) = map(int, input().lstrip().split())
arr = list(map(int, input().lstrip().split()))
arr.sort()
findmedium(s, n)


(n, k) = map(int, input().split())
greedy = list(map(int, input().split()))
greedy.sort()
ans = 0
if n == 1:
	ans += abs(greedy[0] - k)
elif greedy[n // 2] != k:
	if greedy[n // 2] > k:
		ans += greedy[n // 2] - k
		i = 1
		while n // 2 - i >= 0 and greedy[n // 2 - i] > k:
			ans += greedy[n // 2 - i] - k
			i += 1
	else:
		ans += k - greedy[n // 2]
		i = 1
		while n // 2 + i < n and greedy[n // 2 + i] < k:
			ans += k - greedy[n // 2 + i]
			i += 1
print(ans)


(n, s) = 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)


import os
import sys
from io import BytesIO, IOBase
import math
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
if l[n // 2] == k:
	print('0')
elif l[n // 2] < k:
	a = 0
	for i in range(n // 2, n):
		a += max(0, k - l[i])
	print(a)
else:
	a = 0
	for i in range(0, n // 2 + 1):
		a += max(0, l[i] - k)
	print(a)


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


l = list(map(int, input().strip().split()))
n = l[0]
s = l[1]
l = list(map(int, input().strip().split()))
l.sort()
median = l[n // 2]
prox = l[n // 2:]
ant = l[:n // 2 + 1]
ant.reverse()
op = 0
if s > median:
	for el in prox:
		if el >= s:
			break
		if el < s:
			op += abs(s - el)
if s < median:
	for el in ant:
		if el <= s:
			break
		if el > s:
			op += abs(s - el)
print(op)


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

def solv(arr, med):
	half = int(len(arr) / 2)
	sm = []
	gt = []
	for item in arr:
		if item < med:
			sm.append(item)
		elif item > med:
			gt.append(item)
	if len(sm) <= half and len(gt) <= half:
		return 0
	elif len(sm) > half:
		sm.sort(reverse=True)
		li = sm[:len(sm) - half]
		result = 0
		for item in li:
			result += med - item
	else:
		gt.sort()
		li = gt[:len(gt) - half]
		result = 0
		for item in li:
			result += item - med
	return result
print(solv(arr, s))


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


import sys
(n, m) = list(map(int, input().split()))
t = list(map(int, input().split()))
t.sort()
mid = n // 2
if t[mid] == m:
	print(0)
	sys.exit(0)
if t[mid] < m:
	sm = 0
	for i in range(mid, n):
		if t[i] < m:
			sm += t[i] - m
		else:
			break
	print(-sm)
if t[mid] > m:
	sm = 0
	for i in range(mid, -1, -1):
		if t[i] > m:
			sm += m - t[i]
		else:
			break
	print(-sm)


for _ in range(1):
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	l.sort()
	mid = l[n // 2]
	c = 0
	if k > mid:
		for x in range(n // 2, n):
			if k > l[x]:
				c = c + (k - l[x])
			else:
				break
	else:
		for x in range(0, n // 2 + 1):
			if k < l[x]:
				c = c + (l[x] - k)
	print(c)


(n, s) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a = sorted(a)
m = n // 2
i = 0
for x in a:
	if x > s:
		break
	i += 1
if s >= a[m]:
	i -= 1
if i < m:
	(m, i) = (i, m)
incs = 0
for j in range(m, i + 1):
	incs += abs(a[j] - s)
print(incs)


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


from bisect import bisect_right as br
(n, s) = map(int, input().split())
a = sorted(map(int, input().split()))
p = 0
l = n // 2
if s == a[l]:
	print(0)
elif s > a[l]:
	for i in range(l, n):
		if s > a[i]:
			p += s - a[i]
		else:
			break
	print(p)
else:
	for i in range(l, -1, -1):
		if s < a[i]:
			p += a[i] - s
		else:
			break
	print(p)


(n, s) = (int(i) for i in input().split())
mass = [int(z) for z in input().split()]
mass.sort()
k = n // 2
result1 = 0
for i in range(k, n):
	if mass[i] < s:
		result1 += s - mass[i]
result2 = 0
for i in range(k + 1):
	if mass[i] > s:
		result2 += mass[i] - s
print(max(result1, result2))


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


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


(n, s) = map(int, input().split())
a = map(int, input().split())
a = sorted(a)
if n == 1:
	print(abs(s - a[0]))
else:
	index = n // 2
	if a[index] == s:
		print(0)
	elif a[index] < s:
		k = [s - el for el in a[index:] if el < s]
		print(sum(k))
	else:
		k = [el - s for el in a[:index + 1] if el > s]
		print(sum(k))


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


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


c = 0
(n, s) = 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())
a = sorted(list(map(int, input().split())))
operations = 0
for i in range(n // 2):
	if a[i] > s:
		operations += a[i] - s
	elif a[n - 1 - i] < s:
		operations += s - a[n - 1 - i]
print(operations + abs(a[n // 2] - s))


def median(lst, s):
	a = sorted(lst)
	result = abs(a[len(a) // 2] - s)
	for i in range(len(a) // 2 + 1, len(a)):
		if a[i] < s:
			result += s - a[i]
	for i in range(len(a) // 2):
		if a[i] > s:
			result -= s - a[i]
	return result
(n, S) = [int(j) for j in input().split()]
b = [int(x) for x in input().split()]
print(median(b, S))


import sys
input = lambda : sys.stdin.readline().rstrip()
inp = sys.stdin.buffer.readline

def I():
	return list(map(int, inp().split()))
from math import log2
(n, s) = I()
a = I()
a.sort()
ans = abs(a[n // 2] - s)
a[n // 2] = s
for i in range(n // 2 + 1, n):
	if a[i] < s:
		ans += s - a[i]
for i in range(n // 2):
	if a[i] > s:
		ans += a[i] - s
print(ans)


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


(n, s) = map(int, input().split())
arr = [int(x) for x in input().split()]
arr.sort()
ans = abs(s - arr[n // 2])
arr[n // 2] = s
for i in range(n):
	if i < n // 2:
		if arr[i] > s:
			ans += abs(s - arr[i])
	elif arr[i] < s:
		ans += abs(s - arr[i])
print(ans)


(n, m) = map(int, input().split())
s = sorted(list(map(int, input().split())))
need = 0
if s[n // 2] < m:
	for i in range(n // 2, n):
		need += max(0, m - s[i])
elif s[n // 2] > m:
	for i in range(n // 2, -1, -1):
		need += max(0, s[i] - m)
print(need)


(n, m) = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
a = sorted(a)
dif = a[(n - 1) // 2] - m
count = abs(dif)
a[(n - 1) // 2] = m
if dif > 0:
	for i in range(int(n // 2), -1, -1):
		if a[i] > m:
			count = count + a[i] - m
elif dif < 0:
	for i in range(n // 2, n):
		if a[i] < m:
			count = count + m - a[i]
print(count)


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


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


def solve(a, s):
	a.sort()
	(res, n) = (0, len(a) // 2)
	i = n
	if a[n] < s:
		while i < len(a) and a[i] < s:
			res += s - a[i]
			i += 1
	else:
		while i >= 0 and a[i] > s:
			res += a[i] - s
			i -= 1
	return res
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
print(solve(a, s))


(n, s) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
ans = 0
i = n // 2
if arr[i] == s:
	pass
elif arr[i] > s:
	while arr[i] > s:
		ans += arr[i] - s
		if i == 0:
			break
		else:
			i -= 1
else:
	while arr[i] < s:
		ans += s - arr[i]
		if i == n - 1:
			break
		else:
			i += 1
print(ans)


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


import math
from collections import defaultdict as dd
import heapq
from bisect import bisect_left as bl
(n, s) = [int(i) for i in input().split(' ')]
l = [int(i) for i in input().split(' ')]
l.sort()
ans = 0
for i in range(n // 2 + 1):
	if l[i] > s:
		ans += l[i] - s
for i in range(n // 2, n):
	if l[i] < s:
		ans += s - l[i]
print(ans)


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


(n, s) = list(map(int, input().split()))
l = sorted(list(map(int, input().split())))
if n == 1:
	print(abs(s - l[0]))
elif l[n // 2] == s:
	print(0)
elif l[n // 2] > s:
	x = n // 2
	ans = 0
	while x >= 0 and l[x] > s:
		ans += l[x] - s
		x -= 1
	print(ans)
else:
	x = n // 2
	ans = 0
	while x < n and l[x] < s:
		ans += s - l[x]
		x += 1
	print(ans)


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


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


import sys
input = sys.stdin.readline
(n, s) = 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)


from sys import stdin, stdout

def main():
	(n, s) = map(int, stdin.readline().split())
	a = list(map(int, stdin.readline().split()))
	a.sort()
	mid = (n - 1) // 2
	if a[mid] == s:
		return 0
	elif a[mid] > s:
		temp = []
		for i in range(mid):
			if a[i] <= s:
				temp.append(a[i])
			else:
				temp.append(s)
		temp += [s] + a[mid + 1:]
	else:
		temp = []
		for i in range(mid + 1, n):
			if a[i] >= s:
				temp.append(a[i])
			else:
				temp.append(s)
		temp = a[:mid] + [s] + temp
	ans = 0
	for i in range(n):
		ans += abs(a[i] - temp[i])
	return ans
stdout.write('%d' % main())


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


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 map(type, stdin.readline().split())

def readlist(type=int):
	return list(map(type, stdin.readline().split()))

def sorted_indexes(arr):
	return sorted(range(len(arr)), key=arr.__getitem__)

def printr(arr):
	[stdout.write(str(x) + ' ') for x in arr]
	cout('')

def find_lt(a, x):
	i = bisect_left(a, x)
	if i:
		return a[i - 1]
	raise ValueError

def find_gt(a, 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
(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)


from bisect import bisect_right
(N, S) = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
arr.sort()
center_index = N // 2
S_index = bisect_right(arr, S) - 1
moves = 0
if N == 1:
	moves = abs(arr[0] - S)
elif S_index > center_index:
	for i in range(center_index, S_index + 1):
		moves += S - arr[i]
elif S_index < center_index:
	for i in range(S_index + 1, center_index + 1):
		moves += arr[i] - S
else:
	moves = abs(S - arr[center_index])
print(moves)


from math import *
(n, s) = map(int, input().split())
if n == 1:
	print(abs(int(input()) - s))
else:
	ls = list(map(int, input().split()))
	ls.sort()
	start = ls[(n - 3) // 2]
	end = ls[(n + 1) // 2]
	if s in list(range(start, end + 1)):
		print(abs(ls[(n - 1) // 2] - s))
	elif ls[(n - 1) // 2] < s:
		index = (n - 1) // 2
		count = 0
		while index != n:
			if ls[index] < s:
				count += s - ls[index]
			index += 1
		print(count)
	else:
		index = (n - 1) // 2
		count = 0
		while index != -1:
			if ls[index] > s:
				count += ls[index] - s
			index -= 1
		print(count)


n = input().split(' ')
m = input().split(' ')
n = list(map(int, n))
m = list(map(int, m))
m.sort()
global count
count = 0

def med(x, y):
	global count
	if len(y) == 1:
		if y[0] > x[1]:
			count += y[0] - x[1]
			y[0] = x[1]
		else:
			count += x[1] - y[0]
			y[0] = x[1]
	elif y[int(len(y) / 2)] == x[1]:
		count += 0
	elif x[1] > y[int(len(y) / 2)]:
		for i in range(int(len(y) / 2), len(y)):
			if y[i] >= x[1]:
				break
			else:
				count += x[1] - y[i]
				y[i] = x[1]
	else:
		for i in range(int(len(y) / 2), -1, -1):
			if y[i] <= x[1]:
				break
			else:
				count += y[i] - x[1]
				y[i] = x[1]
	return count
print(med(n, m))


(n, k) = map(int, input().split())
l = sorted(list(map(int, input().split())))
l = [k] + l + [k]
n += 2
i = n // 2
total = 0
if l[i] == k:
	print(total)
elif l[i] < k:
	while l[i] < k:
		total += k - l[i]
		i += 1
	print(total)
else:
	while l[i] > k:
		total += abs(k - l[i])
		i -= 1
	print(total)


import sys
line1 = str(sys.stdin.readline())
n = int(line1.split()[0])
s = int(line1.split()[1])
arr = []
line2 = str(sys.stdin.readline())
for i in line2.split():
	arr.append(int(i))
arr.sort()
step = 0
if s >= arr[int((n - 1) / 2)]:
	step += s - arr[int((n - 1) / 2)]
	arr[int((n - 1) / 2)] = s
	i = int((n - 1) / 2)
	while i < n - 1 and arr[i] > arr[i + 1]:
		step += arr[i] - arr[i + 1]
		arr[i + 1] = arr[i]
		i += 1
else:
	step += arr[int((n - 1) / 2)] - s
	arr[int((n - 1) / 2)] = s
	i = int((n - 1) / 2)
	while i > 0 and arr[i - 1] > arr[i]:
		step += arr[i - 1] - arr[i]
		arr[i - 1] = arr[i]
		i -= 1
print(step)


(n, s) = map(int, input().split())
num = list(map(int, input().split()))
num.sort()
import bisect
zuo = bisect.bisect_left(num, s, 0, n)
you = bisect.bisect_right(num, s, 0, n)
me = num[(n + 1) // 2 - 1]
if me == s:
	print(0)
elif me < s:
	print(sum((s - i for i in num[(n + 1) // 2 - 1:zuo])))
else:
	print(sum((i - s for i in num[you:(n + 1) // 2])))


(length, median) = map(int, input().split())
arr = [int(x) for x in input().split()]
arr.sort()
medindex = int(len(arr) / 2)
count = 0
index = medindex
if arr[medindex] < median:
	while index < len(arr):
		if arr[index] >= median:
			break
		count += median - arr[index]
		index += 1
else:
	while index > -1:
		if arr[index] <= median:
			break
		count += arr[index] - median
		index -= 1
print(count)


import heapq
(length, target) = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]
nums = sorted(nums)
lower = [x * -1 for x in reversed(nums[:int(length / 2)])]
median = nums[int(length / 2)]
upper = nums[int(length / 2) + 1:]
required = 0
while median != target:
	required += abs(target - median)
	median = target
	if upper and median > upper[0]:
		heapq.heappush(upper, median)
		median = heapq.heappop(upper)
	else:
		heapq.heappush(lower, median * -1)
		median = heapq.heappop(lower) * -1
print(required)


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
from itertools import accumulate

def Int():
	return int(sys.stdin.readline())

def Mint():
	return map(int, sys.stdin.readline().split())

def Lstr():
	return list(sys.stdin.readline().strip())

def Str():
	return sys.stdin.readline().strip()

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

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

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

def dtob(n):
	return bin(n).replace('0b', '')

def btod(n):
	return int(n, 2)

def common(l1, l2):
	return set(l1).intersection(l2)

def solution():
	(n, s) = Mint()
	p = List()
	a = sorted(p)
	b = sorted(p, reverse=True)
	ans1 = 0
	ans2 = 0
	for i in range(n // 2, n):
		if a[i] < s:
			ans1 += s - a[i]
		else:
			break
	for i in range(n // 2, n):
		if b[i] > s:
			ans2 += b[i] - s
		else:
			break
	print(ans1 + ans2)
solution()


(n, s) = tuple(map(int, input().strip().split(' ')))
num = list(map(int, input().strip().split(' ')))
num.sort()
k = (n - 1) // 2
if num[k] == s:
	print(0)
else:
	sum = 0
	sum = sum + abs(s - num[k])
	num[k] = s
	for u in range(k - 1, -1, -1):
		if num[u] > s:
			sum = sum + abs(s - num[u])
		else:
			break
	for u in range(k + 1, n):
		if num[u] < s:
			sum = sum + abs(s - num[u])
		else:
			break
	print(sum)


class CodeforcesTask1037BSolution:

	def __init__(self):
		self.result = ''
		self.n_s = []
		self.array = []

	def read_input(self):
		self.n_s = [int(x) for x in input().split(' ')]
		self.array = [int(x) for x in input().split(' ')]

	def process_task(self):
		self.array.sort()
		median = self.array[self.n_s[0] // 2]
		if median == self.n_s[1]:
			moves = 0
		elif median > self.n_s[1]:
			moves = -sum([min(self.n_s[1] - x, 0) for x in self.array[:self.n_s[0] // 2 + 1]])
		else:
			moves = -sum([min(0, x - self.n_s[1]) for x in self.array[self.n_s[0] // 2:]])
		self.result = str(moves)

	def get_result(self):
		return self.result
Solution = CodeforcesTask1037BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


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


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


[n, s] = map(int, input().split())
input_list = list(map(int, input().split()))
middle = int(n / 2)
input_list = sorted(input_list)
if input_list[middle] == s:
	print(0)
elif input_list[middle] > s:
	cur = middle
	ret = 0
	while cur >= 0 and input_list[cur] > s:
		ret = ret + input_list[cur] - s
		cur = cur - 1
	print(ret)
elif input_list[middle] < s:
	cur = middle
	ret = 0
	while cur < n and input_list[cur] < s:
		ret = ret + (s - input_list[cur])
		cur = cur + 1
	print(ret)


import bisect
(n, s) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
r = bisect.bisect_left(A, s)
l = bisect.bisect_right(A, s)
ANS = float('inf')
ANS2 = float('inf')
if r > n // 2:
	ANS = (r - n // 2) * s - sum(A[n // 2:r])
if n - l > n // 2:
	ANS2 = sum(A[l:n // 2 + 1]) - (n // 2 + 1 - l) * s
x = min(ANS, ANS2)
if x != float('inf'):
	print(x)
else:
	print(0)


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


(n, m) = 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)


import sys, heapq
(n, s) = map(int, sys.stdin.readline().split())
arr = list(map(int, sys.stdin.readline().split()))
arr.sort()
ans = abs(arr[n // 2] - s)
arr[n // 2] = s
for i in range(n // 2 - 1, -1, -1):
	if arr[i] > s:
		ans += abs(arr[i] - s)
	else:
		break
for i in range(n // 2 + 1, n):
	if arr[i] < s:
		ans += abs(arr[i] - s)
	else:
		break
print(ans)


(n, median) = input().split()
n = int(n)
median = int(median)
myArr = [int(i) for i in input().split()]
myArr.sort()
midIndex = int(n / 2)
cost = 0
k = midIndex
if myArr[midIndex] != median:
	while k >= 0:
		if myArr[k] > median:
			cost = cost + myArr[k] - median
		else:
			break
		k = k - 1
	for j in range(midIndex, n):
		if myArr[j] < median:
			cost = cost + median - myArr[j]
		else:
			break
print(cost)


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


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


(n, median) = map(int, input().split())
lst = sorted(list(map(int, input().split())))
index = (n - 1) // 2
count = 0
if median < lst[index]:
	while index >= 0 and median < lst[index]:
		count += lst[index] - median
		index -= 1
else:
	while index < n and median > lst[index]:
		count += median - lst[index]
		index += 1
print(count)


rd = lambda : map(int, input().split())
(n, s) = rd()
a = sorted(rd())
n >>= 1
print(abs(a[n] - s) + sum((max(0, x - s) for x in a[:n])) + sum((max(0, s - x) for x in a[n + 1:])))


import math
(n, s) = map(int, input().strip().split())
l = list(map(int, input().strip().split()))
l.sort()
c = 0
p = n // 2
k = l[n // 2]
if s > k:
	while p < n and l[p] < s:
		c += s - l[p]
		p += 1
if s < k:
	while p > -1 and l[p] > s:
		c += l[p] - s
		p -= 1
print(c)


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


line1 = input().split(' ')
l = int(line1[0])
med = int(line1[1])
array = input().split(' ')
for i in range(l):
	array[i] = int(array[i])
op = 0
array = sorted(array, key=abs, reverse=False)
if array[i // 2] > med:
	for i in range(i // 2, -1, -1):
		if array[i] < med:
			break
		op += abs(array[i] - med)
elif array[1 // 2] < med:
	for i in range(i // 2, l):
		if array[i] > med:
			break
		op += abs(array[i] - med)
print(op)


import math
(n, needed) = input().split()
n = int(n)
needed = int(needed)
nums = input().split()
nums = list(map(int, nums))
nums.sort()
median = nums[n // 2]
result = math.fabs(needed - median)
for i in range(n // 2 + 1, n):
	if nums[i] < needed:
		result += math.fabs(needed - nums[i])
for i in range(0, n // 2):
	if nums[i] > needed:
		result += math.fabs(needed - nums[i])
print(int(result))


import sys
import math
import bisect

def solve(A, mval):
	n = len(A)
	m = (n - 1) // 2
	A.sort()
	ans = abs(A[m] - mval)
	A[m] = mval
	for i in range(m - 1, -1, -1):
		if A[i] > A[i + 1]:
			ans += A[i] - A[i + 1]
			A[i] = A[i + 1]
	for i in range(m + 1, n):
		if A[i] < A[i - 1]:
			ans += A[i - 1] - A[i]
			A[i] = A[i - 1]
	return ans

def main():
	(n, m) = map(int, input().split())
	A = list(map(int, input().split()))
	ans = solve(A, m)
	print(ans)
main()


def test_1():
	import math
	from collections import Counter
	(n, m) = list(map(int, input().split(' ')))
	data = list(map(int, input().split(' ')))
	data.sort()
	a = data[n // 2:]
	cc = 0
	a_0 = a[0]
	if a_0 < m:
		for a_1 in a:
			if a_1 < m:
				cc += m - a_1
	else:
		a = data[:n // 2 + 1]
		for a_1 in a:
			if a_1 > m:
				cc += a_1 - m
	print(cc)
test_1()


a = input().split()
a = [int(i) for i in a]
b = input().split()
b = [int(i) for i in b]
mid = a[0] // 2
b = sorted(b)
if a[0] == 1:
	print(abs(a[1] - b[0]))
elif a[1] in b:
	ind = b.index(a[1])
	if ind == mid:
		print(0)
	elif ind < mid:
		print(sum([t - a[1] for t in b[ind:mid + 1]]))
	elif ind > mid:
		print(sum([a[1] - t for t in b[mid:ind + 1]]))
elif a[1] not in b:
	if b[mid] > a[1] and a[1] >= b[0]:
		ind = a[0] - 1 - b[::-1].index(max([i for i in b if a[1] > i]))
		print(sum([t - a[1] for t in b[ind + 1:mid + 1]]))
	elif b[mid] > a[1] and a[1] < b[0]:
		print(sum([t - a[1] for t in b[0:mid + 1]]))
	if b[mid] < a[1] and a[1] <= b[-1]:
		ind = b.index(min([i for i in b if a[1] < i]))
		print(sum([a[1] - t for t in b[mid:ind]]))
	elif b[mid] < a[1] and a[1] > b[-1]:
		print(sum([a[1] - t for t in b[mid:]]))


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


import os
from sys import stdin
max_val = int(10000000000000.0)
min_val = int(-10000000000000.0)

def read_int():
	return int(stdin.readline())

def read_ints():
	return [int(x) for x in stdin.readline().split()]

def read_str():
	return input()

def read_strs():
	return [x for x in stdin.readline().split()]

def read_str_list():
	return [x for x in stdin.readline().split().split()]
(nb_elemets, value_needed) = read_ints()
elements = sorted(read_ints())
mid = nb_elemets // 2
ans = abs(elements[mid] - value_needed)
ans += sum((max(0, a - value_needed) for a in elements[:mid]))
ans += sum((max(0, value_needed - a) for a in elements[mid + 1:]))
print(ans)


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


r = lambda : map(int, input().split())
(num, s) = r()
a = sorted(r())
num >>= 1
print(abs(a[num] - s) + sum((max(0, x - s) for x in a[:num])) + sum((max(0, s - x) for x in a[num + 1:])))


import bisect
(n, s) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
(tot, cnt) = (0, 0)
if s >= arr[n // 2]:
	ind = bisect.bisect_left(arr, s)
	for i in range(n // 2, ind):
		tot += s - arr[i]
		cnt += 1
	if cnt == 0:
		tot += s - arr[n // 2]
	print(tot)
else:
	ind = bisect.bisect_left(arr, s)
	for i in range(ind, n // 2 + 1):
		tot += arr[i] - s
		cnt += 1
	if cnt == 0:
		tot += arr[n // 2] - s
	print(tot)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
m = n // 2
k = 0
if a[m] > s:
	k += a[m] - s
	m -= 1
	while m >= 0 and a[m] > s:
		k += a[m] - s
		m -= 1
elif a[m] < s:
	k += s - a[m]
	m += 1
	while m < n and a[m] < s:
		k += s - a[m]
		m += 1
print(k)


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


ligne = input().split(' ')
n = int(ligne[0])
s = int(ligne[1])
tab = input().split(' ')
l = len(tab)
for i in range(l):
	tab[i] = int(tab[i])
tab = sorted(tab, key=abs)
k = 0
if tab[l // 2] < s:
	for i in range(l // 2, l):
		if tab[i] < s:
			k += s - tab[i]
		else:
			break
else:
	for i in range(l // 2, -1, -1):
		if tab[i] > s:
			k += abs(s - tab[i])
		else:
			break
print(k)


(n, s) = [int(el) for el in input().split()]
a = []
a = [int(el) for el in input().split()]
a.sort()
midl = int((n - 1) / 2)
med = a[midl]
if med == s:
	print('0')
	raise SystemExit()
output = s - med
if output > 0:
	for i in range(midl + 1, n, 1):
		if a[i] < s:
			output = output + s - a[i]
		else:
			print(output)
			raise SystemExit()
if output < 0:
	output = -output
	for i in range(midl - 1, -1, -1):
		if a[i] > s:
			output = output + a[i] - s
		else:
			print(output)
			raise SystemExit()
print(abs(output))


inn = input()
(n, k) = inn.split(' ')
(n, k) = (int(n), int(k))
a = list(map(int, input().split()))
a.sort()
sum = 0
c = int(n / 2)
if k > a[c]:
	for i in range(c, n):
		if a[i] < k:
			sum += k - a[i]
		else:
			break
else:
	i = c
	while i >= 0:
		if a[i] > k:
			sum += a[i] - k
		else:
			break
		i -= 1
print(sum)


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


from sys import stdin
import pprint
input_string = list(map(int, stdin.readline().split()))
mediana = input_string[1]
array = list(map(int, stdin.readline().split()))
array.sort()
change = 0
if array[array.__len__() // 2] > mediana:
	for i in range(0, array.__len__() // 2 + 1):
		if array[i] > mediana:
			change += array[i] - mediana
elif array[array.__len__() // 2] < mediana:
	for i in range(array.__len__() // 2, array.__len__()):
		if array[i] < mediana:
			change += mediana - array[i]
print(change)


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


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


def ted():
	(n, s) = [int(i) for i in input().split()]
	a = [int(i) for i in input().split()]
	a.sort()
	m = a[(n - 1) // 2]
	if s == m:
		return 0
	if s < m:
		b = list(filter(lambda x: s < x <= m, a[:(n - 1) // 2 + 1]))
	elif s > m:
		b = list(filter(lambda x: s > x >= m, a[(n - 1) // 2:]))
	return abs(sum(b) - len(b) * s)
print(ted())


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


(n, s) = map(int, input().split())
x = list(map(int, input().split()))
ans = 0
if s not in x:
	x.append(s)
	x.sort()
	if x[n // 2] >= s:
		for j in range(x.index(s), (n + 1) // 2 + 1):
			ans += x[j] - s
	else:
		for j in range(n // 2, x.index(s)):
			if x[j] < s:
				ans += s - x[j]
			else:
				ans += x[j] - s
else:
	x.sort()
	if x[n // 2] > s:
		for j in range(x.index(s), n // 2 + 1):
			ans += x[j] - s
	else:
		for j in range(n // 2, x.index(s)):
			ans += s - x[j]
print(ans)


from bisect import bisect_left, bisect_right

def main():
	(n, s) = map(int, input().split())
	aa = sorted(map(int, input().split()))
	(i, j) = (bisect_left(aa, s), bisect_right(aa, s))
	if i * 2 < n < j * 2:
		r = 0
	elif n < i * 2:
		r = s * (i - n // 2) - sum(aa[n // 2:i])
	else:
		r = sum(aa[j:n // 2 + 1]) - s * (n // 2 + 1 - j)
	print(r)
main()


(n, m) = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
s = 0
for i in range(n):
	if i < n // 2:
		s += max(0, a[i] - m)
	elif i == n // 2:
		s += abs(m - a[i])
	else:
		s += max(0, m - a[i])
print(s)


import bisect

def main():
	(n, s) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	if a[n // 2] == s:
		print(0)
	elif a[n // 2] > s:
		(idx, ans) = (bisect.bisect_left(a, s), 0)
		for i in range(idx, n // 2 + 1):
			ans += a[i] - s
		print(ans)
	else:
		(idx, ans) = (bisect.bisect_left(a, s), 0)
		for i in range(n // 2, idx):
			ans += s - a[i]
		print(ans)
main()


(n, s) = [int(i) for i in input().split()]
med = (n - 1) // 2
a = sorted([int(i) for i in input().split()])
ind = -1
for i in range(n):
	if a[i] <= s:
		ind = i
if ind < med:
	res = 0
	for i in range(ind + 1, med + 1):
		res += a[i] - s
	print(res)
else:
	res = 0
	for i in range(med, ind + 1):
		res += s - a[i]
	print(res)


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


import math
(n, s) = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
pref = [0]
for i in arr:
	pref.append(pref[-1] + i)
l = -1
r = n
while r - l > 1:
	m = (r + l) // 2
	if arr[m] > s:
		r = m
	else:
		l = m
i = r - 1
if i >= n // 2:
	need = s * (i - n // 2 + 1)
	print(abs(need - pref[i + 1] + pref[n // 2]))
else:
	i += 1
	need = s * (n // 2 - i + 1)
	print(abs(pref[n // 2 + 1] - pref[i] - need))


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


def sol():
	(N, S) = [int(x) for x in input().split(' ')]
	a = [int(x) for x in input().split(' ')]
	m_index = N // 2
	a = sorted(a)
	if N == 1:
		print(abs(a[0] - S))
		return
	index = 0
	if a[0] >= S:
		index = 0
	elif a[-1] <= S:
		index = N - 1
	else:
		for i in range(1, len(a) - 1):
			if i < m_index:
				if a[i - 1] <= S and S <= a[i + 1]:
					index = i + 1
					break
			elif i == m_index and a[i - 1] <= S and (S <= a[i + 1]):
				index = i
				break
			elif a[i - 1] <= S and S <= a[i + 1]:
				index = i
				break
	cost = 0
	if index <= m_index:
		for i in range(index, m_index + 1):
			cost += abs(a[i] - S)
	else:
		for i in range(m_index, index + 1):
			cost += abs(a[i] - S)
	print(cost)
sol()


(n, s) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt = 0
if A[n // 2] == s:
	pass
elif A[n // 2] > s:
	x = n // 2
	while x >= 0 and A[x] > s:
		cnt += A[x] - s
		x -= 1
else:
	x = n // 2
	while x < n and A[x] < s:
		cnt += s - A[x]
		x += 1
print(cnt)


import math
(n, s) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
op = 0
loc = math.ceil(n // 2)
median = a[loc]
if median < s:
	for i in range(loc, n):
		if a[i] < s:
			op += s - a[i]
		else:
			break
elif median > s:
	for i in range(loc, -1, -1):
		if a[i] > s:
			op += a[i] - s
		else:
			break
print(op)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
s = 0
if l[n // 2] < m:
	for k in range(n // 2, n):
		x = l[k]
		if x < m:
			s += m - x
		else:
			break
else:
	for k in range(n // 2, -1, -1):
		x = l[k]
		if x > m:
			s += -m + x
		else:
			break
print(s)


def solve():
	(n, mediana_final) = [int(x) for x in input().split(' ')]
	lista = [int(x) for x in input().split(' ')]
	lista.sort()
	i = n // 2
	mediana = lista[i]
	res = abs(mediana - mediana_final)
	if n == 1:
		return res
	if mediana < mediana_final:
		i += 1
		while lista[i] < mediana_final:
			res += abs(lista[i] - mediana_final)
			i += 1
			if i == n:
				return res
	else:
		i -= 1
		while lista[i] > mediana_final:
			res += abs(lista[i] - mediana_final)
			i -= 1
			if i == -1:
				return res
	return res
print(solve())


import statistics as stat
(n, s) = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
median = stat.median(arr)
index = arr.index(median)
cost = 0
if n == 1:
	cost += abs(s - median)
else:
	for x in arr[0:n // 2 + 1]:
		if x > s:
			cost += x - s
	for x in arr[n // 2:len(arr)]:
		if x < s:
			cost += s - x
print(cost)


s1 = input().split()
s2 = input().split()
(n, s) = (int(s1[0]), int(s1[1]))
a = []
for x in s2:
	a.append(int(x))
a.sort()
m = (n - 1) // 2
ans = abs(s - a[m])
if a[m] < s:
	for i in range(m + 1, n):
		if a[i] < s:
			ans += s - a[i]
else:
	for i in range(m - 1, -1, -1):
		if a[i] > s:
			ans += a[i] - s
print(ans)


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


(n, x) = map(int, input().split())
arr = sorted(list(map(int, input().split())))
c1 = abs(arr[n // 2] - x)
for i in range(n // 2):
	if arr[i] > x:
		c1 += arr[i] - x
for i in range(n // 2 + 1, n):
	if arr[i] < x:
		c1 += x - arr[i]
print(c1)


Y = input().split()
n = int(Y[0])
s = int(Y[1])
A = list(map(int, input().split()))
A.sort()
ans = 0
if s == A[n // 2]:
	print(ans)
elif s > A[n // 2]:
	for elem in A[n // 2:]:
		if elem < s:
			ans += s - elem
	print(ans)
else:
	for elem in A[:n // 2 + 1]:
		if elem > s:
			ans += elem - s
	print(ans)


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


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2, floor
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def sumDigits(no):
	return 0 if no == 0 else int(no % 10) + sumDigits(int(no / 10))
MOD = 1000000007
PMOD = 998244353
N = 10 ** 9 + 7
LOGN = 30
T = 1
for _ in range(T):
	(n, s) = list(map(int, stdin.readline().rstrip().split()))
	a = list(map(int, stdin.readline().rstrip().split()))
	a.sort()
	ans = 0
	for i in range(n):
		if i < n // 2:
			ans += max(0, a[i] - s)
		elif i == n // 2:
			ans += abs(s - a[i])
		else:
			ans += max(0, s - a[i])
	print(ans)


(n, s) = map(int, input().split())
lst = list(map(int, input().split()))
lst.sort()
(res1, res2, res3, res4) = (0, 0, 0, 0)
if lst[n // 2] == s:
	from sys import exit
	print(0)
	exit()
for i in range(n // 2 + 1):
	if lst[i] > s:
		res1 += lst[i] - s
	else:
		res2 += s - lst[i]
for i in range(n - 1, n // 2 - 1, -1):
	if lst[i] > s:
		res3 += lst[i] - s
	else:
		res4 += s - lst[i]
print(min(res1 + res4, res2 + res3))


(n, s) = map(int, input().split())
a = sorted(map(int, input().split()))
n2 = n // 2
ans = sum((0 if x < s else x - s for x in a[:n2]))
ans += abs(a[n2] - s)
ans += sum((0 if x > s else s - x for x in a[n2 + 1:]))
print(ans)


l = input().split(' ')
(n, k) = (int(l[0]), int(l[1]))
l = input().split(' ')
for i in range(len(l)):
	l[i] = int(l[i])
l.sort()
median = len(l) // 2
acc = 0
pos = median
while pos >= 0 and l[pos] > k:
	acc += l[pos] - k
	pos -= 1
pos = median
while pos < n and l[pos] < k:
	acc += k - l[pos]
	pos += 1
print(acc)


import bisect
(n, s) = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
c = 0
idx = bisect.bisect_left(a, s)
m = n // 2
if n // 2 > idx:
	m += 1
for i in range(min(m, idx), max(m, idx)):
	c += abs(s - a[i])
if c != 0:
	print(c)
else:
	print(abs(s - a[m]))


(n, s) = map(int, input().split())
arr = list(map(int, input().split()))
a_max = len([1 for i in arr if i > s])
a_min = len(arr) - a_max
import heapq
count = 0
if a_min > a_max:
	b_min = heapq.nsmallest(a_min, arr)
	b_min.sort(reverse=True)
	for i in range(a_min - len(arr) // 2):
		count += s - b_min[i]
	print(count)
else:
	b_max = heapq.nlargest(a_max, arr)
	b_max.sort()
	for i in range(a_max - len(arr) // 2):
		count += b_max[i] - s
	print(count)


import math, sys
import heapq
from fractions import Fraction
from collections import Counter, defaultdict

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

def ls():
	return list(map(int, list(input())))

def la():
	return list(input())

def ii():
	return int(input())

def dic(x):
	return defaultdict(lambda : x)

def isPrime(n):
	i = 2
	if n == 1:
		return False
	while i <= int(math.sqrt(n)):
		if n % i == 0:
			return False
		i = i + 1
	return True

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def LCM(a, b):
	return a * b / gcd(a, b)
(n, s) = li()
a = li()
a.sort()
if n == 1:
	print(abs(s - a[0]))
else:
	total = 0
	if a[n // 2] < s:
		for i in range(n // 2, n):
			if s > a[i]:
				total += abs(a[i] - s)
			else:
				break
		print(total)
	elif a[n // 2] > s:
		for i in range(n // 2, -1, -1):
			if s < a[i]:
				total += abs(a[i] - s)
			else:
				break
		print(total)
	else:
		print(0)


(n, k) = map(int, input().split(' '))
c = [int(x) for x in input().split(' ')]
c.sort()
d = 0
if c[n // 2] < k:
	for i in range(n // 2, n):
		if c[i] < k:
			d += k - c[i]
		else:
			break
	print(d)
elif c[n // 2] > k:
	for i in range(n // 2, -1, -1):
		if c[i] > k:
			d += c[i] - k
		else:
			break
	print(d)
else:
	print(0)


(n, s) = map(int, input().split())
a = sorted(list(map(int, input().split())))
print(abs(a[n // 2] - s) + sum((max(0, x - s) for x in a[:n // 2])) + sum((max(0, s - x) for x in a[n // 2 + 1:])))


(n, s) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
m = n // 2
me = a[m]
ct = m
if me == s:
	print(0)
	exit(0)
elif me < s:
	while ct < n and a[ct] < s:
		ct += 1
	ds = sum([x - s for x in a[m:ct:1]])
elif me > s:
	while ct >= 0 and a[ct] > s:
		ct -= 1
	ds = sum([x - s for x in a[ct + 1:m + 1:1]])
print(abs(ds))


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


(num, zhong) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
b = num // 2
ans2 = 0
if a[b] == zhong:
	print(0)
elif a[b] < zhong:
	for i in range(b, num):
		if a[i] < zhong:
			ans2 += zhong - a[i]
		else:
			break
	print(ans2)
else:
	for i in reversed(range(b + 1)):
		if a[i] > zhong:
			ans2 += a[i] - zhong
		else:
			break
	print(ans2)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
s = n // 2
c = 0
arr.sort()
if arr[s] > m:
	while s >= 0 and arr[s] > m:
		c += arr[s] - m
		s -= 1
else:
	while s < n and arr[s] < m:
		c += m - arr[s]
		s += 1
print(c)


def main():
	(n, s) = map(int, input().split())
	a = sorted((int(c) for c in input().split()))
	i = n // 2
	median = a[i]
	if median == s:
		res = 0
	elif median < s:
		res = s - median
		i += 1
		while 1 <= i < n and a[i] < s:
			res += s - a[i]
			i += 1
	else:
		res = median - s
		i -= 1
		while 0 <= i < n - 1 and a[i] > s:
			res += a[i] - s
			i -= 1
	print(res)
main()


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


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


(n, s) = map(int, input().split())
l = [int(x) for x in input().split()]
l.sort()
(ans, mid) = (0, n // 2)
if l[mid] > s:
	while mid >= 0 and l[mid] > s:
		ans += l[mid] - s
		mid -= 1
else:
	while mid < n and l[mid] < s:
		ans += s - l[mid]
		mid += 1
print(ans)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
x = n // 2
ans = 0
if l[x] == m:
	pass
elif l[x] > m:
	for i in l[x::-1]:
		if i <= m:
			break
		else:
			ans += i - m
elif l[x] < m:
	for i in l[x:]:
		if i >= m:
			break
		else:
			ans += m - i
print(ans)


(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)
	exit(0)
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) = map(int, input().split())
tab = list(map(int, input().split()))
tab.sort()
(ile, m) = (0, n // 2)
if s > tab[m]:
	while m < n and tab[m] < s:
		ile += s - tab[m]
		m += 1
else:
	while m >= 0 and tab[m] > s:
		ile += tab[m] - s
		m -= 1
print(ile)


from collections import Counter, defaultdict, deque
read = lambda : list(map(int, input().split()))
getinfo = lambda grid: print(list(map(print, grid)))
p = lambda x: print(x, end=' ')
mod = 10 ** 9 + 7
inf = float('inf')

def solve(a, s):
	res = 0
	index = len(a) // 2
	if a[index] == s:
		return 0
	elif a[index] < s:
		while index < n and a[index] < s:
			res += s - a[index]
			index += 1
		return res
	else:
		while index >= 0 and a[index] > s:
			res += a[index] - s
			index -= 1
		return res
(n, s) = read()
a = read()
a.sort()
print(solve(a, s))


(n, s) = list(map(int, input().split()))
arr = input().split()
(countm, countb, counte, ans) = (0, 0, 0, 0)
for i in range(len(arr)):
	arr[i] = int(arr[i])
	if arr[i] < s:
		countm += 1
	elif arr[i] > s:
		countb += 1
	else:
		counte += 1
arr.sort()
if countm > countb:
	i = countm - 1
	while countb + counte - 1 < countm:
		ans += s - arr[i]
		i -= 1
		counte += 1
		countm -= 1
elif countb > countm:
	i = countm + counte
	while countm + counte - 1 < countb:
		ans += arr[i] - s
		i += 1
		counte += 1
		countb -= 1
print(ans)


R = lambda : map(int, input().split())
(n, s) = R()
a = sorted(R())
m = n // 2
print(abs(a[m] - s) + sum((max(0, x - s) for x in a[:m])) + sum((max(0, s - x) for x in a[m + 1:])))


(n, target) = [int(i) for i in input().split(' ')]
a = [int(i) for i in input().split(' ')]
a = sorted(a)
med = n // 2
ans = 0
for i in range(len(a)):
	if i < med:
		if a[i] > target:
			ans += a[i] - target
	elif i == med:
		ans += abs(target - a[i])
	elif a[i] < target:
		ans += target - a[i]
print(ans)


(m, n) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
ans = 0
for i in range(m):
	if i <= int((m - 1) / 2) and a[i] > n:
		ans += a[i] - n
	elif i >= int((m - 1) / 2) and a[i] < n:
		ans += n - a[i]
print(ans)


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


from collections import Counter
import string
import math
import sys
from fractions import Fraction

def array_int():
	return [int(i) for i in sys.stdin.readline().split()]

def vary(arrber_of_variables):
	if arrber_of_variables == 1:
		return int(sys.stdin.readline())
	if arrber_of_variables >= 2:
		return map(int, sys.stdin.readline().split())

def makedict(var):
	return dict(Counter(var))
testcases = 1
for _ in range(testcases):
	(n, s) = vary(2)
	num = sorted(array_int())
	med = num[n // 2]
	if med == s:
		print(0)
	else:
		ans = 0
		if med < s:
			for i in range(n // 2, n):
				if s >= num[i]:
					ans += abs(num[i] - s)
		elif med > s:
			for i in range(n // 2, -1, -1):
				if s <= num[i]:
					ans += abs(s - num[i])
		print(ans)


(n, s) = map(int, input().split())
li = list(map(int, input().split()))
li.sort()
i = 0
mid = n // 2
out = abs(li[mid] - s)
li[mid] = s
while i < mid:
	if li[i] > s:
		out += abs(s - li[i])
	i += 1
i += 1
while i < n:
	if li[i] < s:
		out += abs(s - li[i])
	i += 1
print(out)


(n, k) = map(int, input().split())
temp = [int(x) for x in input().split()]
temp.sort()
m = temp[int((n - 1) / 2)]
ans = 0
if m < k:
	for i in temp[int((n - 1) / 2):]:
		if i >= k:
			break
		ans += k - i
elif m > k:
	for i in temp[::-1][int((n - 1) / 2):]:
		if i <= k:
			break
		ans += i - k
print(ans)


(n, s) = map(int, input().split())
if n == 1:
	t = int(input())
	if t == s:
		print('0')
	elif t > s:
		print(t - s)
	else:
		print(s - t)
else:
	a = list(map(int, input().split()))
	a.sort()
	center_pos = n // 2
	if [1, 2][1] == 2:
		while center_pos * 2 < n:
			center_pos += 1
		while center_pos * 2 > n:
			center_pos -= 1
		n -= 1
	else:
		while center_pos * 2 > n:
			center_pos -= 1
		while center_pos * 2 < n:
			center_pos += 1
	t = a[center_pos]
	if t == s:
		print('0')
	elif t > s:
		res = t - s
		center_pos -= 1
		while center_pos > 1 and a[center_pos] > s:
			res += a[center_pos] - s
			center_pos -= 1
		if center_pos == 1 and a[1] > s:
			res += a[1] - s
			if a[center_pos - 1] > s:
				res += a[center_pos - 1] - s
		print(res)
	else:
		res = s - t
		center_pos += 1
		while center_pos <= n and a[center_pos] < s:
			res += s - a[center_pos]
			center_pos += 1
		print(res)


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


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
if l[n // 2] == k:
	print(0)
	exit(0)
if l[n // 2] < k:
	ans = 0
	for i in range(n // 2, n):
		if l[i] < k:
			ans += abs(k - l[i])
		else:
			break
	print(ans)
else:
	ans = 0
	for i in range(n // 2, -1, -1):
		if l[i] > k:
			ans += abs(k - l[i])
		else:
			break
	print(ans)


(n, s) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
if s <= l[0]:
	ans = 0
	ans2 = 0
	for i in range(n // 2):
		ans += abs(s - l[i])
	ans += abs(l[n // 2] - s)
	print(ans)
elif s > l[-1]:
	ans = 0
	ans2 = 0
	for i in range(n // 2 + 1, n):
		ans += abs(s - l[i])
	ans += abs(l[n // 2] - s)
	print(ans)
else:
	ans1 = 0
	ans2 = 0
	for i in range(n // 2):
		if s < l[i]:
			ans1 += abs(s - l[i])
	for i in range(n // 2 + 1, n):
		if s > l[i]:
			ans1 += abs(s - l[i])
	ans1 += abs(s - l[n // 2])
	print(ans1)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
med = l[n // 2]
ans = 0
if med < m:
	for i in range(n // 2, n):
		ans += max(0, m - l[i])
else:
	for i in range(n // 2, -1, -1):
		ans += max(0, l[i] - m)
print(ans)


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


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)


def editor():
	import sys
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def solve():
	(n, s) = map(int, input().split())
	a = [int(x) for x in input().split()]
	a.sort()
	mid = n // 2
	steps = 0
	if a[mid] < s:
		for i in range(mid, n):
			steps += max(0, s - a[i])
	elif a[mid] > s:
		for i in range(mid + 1):
			steps += max(0, a[i] - s)
	print(steps)
solve()


import bisect
(n, s) = map(int, input().split())
a = list(sorted(map(int, input().split())))
pos = bisect.bisect_left(a, s)
if pos < n // 2:
	summ = sum(a[pos:n // 2 + 1])
	cnt = n // 2 - pos + 1
elif pos > n // 2:
	summ = sum(a[n // 2:pos])
	cnt = pos - n // 2
else:
	summ = a[n // 2]
	cnt = 1
print(abs(summ - cnt * s))


def ok(arr1, k):
	n = len(arr1)
	arr1.sort()
	ans = 0
	if arr1[n // 2] > k:
		for i in range(n // 2, -1, -1):
			if arr1[i] < k:
				break
			ans += abs(arr1[i] - k)
	else:
		for i in range(n // 2, n):
			if arr1[i] > k:
				break
			ans += abs(arr1[i] - k)
	return ans
(n, k) = map(int, input().split())
arr1 = list(map(int, input().split()))
print(ok(arr1, k))


import sys
input = sys.stdin.readline

def ceil(x, y):
	return (x + y - 1) // y

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def nCr(n, k):
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def upper_bound(a, x, lo=0):
	hi = len(a)
	while lo < hi:
		mid = (lo + hi) // 2
		if a[mid] < x:
			lo = mid + 1
		else:
			hi = mid
	return lo

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(10000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

def int_array():
	return list(map(int, input().strip().split()))

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
(n, s) = int_array()
a = sorted(int_array())
ans = 0
for i in range(n):
	if i < n // 2:
		if a[i] > s:
			ans += abs(a[i] - s)
	elif i == n // 2:
		ans += abs(a[i] - s)
	elif a[i] < s:
		ans += abs(a[i] - s)
print(ans)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
b = list(enumerate(a))
b = sorted(b, key=lambda x: x[1])
med = b[n // 2][1]
ans = 0
if med == s:
	print(0)
	exit()
if med < s:
	for i in range(n // 2, n):
		ans += max(s - b[i][1], 0)
else:
	for i in range(n // 2 + 1):
		ans += max(b[i][1] - s, 0)
print(ans)


(N, S) = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
mn = (N - 1) // 2
ans = 0
if A[mn] < S:
	for n in range(mn, N):
		ans += max(0, S - A[n])
elif A[mn] > S:
	for n in range(0, mn + 1):
		ans += max(0, A[n] - S)
print(ans)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
lowa = []
higha = []
for i in a:
	if i >= s:
		higha.append(i - s)
	elif i < s:
		lowa.append(s - i)
arr = higha if len(higha) > len(lowa) else lowa
arr = sorted(arr)
mid = (2 * len(arr) - len(a)) // 2
result = sum(arr[0:mid + 1])
print(result)


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import *
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().replace('\n', '').strip()

def grid(r, c):
	return [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
(n, x) = tup()
ls = lint()
ls.sort()
s = sum((max(0, ls[i] - x) if i < n // 2 else max(0, x - ls[i]) for i in range(n))) + abs(ls[n // 2] - x) - max(0, x - ls[n // 2])
print(s)
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


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


(n, s) = [int(s) for s in input().split(' ')]
arr = [int(s) for s in input().split(' ')]
arr_plus = []
arr_minus = []
found_zero = False
min_plus = 10 ** 9 + 1
max_minus = -10 ** 9 - 1
for i in range(n):
	arr[i] -= s
	if arr[i] < 0:
		arr_minus.append(arr[i])
		max_minus = max(max_minus, arr[i])
	elif arr[i] > 0:
		arr_plus.append(arr[i])
		min_plus = min(min_plus, arr[i])
	else:
		found_zero = True
temp = 0
if len(arr_plus) > n // 2:
	arr_plus.sort()
	delta = len(arr_plus) - n // 2
	temp = sum(arr_plus[:delta])
elif len(arr_minus) > n // 2:
	arr_minus.sort()
	delta = len(arr_minus) - n // 2
	temp = abs(sum(arr_minus[-delta:]))
print(temp)


import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)

def getIntList():
	return list(map(int, input().split()))
try:
	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())
(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)


from sys import stdin

def ii():
	return int(stdin.readline())

def mi():
	return map(int, stdin.readline().split())

def li():
	return list(mi())

def si():
	return stdin.readline()
(n, p) = mi()
a = li()
a.sort()
m = n // 2
x = 0
if p >= a[m]:
	for i in range(m, n):
		if a[i] < p:
			x += p - a[i]
		else:
			break
else:
	for i in range(m, -1, -1):
		if a[i] > p:
			x += a[i] - p
		else:
			break
print(x)


(n, s) = map(int, input().split())
l = sorted(list(map(int, input().split())))
k = 0
if s <= l[n // 2]:
	k += l[n // 2] - s
	l[n // 2] = s
	w = n // 2 - 1
	while l[w] > l[n // 2] and w > -1:
		k += abs(l[w] - s)
		l[w] = s
		w -= 1
else:
	k += s - l[n // 2]
	l[n // 2] = s
	w = n // 2 + 1
	while w < n and l[w] < l[n // 2]:
		k += abs(l[w] - s)
		l[w] = s
		w += 1
print(k)


(n, m) = map(int, input().split())
array = list(map(int, input().split()))
flag = 0
greater = []
smaller = []
ptr1 = 0
ptr2 = 0
if n == 1:
	print(abs(array[0] - m))
else:
	for i in range(n):
		if array[i] < m:
			smaller.append(m - array[i])
			ptr2 += 1
		elif array[i] > m:
			greater.append(array[i] - m)
			ptr1 += 1
		else:
			flag += 1
	if flag > 1:
		while flag != 1:
			greater.append(0)
			ptr1 += 1
			flag -= 1
	greater.sort()
	smaller.sort()
	ans = 0
	j = 0
	if ptr2 > ptr1:
		while ptr2 != n // 2:
			ptr1 += 1
			ptr2 -= 1
			ans += smaller[j]
			j += 1
	elif ptr2 < ptr1:
		while ptr1 != n // 2:
			ptr1 -= 1
			ptr2 += 1
			ans += greater[j]
			j += 1
	print(ans)


first = input()
first = first.split()
n = int(first[0])
s = int(first[1])
sec = input()
sec = sec.split()
for i in range(len(sec)):
	sec[i] = int(sec[i])
sec.sort()
mid = int(n / 2)
if sec[mid] == s:
	print(0)
else:
	count = abs(sec[mid] - s)
	sec[mid] = s
	for i in range(mid + 1, n):
		if sec[i] >= s:
			break
		else:
			count += abs(sec[i] - s)
	j = mid - 1
	while j >= 0:
		if sec[j] <= s:
			break
		else:
			count += abs(sec[j] - s)
		j -= 1
	print(count)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

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

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def main():
	(n, s) = LI()
	a = sorted(LI())
	m = n // 2
	r = abs(s - a[m])
	for i in range(m + 1, n):
		if a[i] >= s:
			break
		r += s - a[i]
	for i in range(m - 1, -1, -1):
		if a[i] <= s:
			break
		r += a[i] - s
	return r
print(main())


(n, s) = list(map(int, input().split()))
a = list(map(int, input().split()))
a = sorted(a)
diff = abs(s - a[n // 2])
if s > a[n // 2]:
	for x in a[n // 2 + 1:]:
		if x < s:
			diff += abs(s - x)
elif s < a[n // 2]:
	for x in a[:n // 2]:
		if x > s:
			diff += abs(x - s)
print(diff)


import heapq
(n, m) = list(map(int, list(input().split())))
list = list(map(int, input().split()))
more = []
less = []
amount_mid = 0
amount_more = 0
amount_less = 0
for el in list:
	if el > m:
		amount_more += 1
		more.append(el - m)
	elif el < m:
		amount_less += 1
		less.append(m - el)
	else:
		amount_mid += 1
need_to_change = max(abs(amount_more - amount_less) - max(amount_mid - 1, 0), 0)
if need_to_change % 2 == 1:
	need_to_change //= 2
	need_to_change += 1
else:
	need_to_change //= 2
changes = 0
if need_to_change > 0:
	if amount_more > amount_less:
		different = heapq.nsmallest(need_to_change, more)
	else:
		different = heapq.nsmallest(need_to_change, less)
	for el in different:
		changes += el
print(changes)


import sys
input = sys.stdin.readline
(n, s) = map(int, input().split())
ans = 0
l = sorted(list(map(int, input().split())))
m = n // 2
ans += abs(s - l[m])
for i in range(m):
	if l[i] > s:
		ans += abs(l[i] - s)
for i in range(m + 1, n):
	if l[i] < s:
		ans += abs(l[i] - s)
print(ans)


import sys
in_lines = [line.rstrip() for line in sys.stdin]
(n, s) = map(int, in_lines[0].split())
arr = map(int, in_lines[1].split())

def do(n, s, arr):
	c = 0
	arr = sorted(arr)
	for i in range(n // 2):
		if arr[i] > s:
			c += arr[i] - s
		if arr[n - i - 1] < s:
			c += s - arr[n - i - 1]
	return c + abs(arr[n // 2] - s)
print(do(n, s, arr))


def go():
	(n, s) = [int(i) for i in input().split(' ')]
	a = [int(i) for i in input().split(' ')]
	a.sort()
	x = 0
	for i in range(n // 2):
		x += max(0, a[i] - s)
		x += max(0, s - a[n - i - 1])
	x += abs(a[n // 2] - s)
	return x
print(go())


import bisect
inp = input().split()
n = int(inp[0])
s = int(inp[1])
arr = list(map(lambda x: int(x), input().split()))
arr.sort()
ans = 0
for i in range(0, n // 2):
	if arr[i] > s:
		ans += arr[i] - s
	if arr[n - 1 - i] < s:
		ans += s - arr[n - 1 - i]
print(ans + abs(arr[n // 2] - s))


(n, s) = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort()
m = n // 2
cnt = int(0)
if a[m] == s:
	cnt = int(0)
elif a[m] < s:
	for i in range(m, n):
		if a[i] < s:
			cnt += s - a[i]
		else:
			break
elif a[m] > s:
	for i in range(m, -1, -1):
		if a[i] > s:
			cnt += a[i] - s
		else:
			break
print(cnt)


(n, s) = list(map(int, input().strip().split(' ')))
a = sorted(list(map(int, input().strip().split(' '))))
i = n // 2
inc = 0
if a[i] < s:
	while True:
		if i == n or a[i] >= s:
			break
		else:
			inc += s - a[i]
			i += 1
elif a[i] > s:
	while True:
		if i == -1 or a[i] <= s:
			break
		else:
			inc += a[i] - s
			i -= 1
else:
	inc = 0
print(inc)


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


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


from sys import stdin
(n, s) = map(int, stdin.readline().split())
a = [int(x) for x in stdin.readline().split()]
a.sort()
med = a[n // 2]
ans = 0
if med < s:
	for i in range(n // 2, n):
		if a[i] < s:
			ans += s - a[i]
		else:
			break
elif med > s:
	for i in range(n // 2, -1, -1):
		if a[i] > s:
			ans += a[i] - s
		else:
			break
print(ans)


(n, s) = [int(x) for x in input().split()]
a = sorted([int(x) for x in input().split()])
if a[n // 2] == s:
	print(0)
elif a[n // 2] < s:
	print(sum([max(0, s - x) for x in a[n // 2:n]]))
else:
	print(sum([max(0, x - s) for x in a[:n // 2 + 1]]))


import sys
import math
sys.setrecursionlimit(100000)
input = sys.stdin.readline

def inp():
	return int(input())

def inara():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())
(n, k) = invr()
ara = inara()
ara.sort()
ans = 0
for i in range(n // 2, n):
	if ara[i] <= k:
		ans += k - ara[i]
for i in range(n // 2 + 1):
	if ara[i] >= k:
		ans += ara[i] - k
print(ans)


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


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


(n, m) = map(int, input().split())
lis = list(map(int, input().split()))
lis.sort()
if len(lis) == 1:
	print(abs(m - lis[0]))
	exit()
median_index = n // 2
median = lis[n // 2]
ans = abs(median - m)
if lis[median_index + 1] >= m and lis[median_index - 1] <= m:
	print(ans)
elif lis[median_index + 1] < m:
	ans += abs(lis[median_index + 1] - m)
	median_index += 2
	while median_index < len(lis) and lis[median_index] < m:
		ans += abs(lis[median_index] - m)
		median_index += 1
	print(ans)
elif lis[median_index - 1] > m:
	ans += abs(lis[median_index - 1] - m)
	median_index -= 2
	while median_index >= 0 and lis[median_index] > m:
		ans += abs(lis[median_index] - m)
		median_index -= 1
	print(ans)


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


(n, s) = [int(x) for x in input().split()]
L = [int(x) for x in input().split()]
L.sort()
t = (n - 1) // 2
index = t
if L[t] < s:
	while index < n and L[index] < s:
		index += 1
	A = 0
	for j in range(t, index):
		A += s - L[j]
elif L[t] > s:
	while index > -1 and L[index] > s:
		index += -1
	A = 0
	for j in range(t, index, -1):
		A += L[j] - s
else:
	A = 0
print(A)


t = 1
for test in range(1, t + 1):
	(n, s) = map(int, input().split())
	a = list(map(int, input().split()))
	a.sort()
	mid = n // 2
	ans = 0
	if a[mid] - s > 0:
		ind = mid
		while ind > -1 and a[ind] > s:
			ans += a[ind] - s
			ind -= 1
	else:
		ind = mid
		while ind < n and a[ind] < s:
			ans += s - a[ind]
			ind += 1
	print(ans)


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


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
operations = 0
a = sorted(a)
median_pos = n // 2
try:
	index = a.index(s)
except:
	index = len(a)
	for (idx, val) in enumerate(a):
		if val > s:
			if idx <= median_pos:
				idx -= 1
			index = idx
			break
to_change = []
if median_pos < index:
	to_change = a[median_pos:index]
if median_pos > index:
	to_change = a[index + 1:median_pos + 1]
operations += abs(sum(to_change) - s * len(to_change))
print(operations)


MOD = 10 ** 9 + 7
I = lambda : list(map(int, input().split()))
(n, s) = I()
l = I()
l.sort()
ans = 0
m = n // 2
if l[m] == s:
	ans = 0
elif l[m] < s:
	ans = 0
	for i in range(m, n):
		if l[i] < s:
			ans += abs(l[i] - s)
else:
	ans = 0
	for i in range(m, -1, -1):
		if l[i] > s:
			ans += abs(l[i] - s)
print(ans)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
mid = (n - 1) // 2
import bisect
suma = 0
if s > a[mid]:
	val = bisect.bisect_left(a, s)
	for i in range(mid, val):
		suma += s - a[i]
	print(suma)
elif s < a[mid]:
	val = bisect.bisect_right(a, s)
	for i in range(val, mid + 1):
		suma += abs(s - a[i])
	print(suma)
else:
	print(0)


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


import bisect
(n, m) = [int(a) for a in input().split(' ')]
a = [int(a) for a in input().split(' ')]
a.sort()
pos = bisect.bisect(a, m)
ans = 0
if pos > int(n / 2):
	for i in range(int(n / 2), pos):
		ans += abs(m - a[i])
else:
	for i in range(pos, int(n / 2) + 1):
		ans += abs(a[i] - m)
print(ans)


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


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
(i, j) = (n // 2, 0)
if s[i] < m:
	while i < n and s[i] < m:
		j += m - s[i]
		i += 1
else:
	while i >= 0 and s[i] > m:
		j += s[i] - m
		i -= 1
print(j)


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


number = input().split()
n = int(number[0])
s = int(number[1])
a = list(map(int, input().split()))
a = sorted(a)
step = 0
mid = int(n / 2)
if s < a[mid]:
	step += a[mid] - s
	a[mid] = s
	i = mid
	while i > 0:
		if a[i] >= a[i - 1]:
			break
		else:
			step += a[i - 1] - a[i]
			a[i - 1] = a[i]
			i -= 1
elif s > a[mid]:
	step += s - a[mid]
	a[mid] = s
	i = mid
	while i < n - 1:
		if a[i] <= a[i + 1]:
			break
		else:
			step += a[i] - a[i + 1]
			a[i + 1] = a[i]
			i += 1
print(step)


from sys import *
from math import *
(n, k) = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
a.sort()
p = n // 2
if a[p] == k:
	print(0)
else:
	if a[p] > k:
		x = -1
	else:
		x = 1
	ans = 0
	for i in range(n // 2 + 1):
		if x == -1:
			if a[p - i] > k:
				ans += abs(a[p - i] - k)
		if x == 1:
			if a[p + i] < k:
				ans += abs(a[p + i] - k)
	print(ans)


(n, s) = map(int, input().split())
a = [-1] + list(map(int, input().split())) + [1000000001]
a.sort()
ans = 0
i = n // 2 + 1
if a[i] < s:
	while a[i] < s:
		ans += s - a[i]
		i += 1
else:
	while a[i] > s:
		ans += a[i] - s
		i -= 1
print(ans)


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


(m, n) = map(int, input().split())
l = [int(i) for i in input().split()]
l.sort()
if n >= l[(m - 1) // 2]:
	sumi = n - l[(m - 1) // 2]
	for i in range((m - 1) // 2 + 1, len(l)):
		if l[i] < n:
			sumi += n - l[i]
		else:
			break
	print(sumi)
else:
	sumi = l[(m - 1) // 2] - n
	for i in reversed(range(0, (m - 1) // 2)):
		if l[i] > n:
			sumi += l[i] - n
		else:
			break
	print(sumi)


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


(n, m) = map(int, input().split())
a = sorted([i for i in map(int, input().split())])
c = 0
for i in range(int(n / 2)):
	c += max(0, a[i] - m)
	c += max(0, m - a[-1 - i])
c += abs(a[int(n / 2)] - m)
print(c)


(n, m) = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
i = (n - 1) // 2
res = 0
if m > l[i]:
	while l[i] < m:
		res += m - l[i]
		i += 1
		if i == n:
			break
elif m < l[i]:
	while l[i] > m:
		res += l[i] - m
		i -= 1
		if i < 0:
			break
print(res)


from bisect import bisect_left, bisect_right
(n, s) = map(int, input().split(' '))
a = sorted(list(map(int, input().split(' '))))
bl = bisect_left(a, s)
br = bisect_right(a, s)
if bl <= n // 2 and br >= n // 2:
	print(abs(a[n // 2] - s))
elif bl < n // 2 and br < n // 2:
	print(sum(map(lambda x: abs(s - x), a[br:n // 2 + 1])))
elif bl > n // 2 and br > n // 2:
	print(sum(map(lambda x: abs(s - x), a[n // 2:bl])))


import sys
import math

def main():
	(n, s) = [int(x) for x in sys.stdin.readline().split(' ')]
	nums = [int(x) for x in sys.stdin.readline().split(' ')]
	low = []
	high = []
	sCount = 0
	numChanges = 0
	for x in nums:
		if x == s:
			sCount += 1
		elif x < s:
			low.append(x)
		else:
			high.append(x)
	low.sort()
	low.reverse()
	high.sort()
	diff = len(high) - len(low)
	midPoint = n // 2
	biggerLength = max(len(low), len(high))
	changesNeeded = biggerLength - midPoint
	if diff > sCount:
		for i in range(changesNeeded):
			numChanges += high[i] - s
	elif diff < sCount:
		for i in range(changesNeeded):
			numChanges += s - low[i]
	return numChanges
print(main())


fast = lambda : stdin.readline().strip()
zzz = lambda : [int(i) for i in fast().split()]
(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from re import *
from sys import *
from math import *
from heapq import *
from queue import *
from bisect import *
from string import *
from itertools import *
from collections import *
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from collections import Counter as cc
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer):
	stdout.write(str(answer))
(n, m) = zzz()
arr = szzz()
p = n // 2
mid = arr[p]
ans = 0
if mid > m:
	for i in range(p + 1):
		if arr[i] > m:
			ans += arr[i] - m
if mid < m:
	for i in range(p, n):
		if m > arr[i]:
			ans += m - arr[i]
print(ans)


(n, m) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
c = 0
mid = s[n // 2]
if mid < m:
	i = n // 2
	while i < n and s[i] < m:
		c = c + abs(s[i] - m)
		i = i + 1
elif mid > m:
	i = n // 2
	while i >= 0 and s[i] > m:
		c = c + abs(s[i] - m)
		i = i - 1
print(c)


def mi():
	return map(int, input().split())
(n, k) = mi()
a = list(mi())
a.sort()
ans = 0
if a[n // 2] < k:
	ans += abs(a[n // 2] - k)
	a[n // 2] = k
	for i in range(n // 2 + 1, n):
		if a[i] < a[i - 1]:
			ans += a[i - 1] - a[i]
			a[i] = a[i - 1]
elif a[n // 2] > k:
	ans += abs(a[n // 2] - k)
	a[n // 2] = k
	for i in range(n // 2 - 1, -1, -1):
		if a[i] > a[i + 1]:
			ans += a[i] - a[i + 1]
			a[i] = a[i + 1]
print(ans)


(n, s) = map(int, input().split())
a = list(map(int, input().split()))
a.append(s)
a.sort()
x = a.index(s)
n += 1
if x >= n / 2:
	z = 0
	for t in range(n // 2 - 1, x):
		z += s - a[t]
	print(abs(z))
else:
	z = 0
	for t in range(x + 1, n // 2 + 1):
		z += s - a[t]
	print(abs(z))


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