Problem:
 Score : 200 points    Problem Statement There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right.  Initially, you are in Square X .
You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N .
However, for each i = 1, 2, ..., M , there is a toll gate in Square A_i , and traveling to Square A_i incurs a cost of 1 .
It is guaranteed that there is no toll gate in Square 0 , Square X and Square N .  Find the minimum cost incurred before reaching the goal.      Constraints  1 \leq N \leq 100  1 \leq M \leq 100  1 \leq X \leq N - 1  1 \leq A_1 < A_2 < ... < A_M \leq N  A_i \neq X  All values in input are integers.         Input Input is given from Standard Input in the following format:  N  M  X  A_1  A_2  ...  A_M       Output Print the minimum cost incurred before reaching the goal.        Sample Input 1 5 3 3
1 2 4      Sample Output 1 1  The optimal solution is as follows:   First, travel from Square 3 to Square 4 . Here, there is a toll gate in Square 4 , so the cost of 1 is incurred.  Then, travel from Square 4 to Square 5 . This time, no cost is incurred.  Now, we are in Square 5 and we have reached the goal.   In this case, the total cost incurred is 1 .       Sample Input 2 7 3 2
4 5 6      Sample Output 2 0  We may be able to reach the goal at no cost.       Sample Input 3 10 7 5
1 2 3 4 6 8 9      Sample Output 3 3

Solution (Python):

N, M, X = map(int, input().split())
A = list(map(int, input().split()))
tmp = 0
for i in range(M):
    if X < A[i]:
        tmp = i
        break
    else:
        pass
if tmp > M/2:
    print(M-tmp)
else:
    print(tmp)

Solution (Python):
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
ans1=0
ans2=0
for i in A:
    if i >=X:
        ans1+=1
    else:
        ans2+=1
print(min(ans1,ans2))

Solution (Python):
N, M, X = map(int, input().split())
*a, = map(int, input().split())

hot = [0] * N
for i in a:
    hot[i] = 1
ans = min(sum(hot[:X]), sum(hot[X + 1 :]))
print(ans)

Solution (Python):
x,m,x=map(int,input().split())
a=list(map(int,input().split()))
a.append(x)
a.sort()
start=len(a[:a.index(x)])
goal=len(a[a.index(x):])-1
print(min(start,goal))

Solution (Python):
n,m,x = map(int,input().split())
a=list(map(int,input().split()))
s_cnt = 0
b_cnt = 0
for num in a:
  if num < x:
    s_cnt += 1
  else:
    b_cnt += 1
print(min(s_cnt,b_cnt))

Solution (Python):
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*N

for i in A:
  B[i]=1


print(min(sum(B[X:]),sum(B[:X])))

Solution (Python):
N,M,X = map(int,(input().split()))
AList = list(map(int,input().split()))
left = 0
right = 0
for a in AList:
    if a < X:
        left += 1
    elif a > X:
        right += 1
print(min(left,right))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
low = 0
high = 0
for i in range(m):
  if(a[i]<x):
    low += 1
  else:
    high += 1
print(min(low, high))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
     
a.append(x)
a.sort()
     
i = a.index(x)
print(min(i, m - i))

Solution (Python):
n, m, x = map(int, input().split())

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

to_0_cost = len(list(filter(lambda v: v < x, a)))
to_n_cost = len(list(filter(lambda v: v > x, a)))

print(min(to_0_cost, to_n_cost))

Solution (Python):
n,m,x=map(int,input().split())
s=sum(int(i)<x for i in input().split())
print(min(s,m-s))

Solution (Python):
n,m,x=map(int,input().split())
s=list(map(int,input().split()))
a=0
b=0
for i in s:
    if i<x:
        a+=1
    else:
        b+=1
print(min(a,b))

Solution (Python):
[n,m,x]=list(map(int,input().split()))
a=list(map(int,input().split()))

anslist=[0]*(n+1)
for i in a:
  anslist[i]=1
print(min(sum(anslist[:x]),sum(anslist[x:n])))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

