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 = [int(i) for i in input().split() if int(i) < x]
print(len(A) if m - len(A) > len(A)  else m - len(A))

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

Solution (Python):

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

count_l = 0
count_r = 0
for i in range(m):
    if a[i] < x:
        count_l += 1
    if a[i] > x:
        count_r += 1
print(min(count_l, count_r))

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

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
  elif(a > X):
    r += 1
print(min(l, r))

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

fee=[]

for i in range(n):
    fee.append('1' if i in a else '0')

print(min(fee[0:x].count('1'),fee[x::].count('1')))

Solution (Python):
int_n, int_m, int_x = map(int, input().split())

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


to_start = len([x for x in int_a_ar if x < int_x])

to_end = len([x for x in int_a_ar if x > int_x])


cost = to_start if to_start < to_end else to_end

print(cost)

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

c = 0
for i in range(len(A)):
    if A[i] < X:
        c += 1
cost.append(c)

c = 0
for i in range(len(A)):
    if X < A[i]:
        c += 1
cost.append(c)

print(min(cost))

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

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

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

cost0 = 0
costN = 0

for i in range(1, N):
    if i in A:
        if i < X:
            cost0 += 1
        else:
            costN += 1

print(min(cost0, costN))

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

xr = 0
xl = 0

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

Solution (Python):
n,m,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
before=0
after=0
for i in range(x):
    if i in a:
        before+=1
for j in range(x+1,n):
    if j in a:
        after+=1
print(min(before,after))

Solution (Python):
n, m, x = map(int,input().split())
a = list(map(int,input().split()))
ans1 = 0
ans2 = 0
if x == 1 or x == n:
    print(0)
else:
    for i in range(1, x):
        if len(a) != 0:
            if a[0] == i:
                ans1 += 1
                a.pop(0)
    if len(a) != 0:
        for i in range(x, n):
            if len(a) != 0:
                if a[0] == i:
                    ans2 += 1
                    a.pop(0)
    ans = min(ans1, ans2)
    print(ans)

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

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

Solution (Python):

import sys



def solve(lines):
    N,M,X = map(int, lines.pop(0).split(' '))
    A = list(map(int, lines.pop(0).split(' ')))
    less = more = 0
    for i in A:
        if i < X:
            less += 1
        else:
            more += 1
    print(min(more, less))





lines = [x.strip() for x in sys.stdin.readlines()]




solve(lines)

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

Solution (Python):

n,m,x = map(int,input().split())
aa = list(map(int,input().split()))
aa.append(x)
aa = sorted(aa)

idx=aa.index(x)
print(min(idx, m-idx))

Solution (Python):
""" AtCoder """

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

A.append(X)
A.sort()

print(min(A.index(X), M - A.index(X)))

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

first = X
last = N+1-X
first_count = 0
last_count = 0

for a in range(len(A)):
    if X < A[a]:
        first_count += 1
    else:
        last_count += 1

if first_count > last_count:
    ans = last_count
else :
    ans = first_count

print(ans)

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

for i in range(m):
    if a[i]<x:
        o += 1
    elif a[i]>x:
        l += 1
print(min(o,l))

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

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

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

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

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

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


main()

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

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

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

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

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

print(min(left,right))

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

l_even = [i for i in gate if i < X]
print(min(len(l_even),M-len(l_even)))

Solution (Python):
n,m,x=map(int,input().split())
a=[int(i) for i in input().split()]
be=0
af=0
for i in range(m):
    if a[i]<x:
        be+=1
    elif a[i]>x:
        af+=1
print(be if be<af else af)

Solution (Python):

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

A = [i for i in map(int, input().split())]
squares=[i for i in range(N+1)]
V=squares[X]
lowest=[]
highest =[]
for i in range(len(A)):
    if A[i]<V:
        lowest.append(A[i])
    else:
        highest.append(A[i])
if len(lowest)>len(highest):
    cost = len(highest)
else:
    cost = len(lowest)

print(cost)

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

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

    print(min(l, r))


if __name__ == '__main__':
    main()

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

    p1 = 0
    for i in range(x, 0, -1):
        if i in a_:
            p1 += 1

    p2 = 0
    for i in range(x, n):
        if i in a_:
            p2 += 1

    print(min([p1, p2]))


