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())
S = map(int,input().split())
Fees = list(S)
Goal1 = []
Goal2 = []
count1 = 0
count2 = 0
point0 = 0

for i in range(X):
    point0 += 1
    Goal1.append(point0)


for j in range(N-X):
    X += 1
    Goal2.append(X)


for fee in Fees:
    if fee in Goal1:
        count1 += 1
    if fee in Goal2:
        count2 += 1

if count1 >= count2:
    print(count2)
if count1 < count2:
    print(count1)

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

for i in range(x,n):
    if a.count(i) == 1:
        count += 1
cost.append(count)
count = 0
c = range(0,x)
for i in reversed(c):
    if a.count(i) == 1:
        count += 1
cost.append(count)
print(min(cost))

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

l_cost = 0
g_cost = 0

for i in A:
    if i > X:
      l_cost += 1
    else:
        g_cost += 1
        
print(min(l_cost, g_cost))

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

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

a_cost = 0
b_cost = 0
for i in lst:
    if i > x:
        a_cost += 1
    else:
        b_cost += 1
print(min(a_cost, b_cost))

Solution (Python):
def tool_gate(now: int, gate_list: list) -> int:
    back_count = sum(i < now for i in gate_list)
    forward_count = sum(i > now for i in gate_list)
    return min(back_count, forward_count)


if __name__ == "__main__":
    n, m, now = map(int, input().split())
    gate_list = list(map(int, input().split()))
    print(tool_gate(now, gate_list))

Solution (Python):
lst = input().split()
N = int(lst[0])
M = int(lst[1])
X = int(lst[2])
L = input().split()

cost_0 = 0
for n in L:
   if 0 < int(n) < X:
      cost_0 += 1
   elif X < int(n):
      break

cost_N = 0
for n in L:
   if X < int(n) < N:
      cost_N += 1

print(min([cost_0, cost_N]))

Solution (Python):
N, M, X = map(int, input().split())
a_point = list(map(int,input().split()))
lg = 0
sl = 0
for i in range(len(a_point)):
    if X < a_point[i]:
        lg  += 1
    else:
        sl += 1

if lg > sl:
    print(sl)
else:
    print(lg)

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

cnt1 = 0
for i in range(0, X):
  if i in AS:
    cnt1 += 1

cnt2 = 0
for i in range(X+1, N+1):
  if i in AS:
    cnt2 += 1

print(cnt1 if cnt1 < cnt2 else cnt2)

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

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

Solution (Python):


def main():
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(m):
        if a[i] > x:
            ans = min(i, len(a) - i)
            break
    else:
        ans = 0
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

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

square = list(range(0, N + 1))

a = square[:X + 1]
b = square[X:]

a_costs = []
b_costs = []

for i in a:
    if i in A:
        a_costs.append(i)
for i in b:
    if i in A:
        b_costs.append(i)

a_cost = len(a_costs)
b_cost = len(b_costs)

if a_cost > b_cost:
    print(b_cost)
else:
    print(a_cost)

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

for i in A:
    if X > i:
        l1.append(i)
    else:
        l2.append(i)

print(min(len(l1), len(l2)))

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

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

low = 0
high = 0
for i in range(m):
  if a[i] < s:
    low += 1
  else:
    high += 1
print(min(low,high))

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

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
cnt1 = 0
cnt2 = 0
x1 = x
x2 = x

while x1 < n+1:
    x1 += 1
    if x1 in a:
        cnt1 += 1

while x2 > 0:
    x2 -= 1
    if x2 in a:
        cnt2 += 1



if cnt1 < cnt2:
    ans = cnt1
else:
    ans = cnt2

print(ans)

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

Solution (Python):
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
d=list(map(int,input().split()))
e=0
f=0
for i in range(b):
  if d[i]>c:
    e=e+1
  if d[i]<c:
    f=f+1
if e>f:
  print(f)
else:
  print(e)

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

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

mn = 0
l_cost = 0
r_cost = 0


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


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

print(min(l_cost, r_cost))

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

Solution (Python):

import sys


def solve(N: int, M: int, X: int, A: "List[int]"):
    ans = 0
    for i in range(X-1, 0, -1):
        if i in A:
            ans += 1
    c = 0
    for i in range(X+1, N):
        if i in A:
            c += 1
    if ans > c:
        ans = c
    print(ans)


    return