right = len([int(i) for i in a if x < i])
left = len([int(i) for i in a if x > i])

print(min(right, left))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
l = []

right = [l for i in a if x < i]
left = [l for i in a if x > i]

print(min(len(right), len(left)))

Solution (Python):
n, m, x = map(int, input().split())
a_list = list(map(int, input().split()))

cost_1 = 0

current = x
while current != n:
    current += 1
    if current in a_list:
        cost_1 += 1

cost_2 = 0
current = x
while current != 0:
    current -= 1
    if current in a_list:
        cost_2 += 1

print(min(cost_1, cost_2))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

right = 0
for i in range(X, N+1):
    if i in A:
        right += 1

left = 0
for i in range(0, X)[::-1]:
    if i in A:
        left += 1

print(min(left, right))

Solution (Python):
n, m, x = list(map(int, input().split()))

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

b = 0
c = 0

for i in a:
    if i < x:
        b += 1
    else:
        c += 1
print(min(b, c))

Solution (Python):
N,M,X = map(int, input().strip().split(' '))
A = list(map(int, input().strip().split(' ')))

to0 = len([a for a in A if a < X])
print(min(to0, M-to0))

Solution (Python):
import numpy as np

n, m, x = map(int, input().split())
a_list = np.array(list(map(int, input().split())))

upper = np.sum((a_list > x))
lower = len(a_list) - upper

print(min(lower, upper))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
ans1 = 0
ans2 = 0
for i in range(x+1, n+1):
        if i in a:
                ans1 += 1

for i in range(x):
        if i in a:
                ans2 += 1
print(min(ans1, ans2))

Solution (Python):
n,m,x = map(int, input().split())
a = list(map(int,input().split()))
cost = (n+1)*[0]
for i in range(len(a)):
    cost[a[i]] = 1

c1 = cost[0:x]
c2 = cost[x+1:n+1]
print(min(sum(c1),sum(c2)))

Solution (Python):


N,M,X = map(int, input().split())

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

A.append(X)




A.sort()

X_index = int(A.index(X))


t = len(A)




diff_s = X_index
diff_b = t - X_index - 1





if diff_b == 0 or diff_s == 0:
  print(0)
elif diff_b < diff_s:
  print(diff_b)
else:
  print(diff_s)

Solution (Python):

from bisect import bisect_left


def main():
    N, M, X, *A = map(int, open(0).read().split())
    A.sort()
    cur = bisect_left(A, X)
    ans = min(cur, M - cur)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
n, m, x = map(int, input().split())
cnt = sum(x > i for i in list(map(int, input().split())))
print(min(cnt, m - cnt))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = sum(x > i for i in a)
print(min(cnt, m - cnt))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(m):
    if a[i] < x:
        cnt += 1
    else:
        break
print(min(cnt, m - cnt))

Solution (Python):
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
l = 0
r = 0
for a in A:
    if a < x:
        l += 1
    else:
        r += 1
print(min(l,r))

Solution (Python):
import bisect

n, m, x = map(int, input().split())
ls = list(map(int, input().split()))
l = bisect.bisect(ls, x)
print(min(l, m - l))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
count_f = 0
count_b = 0
for i in range(len(a)):
    if a[i] < x:
        count_f += 1
    elif a[i] > x:
        count_b += 1
print(min(count_f, count_b))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
C_L = 0
C_R = 0
for i in range(M):
  if A[i] < X:
    C_L += 1
  elif A[i] >X:
    C_R += 1
print(min(C_L, C_R))

Solution (Python):
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
cost1 = 0
for i in range(X):
  if i in A:
    cost1 += 1
cost2 = 0
for i in range(X+1,N+1):
  if i in A:
    cost2 += 1
print(min(cost1,cost2))

Solution (Python):
import numpy as np
N, M, X = map(int, input().split())
*A,     = map(int, input().split())



sum_right = 0
sum_left  = 0

