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):
import numpy as np
N, M, X = map(int, input().split())












A = [int(i) for i in input().split()]


S = np.zeros((N + 1))
for i in range(M):
    S[A[i]] = 1



ans1 = 0
ans2 = 0

for i in range(0 , X + 1):
    if S[i] == 1:
        ans1+=1

for i in range(X , N + 1):
    if S[i] == 1:
        ans2+=1

print(min(ans1,ans2))

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

pay_list= [0,0]

for i in range(x,n+1):
    if i in fee_list:
        pay_list[0] += 1

for j in range(x):
    if j in fee_list:
        pay_list[1] += 1

if pay_list[0] < pay_list[1]:
    print(pay_list[0])
else:
    print(pay_list[1])

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
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 main():
    n,m,x = LI()
    t = LI()
    a = collections.defaultdict(int)
    for c in t:
        a[c] = 1
    r = inf
    tr = 0
    for i in range(x+1,n):
        tr += a[i]
    r = tr
    tr = 0
    for i in range(x-1,-1,-1):
        tr += a[i]
    if r > tr:
         r = tr

    return r


print(main())

Solution (Python):
N, M, X = [int(i) for i in input().split()]
mass = [0 for i in range(N + 1)]
for i in input().split():
    mass[int(i)] = 1

r = 0
for i in range(X, N + 1):
    r += mass[i]
l = 0
for i in range(X, 0, -1):
    l += mass[i]

if r >= l:
    print(l)
else:
    print(r)

Solution (Python):
import math
import sys

def getinputdata():

    
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()


n = int(arr_data[0][0])


m = int(arr_data[0][1])


x = int(arr_data[0][2])

arr=list(map(int, arr_data[1]))



kingaku1=0
kingaku2=0

for i in range(1,x):
    
    if i in arr:
        
        kingaku1+=1

for j in range(x+1,n+1):
    
    if j in arr:
        
        kingaku2+=1

    
print(kingaku1 if kingaku1<=kingaku2 else kingaku2)

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

print(min(left, right))

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

for i in range(m):
    if P[i]  > x:
        a += 1
    else:
        b += 1
print(min(a, b))

Solution (Python):
N, M, X = map(int, input().split())
A = [int(i) for i in input().split()]
left = 0
for i in range(M):
    if A[i] < X:
        left += 1
right = M - left
print(min(left, right))

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

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

Solution (Python):
def main():
    N,M,X = list(map(int,input().split()))
    A = [0]
    A.extend(list(map(int,input().split())))
    for i in range(100):
        A.append(0)    
    Map = [0]
    for i in range(1,N+1):
        if i in A:
            Map.append(1)
        else:
            Map.append(0)
    right = sum(Map[X+1:])
    left = sum(Map[:X])
    
    if right < left:
        print(right)
    else:
        print(left)
if __name__ == '__main__':
    main()

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

ans = len(list(filter(lambda i : A[i] < X, range(M))))
ans = min(ans, len(A)-ans)
print(ans)

Solution (Python):
n,m,x = map(int,input().split())
a = list(map(lambda ai:0 if (int(ai) < x) else 1,input().split()))
print(min(sum(a),m-sum(a)))

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

for a in map(int, input().split()) :
    if a < x :
        down += 1
    elif x < a and x < n :
        up += 1

print(min(down, up))

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

to_zero = 0
to_N = 0

for a in A:
    if a < X:
        to_zero += 1
    elif a > X:
        to_N += 1

print(min(to_zero, to_N))

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

L=0
R=0
for i in range(M):
  if A[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()))

B=0
C=0

D=[]

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

D.append(B)
        
        
for i in range(X):
    if i in A:
        C=C+1

D.append(C)

print(min(D))

Solution (Python):
Cost0 = 0
CostN = 0
length = 0

listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
X = listA[0][2]

for x in listA:
   length += len(x)

for i in range(length - 3):
    if (listA[1][i] < X):
        Cost0 = Cost0 +1
    else:
        CostN = CostN +1

if (Cost0 < CostN):
    print(Cost0)
else:
    print(CostN)

Solution (Python):


a = input().split()
A = input().split()

for i in range(0, len(a)):
    a[i] = int(a[i])

for i in range(0, len(A)):
    A[i] = int(A[i])

count = 0
for i in range(0, len(A)):
    if(A[i] < a[2]):
        count = count + 1


if(count > (len(A) -  count)):
        count = len(A) -  count

print("{0}".format(count))

