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

Solution (Python):
import sys
input = sys.stdin.readline

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

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

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

ans1 = 0
ans2 = 0
for r in a:
    if(r < 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()))

left = 0
right = 0
for _a in a:
    if _a < x:
        left += 1
    elif x < _a:
        right += 1

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

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

    answer1 = 0
    answer2 = 0
    for i in range(M):
        if X < A_list[i]:
            answer1 += 1
        if X > A_list[i]:
            answer2 += 1
    print(min(answer1, answer2))

Solution (Python):
n=input().split()
M,X=int(n[1]),int(n[2])
A=input().split()
p=0
for i in range(M):
    if int(A[i])>X:
        p+=1
if p>M/2:
    print(M-p)
else:
    print(p)

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

Solution (Python):
N, M, X = [int(nmx) for nmx in input().split()]
A = [int(a) for a in input().split()]
A.append(X)
A.sort()
idx_X = A.index(X)
if len(A)//2 < idx_X+1:
  ans = len(A)- (idx_X+1)
else:
  ans = (idx_X+1) - 1
print(ans)

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

left = 0
right = 0

for i in lst:
    if i < x:
        left += 1
    else:
        right += 1

print(min(left,right))

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

left = sum(1 if x < X else 0 for x in A)
right = M-left

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

Solution (Python):
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, M, X = list(map(int, sys.stdin.readline().split()))
A = np.array(list(map(int, sys.stdin.readline().split())))

print(min(len(A[A > X]), len(A[A<X])))

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

cnt1 = len([i for i in lia if i<x])
cnt2 = m - cnt1
print(min(cnt1,cnt2))

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

left = list(filter(lambda el: el < x, a))
right = list(filter(lambda el: el > x, a))

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

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

right = 0
left = 0

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

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

Solution (Python):
nmx = list(map(int, input().split()))
toll = list(map(int, input().split()))
s = 0
lng = len(toll)
for i in range(lng):
    if toll[i] < nmx[2]:
        s = s + 1
    else:
        break

if s < nmx[1] - s:
    print(s)
else:
    print(nmx[1] - s)

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

Solution (Python):


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

ar = list(range(1,x))

cnt = 0

for i in range(len(ar)):
    cnt += a.count(ar[i])

print(min(cnt, m-cnt))

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

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

s=0
for i in range(M):
    if tg[i]<=X:
        s+=1


print(min(s,M-s))

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

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

if N == X or 0 == X:
    print(0)

else:
    s_cost = 0
    e_cost = 0
    for i in range(0,X):
        if i in A:
            s_cost += 1
    for i in range(X,N):
        if i in A:
            e_cost += 1
    print(min(s_cost,e_cost))

Solution (Python):
n,m,x=map(int,input().split())
A=list(map(int,input().split()))
A.append(x)
A.sort()
c=A.index(x)
print(min(c,len(A)-c-1))

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

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

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

g=list(map(int, input().split()))
r=0
l=0
for i in range(m):
    if g[i]<x:
        l+=1
    else:
        r+=1

print(min(r,l))

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

Solution (Python):
list = input().split()
N = int(list[0])
M = int(list[1])
X = int(list[2])
A = input().split()
A = [int(i) for i in A]

cnt_left,cnt_right = 0,0
for i in range(X,N+1):
    for j in A:
        if j == i:
            cnt_right += 1
for i in range(0,X):
    for j in A:
        if j == i:
            cnt_left += 1
print(min(cnt_left,cnt_right))

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

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

Solution (Python):
N,M,X=map(int,input().split())
a=list(map(int,input().split()))
k=0
x=X
y=N-X
c=0
for i in range(M):
    if X<a[i]:
        k+=1
    elif X>a[i]:
        c+=1
print(min(c,k))

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

xaxis = [1 if i in ag else 0 for i in range(n+1)]
print(min(sum(xaxis[:x+1]), sum(xaxis[x:])))

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

x_large = len([i for i in range(len(toll)) if toll[i] > x])
x_small = len([i for i in range(len(toll)) if toll[i] < x])

print(min(x_large, x_small))

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

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

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

cnt0 = 0

cntn = 0

for i in a:
    if i>x:
        cntn += 1
    else:
        cnt0 += 1

print(min(cnt0,cntn))

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

cnt = 0
while a[cnt] < x and cnt != m-1:
    cnt += 1
cnt2 = 0
while a[m - 1 - cnt2] > x and m - 1 - cnt2 != 0:
    cnt2 += 1
print(min(cnt,cnt2))

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

cost_to_reach_0 = len([i for i in A if i < X])
cost_to_reach_N = len([i for i in A if i > X])

print(min(cost_to_reach_0, cost_to_reach_N))

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

cost0 = 0
costN = 0

for 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 = [int(i) for i in input().split()]
loc = 0
for i, j in enumerate(a):
    while j < x:
        loc += 1
        break