I         = np.zeros((1, N+1))
I[0][0]   = 0
I[0][N]   = 0
I[0][X]   = 0

for i in A:
    I[0][i] = 1

print(int(min(np.sum(I[0][0:X]), np.sum(I[0][X:N+1]))))

Solution (Python):
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
A = B = 0
for i in range(m):
    if a[i] < x:
        A += 1
    else:
        B += 1
print(min(A,B))

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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

left = 0
right = 0
for i in a:
    if (i > x):
        left += 1
    else:
        right += 1
print(min(left, right))

Solution (Python):
n, m, x = map(int, input().split())
a = map(int, input().split())
cnt = sum( x < i for i in a)
print(min(cnt,m - cnt))

Solution (Python):
import bisect
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
t = bisect.bisect(a, x)
print(min(len(a[:t]), len(a[t:])))

Solution (Python):
n,m,x=map(int,input().split())
*a,=map(int,input().split())
cnt=sum(i>x for i in a)
print(min(cnt,m-cnt))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
a = 0
b = 0

for i in A:
    if i > X:
        a += 1
    else:
        b += 1

print(min(a, b))

Solution (Python):
N, M, X = map(int, input().split())
n = sum(int(i) < X for i in list(map(int, input().split())))
print(min(n, M - n))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

lst = [0] * (N+1)
for a in A:
    lst[a] = 1
print(min(sum(lst[:X]), sum(lst[X:])))

Solution (Python):
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
cntt=0

for i in a:
	if i<x:
		cnt+=1
	if i>x:
		cntt+=1
		
print(min(cnt,cntt))

Solution (Python):
n, m, x = map(int, input().split())
As = list(map(int, input().split()))
count1 = 0
count2 = 0
for i in range(x, n + 2):
    if i in As and i != n and i != 0 and i != x:
        count1 += 1
for i in range(0, x):
    if i in As and i != n and i != 0 and i != x:
        count2 += 1
print(min(count1, count2))

Solution (Python):
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
cost = [0]*N
for i in A: cost[i] = 1
print(min(sum(cost[X:]),sum(cost[:X+1])))

Solution (Python):
n, m, x = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = []
pos = x
cost = 0
for i in range(0, x):
  pos -= 1
  if pos in a:
    cost += 1
ans.append(cost)
pos = x
cost = 0
for i in range(x, n):
  pos += 1
  if pos in a:
    cost += 1
ans.append(cost)
print(min(ans))

Solution (Python):
n, m, x = map(int, input().split())
A = [int(num) for num in input().split()]

cost_0 = 0
cost_n = 0
for num in A:
  if num < x:
    cost_0 += 1
  else:
    cost_n += 1
  
print(min(cost_0, cost_n))

Solution (Python):
N, M, X = list(map(int, input().split()))
A = list(map(int, input().split()))
cost1 = 0
for i in range(X, 0, -1):
    if i in A:
        cost1 += 1
cost2 = 0
for i in range(X, N):
    if i in A:
        cost2 += 1
print(min(cost1, cost2))

Solution (Python):
N,M,X = map(int,input().split())
A = list(map(int,input().split()))

hidari = 0
migi = 0
for i in range(M):
    if A[i] < X:
        hidari += 1
    else:
        migi += 1
print(min(migi,hidari))

Solution (Python):
n,m,x = map(int,input().split())
a =list(map(int,input().split()))
c = [0]*(n+1)
for i in range(m):
    c[a[i]]=1
print(min(sum(c[:x+1]),sum(c[x:])))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

left = 0
right = 0
for i in range(m):
    if a[i] < x:
        left += 1
    else:
        right += 1

print(min(left, right))

Solution (Python):
n, m, x = map(int,input().split())
s = sum(int(i)<x for i in input().split())
print(min(s, m-s))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

left = sum(i < x for i in a)
right = sum(i > x for i in a)

print(min(left, right))

Solution (Python):
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
left=0
right=0
for i in a:
    if i<x:
        left+=1
    else:
        right+=1
print(min(left,right))