Solution (Python):
from collections import deque

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

Q = deque([(X, 1, 0), (X, -1, 0)])
R = []
while Q:
    P = Q.popleft()
    N1 = P[0] + P[1]
    if N1 == 0 or N1 == N:
        R.append(P[2])
        continue
    C = P[2] + (1 if N1 in A else 0)
    Q.append((N1, P[1], C))

print(min(R))

Solution (Python):
def main():
    N,M,X = list(map(int,input().split()))
    A = [0]
    A.extend(list(map(int,input().split())))
    for i in range(100):
        A.append(0)    
    Map = [0]
    for i in range(1,N+1):
        if i in A:
            Map.append(1)
        else:
            Map.append(0)
    right = sum(Map[X+1:])
    left = sum(Map[:X])
    
    if right < left:
        print(right)
    else:
        print(left)
if __name__ == '__main__':
    main()

Solution (Python):
n, m, x = list(map(int, input().split()))
alist = list(map(int, input().split()))
leftcost = len(list(filter(lambda num: num < x, alist)))
rightcost = len(list(filter(lambda num: num > x, alist)))
print(leftcost if leftcost <= rightcost else rightcost)

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

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

flg = 0
costA = 0
costB = 0

for i in range(N+2):
    if i == X:
        flg = 1
    elif i in A:
        if flg == 0:
            costA += 1
        else:
            costB += 1
            

if costA > costB:
    print(costB)
else:
    print(costA)

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

small = 0
big = 0
for j in A:
    if j < X:
        continue
    else:
        small=small+1

for j in A:
    if j > X:
        continue
    else:
        big=big+1



if big>=small:
    print(small)
else:
    print(big)

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


counter = 0
for i in range(M):
	if X < M_list[i]:
		break
	counter += 1

if counter <= M - counter:
	print(counter)
else:
	print(M-counter)

Solution (Python):



import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

sm = l[2]
la = l[2]
while(True):
    if sm == 0:
        print 0
    if la == l[0]:
        print 0
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2 + 0.5
        break
    if sm in A:
        ix = A.index(sm) + 0.5
	break
    if la in A:
	ix = A.index(la) - 0.5
	break
M = l[1] - ix - 1
if M > ix:
    print int(math.ceil(ix))
else:
    print int(math.ceil(M))

Solution (Python):
import numpy as np
import sys
N,M,X = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
temp = []
ans1 = 0
ans2 = 0
for i in range(N+1):
    if (i == 0) or (i==N):
        temp.append(0)
    elif i in A:
        temp.append(1)
    
    
    else:
        temp.append(0)
for i in range(X,N+1):
    ans1 += temp[i]

for i in range(X):
    ans2 += temp[i]

print(min(ans1,ans2))

Solution (Python):

n,m,x = map(int, raw_input().split())
list =[]
list = map(int, raw_input().split())
r_sum = 0
h_sum =0
for i in range(m):
 if list[i] < x:
  r_sum += 1
 if list[i] > x:
  h_sum += 1

if h_sum > r_sum:
 print(r_sum)
else:
 print(h_sum)

Solution (Python):
N, M, X = map(int, input().split())
n = [int(x) for x in input().split()]
num1 = 0
for i in n:
    if i < X:
        num1 += 1
num2 = M - num1
smaller = lambda y, z: z if z < y else y
smaller_num = smaller(num1, num2)
print(smaller_num)

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

A=np.array(A)

print(min(np.count_nonzero(A<X),np.count_nonzero(A>X)))

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

l = 0
r = 0

for a in aes:
    if a <= (x-1):
        l+=1
    elif x < a:
        r+=1

print(min([l, r]))

Solution (Python):
N, M, X = map(int, input().split())
A_list = [int(x) for x in input().split()]
minus_counter = 0
plus_counter = 0
for i in range(len(A_list)):
    if A_list[i] > X:
        break
    minus_counter += 1
for i in range(minus_counter, len(A_list)):
    plus_counter += 1
print(min(minus_counter, plus_counter))

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

small,big=0,0
for i in range(X):
    if i in A:
        small+=1
for i in range(X+1,N+1):
    if i in A:
        big+=1
print(min(small,big))

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

for i in range(x):
    if i in a:
        cntF +=1
for i in range(x+1, n+1):
    if i in a:
        cntL +=1
print(min(cntF, cntL))

Solution (Python):



cell_size, toll_size, start_cell = map(int, input().split())

toll_list = [int(i) for i in input().split()]