print(min(loc, m-loc))

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

cell = [0] * (N+1)

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

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

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

l = [0] * n
for c in a:
  l[c] = 1

print(sum(l[x:]) if sum(l[:x]) > sum(l[x:]) else sum(l[:x]))

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

Solution (Python):

import sys


def solve(N: int, M: int, X: int, A: "List[int]"):
    L = [0] * (N+1)
    for a in A:
        L[a] = 1
    print(min(sum(L[0:X]),sum(L[X+1:])))

    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())
list_a = list(map(int,input().split()))
goal_0 = 0
goal_N = 0
for i in list_a:
    if i > X:
        break
    goal_0 += 1
for i in list_a[::-1]:
    if i < X:
        break
    goal_N += 1
print(min(goal_0,goal_N))

Solution (Python):
def smaller(x, y):
	if x < y: return x
	return y

N, M, X = map(int, raw_input().split())
A = map(int, raw_input().split())
left = 0
right = 0
for i in range(0, X):
	if i in A: left += 1
for i in range(X+1, N+1):
	if i in A: right += 1
print smaller(left, right)

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

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

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


print(min(len([i for i in A if i<X]), len([i for i in A if i>X])))

Solution (Python):
n,m,x=map(int,input().split())
l=list(map(int,input().split()))+[x]
l1=sorted(l)
i=l1.index(x)
print(min(i,m-i))

Solution (Python):
n, m, x = [ int(v) for v in input().split() ]
point_list = [ int(v) for v in input().split() ]
point_left = [ v for v in point_list if v < x ]
point_right = [ v for v in point_list if v > x ]
print(min(len(point_left),len(point_right)))

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

costs = [0] * (N + 1)

for val in A:
    costs[val] = 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()))
a = 0
b = 0

for i in range(X):
    if i in A:
        a += 1

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

print(min(a, b))

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

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

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

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

a = 0
b = 0
for i in lst:
    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()))
number1 = 0
number2 = 0

for i in range(M):
    if X > A[i]:
        number1 += 1
    else:
        number2 += 1

if number1 > number2:
    print(number2)
else:
    print(number1)

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

'''
for i,c in enumerate(a):
    if X < c:
        print(min(i,M-i))
        break
'''
import bisect
i = bisect.bisect_left(a,X)
print(min(i,M-i))

Solution (Python):
_,M,X = list(map(int,input().split()))
a = list(map(int,input().split()))
for i,c in enumerate(a):
    if X < c:
        print(min(i,M-i))
        break

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

Solution (Python):

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


_X=X


c1=c2=0


for i in range(N-X):
  
  _X+=1

  
  if l.count(_X)>0:
    c1+=1


_X=X


for i in range(X-0):
  
  _X-=1

  
  if l.count(_X)>0:
    c2+=1


print(min(c1,c2))

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

Solution (Python):

import sys


def solve(N: int, M: int, X: int, A: "List[int]"):
    l, r = 0, 0
    for a in A:
        if a < X:
            l += 1
        else:
            r += 1
    ret = min(l, r)
    print(ret)
    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()))
i = 0
cnt = 0
while A[i] < X:
	cnt += 1
	i += 1
if A[i] == X:
	opp = M - cnt -1
else:
	opp = M - cnt
print(min(cnt, opp))

Solution (Python):


from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)





def main():
    n, m, x = intin()
    alist = intina()

    left = 0
    right = 0

    for a in alist:
        if a < x:
            left += 1
        else:
            right += 1

    print(min(left, right))


if __name__ == '__main__':
    main()

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

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

cd = 0
cu = 0
for i in range(M):
    if A[i] > X:
        cu += 1
    elif A[i] < X:
        cd += 1
    else:
        ca += 1
        cd += 1
print(min(cu,cd))

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

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

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

List = list(map(int, input().split()))
List.append(x)

List.sort()

cnt = List.index(x)

print(cnt if cnt < m-cnt else m-cnt)

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

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

B = [0]*(N+1)
for i in range(N+1):
    if i in A:
        B[i] += 1
cost = min(sum(B[:X]),sum(B[X:]))

print(cost)

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

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

cnt0 = 0
cntn = 0
for item in lst:
    if item < x:
        cnt0 += 1
    elif item > x:
        cntn += 1
print(min(cnt0, cntn))

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

cnt0 = 0
cntn = 0
for item in lst:
    if item < x:
        cnt0 += 1
    elif item > x:
        cntn += 1
print(min(cnt0, cntn))

Solution (Python):
a, b, c = (int(i) for i in input().split())  
l = [int(i) for i in input().split()] 
print(min(sum([1 for i in l if i > c]),sum([1 for i in l if i < c])))

Solution (Python):
n,m,x=map(int,input().split())
a=list(map(int,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()))
yy = 0
zz = 0
for i in a:
    if i<x:
        yy += 1
    else:
        zz += 1
