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()))
x = 0
for i in range(X,N+1):
  if i in A:
    x += 1
y = 0
for i in range(X+1):
  if i in A:
    y += 1
print(min(x,y))

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




n_list = [0] * (n + 1)


n_list[x] = 'X'
for i in range(m):
    n_list[a_list[i]] = 1




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

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

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())
List = list(map(int, input().split()))
pattern1 = 0
pattern2 = 0
setCost = set(List)
for i in range(N):
  if i in setCost:
    pattern1 += 1
  if i == X:
    break
for j in range(N,0,-1):
  if j in setCost:
    pattern2 += 1
  if j == X:
    break
if pattern1 < pattern2:
  print(pattern1)
else:
  print(pattern2)

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

Solution (Python):
n,m,*a=map(int,open(0).read().split());print(min(c:=sorted(a).index(a[0]),m-c))

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

cost = [0 for _ in range(N+1)]
for a in A:
    cost[a] = 1

cost_1 = 0
cost_2 = 0
for i in range(N+1):
    if i < X:
        cost_1 += cost[i]
    elif i > X:
        cost_2 += cost[i]

print(min(cost_1,cost_2))

Solution (Python):


N,M,X = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

B = [0] * (N+1)

for a in A:
    B[a] = 1

print(min(B[:X].count(1), B[X+1:].count(1)))

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()))
root = [0]*n
for i in a:
    root[i] += 1
print(min(sum(root[:x+1]), sum(root[x:])))

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

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

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

Solution (Python):
MM = input().split()
N = int(MM[0])
M = int(MM[1])
X = int(MM[2])
LL = input().split()
a = 0
b = 0
for i in LL:
  if int(i) <X:
    a +=1
  else:
    b +=1
if a <= b:
  print(a)
else:
  print(b)

Solution (Python):
N, M, X = map(int,input().split())
A = list(map(int,input().split()))
ans = []
z = 0
y = 0
for i in range(X + 1, N + 1):
    if  i in A:
        z += 1
ans.append(z)
for i in range(1,X):
    if  i in A:
        y += 1
ans.append(y)
ans = sorted(ans)
print(ans[0])

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

import numpy as np
A_np = np.array(A)

cost_R = sum(X < A_np)
cost_L = sum(X > A_np)

print(min(cost_R, cost_L))

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

Solution (Python):
s = input().split()
n = int(s[0])
m = int(s[1])
x = int(s[2])

masu = []
for i in range(n + 1):
    masu.append(False)

v = input().split()
for i in range(m):
    z = int(v[i])
    masu[z] = True

left = 0
right = 0

for i in range(x):
    if masu[i]:
        left += 1

for i in range(x, len(masu)):
    if masu[i]:
        right += 1



answer = min(left, right)
print(answer)

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

r_count = 0
l_count = 0

tmp_1 = X
tmp_2 = X


while tmp_1 != N:
    tmp_1 += 1
    if tmp_1 in A:
        r_count += 1

while tmp_2 != 0:
    tmp_2 -= 1
    if tmp_2 in A:
        l_count += 1


res = min(l_count, r_count)
print(res)

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

left = []
right = []
for i in A:
    if i > X:
        right.append(i)
    else:
        left.append(i)
    

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

Solution (Python):






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

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

for j in range(len(A)):
    if X > A[j]:
        s+=1

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

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

B = [i for i in A if i < X]
C = [i for i in A if i > X]

print( min(len(B), len(C)))

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

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,-1,-1):
    if i+1 in a:
        ans1 += 1 
for j in range(x-1,n):
    if j+1 in a:
        ans2 += 1
print(min(ans1,ans2))

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

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

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

ans = min(ans1, ans2)
print(ans)

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

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m, x, *a = map(int, read().split())
left_cost = len([i for i in a if 0 < i < x])
right_cost = len([i for i in a if x < i < n])

print(min(left_cost, right_cost))

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

cost1 = 0

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

cost2 = 0

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

print(min(cost1, cost2))

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

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

m = [0]*(n+1)

for i in r:
    m[i] = 1
    
print(min(sum(m[:x]),sum(m[x:])))

Solution (Python):


import copy
import random
import bisect 
import fractions 
import math
import sys
import collections
from decimal import Decimal 

mod = 10**9+7
sys.setrecursionlimit(mod) 

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, M, X = LI()
A = LI()

left = 0
right = 0