Solution (Python):

"""
Created on Tue Sep  3 23:09:02 2019

@author: Yamazaki Kenichi
"""

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

A.sort()
map_ = [0 for i in range(N+1)]

for a in A:
    map_[a] = 1

ans = min(sum(map_[0:X]),sum(map_[X+1:N+1]))
print(ans)

Solution (Python):


def main():


   N,M,X = map(int,input().split())
   tollList = list(map(int,input().split()))
   leftToll = [i for i in tollList if i < X]
   rightToll = [i for i in tollList if i > X]
   print(min(len(leftToll),len(rightToll)))




if __name__== "__main__":
    main()

Solution (Python):

import sys


def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N, M, X = ISI()
A = ILI()
cost_a = 0
cost_b = 0

for x in A:
    if x < X:
        cost_a += 1
    else:
        cost_b += 1
print(min(cost_a, cost_b))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

l = 0
r = 0
for a_ele in a:
    if a_ele < x:
        l += 1
    else:
        r += 1

print(min(l, r))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

c1 = 0
c2 = 0

for a in A:
  if a < X:
    c1 += 1
  else:
    c2 += 1
print(min(c1,c2))

Solution (Python):
k, m, x = map(int, input().split())
src = list(map(int, input().split()))
big = len(list(filter(lambda l: l>x, src)))
small = len(list(filter(lambda l: l<x, src)))
print(min(big,small))

Solution (Python):
(n, m, x) = (int(tok) for tok in input().split())
left = 0
right = 0

for pos in [int(tok) for tok in input().split()]:
  left += (1 if pos < x else 0)
  right += (1 if pos > x else 0)

print(min(left, right))

Solution (Python):
n, m, x = map(int,input().split())
a = sum([i<x for i in (map(int,input().split()))])
print(min(a,m-a))

Solution (Python):
n, m, x = map(int,input().split())
a = list(map(int,input().split()))
ary = [0 for _ in range(n+1)]
for i in range(m):
    ary[a[i]] += 1
print( min( sum(ary[:x]), sum(ary[x:])) )

Solution (Python):
n,m,x=map(int,input().split())
a=[int(i) for i in input().split()]
a=set(a)
ans=10**100
tmp=0
for i in range(x+1):
    if i in a:
        tmp+=1
ans=min(ans,tmp)
tmp=0
for i in range(x,n+1):
    if i in a:
        tmp+=1
ans=min(ans,tmp)
print(ans)

Solution (Python):
import bisect as b
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
tmp = b.bisect_left(a,x)

if tmp >= m-tmp:
  print(m-tmp)
else:
  print(tmp)

Solution (Python):
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
c = 0
d = m

for i in range(m):
  if a[i] < x:
    c += 1
    d -= 1

if c >= d:
  print(d)
else:
  print(c)

Solution (Python):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m, x = na()
aaa = na()
print(min(len([a for a in aaa if a < x]), len([a for a in aaa if a > x])))

Solution (Python):
N, M, X = map(int, input().split())
As = list(map(int, input().split()))
nl = len(list(filter(lambda A: A < X, As)))
nr = len(list(filter(lambda A: A > X, As)))
r = min(nl, nr)
print(r)

Solution (Python):
n, m, x = map(int, input().split())
As = sorted(list(map(int, input().split())))
a = 0
b = 0
for i in range(m):
    if As[i] < x:
        a += 1
    else:
        b += 1
print(min(a, b))

Solution (Python):
def main():
  N, M, X = map(int, input().split())
  a = list(map(int, input().split()))
  
  i = 0
  while i < M:
    if a[i] > X:
      break
    i += 1
  print(min(i, M - i))

if __name__ == "__main__":
  main()

Solution (Python):
from bisect import bisect
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
i = bisect(a, x)
print(min(i, m-i))

Solution (Python):
n,m,p = map(int,input().split())
a = list(map(int,input().split()))
up = len(list(filter(lambda x:x>p,a)))
down = len(list(filter(lambda x:x<p,a)))
print(min(up,down))