print(min(yy,zz))

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

S=n[0:X]
B=n[X:]
print(min(sum(S),sum(B)))

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

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

print(min(a,b))

Solution (Python):
from collections import defaultdict
import math


def kari():
    map(int, input().split())
    list(map(int, input().split()))
    math.ceil()

def main():
    num, coust_num, start = map(int, input().split())
    data = set(list(map(int, input().split())))

    left = 0
    for i in range(1, start):
        if i in data:
            left += 1


    right = 0
    for i in range(start + 1, num):
        if i in data:
            right += 1

    print(min(right, left))








if __name__ == '__main__':
    main()

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

fee_to_head = len(list(filter(lambda n: n < X, A)))
fee_to_tail = len(list(filter(lambda n: n > X, A)))
print(min(fee_to_head, fee_to_tail))

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

for i in l:
    a[i] = 1

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

Solution (Python):
import sys, os
import bisect

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,m,x = f()
    a = f()

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

solve()

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

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

Solution (Python):
n,m,x=map(int,input().split())
a=map(int,input().split())
A=[0]*100

for i in a:
    A[i]+=1
print(min(sum(A[:x]),sum(A[x+1:])))

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

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

print(min(Lcnt,Rcnt))

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

Solution (Python):
import sys
import math

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

Solution (Python):
n,m,x=map(int,input().split())
a=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):
box_l, _, start = map(int, input().split())
cost_arr = list(map(int, input().split()))
left = len([num for num in cost_arr if num < start])
right = len([num for num in cost_arr if num > start])
print(min(left, right))

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
if x<a[0]:
    p=0
print(min(p,m-p))

Solution (Python):
def main():
  N, M, X = [int(x) for x in input().split()]
  costs = [0] * (N + 1)
  for x in [int(x) for x in input().split()]:
    costs[x] = 1

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


if __name__ == "__main__":
  main()

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

a.append(x)
a.sort()
y=a.index(x)

print(min(len(a[:y]),len(a[y+1:])))

Solution (Python):
N,M,X=map(int,input().split())
A=input().split()
A=[int(i) for i in A]
F=[]
B=[]
for i in range(M):
	if X<A[i]:
		F=A[:i]
		B=A[i:]
		break
print(min(len(F),len(B)))

Solution (Python):

def read_input():
    n, m, x = map(int, input().split())
    costs = [0] * (n + 1)

    alist = map(int, input().split())
    for a in alist:
        costs[a] = 1

    return n, m, x, costs


def submit():
    n, m, x, costs = read_input()


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


if __name__ == '__main__':
    submit()

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

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

x = 0
y = 0
for a in range(0,N):
  if a in A and a < X:
    x += 1
  elif a in A and X < a:
    y += 1
  else:
    continue

print(x if x < y else y)

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 x > a[i]:
        l += 1
    else:
        r += 1


print(min(l, r))

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

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

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(' '))))
pre = [a for a in A if a < X]
bih = [b for b in A if X < b]
X = len(pre)
Y = len(bih)
MIN = min(X,Y)
print(MIN)

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 = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
lst.append(x)
lst = sorted(lst)
print(min(len(lst[: lst.index(x)]), len(lst[lst.index(x) + 1 :])))

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

l, r = 0, 0
for ai in a:
    if ai < 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()))
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()))
count=0
for a in A:
    if a<X:
        count+=1
print(min(count,M-count))

Solution (Python):
import sys
from collections import Counter

n, m, x = map(int, input().split())
a_list = list(map(int, input().split()))
math_list = []

for i in range(n):
    if i in a_list:
        math_list.append(1)
    else:
        math_list.append(0)

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

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

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

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

Solution (Python):
N,M,X = map(int, input().split())
A = list(map(int, input().split()))
sorted_A = sorted(A)
for i in range(M):
    if A[i]>=X:
        cnt = i
        break
ans1 = len(A[cnt:])
ans2 = len(A[:cnt])
ans = min(ans1,ans2)
print(ans)

Solution (Python):
def main():
	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))


if __name__ == '__main__':
	main()

Solution (Python):
N,M,X = map(int,input().split())
a_list = [int(i) for i in input().split()]
result1 = 0
result2 = 0
for item in a_list:
	if item >X:
		result1+=1
	elif item <X:
		result2+=1
print(min(result1,result2))

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

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

temp1, temp2 = 0, 0
for i in A:
    if 0 < i < X:
        temp1 += 1
    elif X < i < N:
        temp2 += 1
print(min(temp1, temp2))

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

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

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

a = np.array(a)


print(min(sum(a>x), sum(a<x)))

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

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

goal_0 = 0
goal_N = 0

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

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

if goal_0 >= goal_N:
    print(goal_N)
else:
    print(goal_0)