zero_to_start = 0
for i in range(0, start_cell):
	
	if i in toll_list:
		zero_to_start += 1


start_to_end = 0
for i in range(start_cell, cell_size):

	if i in toll_list:
		start_to_end += 1


if zero_to_start <= start_to_end:
	print(zero_to_start)
else:
	print(start_to_end)

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

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

counta=0;
countb=0;

for i in a:
    if (n<i and i<x) or (x<i and i<n):
        counta+=1

for i in a:
    if (0<i and i<x):
        countb+=1


if (counta<countb):
    ans = counta
else:
    ans = countb

print(ans)

Solution (Python):

n, m, x = map(int, input().split())
a = list(map(int, input().split()))
a1 = [aa for aa in a if aa > x]
a2 = [aa for aa in a if aa < x]
if len(a1) > len(a2):
    print(len(a2))
else:
    print(len(a1))

Solution (Python):
N,M,X=map(int,input().split())
nums = list(map(int,input().split()))
l,h=0,0
for i in range(M):
    if X < nums[i]:
        h += 1
    else:
        l += 1
print(min(h,l))

Solution (Python):


if __name__ == '__main__':
    N,M,X = map(int,input().split())
    C = [0] * N
    A = list(int(i) for i in input().split())
 
    for i in range(N):
        if i in A:
            C[i] = 1

    cost = min(sum(C[X:N]),sum(C[0:X]))
    
    print(cost)

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

C = [0 for i in range(N)]
for j in range(len(A)):
    C[A[j]-1] = 1
C_left = C[:X-1]
C_right = C[X:]
result = min(sum(C_left),sum(C_right))
print(result)

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

cfee = 0 
for a in A:
  if a < X:
    cfee += 1
print (min(cfee, M-cfee))

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

a.append(x)
a.sort()
position = a.index(x)+1

if position == 0 or position == m+1:
	print(0)
else:
	if (m+1)-position <= (m+1)/2:
		print(m+1-position)
	else:
		print(position-1)

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

arr = [ 0 for i in range(N) ]
for p in A:
    arr[p] = 1

x2r = sum(arr[X:N])
x2l = sum(arr[0:X])

print(min([x2r, x2l]))

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

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

print(min(ansn,ans0))

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

now = x

res1 = 0
for i in range(n - x - 1):
    now += 1
    if a.count(now):
        res1 += 1

now = x
res2 = 0
for i in range(x):
    now -= 1
    if a.count(now):
        res2 += 1

if res1 < res2:
    print(res1)
else:
    print(res2)

Solution (Python):
n, m, x = map(int, input().split(" "))
nums = list(map(int, input().split(" ")))
lefts = [t for t in nums if t < x]
rights = [t for t in nums if t > x]

if len(lefts) > len(rights):
	print(len(rights))
else:
	print(len(lefts))

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

a=list(map(int,input().split()))
lc=0
rc=0
for i in a:
    lc+=(1 if i<x else 0)
    rc+=(1 if i>x else 0)
print(min(lc,rc))

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

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

A = map(int, input().split())
ans1 = 0
ans2 = 0

for a in A:
  if a > x:
    ans1 += 1
  else:
    ans2 += 1

print(min(ans1, ans2))

Solution (Python):
x,y,z=[int(i) for i in input().split()]
tag_list=input().split()

tag_set=set(tag_list)

obj_list=[]
for i in range(0,x+1):
    obj_list.append(str(i))

result=[]

obj_set=set(obj_list[z+1:])
a=list(obj_set & tag_set)
result.append(len(a))

obj_set=set(obj_list[:z+1])
a=list(obj_set & tag_set)

result.append(len(a))

print(min(result))

Solution (Python):
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
S=0
for i in range (M):
 if A[i]<X:
  S+=1
if M-S<S:
 print(M-S)
else:
 print(S)

Solution (Python):
c = 0
list1=input().split()
N = int(list1[0])
M = int(list1[1])
X = int(list1[2]) 
list2 = list(map(int, input().split()))
for i in range(M):
    if list2[i] < X:
        c+=1
if c<=M-c:
    print(c)
else:
    print(M-c)

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

a=0
b=0
for i in range(N+1):
    if i in Ms:
        if i > X :
            a+=1 
        elif X > i :
            b+=1

print(min(a,b))