Solution (Python):
N,M,X=map(int,input().split())
cost=list(map(int,input().split()))
cost1=0
cost2=0
for i in cost:
  if i>X:
    cost2+=1
  elif i<X:
    cost1+=1
    
print(min(cost1,cost2))

Solution (Python):
N, M, X = map(int, input().split())
A_list = list(map(int, input().split()))

cost_to_zero = sum([1 for A in A_list if 0 < A < X])
cost_to_n = sum([1 for A in A_list if X < A < N])

print(min(cost_to_zero, cost_to_n))

Solution (Python):
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
cnt = 0
for x in A:
    if x<X:
        cnt += 1
print(min(cnt,M-cnt))

Solution (Python):
import bisect
n,m,x=map(int, input().split())
a=list(map(int, input().split()))
ind=bisect.bisect_right(a,x)
print(min(len(a[:ind]),len(a[ind:])))

Solution (Python):
n, m, x = map(int, input().split())
A = list(map(int, input().split()))

a = len([i for i in A if i < x])
b = len([i for i in A if i > x])
print(min(a, b))

Solution (Python):
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
print(min((len([i for i in a if i<x])),(len([i for i in a if i>x]))))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
goalA = 0
goalB = 0
for i in range(1, X):
    goalA += A.count(i)
for j in range(X + 1, N):
    goalB += A.count(j)
print(min(goalA, goalB))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split())) 

l = 0
r = 0
for i in range(M):
    if A[i] < X:
        l += 1
    else:
        r += 1

ans = min(l, r)
print(ans)

Solution (Python):
def test():
    n,m,x = map(int,input().split())
    a = list(map(int,input().split()))
    count1 = 0
    count2 = 0
    for i in range(x):
        if i in a:
            count1 += 1
    for i in range(x,n+1):
        if i in a:
            count2 += 1
    print(min(count1,count2))


if __name__ == "__main__":
    test()

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
print(min(len([a for a in A if a < X]), len([a for a in A if a > X])))

Solution (Python):
n,m,x=map(int,input().split())
b=[0]*(n+1)
A=list(map(int,input().split()))
for a in A:
  b[a]=1
c=0
for i in range(x):
  c+=b[i]
print(m-c if c>=m-c else c)

Solution (Python):
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
l,r=0,0
for i in range(len(a)):
  if a[i]<x:
    l=l+1
  elif a[i]>x:
    r=r+1
print(min(l,r))

Solution (Python):
n,m,x=map(int,input().split())
a=map(int,input().split())
left=0
right=0
for ai in a:
    if ai<x:
        left+=1
    else:
        right+=1
print(min(left,right))

Solution (Python):
n,m,x = map(int,input().split())
toll = list(map(int,input().split()))
left = 0
right = 0
for i in toll:
    if i < x :
        left += 1
    else:
        right += 1
print(min(left,right))

Solution (Python):
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
zero = 0
goal = 0
for i in range(m):
  if a[i]<x:
    zero+=1
  else:
    goal+=1
print(min(zero,goal))

Solution (Python):
n,m,starts=map(int,input().split())
li = list(map(int,input().split()))
cnt=0
q=0
while li[q]<starts:
  cnt+=1
  q+=1
print(min(cnt,len(li)-cnt))

Solution (Python):
def resolve():
    n, m, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    ans = min(sum([1 for ai in a if ai >= x]), sum([1 for ai in a if ai < x]))
    print(ans)


if __name__ == "__main__":
    resolve()

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

cnt = 0
for i in range(X,N):

  if i in A:
    cnt += 1
print (min(cnt, M-cnt))

Solution (Python):

n,m,x=map(int,input().split())

r=map(int,input().split())

toZero=0
for i in r:
  if i<x:toZero +=1 

print(min(toZero,m-toZero))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

zero_cost = 0
N_cost = 0
for a in A:
    if X < a:
        N_cost += 1
    else:
        zero_cost +=1
        