def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    M = int(next(tokens))  
    X = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(M)]  
    solve(N, M, X, A)

if __name__ == '__main__':
    main()

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

X_high = 0
X_low = 0

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

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

print(min(X_high, X_low))

Solution (Python):

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


goto_goal_0 = 0 
goto_goal_n = 0 


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


for i in range(x, n + 1):   
    if i in a:
        goto_goal_n += 1
        

if goto_goal_0 < goto_goal_n:
    print(goto_goal_0)
else:
    print(goto_goal_n)

Solution (Python):


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

goto_goal_0 = 0 
goto_goal_n = 0 


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


for i in range(x, n + 1):   
    if i in a:
        goto_goal_n += 1
        

if goto_goal_0 < goto_goal_n:
    print(goto_goal_0)
else:
    print(goto_goal_n)

Solution (Python):

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

A.append(X)
A.sort()

A_index = A.index(X)

len_bef = len(A[0:A_index])
len_aft = len(A[A_index+1:])
ans = len_bef

if len_bef > len_aft:
    ans = len_aft

print(ans)

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

goal_N = 0
goal_0 = 0

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

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

min_cost = min(goal_N,goal_0)

print(min_cost)

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

goto_0=0
goto_N=0

for i in range(X,0,-1):
    if i in Ai:
        goto_0 += 1

for i in range(X,N):
    if i in Ai:
        goto_N += 1

print(min(goto_0,goto_N))

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

goto_0=0
goto_N=0

for i in range(0,X):
    if i in Ai:
        goto_0 += 1

for i in range(X,N):
    if i in Ai:
        goto_N += 1

print(min(goto_0,goto_N))

Solution (Python):
S_list = [input() for i in range(2)]
N, M, X= map(int,S_list[0].split())    
A_list = list(map(int,S_list[1].split()))

A_goal_N = [i for i in A_list if X < i and i < N]
A_goal_0 = [i for i in A_list if 0 < i and i < X]
result = min(len(A_goal_N),len(A_goal_0))
print(result)

Solution (Python):
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
n, m, x = [int(num) for num in lines.pop(0).split(" ")]
a_list = [int(num) for num in lines.pop(0).split(" ")]

for i in range(m):
    if a_list[i] > x:
        break

ans = min(i, m - i)
print(ans)

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

L = 0
R = 0

for ai in A:
    if ai < X:
        L = L + 1
    else:
        R = R + 1
print(min(L, R))

Solution (Python):
N, M, X = map(int,input().split())
fee = list(map(int,input().split()))
result_1 = []
result_2 = []

for i in fee:
    if i > X:
        result_1.append(i)
    else:
        result_2.append(i)

result = (min(len(result_1) ,len(result_2)))
print(result)

Solution (Python):
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
k = n-1
for i in range(m):
    if a[i] > x:
        k = i
        break
if k==0 or k==n-1:
    print('0')
    exit()
else:
    print(min(k,m-k))

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

s=0
b=0
for i in a:
    if i<x:
        s+=1
    if i>x:
        b+=1
print(min(s,b))

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

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

Solution (Python):
total_square, total_toll_gate, current_square = map(int, input().split())
toll_gate_square = list(map(int, input().split()))
route1 = 0
route2 = 0
for i in range(total_toll_gate):
    if toll_gate_square[i] < current_square:
        route1 += 1
    else:
        route2 += 1
print(min(route1, route2))

Solution (Python):
N,M,X=list(map(int, input().split()))
L=list(map(int, input().split()))
c=0
d=0
for i in range(M):
  if L[i]>X:
    c+=1
  else:
    d+=1
print(min(c,d))

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

Solution (Python):
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a = sorted(a)
print(len(a[:a.index(x)]) if len(a[:a.index(x)+1]) <= len(a[a.index(x)+1:]) else len(a[a.index(x)+1:]))

Solution (Python):
n,m,x=map(int,input().split())
am=sorted(map(int,input().split()))
print(min(len(list(filter(lambda a:a<x,am))),len(list(filter(lambda a:x<a,am)))))

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

for i in range(m):
    if a[i] > x:
        if i < m-i: ans = i
        else      : ans = m-i
        break
print(ans)

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

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

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

def answer(n: int, m: int, x: int, a:list) -> int:
    left = 0
    right = 0
    for i in a:
        if i < x:
            left += 1
        else:
            right += 1
    return min(left, right)

print(answer(n, m, x, a))