Solution (Python):
def main():
    N, M, X = (int(i) for i in input().split())
    a = [int(i) for i in input().split()]
    route = [None for i in range(N+1)]
    route = []
    for i in range(N+1):
        if (i == 0) or (i == N) or (i == X):
            ret = False
        elif i in a:
            ret = True
        else:
            ret = None
        route.append(ret)
    min_0 = route[:X].count(True)
    min_N = route[X:].count(True)
    print(min(min_0, min_N))

if __name__ == '__main__':
    main()

Solution (Python):
l = input().split()
N = int(l[0])
M = int(l[1])
X = int(l[2])
cost1 = 0
cost2 = 0
j = 0
k = input().split()
for e in k:
    if int(e) >= X:
        j = k.index(e)
        break
    cost1 = cost1 + 1

for i in range(j, M):
    cost2 = cost2 + 1
if cost1 > cost2:
    print(cost2)
else:
    print(cost1)

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

for i in range(x,n):
    ans2 += A[i]

print(min(ans1, ans2))

Solution (Python):
N, M, X = map(int, input().split())
list = list(map(int, input().split()))
A = sum(n > X for n in list)
B = sum(n < X for n in list)
if A >= B:
  print(B)
else:
  print(A)

Solution (Python):
def m():
    N, M, X = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [0 for _ in range(N)]
    for a in A:
        B[a] = 1
    cost = min(sum(B[X:]), sum(B[:X]))
    return cost


print(m())

Solution (Python):
def main():
    n, m, x = (int(i) for i in input().split())
    a = [int(i) for i in input().split()]
    u=0
    d=0
    for i in range(x+1,n):
        if(i in a):
            u += 1
    for j in range(x-1,0,-1):
        if(j in a):
            d += 1
    if(u<d):
        print(u)
    else:
        print(d)

main()

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

list_A = [int(A) for A in input().split(' ')]

left, right = 0, 0

if X > list_A[len(list_A) - 1]:
    print(0)
    exit()

if X < list_A[0]:
    print(0)
    exit()

for A in list_A:
    if X > A:
        left += 1
        continue
    right += 1

print(min(left, right))

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

cost = [0, 0]

for i in A:
	if i < X:
		cost[0] += 1
	else:
		cost[1] += 1
print(min(cost))

Solution (Python):

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

N = A[0]
M = A[1]
X = A[2]
little = 0
large = 0

for i in range(M):
    if X > R[i]:
        little += 1
    else:
        large += 1

if little > large:
    ans = large
else:
    ans = little
    
print(ans)

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

right_cost = 0
left_cost = 0

for i in range(1,N):
	location = i + X

	if location in cost_spot:
		
		right_cost = right_cost + 1
	else:
		pass
		

	if location == N:
		break

for i in range(1,N):
	location = X - i

	if location in cost_spot:
		
		left_cost = left_cost + 1
	else:
		pass
		

	if location == 0:
		break



print(min(right_cost,left_cost))

Solution (Python):
i = input()
N, M, X = i.split()
A = input()
array = A.split()
ind = 0
for n in array:
    array[ind] = int(n)
    ind = ind+1

X = int(X)
bef = [cost < X for cost in array]
aft = [cost > X for cost in array]

be = sum(bef)
af = sum(aft)

if be <= af:
    print(be)
else:
    print(af)

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

Solution (Python):
N,M,X = map(int,input().split())
li = list(map(int,input().split()))
A=0
B=0
for i in range(M):
    if li.pop(0) < X:
        A=A+1
    else:
        B=B+1

print(min(A,B))

Solution (Python):
import math

n, m, x = input().strip().split(' ')
N, M, X = [int(n), int(m), int(x)]
tollGates  = list(map(int, input().strip().split(' ')))
grids = [int(0)] * N
for i in tollGates:
    grids[i]=1

print(min(sum(grids[0:X]),sum(grids[X+1::])))

Solution (Python):
N, M, X = map(int, input().split())
A = [int(i) for i in input().split()]
score1 = 0
score2 = 0
for i in range(X, N):
    if i in A:
        score1 += 1
for i in range(0, X):
    if i in A:
        score2 += 1
print(min(score1, score2))

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


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

cost_right = 0
for i in range(x+1, n):
    if i in a:
        cost_right+= 1
    
print(min(cost_left, cost_right))

Solution (Python):
length, _, position = [int(x) for x in input().split()]
fee_stations = [int(x) for x in input().split()]
former = 0
latter = 0

for station_place in fee_stations:
    if station_place < position:
        former += 1
    else:
        latter += 1
print(min(former, latter))

Solution (Python):


import numpy as np

X = [int(i) for i in input().split()]
C = np.array([int(i) for i in input().split()])