print(min(zero_cost, N_cost))

Solution (Python):
n, m ,x =map(int, input().split())
a = list(map(int, input().split()))
ans_l = 0
ans_r = 0

for i in range(x,0,-1):
    if i in a:
        ans_l += 1

for j in range(x,n):
    if j in a:
        ans_r += 1

print(min(ans_l, ans_r))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

a.append(x)
a.sort()

i = a.index(x)

print(min(i, m - i))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
A.append(X)
A.sort()
idx = A.index(X)
print(idx if idx < M - idx else M - idx)

Solution (Python):
n, m, x = map(int, input().split())
s = sum(int(i) < x for i in input().split())
print(min(s, m-s))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
count = len([1 for value in a if 0 < value < x])
print(min(count, m-count))

Solution (Python):
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
b=[i-x for i in a if i-x>0]
c=[i-x for i in a if i-x<0]
print(min(len(b),len(c)))

Solution (Python):
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
mi,ma=0,0
for i in a:
  if x>i:
    mi+=1
  else:
    ma+=1
print(min(mi,ma))

Solution (Python):
n, m, x = map(int,input().split())
a = list(map(int,input().split()))
cost_l = 0
cost_r = 0
for i in range(m):
    if a[i] < x:
        cost_l += 1
    else:
        cost_r += 1
print(min(cost_l, cost_r))

Solution (Python):
n,m,x=map(int,input().split())
As=list(map(int,input().split()))

way=[]
for i in range(n):
  way.append(i)
  
ans1,ans2=0,0
for i in range(x,n,1):
  if i in As:
    ans1+=1
for i in range(x,0,-1):
  if i in As:
    ans2+=1
print(min(ans1,ans2))

Solution (Python):
def main():
    N, M, X = map(int, input().split())
    A = [int(a) for a in input().split()]
    costL = 0
    for i in range(len(A)):
        if A[i] < X:
            costL += 1
    return min(costL, M-costL)
    
if __name__ == '__main__':
    print(main())

Solution (Python):
n,m,x=map(int,input().split())
A=list(map(int,input().split()))
l=0
r=0
for a in A:
    if a<x:
        l+=1
    else:
        r+=1
print(min(l,r))

Solution (Python):
from copy import copy

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

goal0 = 0
goaln = 0

X2 = copy(X)


while True:
    if X-1 == 0:
        break
    else:
        if X-1 in A:
            goal0 += 1

        X -= 1

while True:
    if X2+1 == N:
        break
    else:
        if X2+1 in A:
            goaln += 1

        X2 += 1

print(min(goal0,goaln))

Solution (Python):
n, m ,x= map(int, input().split())
a = map(int, input().split())

r = 0
l = 0

for i in a:
    if i < x:
        l += 1
    else:
        r += 1

print(min(l,r))

Solution (Python):


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

to0 = len([a for a in A if a < X])
toN = len(A) - to0

ans = min(to0, toN)
print(ans)

Solution (Python):
n,m,x=map(int,input().split())
s=sum(int(i)<x for i in input().split())
print(min(s,m-s))

Solution (Python):
n,m,x=map(int,input().split())
s=sum(int(i)<x for i in input().split())
print(min(s,m-s))

Solution (Python):
n, m, x = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
ans = 0
from bisect import bisect
i = bisect(a,x)
print(min(len(a[:i]),len(a[i:])))

Solution (Python):
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
c = 0
d = 0
for i in range(x):
    if i in a:
        c += 1
for i in range(x+1,n+1):
    if i in a:
        d += 1
print(min(c,d))

Solution (Python):
import sys
stdin = sys.stdin
import numpy as np

 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, m, x = na()
a = np.array(na())

left = sum(a < x)
right = sum(a > x)
print(left if left < right else right)

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
L = 0
R = 0
for a in A:
    if a < X:
        L += 1
    elif a > X:
        R += 1
print(min(L, R))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
A.append(X)
A.sort()
print(min(len(A[:A.index(X)]), len(A[A.index(X) + 1:])))