Solution (Python):
n, m, x = input().split()
list01 = input().split()
list02 = [int(a) for a in list01]
b = sum(c > int(x) for c in list02)
d = sum(e < int(x) for e in list02)
print(min(b, d))

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

for i in A:
    if X > i:
        l1.append(i)
    else:
        l2.append(i)

print(min(len(l1), len(l2)))

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

Solution (Python):
a=input().split()
N=int(a[0])
M=int(a[1])
X=int(a[2])
ryokinjo=[]
b=input().split()
for i in range(len(b)):
  ryokinjo.append(int(b[i]))
count1=0
count2=0
for i in range(len(ryokinjo)):
  if ryokinjo[i]<X:
    count1+=1
  if ryokinjo[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 = 0
cost_last = 0

for n in A:
  if n > X:
    cost_last += 1
  elif n < X:
    cost_0 += 1


if cost_0 >= cost_last:
  print(cost_last)
elif cost_0 < cost_last:
  print(cost_0)

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

goal_N = 0
goal_0 = 0

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

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

min_cost = min(goal_N,goal_0)

print(min_cost)

Solution (Python):



N, M, X = map(int, input().split())
my_list = list(map(int, input().split(maxsplit=M)))
count_start = 0
count_goal = 0


for i in range(1, X):
    if i in my_list:
        count_start += 1

for i in range(X, N):
    if i in my_list:
        count_goal += 1

if count_start >= count_goal:
    answer = count_goal
else:
    answer = count_start

print(answer)

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

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

for i in range(m):
    if a[i] > x:
        less = len(a[:i])
        more = len(a[i:])
        print(min(less, more))
        break

Solution (Python):

last,fee,cur = map(int,input().split())
feesqu = list(map(int,input().split()))
total = len(feesqu)


tcost = 0
gcost = 0
for cnt in range(0,total,1):
    if feesqu[cnt] < cur:
        tcost += 1
gcost = total - tcost
print(min(tcost,gcost))

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

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

cost_ToZero = cost_ToEnd = 0

for cost_mass in cost_masses:
    if X < cost_mass:
        cost_ToEnd = cost_ToEnd + 1
    elif X > cost_mass:
        cost_ToZero = cost_ToZero + 1
else:
  print(min([cost_ToZero, cost_ToEnd]))

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

left_cost = 0
right_cost = 0
for square in squares:
    if square < x:
        left_cost = left_cost + 1
    else:
        right_cost = right_cost + 1

print(min(right_cost, left_cost))

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


small_cost = 0

big_cost = 0


for i in a:
    
    if x > i:
        small_cost += 1
    
    elif x < i:
        big_cost += 1

if small_cost <= big_cost:
    print(small_cost)
else:
    print(big_cost)

Solution (Python):


def atc_094b(NMX: str, Ai_input: str) -> int:
    N, M, X = map(int, NMX.split(" "))
    Ai = [int(ai) for ai in Ai_input.split(" ")]

    up_cost = 0
    down_cost = 0

    for i in range(X + 1, N + 1):
        if i in Ai:
            up_cost += 1
    for i in range(X - 1, 0, -1):
        if i in Ai:
            down_cost += 1
    return min(up_cost, down_cost)


NMX_input_value = input()
Ai_input_value = input()
print(atc_094b(NMX_input_value, Ai_input_value))

Solution (Python):
N, M, X = map(int,input().split())
L = list(map(int,input().split()))
s = 0
b = 0
for i in L:
    if i > X:
        s += 1
    else:
        b += 1

if s >= b:
    print(b)
else:
    print(s)

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

right = [int(i) for i in A if i > X]
left = [int(i) for i in A if i < X]

r = len(right)
l = len(left)

if r < l:
    print(r)

else:
    print(l)

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

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

Solution (Python):
num, count_station, my_position = map(int, input().split())
a = map(int, input().split())
station_list = list(a)
space = num + 1
first_me_cost = 0
last_me_cost = 0

distance_me_first = my_position
distance_me_last = num - my_position

for i in station_list:
    if 1 <= i <= my_position - 1:
        first_me_cost += 1

for i in station_list:
    if my_position + 1 <= i < num:
        last_me_cost += 1

if first_me_cost > last_me_cost:
    print(last_me_cost)
elif last_me_cost > first_me_cost:
    print(first_me_cost)
elif last_me_cost == first_me_cost:
    print(first_me_cost)

Solution (Python):
a = [int(c) for c in input().split()]
N=a[0]
M=a[1]
X=a[2]
A = [int(c) for c in input().split()]
A2 = [0]*(N+1)
for i in range(M):
    A2[A[i]] = 1

cnt = X
cost1 = 0
while cnt < N+1:
    cost1+=A2[cnt]
    cnt+=1

cnt = X
cost2 = 0
while cnt > 0:
    cost2+=A2[cnt]
    cnt-=1

if cost1<cost2:
    print(cost1)
else:
    print(cost2)

Solution (Python):
N, M, X, *A = map(int, open(0).read().split())

l = [0] * N
for a in A:
    l[a-1] = 1

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

Solution (Python):
import bisect


def answer(n: int, m: int, x: int, a: []) -> int:
    i = bisect.bisect_left(a, x)
    return min(i, len(a) - i)


def main():
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))
    print(answer(n, m, x, a))