if __name__ == '__main__':
    main()

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

    p1 = 0
    for i in range(x - 1, -1, -1):
        if i in a_:
            p1 += 1

    p2 = 0
    for i in range(x + 1, n):
        if i in a_:
            p2 += 1

    print(min([p1, p2]))


if __name__ == '__main__':
    main()

Solution (Python):
N, M, X, = map(int,input().split())
L = list(map(int,input().split()))
cnt1 = 0
cnt2 = 0
for x in L:
    if x < X:
        cnt1 += 1
    else :
        cnt2 += 1

print(min(cnt1, cnt2))

Solution (Python):
from bisect import bisect_right

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

i = bisect_right(As, X)
print(min(i, M-i))

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

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

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

Solution (Python):
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
s=0
i=0
while a[i]<=x:
    s+=1
    i+=1
print(min(s,m-s))

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

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

count_left=0
count_right=0

for i in range(m):
  if a[i]<x:
    count_left +=1
  if a[i]>x:
    count_right+=1

print(min(count_left,count_right))

Solution (Python):
n, m, x = (int(y) for y in input().split())
A_lis = [int(y) for y in input().split()]
res = 0

for i in A_lis:
    if (i>x):
        res +=1

print(min(res,m-res))

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 = [int(i) for i in input().split()]

A.append(x)
A.sort()
idx = A.index(x)

l = len(A[:idx])
r = len(A[idx:]) - 1
if l < r:
    print(l)
else:
    print(r)

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

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

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

print(min(s,d))

Solution (Python):

import bisect

def main():
    na = list(map(int, input().split()))
    N, M, X = na[0], na[1],na[2]
    A = list(map(int, input().split()))

    i = bisect.bisect_left(A, X)

    print(min(i, M - i))


if __name__ == '__main__':
    main()

Solution (Python):
n, m, x = map(int, input().split())
l = list(map(int, input().split()))
a = {}
for t in l:
    a[t] = 1

total1 = 0
i = x
while i >= 0:
    i -= 1
    total1 += a.get(i, 0)

total2 = 0
i = x
while i <= n:
    i += 1
    total2 += a.get(i, 0)

print(min(total1, total2))

Solution (Python):
a,b,k=map(int,input().split())
p=[i for i in list(map(int,input().split()))if i<k]
print(min(b-len(p),len(p)))

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

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

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

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

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

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

L = list(filter(lambda x:x<X,A))
R = list(filter(lambda x:x>X,A))

print(min(len(L),len(R)))

Solution (Python):
n,b,sta=map(int,input().split())
A=list(map(int,input().split()))
Z=["F" for i in range(n+1)]
for i in A:
  Z[i]="B"
fi=Z[:sta:]
se=Z[sta+1::]
print(min(fi.count("B"),se.count("B")))

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

Solution (Python):

import sys
input = sys.stdin.readline

N, M, start = map(int, input().split())
lst_gate = map(int, input().split())

left = 0
right = 0
for gate in lst_gate:
    if gate < start:
        left += 1
    else:
        right += 1
print(min(left, right))

Solution (Python):

import sys
input = sys.stdin.readline

N, M, start = map(int, input().split())
lst_station = input().split()

cost2zero = sum(1 for i in range(start) if str(i) in lst_station)
cost2N = sum(1 for i in range(start+1, N+1) if str(i) in lst_station)

print(min(cost2zero, cost2N))

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

for i in range(len(A_LIST)):
    A_LIST[i]=int(A_LIST[i])

left_counter=0
right_counter=0

for i in A_LIST:
    if i<X:
        left_counter+=1
    else:
        right_counter+=1

print(left_counter if left_counter<right_counter else right_counter)

Solution (Python):
a,b,c= map(int, input().split())
p = list(map(int, input().split()))
k = 0
for i in range(b):
    if p[i] < c:
        k+=1
print(min(k,b-k))

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

Solution (Python):
import bisect
A,B,X = list(map(int,input().split()))
l = list(map(int,input().split()))

print(min(bisect.bisect_left(l,X),(len(l)-bisect.bisect_left(l,X))))

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

countmax=0
count0=0

for i in range(M):
    if(A[i]<X):
        count0+=1
    elif(A[i]>X):
        countmax+=1
    else:
        count0+=1
        countmax+=1

if(count0>countmax):
    print(countmax)
else:
    print(count0)