Solution (Python):
N,M,X = map(int,input().split())
*a, = map(int,input().split())

s = sum(i<X for i in a)

print(min(s,M-s))

Solution (Python):
n, m, x = map(int, input().split(" "))
a = sorted(list(map(int, input().split(" "))))

for i in range(m):
    if (x <= int(a[i])):
        print(min(i, m - i))
        break

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

print(min(sum(i > x for i in a), sum(i < x for i in a)))

Solution (Python):
n, m, x = map(int, input().split())
l = list(map(int, input().split()))
left = 0
right = 0
i = 0
while i < x:
    if i in l:
        left += 1
    i += 1
j = n-1
while j > x:
    if j in l:
        right += 1
    j -= 1

print(min(left, right))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
A.append(X)

A.sort()

index = A.index(X)

print(len(A[0:index]) if len(A[0:index]) <= len(A[index+1:len(A)]) else len(A[index+1:len(A)]))

Solution (Python):
N,M,X=(map(int, input().split(" ")))
S= sum(int(i)<X for i in input().split(" "))
print(min(S, M-S))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
L = 0
R = 0
for a in A: L += a < X
for a in A: R += a > X
print(min(L, R))

Solution (Python):
N,M,X=map(int, input().split())
A=[0]*(N+1)
for i in list(map(int, input().split())):A[i]=1
print(min(sum(A[:X]), sum(A[X+1:])))

Solution (Python):
n,m,x=map(int, input().split())

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

mas=[0]*(n+1)

for i in range(len(a)):
    mas[a[i]-1]=1

left_count=mas[:x].count(1)
right_count=mas[x:].count(1)

print(min(left_count,right_count))

Solution (Python):
N,M,X=map(int,input().split())
b=0
c=0
a=list(map(int,input().split()))
for i in range(X):
  if i in a:
    b+=1
for j in range(X,N+1):
  if j in a:
    c+=1
print(min(b,c))

Solution (Python):
n,m,x=map(int,input().split())
s=sum(int(i)<x for i in input().split())
print(min(s,m-s))

Solution (Python):
n, m, x = map(int, input().split())
a = map(int, input().split())
count = 0
for i in a:
  if i < x:
    count += 1
print(min(count, m - count))

Solution (Python):
n,m,x = map(int,input().split())
a = [0]*(n+1)
for i in map(int,input().split()):
    a[i] = 1
print(min(a[0:x].count(1),a[x:n+1].count(1)))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
sum_list = []
count = 0

for i in range(n+1):
    if i in a:
        count += 1
    sum_list.append(count)

sum_front = sum_list[x] - sum_list[0]
sum_rear = sum_list[n] - sum_list[x]

print(min(sum_front, sum_rear))

Solution (Python):
n,m,x=map(int,input().split())
s=sum(int(i)<x for i in input().split())
print(min(s,m-s))

Solution (Python):
n,m,x,*a=list(map(int,open(0).read().split()))
arr=[0]*(n+1)
for i in a:
  arr[i]=1
print(min(sum(arr[:x]), sum(arr[x+1:])))

Solution (Python):
n, m, x = map(int, input().split())
a = [int(inp) for inp in input().split()]

cnt = sum(a[i] < x for i in range(m))

print(min(cnt, m - cnt))

Solution (Python):
n, m, x = map(int, input().split())
a = [int(inp) for inp in input().split()]

cnt = 0
for i in range(m) :
    if a[i] < x :
        cnt += 1

print(min(cnt, m - cnt))

Solution (Python):
n,m,x=map(int,input().split())
a=list(map(int,input().split()))

route=[0]*n
for i in a:
  route[i-1]=1
ans=min(sum(route[:x]),sum(route[x:]))
print(ans)

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

c0 = 0
c1 = 0

for i in range(M):
    if A[i] < X:
        c0 += 1
    elif A[i] > X:
        c1 += 1
print(min(c0, c1))