if __name__ == '__main__':
    main()

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

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

for i , a in enumerate(A):
    if X < a:
        break

if i > len(A) / 2:
    ans = len(A[i:])
else:
    ans = len(A[:i])

print(ans)

Solution (Python):
import bisect

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

index = bisect.bisect_left(A,X)
ans = min(M-index,index)
print(ans)

Solution (Python):

import sys
input=sys.stdin.readline

def main():
    n,m,x = map(int,input().split())
    maps=[]
    maps=list(map(int,input().split()))
    dp=[0]*(n+1)
    left=0
    right=0

    for i in maps:
        dp[i]=1

    left = sum(dp[x:])
    right = sum(dp[:x])

    print(min(left,right))

if __name__=="__main__":
    main()

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

for i, a in enumerate(a_l):
    if x < a:
        break
if i > len(a_l)/2:
    ans = len(a_l[i:])
else:
    ans = len(a_l[:i])
print(ans)

Solution (Python):
from bisect import bisect_left
n, m, x, *a = map(int, open(0).read().split())

b = bisect_left(a, x)
print(min(m - b, b))

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

Solution (Python):
import bisect

x = int(input().split()[2])
a = list(map(int, input().split()))
i = bisect.bisect(a, x)

print(min(i, len(a) - i))

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


N,M,X = MI()
A = LI()
a = sum(A[i] < X for i in range(M))
print(min(a,M-a))

Solution (Python):
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,m,x=nii()
a=lnii()

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 = list(map(int, input().split()))

cnt1, cnt2 = 0, 0
for a in A:
    if a < x:
        cnt1 += 1
    if a > x:
        cnt2 += 1
        
ans = min(cnt1, cnt2)
print(ans)

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

cost = [0]*(N+1)

for a in A:
    cost[a-1] = 1

ans = min(sum(cost[:X]), sum(cost[X:]))

print(ans)

Solution (Python):
def main():
    N,M,X = map(int,input().split())
    A = list(map(int,input().split()))
    left = 0
    right = 0
    for i in range(N):
        if i == X:
            continue
        elif i < X and i in A:
            left += 1
        elif i > X and i in A:
            right += 1

    ans = min(left,right)
    return ans

print(main())

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

b = sum(1 for i in range(m) if a[i] <= x)

print(min(b, m - b))

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

for i in range(x,n+1):
    if i in A:
        end += 1

print(min(start, end))

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M, X = mapint()
As = set(list(mapint()))
to_zero = 0
for i in range(X, 0, -1):
    if i in As:
        to_zero += 1

to_N = 0
for i in range(X, N+1):
    if i in As:
        to_N += 1
print(min(to_zero, to_N))

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

Solution (Python):
from bisect import bisect_left

n, m, x = map(int, input().split())
alst = list(map(int, input().split()))
pos = bisect_left(alst, x)
print(min(pos, m - pos))

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

Solution (Python):
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  
def LS2(): return list(sys.stdin.readline().rstrip())  


N,M,X = MI()
A = LI()
a = sum(A[i] < X for i in range(M))
print(min(a,M-a))

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,X = inpl()
a = inpl()
f = [False] * n
for x in a:
    f[x] = True
print(min(sum(f[:X]), sum(f[X:])))

Solution (Python):
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
from bisect import bisect
i = bisect(A,X)
print(min(i,M-i))

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

mae = [i for i in A if i > X]
ushiro = [i for i in A if i < X]
m = len(mae)
u = len(ushiro)