Solution (Python):



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

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

    for i in range(n - x):
        temp = x + i + 1
        if temp in a:
            right += 1

    print(min(left, right))


if __name__ == "__main__":
    main()

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

count = 0
for i in input().split():
    if int(i) > X:
        break
    count += 1

print(min(count , M-count))

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


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

Solution (Python):
import bisect

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

l = bisect.bisect_left(A, X)
r = M - l

print(min(l, r))

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

A = map(int, input().split())
count0=0
count1=0
for i in A:
    if(i<X):
        count0+=1
    else:
        count1+=1
print(min(count0, count1))

Solution (Python):


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

b=[]
c=[]
for i in range(X+1,N): 
  if i in a: 
    b.append(1)
for i in range(1,X): 
  if i in a: 
    c.append(1)
print(min(sum(b),sum(c)))

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


if __name__ == '__main__':
    main()

Solution (Python):
from statistics import mean, median,variance,stdev
import sys
import math
import fractions
def j(a):
    if a==1: print("Yes")
    else :print("No")


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())



x,y,z = (int(i) for i in input().split())    

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


c = z
a.append(c)
a.sort()
p = a.index(c)
print(min(len(a)-p-1,p))

Solution (Python):

 
n, m, x = map(int, input().split())
gates = list(set(map(int, input().split())))
costs = [0]*n

for gate in gates:
    costs[gate] = 1

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

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

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

fare = 0


for i in range(X) :
    if (i in gates) :
        fare += 1

min_fare = fare
fare = 0
for i in range(X,N+1) :
    if (i in gates) :
        fare += 1

if (min_fare > fare) :
    min_fare = fare

print(min_fare)

Solution (Python):
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([c for c in a if c >x])))

Solution (Python):
N,M,X=map(int,input().split())
a=[int(i) for i in input().split()]
n=X
for i in  range(M):
    if a[i]>X:
        n=i
        break
print(min(n,M-n))

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

Solution (Python):
N,M,X = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = []
count = 0
for i in range(X,N+1):
    if i in ar:
        count += 1
br.append(count)
count = 0
for i in range(X,-1,-1):
    if i in ar:
        count += 1
br.append(count)
print(min(br))

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

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

for item in clist:
    if item<x:
        lroot += 1
    else:
        rroot += 1

print(min(lroot,rroot))

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

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

res = min(sum([True for _ in a if _<x]), sum([True for _ in a if _>x]))
print(res)

Solution (Python):
a,b,c=map(int,input().split())
d=[int(i) for i in input().split()]

e=[]
f=[]
for i in range(b):
	if d[i]<c:
		e.append(d[i])
	else:
		f.append(d[i])


g=len(e)
h=len(f)
if g<=h:
	print(g)
else:
	print(h)

Solution (Python):

n, m, x = map(int, input().split())
a = list(map(int, input().split()))
s = sum(1 if b < x else 0 for b in a)
print(min(s, m-s))

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

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

s = [c for c in a if c<x]
l = [c for c in a if c>x]

print(min(len(s),len(l)))

Solution (Python):



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

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


if __name__ == '__main__':
    solve()

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

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

    c1 = 0
    c2 = 0
    for a in A:
        if a < x:
            c1 += 1
        else:
            c2 += 1

    print(min(c1, c2))

if __name__ == "__main__":
    main()

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

result = min(sum(a < X for a in A), sum(a > X for a in A))
print(result)

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

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


left, right = 0, 0
for a in A:
    if a < X:
        left += 1
    else:
        right += 1

print(min(left, right))

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


left, right = 0, 0
for a in A:
    if a < X:
        left += 1
    else:
        right += 1

print(min(left, right))

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

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

sum0 = 0
sumn = 0

route = [0] * (n+1)

for i in m_index:
    route[i] = 1

for i in range(x, n+1):
    sumn += route[i]
for i in range(x+1):
    sum0 += route[i]

print(min(sumn,sum0))

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

left_toll, right_toll = 0, 0
for a_i in A_m:
    if a_i < X:
        left_toll += 1
    else:
        right_toll += 1

print(left_toll if left_toll < right_toll else right_toll)

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

Solution (Python):
n,m,x=(int(i) for i in input().split(' '))
a=[int(i) for i in input().split(' ')]
a+=[x]
a.sort()
print(min(a.index(x),m-a.index(x)))

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

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

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