high = np.sum(C > X[2])
low  = np.sum(C < X[2])

print(min(high,low))

Solution (Python):

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

ll = [0] * (N + 1)
for i in l:
    ll[i] = 1

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

Solution (Python):



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


right = 0
left = 0

for i in range(len(A)):
    if (A[i] > X):
        right += 1
    if (A[i] < X):
        left += 1

if (right < left):
    print(right)
else:
    print(left)

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
c = 0
for t in a:
  if t < x:
    c += 1

print([len(a)-c, c][c<len(a)-c])

Solution (Python):
NMX = list(int(i) for i in input().split())
A = list(int(i) for i in input().split())
ans0 = 0
ansN = 0
for j in range(0, NMX[2]):
    if j in A:
        ans0 += 1
for j in range(NMX[2], NMX[0]):
    if j in A:
        ansN += 1
anslist = [ans0, ansN]
ans = min(anslist)
print(ans)

Solution (Python):
N, M, X = map(int,input().split())
A = set(map(int,input().split()))
lat = {i for i in range(X+1,N)}
fwd = {i for i in range(1,X)}
print(min(len(A&lat),len(A&fwd)))

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

A.append(X)

C=sorted(A)


search=C.index(X)
length=len(C)

print(min(search,length-search-1))

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

N_more_count =0
N_less_count =0

for i in range (M):
    AM = int(A[i])
    if AM>X:
        N_more_count=N_more_count+1
    if AM<X:
        N_less_count=N_less_count+1
print(min(N_less_count,N_more_count))

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

a_behind = [elem for elem in a if elem < x]
a_front = [elem for elem in a if elem > x]

print(min(len(a_behind), len(a_front)))

Solution (Python):


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

left = 0
for i in range(M):
  if A[i] > X: break
  left += 1

if left < (M-left): print(left)
else: print(M-left)

Solution (Python):
import sys
  
l = map(int, raw_input().split())
N, M, X = l[0], l[1], l[2]
m = map(int, raw_input().split())
cost_N = 0
if m[0] > X or m[-1] < X:
    print(0)
    sys.exit()
for a in m:
    if a > X:
        idx = m.index(a)
        count_N = M - idx
        count_0 = idx
        print(min(count_N, count_0))
        sys.exit()

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

Rcost = 0
Lcost = 0
for i in array:
    if i <  X:
        Lcost += 1
    elif i > X:
        Rcost += 1
print(min(Rcost,Lcost))

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

road_list = [0] * (N + 1)
for i in A_list:
    road_list[i] = 1

right = sum(road_list[X:])
left = sum(road_list[:X])
print(min(right, left))

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

	p = x
	cost = 0
	while p > 0:
		if p in a:
			cost += 1
		p -= 1
	cost_left = cost

	p = x
	cost = 0
	while p < n:
		if p in a:
			cost += 1
		p += 1
	cost_right = cost

	print(min((cost_left, cost_right)))

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

cost = 0
for i in range(X-1):
    if i+1 in A:
        cost += 1

mincost = cost
cost = 0
for i in range(N-X-1):
    if X+1+i in A:
        cost += 1

if mincost < cost:
    print(mincost)
else:
    print(cost)

Solution (Python):
N, M, X = map(int, input().split())
L = [0 for x in range(N+1)]
gate = list(map(int, input().split()))
p = X
c = 0
min_c = 2e9

for x in gate:
    L[x] = 1

while p != N:
    if L[p] == 1:
        c += 1

    p += 1

min_c = min(min_c, c)

p = X
c = 0

while p != 0:
    if L[p] == 1:
        c += 1

    p -= 1

min_c = min(min_c, c)

print(min_c)

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

cost_to_l = 0
cost_to_r = 0

for x in a:
    if(x < X):
        cost_to_l += 1
    else:
        cost_to_r += 1

print(min(cost_to_l, cost_to_r))

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

Solution (Python):
da = list(map(int,input().split()))
ta = list(map(int,input().split()))

l1 = 0
l2 = 0

for i in range(da[2]):
  for j in range(da[1]):
    if i == ta[j]:
      l1 += 1
      
for i in range(da[0] - da[2]):
  for j in range(da[1]):
    if i + da[2] == ta[j]:
      l2 += 1
      
print(min(l1,l2))

Solution (Python):
N,M,X = map(int,input().split())
cost = list(map(int,input().split()))
ans1 =0
ans2 =0