cs = [0 for i in range(N)]
for a in A:
    cs[a] = 1
for i in range(X):
    if cs[i]:
        left += 1

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

print(min(left, right))

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

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

res = sum(y < x for y in al)  
ress = m-res

print(min(res,ress))

Solution (Python):
N, M, X  = map(int, input().split())
a=[]
for i in input().split():
  a.append(int(i) < X)
  c = a.count(True)
print(min(c, M-c))

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

lst = [0]*(N+1)

for i in range(M):
    lst[A[i]] = 1

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

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

print(min(sum(ans[:x]), sum(ans[x:])))

Solution (Python):
def solve():
    N, M, X = map(int, input().split())
    A = map(int, input().split())
    squares = [0 for _ in range(0, N+1)]
    for a in A:
        squares[a] = 1
    print(min(squares[:X].count(1), squares[X+1:].count(1)))


if __name__ == "__main__":
    solve()

Solution (Python):
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N,M,X = LI()
A =LI()
cost = 0
go_right = N-X
go_left = X
cost_right = 0
cost_left = 0
for i in range(X+1, N):
    if i in A:
        cost_right += 1

for j in range(1,X):
    if j in A:
        cost_left += 1

print(min(cost_left,cost_right))

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


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


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

print(min(cnt_g, cnt_s))

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

ans=sum([a[i]>x for i in range(m)])
ans=min(ans,m-ans)
print(ans)

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 i in range(X, N, 1):
    if i in A:
        ans_r += 1


min_cost = min(ans_l, ans_r)

print(min_cost)

Solution (Python):
import bisect

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

num = bisect.bisect_left(A, X)

result = min(M-num, num)

print(result)

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

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

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

c1 = [i for i in range(x)]
c2 = [i for i in range(x,n+1)]
y=0
z=0
for i in c1:
  if i in a:
    y += 1
for i in c2:
  if i in a:
    z += 1
print(min(y,z))

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

count = [i for i in a if i > X]
print(min(len(count), len(a)-len(count)))

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

for a in A:
  L[a]+=1

print(min(sum(L[:X]),sum(L[X+1:N])))

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


cost = 0
for i in range(x,m+1):
  if i in al:
    cost += 1

cost2 = 0
for i in range(x,0,-1):
  if i in al:
    cost2 += 1
    
print(min(cost, cost2))

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
    elif a[i] > X:
        sum2 += 1
    
if sum1 >=sum2 :
    print(sum2)
else:
    print(sum1)

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())
L=list(map(int,input().split()))
K=[i for i in L if i>X]
T=[i for i in L if i<X]
print(min(len(K),len(T)))

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
for i in range(M):
    if X < A[i]:
        ans = i
        break
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 X > A[i]:
        cnt += 1
print(min(cnt, M-cnt))

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

for i in range(m):
    if a[i] >= x:
        idx = i
        break

print(min(i, m-i))

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

s1 = 0
s2 = 0
for num in a:
    if num < x:
        s1 += 1
    elif num > x:
        s2 += 1
print(min(s1, s2))

Solution (Python):
N, M, X = input().split()
N = int(N)
M = int(M)
X = int(X)
A = input().split()
A = [int(A[i]) for i in range(M)]
A.append(X)
A = sorted(A)
if M/2 > A.index(X):
  print(A.index(X))

elif  M/2 < A.index(X):
  print(int(M-A.index(X)))

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

Solution (Python):
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
cost=sum(a>X for a in A)
print(min(cost,M-cost))

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

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

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

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

l = [i for i in A if i > X]

l2 = [i for i in A if i < X]

print(min(len(l), len(l2)))

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

Solution (Python):
from bisect import bisect_left
N,M,X = map(int, input().split())
A = [int(i) for i in input().split()]
print(min(bisect_left(A, X), len(A) - bisect_left(A, X)))

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

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

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

up = 0
down = 0
for a in an :
  if a > x :
    up += 1
  else :
    down += 1

if up > down :
  print(down)
else :
  print(up)

Solution (Python):
import bisect
n,m,x = map(int,input().split())
li = list(map(int,input().split()))
a = bisect.bisect_left(li,x)
if m - a >= a:
    print(a)
else:
    print(m-a)

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

Solution (Python):
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int, sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,M,X=LI()
AS=LI()

bef=0
aft=0
for i in AS:
    if i <= X:
        bef += 1
    else:
        aft += 1

print(min(bef, aft))