Solution (Python):
N, M, X = [int(x) for x in input().split()]
AN = [int(x) for x in input().split()]
print(min(len([i for i in AN if i < X]),len([i for i in AN if i > X])))

Solution (Python):
n,m,x=map(int,input().split())
right=0
left=0
for i in list(map(int,input().split())):
    if 0<i<x:
        right +=1
    elif x<i<n:
        left +=1
print(min(right,left))

Solution (Python):
n,m,x = map(int, input().split())
s = sum(int(a)<x for a in input().split())
print(min(s,m-s))

Solution (Python):
n,m,x = map(int, input().split())
a = map(int, input().split())
f = [0]*(n+1)
for i in a:
    f[i] = 1
print(min(sum(f[:x]), sum(f[x+1:])))

Solution (Python):
n,m,x = map(int,input().split())
m_list = list(map(int,input().split()))
under_list = list(filter(lambda a:a<x,m_list))
over_list = list(filter(lambda a:a>x,m_list))
print(min(len(under_list),len(over_list)))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
for i,j in enumerate(a):
  if j > x:
    cnt = i
    break
print(min(cnt, m-cnt))

Solution (Python):
n, m, x = map(int, input().split())
grid = [0]*(n+1)
a = list(map(int, input().split()))

for i in a:
    grid[i-1] = 1

if sum(grid[0:x]) >= sum(grid[x:n]):
    print(sum(grid[x:n]))
else:
    print(sum(grid[0:x]))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
m1 = 0
m2 = 0
for i in a:
    if x > i:
        m1 += 1
    elif x < i:
        m2 += 1
print(min(m1, m2))

Solution (Python):
n,m,x = map(int,input().split())
a = list(input().split())
goal = 0
zero = 0
for i in range(m):
  if x < int(a[i]):
    goal += 1
  else:
    zero += 1
print(min(goal,zero))

Solution (Python):
N,M,X=map(int,input().split())
A=[int(s) for s in input().split()]

countx=0
county=0
for i in range(0,M):
    if X > A[i]:
        countx+=1
    elif X < A[i]:
        county+=1
print(min(countx,county))

Solution (Python):
import bisect

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

left = bisect.bisect_left(A, X)
right = len(A) - left
ans = min(left, right)
print(ans)

Solution (Python):
_, _, x = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
cost_lower = 0
cost_upper = 0
for ai in a:
    if ai < x:
        cost_lower += 1
    else:
        cost_upper += 1
print(min(cost_lower, cost_upper))

Solution (Python):
from bisect import bisect
n, m, x = map(int, input().split())
a = list(map(int, input().split()))

a.insert(bisect(a, x), x)
idx = a.index(x)
print(min(idx, m - idx))

Solution (Python):
n,m,x=input().split()
n,m,x=int(n),int(m),int(x)

a1=input().split()
a2=[]
for i in range(n+1):
    if str(i) in a1:
        a2.append(1)
    else:
        a2.append(0)

print(min([sum(a2[:x]),sum(a2[x+1:])]))

Solution (Python):
n, m, x = map(int, input().split())
p = 0
q = 0
a = list(map(int, input().split()))
for i in a:
    if (i < x):
        p += 1
    else:
        q += 1
print(min(q, p))

Solution (Python):
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
N_cost=len(list(filter(lambda x:x >X, A)))
Z_cost=len(list(filter(lambda x:x <X, A)))
print(min(N_cost,Z_cost))

Solution (Python):
n,m,x=map(int,input().split())
s=sum(int(i)<x for i in input().split())
print(min(s,m-s))

Solution (Python):
n, m, x  = map(int, input().split())
List = [int(i) for i in input().split()]

s_count = 0
b_count = 0

for i in range(m):
    if List[i] < x:
        s_count += 1
    elif List[i] > x:
        b_count += 1

print(s_count if s_count < b_count else b_count)

Solution (Python):
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
f,b=0,0
for i in a:
  if i<x:
    b+=1
  else:
    f+=1
    
print(min(f,b))