if m > u:
    print(u)
else:
    print(m)

Solution (Python):
import bisect
N,M,X = map(int,input().split())
a = list(map(int, input().split()))
l = bisect.bisect_left(a, X)
print(min(l, M-l))

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

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

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

L = [0]*(N+1)
for i in range(M):
  L[A[i]] = 1

left = L[:X]
right = L[X:]

print(min(sum(left), sum(right)))

Solution (Python):
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
i = x
ans = 0
while i > 0:
    i -= 1
    if i in a:
        ans += 1
c = 0
i = x
while i < n:
    i += 1
    if i in a:
        c += 1
ans = min(ans,c)
print(ans)

Solution (Python):
N, M, X = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
x = [0 for i in range(N+1)]
for i in range(M):
  x[A[i]] = 1
ans1 = 0
for i in range(0,X):
  ans1 += x[i]
ans2 = 0
for i in range(X,N):
  ans2 += x[i]
print(min(ans1, ans2))

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

tmp = bisect(s, x)
print(min(tmp, m - tmp))

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

tmp = bisect(s, x)
print(min(tmp, m - tmp))

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

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

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

    for a in a_list:
        if a < x:
            cnt += 1
        if x < a:
            break

    print(min(cnt, m - cnt))


if __name__ == "__main__":
    main()

Solution (Python):
n, m, x = (int(i) for i in input().split())
list_a = [int(i) for i in input().split()]
list_toll = []
for i in range(0, n + 1):
    if i in list_a: list_toll.append(1)
    else: list_toll.append(0)
print(min(sum(list_toll[:x]), sum(list_toll[x:])))

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

Solution (Python):

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

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

cost = [0] * (N + 1)

for a in A:
  cost[a] = 1
  
ans = min(sum(cost[:X+1]), sum(cost[X+1:]))
print(ans)

Solution (Python):
from bisect import bisect
_, 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,X = map(int,input().split())
S = list(map(int,input().split()))
path = [0 for _ in range(N+1)]
for n in S:
  path[n] = 1
  
left = sum(path[1:X])
right = sum(path[X:-1])

print(min(left,right))

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


left = 0
right = 0

for a in A:
    if a > X:
        right += 1
    else:
        left += 1
print(min(left, right))

Solution (Python):
def count_fee_station(a, n_list):
    cost = 0
    for i in n_list:
        if i in a:
            cost += 1
    return cost


def main():
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))
    n_list_a = list(range(0, x + 1))
    n_list_b = list(range(x, n + 1))
    cost_a = count_fee_station(a, n_list_a)
    cost_b = count_fee_station(a, n_list_b)
    print(min(cost_a, cost_b))


if __name__ == '__main__':
    main()

Solution (Python):
def count_fee_station(a, n_list):
    cost = 0
    for i in n_list:
        if i in a:
            cost += 1
    return cost


def main():
    n , m , x  = map(int,input().split())
    a = list(map(int, input().split()))
    
    
    n_list_a = list(range(0,x+1))
    n_list_b = list(range(x,n+1))
    cost_a = count_fee_station(a,n_list_a)
    cost_b = count_fee_station(a,n_list_b)
    print(min(cost_a,cost_b))

if __name__ == '__main__':
    main()

Solution (Python):
def count_fee_station(a, n_list):
    cost = 0
    for i in n_list:
        if i in a:
            cost += 1
    return cost


def main():
    n , m , x  = map(int,input().split())
    a = list(map(int, input().split()))
    if n in a:
        a.remove(n)
    n_list_a = list(range(0,x+1))
    n_list_b = list(range(x,n+1))
    cost_a = count_fee_station(a,n_list_a)
    cost_b = count_fee_station(a,n_list_b)
    print(min(cost_a,cost_b))

if __name__ == '__main__':
    main()

Solution (Python):
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    N, M, X = map(int, readline().split())
    A = list(map(int, readline().split()))

    a = 0
    b = 0

    for x in A:
        if x <= X:
            a += 1
        if X <= x:
            b += 1

    print(min(a, b))


if __name__ == '__main__':
    main()

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

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

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
if cnt > M - cnt:
    cnt = M - cnt

print (cnt)

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

to_z, to_n = 0, 0
for i in a:
    if i > x:  to_n += 1
    else:  to_z += 1

print(min(to_z, to_n))

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

print(min(b,m-b))