Solution (Python):
from bisect import bisect_left

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

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

Solution (Python):
from bisect import bisect_right

n, m, x = (int(x) for x in input().split())
A = list(int(x) for x in input().split())
index = bisect_right(A, x)
print(min(len(A[:index]), len(A[index:])))

Solution (Python):
def resolve():
    '''
    code here
    '''
    N, M, X = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]

    low = [item for item in As if item < X]
    high = [item for item in As if item > X]

    print(min(len(low), len(high)))


if __name__ == "__main__":
    resolve()

Solution (Python):
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    n, m, x = map(int, input().split())
    A = list(map(int, input().split()))
    idx = bisect_left(A, x)
    print(min(idx, m - idx))


if __name__ == "__main__":
    main()

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

Solution (Python):
import sys
N,M,X = map(int,input().split())
array_gate = list(map(int,input().split()))
array_base = [0] * (N+1)

if not ( 1 <= N,M <= 100):
    sys.exit()
if not ( 1 <= X <= N -1 ):
    sys.exit()
if not ( 1 <= min(array_gate) <= max(array_gate) <= N - 1):
    sys.exit()

for I in range(len(array_base)):
    if I in array_gate:
        array_base[I] = 1

left = array_base[0:X]
right = array_base[X:-1]
if left.count(1) <= right.count(1):
    result = left.count(1)
else:
    result = right.count(1)

print(result)

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

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

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

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

print(min(cost[0],cost[1]))

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

cnt_down = 0
cnt_up = 0
for i in range(x, 0, -1):
    if i in A: cnt_down += 1

for j in range(x, n+1, 1):
    if j in A: cnt_up += 1

ans = min(cnt_down, cnt_up)
print(ans)

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

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

cost2 = 0
for i in range(X, 0, -1):
    if i in A:
        cost2 += 1
print(min(cost1, cost2))

Solution (Python):
N,M,X=map(int,input().split())
A=[int(x) for x in input().split()]
ans=min(sum(x<X for x in A),sum(x>X for x in A))
print(ans)

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

toN =0
to0 =0

for i in range(X+1,N):
  if i in As:
    toN +=1
for i in range(X-1,0,-1):
  if i in As:
    to0 +=1
print(min(toN,to0))

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

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

count_b=m-count_a

print(min(count_a,count_b))

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

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

Solution (Python):
n, m, x, *aa = map(int, open(0).read().split())

print(min(len([a for a in aa if a<x]), len([a for a in aa if a>x])))

Solution (Python):
def actual(N, M, X, A):
    
    toll_gates_left = [a_i for a_i in A if a_i < X]
    toll_gates_right = [a_i for a_i in A if X < a_i]

    return min(len(toll_gates_left), len(toll_gates_right))

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

print(actual(N, M, X, A))

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

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

l = list(range(1, X))
r = list(range(X+1, N+1))

l_c = len(set(A)&set(l))
l_r = len(set(A)&set(r))

print(min(l_c, l_r))

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

Solution (Python):
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
B = len([a for a in A if a<X])
print(B if B<M//2 else M-B)

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

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

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

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

Solution (Python):
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,m,x = nm()
a=nl()

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

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

print(min(len([w for w in a_li if 0 <= w <= x]),
          len([w for w in a_li if min(x, n) <= w <= max(x, n)])))

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





left = bisect.bisect_left(a,x)
print(min(left,len(a)-left))

Solution (Python):









import sys
input = sys.stdin.readline

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

for A in list_A:
    if A < X:
        l += 1
    else:
        r += 1

print(min(l, r))

Solution (Python):
import numpy as np

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

ans = 0
if N <= X:
    ans = np.intersect1d(A[A > N], A[A < X]).shape[0]
else:
    ans = min(
        np.intersect1d(A[A > 0], A[A < X]).shape[0],
        np.intersect1d(A[A < N], A[A > X]).shape[0],
    )

print(ans)

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

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

print(min(ans1,ans2))

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

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

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

nlis = [0]*(n+1)

for i in lis:
    nlis[i] = 1

ans = min(sum(nlis[:x]), sum(nlis[x:]))

print(ans)

Solution (Python):
a,b,c=map(int,input().split())
d=list(map(int,input().split()))
result1=list(range(0,c+1))
result2=list(range(c,a+1))
ans1=0
ans2=0
for i in result1:
  if i in d:
    ans1+=1
for i in result2:
  if i in d:
    ans2+=1
print(min(ans1,ans2))

Solution (Python):
N,M,X = map(int, input().split())
A = list(map(int, input().split()))
B = []
C = []
for i in range(0, X):
  if i in A:
    B.append(i)
for j in range(X, N):
  if j in A:
    C.append(j)
print(min(len(B), len(C)))

Solution (Python):









import os
import sys




def main():
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    if x<a[0] or a[-1]<x:
        print("0")
        return

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



if __name__ == "__main__":
    main()

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

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

print(min(len(lst[:z]), len(lst[z:])))

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

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=[int(x) for x in input().split()]
B=[0 for i in range(N)]
for i in range(M):
  B[A[i]]=1

left=sum(B[:X])
right=M-left
print(min(left,right))

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

A = list(map(int, input().split()))
for a in A:
    squares[a] = 1

root_a = sum(squares[0: X])
root_b = sum(squares[X: N+1])

if root_a < root_b:
    print(root_a)
else:
    print(root_b)

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

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

for i in range(m):
	if x<S[i]:
		F=S[:i]
		break

print(min(len(F), len(S)-len(F)))

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

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

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

for i in A:
  if 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()))