print( min( [total,m-total] ))

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

former = len([a for a in A_list if a < X])
later = len([a for a in A_list if X < a])

print min(former, later)

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

from bisect import *

p = bisect_left(A, X)
l = p
r = M - p
print(min(l, r))

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

c1 = 0
c2 = 0

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

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

print(min(c1,c2))

Solution (Python):
import bisect
N, M, X = map(int, raw_input().split())
A = map(int, raw_input().split())
i = bisect.bisect_left(A, X)
if i == 0 or M - i == 0:
	print 0
elif i < M - i:
	print i
else:
	print M - i

Solution (Python):
n,m,x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
rn = [i for i in a if n>=i>=x]
r0 = [i for i in a if x>=i>=0]
print(len(rn)) if len(rn)<len(r0) else print(len(r0))

Solution (Python):
import bisect

n, m, x = map(int, input().split())
a = [int(s) for s in input().split()]
idx = bisect.bisect(a, x)
print(min(idx, m - idx))

Solution (Python):
nmx = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in a:
    if i > nmx[2]:
        print(min(a.index(i),nmx[1]-a.index(i)))
        break

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

Solution (Python):
import bisect

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

i = bisect.bisect_right(a, x)
print(min(i, m-i))

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

ans = 0
for x in range(X,N+1):
    if x in A:
        ans += 1
ans2 = M - ans

print(min(ans, ans2))

Solution (Python):
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m,x = li()
a = list(li())
small = 0
large = 0
for ai in a:
    if ai < x:
        small += 1
    else:
        large += 1

print(min(small, large))

Solution (Python):


import sys


input = sys.stdin.readline


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


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

cnt = 0
for a in A:
    if X > a:
        cnt += 1

print(min(cnt, M - cnt))

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

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

print(min(pre, fo))

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
    else:
        print(min(S, M - i))
        exit()

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

Solution (Python):
from sys import stdin


def main() -> None:
    n, m, x = [int(s) for s in input().split()]
    up = down = 0
    for i in range(m):
        ai = int(next_str())
        if ai < x:
            down += 1
        else:
            up += 1

    print(min(up, down))


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

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

Solution (Python):
n,_,x=map(int,input().split())
l=list(map(int,input().split()))
print(min(sum(a>x for a in l),sum(a<x for a in l)))

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

c1, c2 = 0, 0
for i in range(m):
    if a[i] < x:
        c1 += 1
    else:
        c2 += 1
print(min(c1, c2))

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

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

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

l = r = 0
for a in aa:
    if a < x:
        l = l + 1
    else:
        r = r + 1
print(min(l, r))

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

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

hidari = [i for i in A if i<=X]
migi = [i for i in A if X<=i]
print(min(len(hidari), len(migi)))

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

if x >= max(a) or x <= min(a):
    print(0)
else:
    cnt = 0
    for i in range(m):
        if a[i] > x:
            cnt += 1
    print(min(cnt,len(a)-cnt))

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

x_more = [x < a_i for a_i in a]

print(min(x_more.count(True), x_more.count(False)))

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

Solution (Python):
"""
B - Toll Gates
"""

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

value = []
for part in input().split():
    value.append(int(part))

left = 0
right = 0
for i in value:
    if 1 <= i and i < x:
        left += 1
    if x < i and i <= n:
        right += 1

print(min(left, right))

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

arr = [0]*(N+1)

for a in A:
    arr[a] = 1

ans = min(sum(arr[1:X]), sum(arr[X:-1]))

print(ans)

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

Y = X
S1 = []
while Y < N:
    Y += 1
    S1.append(Y)

Z = X
S2 = []
while Z > 0:
    Z -= 1
    S2.append(Z)

risuto = []
risuto.append(len(set(A) & set(S1)))
risuto.append(len(set(A) & set(S2)))
print(min(risuto))

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

result=0

if x>cost_list[m-1] or x<cost_list[0]:
    result=0
else:
    cost_larger_n=sum([1 for i in cost_list if i>x and i<n]) 
    if cost_larger_n <= m-cost_larger_n:
        result=cost_larger_n
    else:
        result=m-cost_larger_n

print(result)

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

ans1 = 0
ans2 = 0

for i in range(n + 1):
    if i in a:
        if i < x:
            ans1 += 1
        elif i > x:
            ans2 += 1


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