for i in range(M):
  if cost[i] < X:
    ans1 +=1
  else:
    ans2 +=1

print(min(ans1,ans2))

Solution (Python):
n,m,x=input().split()
N=int(n);M=int(m);X=int(x)
a=[int(x) for x in input().split()]

L=0
R=0
i=X
while i!=0:
    if i-1 in a:
        L+=1
    i-=1
i=X
while i!=N:
    if i+1 in a:
        R+=1
    i+=1
print(min(L,R))

Solution (Python):
def solve(N, M, X, A):
    a = sum(A[:X])
    if x == N:
        return 0
    b = sum(A[X+1:])
    return min(a, b)
if __name__ == "__main__":
    s = input()
    N, M, X = list(map(lambda x: int(x), s.split()))
    A = [0 for x in range(N)]
    for x in map(lambda x: int(x), input().split()):
        A[x] = 1 
    print(solve(M, N, X, A))

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

left=sum(num[:x+1])
right=sum(num[x:n+1])
print(min(left,right))

Solution (Python):


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

cost_l = 0
for i in range(1,X):
    if i in A:
        cost_l = cost_l + 1
    else:
        pass

cost_r = 0
for i in range(X+1,N):
    if i in A:
        cost_r = cost_r + 1
    else:
        pass
    
if cost_l < cost_r:
    print(cost_l)
else:
    print(cost_r)

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

r = (n+1)*[0]
for i in a:
    r[i] = 1

if(sum(r[0:x]) > sum(r[x:])):
    print(sum(r[x:]))
else:
    print(sum(r[0:x]))

Solution (Python):


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

if __name__ == '__main__':
    main()

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

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

counta = 0
countb = 0

for i in range(0,x+1):
    counta += a.count(i)
for i in range(x+1,n):
    countb += a.count(i)

print(min(counta,countb))

Solution (Python):
N, M, X = map(int, input().split())
A = map(int, input().split())
n1 = 0
n2 = 0
for a in A:
    if a < X:
        n1 += 1
    else:
        n2 += 1
if n1 <= n2:
    print(n1)
else:
    print(n2)

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

for i in A:
    if X<i:
        ue+=1
    else:
        sita+=1

print(min(ue,sita))

Solution (Python):


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

a = map(int, raw_input().split())

p1 = 0
p2 = 0
for i in a:
    if X > i:
        p1 += 1
    else:
        p2 += 1

print min(p1, p2)

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

cnt_l = 0
for i in range(x-1,0,-1):
    for j in range(len(A)):
        if i==A[j]:
            cnt_l+=1
cnt_r = 0
for i in range(x+1,n):
    for j in range(len(A)):
        if i==A[j]:
            cnt_r+=1
print(min(cnt_l,cnt_r))

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



nl = 0
nu = 0
for i in range(m):
    if a[i] < x:
        nl += 1
    elif a[i] > x:
        nu += 1
if nl <= nu:
    print(nl)
else:
    print(nu)

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

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

Solution (Python):
N, M, X = map(int, input().split())
A = [int(i) for i in input().split()]
l = sum([1 for i in A if i < X])
r = sum([1 for i in A if i > X])
print(l if l < r else r)

Solution (Python):
import collections


n, m, x = map(int, input().split())
c = collections.defaultdict(int)
for key in map(int, input().split()):
    key = int(key)
    c[key] += 1

forward = 0
backword = 0
touch_x = False

for i in range(n):
    if i == x:
        touch_x = True

    if not touch_x and c[i]:
        forward += 1

    else:
        if c[i]:
            backword += 1


print(min(forward, backword))

Solution (Python):

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



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


if ans > (m/2):
    ans = m-ans
    
print(ans)

Solution (Python):
l = list(map(int, input().split()))
N, M, X = l[0], l[1], l[2]

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

import numpy as np
fee = np.array(fee)
left = np.sum(fee < X)
right = np.sum(fee > X)

if left > right:
    print(right)
else:
    print(left)

Solution (Python):
from sys import stdin


def main():
    N, M, X = [int(x) for x in stdin.readline().rstrip().split()]
    Ai = [int(x) for x in stdin.readline().rstrip().split()]
    spam = [1 if i in Ai else 0 for i in range(N + 1)]
    print(min(sum(spam[:X]), sum(spam[X + 1:])))


if __name__ == '__main__':
    main()

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

for i in range(1,X):
    if i in A:
        R1+=1
for i in range(X+1,N):
    if i in A:
        R2+=1
    
print(min(R1,R2))