for i in range(m):
    if a[i] > x:
        p = i
        break


i = p
j = m - p

print(min(i,j))

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

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

cost = [1 if i+1 in A else 0 for i in range(N)]

if sum(cost[:X]) > sum(cost[X:]):
    print(sum(cost[X:]))
else: print(sum(cost[:X]))

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

Solution (Python):
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
au = []
at = []
for i in range(m):
  if a[i] < x:
    au.append(a[i])
  else:
    at.append(a[i])

auv = len(au)
atv = len(at)
print(min(auv,atv))

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

print(min(left,right))

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

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

m_low =0

for a in A:
  if X < a:
    break
  m_low+=1
  
m_high = M - m_low

print(m_low if m_low<m_high else m_high)

Solution (Python):

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


cost = min(len([a for a in A if a > X]), len([a for a in A if a < X]))
print(cost)

Solution (Python):
import sys
INF = 1 << 60
MOD = 10**9 + 7 
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, m, x = map(int, input().split())
    toll = [False] * (n + 1)
    for a in map(int, input().split()):
        toll[a] = True

    back = 0
    for i in range(x - 1, -1, -1):
        back += toll[i]
    forth = 0
    for i in range(x + 1, n + 1):
        forth += toll[i]
    print(min(back, forth))
resolve()

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,list(input().split()))
A =  list(input().split())
count = 0
for i in range(M):
    if int(A[i]) < X:
        count += 1
print(min(count,M-count))

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

Solution (Python):

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


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

print(min(right,left))

Solution (Python):
def resolve():
    N, M, X = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    for i in range(M):
        if A[i] > X:
            break
    print(min(len(A[:i]), len(A[i:])))


resolve()

Solution (Python):
a = [input().split() for l in range(2)]

N = int(a[0][0]) 
M = int(a[0][1]) 
X = int(a[0][2]) 

goal_len01 = N - X 
goal_len02 = X 

cost1 = 0
for i in range(goal_len01):
  if str(X+i+1) in a[1]:
    cost1 += 1

cost2 = 0
for i in range(goal_len02):
  if str(i+1) in a[1]:
    cost2 += 1

min_cost = 0
if cost1 >= cost2:
  min_cost = cost2
else:
  min_cost = cost1
  
print(min_cost)

Solution (Python):


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

L = []
for i in range(1, N):
    if i in A:
        L.append(True)
    else:
        L.append(False)

index = X - 1

ans1 = L[:index].count(True)
ans2 = L[index+1:].count(True)

if ans1 < ans2:
    print(ans1)
else:
    print(ans2)

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

a = 0
b = 0
for i in range(M):
    if S[i] < X:
        a += 1
    else:
        b += 1
print(min(a, b))

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

l_cnt = 0
for a in A_list:
    l_cnt += 1 if a < X else 0
print(min(l_cnt, M-l_cnt))

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

Solution (Python):
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
money=[False]*N
leftcount=0
rightcount=0
for i in A:
    money[i]=True
for i in range(X,0,-1):
    if money[i]==True:
        leftcount+=1
for i in range(X,N):
    if money[i]==True:
        rightcount+=1
if leftcount>rightcount:
    print(rightcount)
else:
    print(leftcount)

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