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

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M, X = lr()
A = lr()
left = sum(1 for y in A if y < X)
right = M - left
answer = min(left, right)
print(answer)

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

ans = 0
for i in range(m):
  if A[i] <= x:
    ans += 1
  else:
    break
    
print(min(ans, m-ans))

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

nums = [0] * (n + 1)
indices = list(map(int, input().split()))

for i in indices:
    nums[i] = 1

print(min(nums[:x].count(1), nums[x:].count(1)))

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

Solution (Python):

import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial
from bisect import bisect_left 
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

cos = [0]*(N+1)
for a in A:
    cos[a] += 1

toz = sum(cos[:X])
ton = sum(cos[X:])
print(min(toz, ton))

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

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

for i in range(m):
  if a[i] > x:
    print(min(i,m-i))
    break

Solution (Python):




from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""













if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip



"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""




def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): 
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) 
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) 
def mi(): return map(int, input().split()) 
def li(): return list(map(int, input().split())) 
def lw(): return input().split() 
def lcm(a, b): return abs(a * b) // gcd(a, b) 
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) 
def dd(): return defaultdict(int) 
def ddl(): return defaultdict(list) 
def write(s): return sys.stdout.write(s)













def main():
    
    n,m,x=mi()
    a=li()
    left=0
    right=0
    for i in a:
        if i<x:
            left+=1
        else:
            right+=1
    print(min(left,right))


















    
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')



""" main function"""

if __name__ == '__main__':
    main()

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

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

ans = 0
for i in range(m):
  if A[i] <= x:
    ans += 1
  else:
    break
    
print(min(ans, m-ans))

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):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(m):
    if a[i] > x:
        cnt = i
        break
print(min(cnt, m-cnt))

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

b = [0] * (n + 1)
for i in a:
    b[i] = 1
    
l_s = 0
r_s = 0
for i in range(x + 1):
    l_s += b[i]
    
for i in range(x, n + 1):
    r_s += b[i]
print(min(l_s, r_s))

Solution (Python):

if __name__ == '__main__':
    n, m,x = map(int, input().split())
    a = [int(i) for i in input().split()]
    count1=0
    count2=0
    for i in a:
        if i < x:
            count1+=1
        elif i>x:
            count2+=1

    print(min(count1,count2))

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

Solution (Python):
import sys

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

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


for i in range(M):
  if A[i] > X:
    AX_index = i
    break
cost_n = len(A) - AX_index
cost_0 = AX_index

print(min(cost_n,cost_0))

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

s=[0]*(n+1)
l=list(map(int,input().split()))
       
for i in range(m):
    s[l[i]]=1
       
       
if sum(s[0:x])>sum(s[x+1:]):
       print(sum(s[x+1:]))
else:
       print(sum(s[0:x]))

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
    else:
        ans2 += 1

print(min(ans1, ans2))

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

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

for i in range(X, N+1):
    if i in FS:
        cost_N += 1

for i in range(1, X+1):
    if i in FS:
        cost_0 += 1

print(min(cost_N, cost_0))

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

squares = np.zeros(N+1)
squares[A] = 1

cost0 = squares[:X].sum()
costN = squares[X+1:].sum()

if cost0 >= costN:
    print(int(costN))
else:
    print(int(cost0))

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

nums = [0] * (n + 1)
indices = list(map(int, input().split()))

for i in indices:
    nums[i] = 1

print(min(nums[:x].count(1), nums[x:].count(1)))

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

print(min(cost_for_0, cost_for_N))

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
    else:
        right += 1
        
print(min(left, right))

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

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

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

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

arr = list(range(n + 1))

for i in arr:
    for j in a:
        if i == j:
            arr[i] = 1
            break
        else:
            arr[i] = 0

low = arr[:x]
high = arr[x:]
c = 0
d = 0
for i in low:
    c += i
for i in high:
    d += i
print(min(c, d))

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

Solution (Python):
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
count = 0
for a in A:
    if x > a:
        count += 1

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

Solution (Python):
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
count = 0
for a in A:
    if x > a:
        count += 1

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

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

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





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

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

print(min(cost_0, cost_n))

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

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

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

i = 0
j = 0
for k in range(len(A)):
  if A[k] < x:
    i += 1
  elif A[k] > x:
    j += 1
    
print(min(i,j))

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

Solution (Python):
n, m, x = map(int, input().split())
A= list(map(int, input().split()))
cost1 = 0
cost2 = 0
now1 = x
now2 = x
while now1 < n:
    now1 += 1
    if now1 in A:
        cost1 += 1
while now2 > 0:
    now2 -= 1
    if now2 in A:
        cost2 += 1
print(min(cost1, cost2))

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):
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):
def main():
    from builtins import int, map, list, print, len, min
    from bisect import bisect_right
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N, M, X = input_number_list()
    A = input_number_list()
    A.sort()
    idx = bisect_right(A, X)
    l = len(A[:idx])
    r = len(A[idx:])
    print(min(l, r))


if __name__ == '__main__':
    main()

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

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

to_zero = len([i for i in a if i < x])
to_n = len([i for i in a if i > x])

print(min(to_n, to_zero))

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

print(min(cost_list[X], cost_list[-1] - cost_list[X]))

Solution (Python):
cost_zero = 0
cost_n = 0
n, m, x = (int(i) for i in input().split())
A = [int(i) for i in input().split()]

index = 0
for i in range(n+1):
    if i == A[index]:
        if i < x:
            cost_zero += 1
        else:
            cost_n += 1
        index = min(index+1, m-1) 
print(min(cost_zero, cost_n))

Solution (Python):
def resolve():
    N, M, X = list(map(int, input().split()))
    A = list(map(int, input().split()))
    cost1 = len([a for a in A if a > X])

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

    return
 

resolve()

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
l = [i for i in range(n + 1)]
b = set(l[:x]) & set(a)
c = set(l[x + 1:]) & set(a)
print(min(len(list(b)), len(list(c))))

Solution (Python):

from bisect import bisect_left

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

a = bisect_left(A, X)
print(min(a, M-a))

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

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

cost = [0,0]
for i in list:
    if 0 < i < X:
        cost[0] += 1
    if X < i < N:
        cost[1] += 1

print(min(cost))

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

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

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

a.append(x)
newa = sorted(a)

y=newa.index(x)
ans=min(len(newa[:y]),len(newa[y+1:]))
print(ans)

Solution (Python):
def resolve():
    N,M,X = map(int,input().split())
    A = list(map(int,input().split()))
    sumLow = min((j for j in range(len(A)) if A[j] > X) , default=-1)
    ans = min(sumLow,M-sumLow)
    print(ans)
resolve()

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

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

Solution (Python):


def simCost(n,a,c,direction,cost=0):
    if c == 0 or c == n:
        return cost
    elif c in a:
        return simCost(n,a,c+direction,direction,cost+1)
    else:
        return simCost(n,a,c+direction,direction,cost)

    

def solve(n,x,a):
    return min(simCost(n,a,x,+1),simCost(n,a,x,-1))

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




if __name__ == '__main__':
    main()

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

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

Solution (Python):






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





goal0_cost = sum(pos < X for pos in A)
goalN_cost = sum(pos > X for pos in A)
print(min(goal0_cost, goalN_cost))

Solution (Python):
n, m, x = map(int, input().split())
A = [int(i) for i in input().split()]
cnt = 0
for e in A:
    if x > e:
        cnt += 1
    else:
        break

print(min(len(A[:cnt]), len(A[cnt:])))

Solution (Python):
n, m, x = map(int, input().split())
A = list(map(int, input().split()))
cost = 0
for i in range(x, n+1):
  if A.count(i) > 0:
    cost += 1
cost_nomal = cost
cost = 0 
for i in range(1, x+1):
  if A.count(i) > 0:
    cost += 1
cost_reverse = cost

print(min(cost_nomal,cost_reverse))

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

fee = 0
flist = []
for i in range(len(a)):
    if a[i] < x:
        fee += 1
    else:
        flist.append(fee)
        flist.append(len(a) - i)
        break

print(min(flist))

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





cost = 0
cost2 = 0

for i in a:
  if i > x:
    cost += 1
  else:
    cost2 += 1
    
if cost < cost2:
  print(cost)
else:
  print(cost2)

Solution (Python):
import sys

input = sys.stdin.readline


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

    cost_0 = 0
    cost_N = 0
    for a in A:
        if a < X:
            cost_0 += 1
        else:
            cost_N += 1

    ans = min(cost_0, cost_N)
    print(ans)


if __name__ == "__main__":
    main()

Solution (Python):

import sys


def solve(N: int, M: int, X: int, A: "List[int]"):
    price = [1 if i in A else 0 for i in range(1, N)]
    X -= 1
    left = price[:X]
    right = price[X:]
    print(min(sum(left), sum(right)))
    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 = [int(a) for a in input().split()]
count = 0
for a in A:
    if a > X:
        count += 1
print(count if count < M - count else M - count)

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

Solution (Python):
n,m,x=map(int,input().split())
la=list(map(int,input().split()))
count1=0
count2=0
y=x
while y>=0:
    for i in la:
        if y==i:
            count1+=1
    y-=1

while x<=n:
    for i in la:
        if x==i:
            count2+=1
    x+=1
if count2>count1:
    print(count1)
else:
    print(count2)

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

B = [0 for _ in range(n+1)]
for a in A:
    B[a] = 1

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

Solution (Python):
n,m,x = map(int, input().split())
a = list(map(int, input().split()))
s = x
cost = 0
while s!=0:
    s-=1
    if s in a:
        cost+=1
ans = cost
cost = 0
s = x
while s!=n:
    s+=1
    if s in a:
        cost+=1 
ans = min(ans,cost)
print(ans)

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

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

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

cnt = 0
for m in range(M):
    if A[m] < X:
        cnt += 1

print(min(cnt,M-cnt))

Solution (Python):
N,M,X=map(int,input().split())
AM=list(map(int,input().split()))
Ns=[0]*(N+1)
for a in AM:
  Ns[a]=1
  pass

i = X
mincost,cost=0,0
while i != 0:
  if Ns[i] == 1:cost+=1
  i-=1
  pass
mincost=cost
cost,i=0,X
while i != N:
  if Ns[i] == 1:cost+=1
  i+=1
  pass
mincost=min(mincost,cost)
print(mincost)

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

c = len([x for x in A if x <X])
print(min(c,M-c))

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

cnt_a = len([x for x in A if x < X])
cnt_b = len([x for x in A if x >= X])

print(min(cnt_a, cnt_b))

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

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

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

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

cost =[0]*(N+1)

for i in A:
    cost[i] = 1

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

Solution (Python):
n,m,x = map(int, input().split())
a = sorted(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()))
a.sort()
cnt = 0
for num in a:
    if num > x:
        break
    cnt += 1
print(min(cnt, len(a) - cnt))

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

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

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

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

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

Solution (Python):
def li():
    return list(map(int, input().split()))


def mi():
    return map(int, input().split())


def ii():
    return int(input())


N, M, X = mi()
A = li()

filterdA = list(filter(lambda x: x <= X, A))

print(min(M - len(filterdA), len(filterdA)))

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

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

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

print( min( len(a[0:memo]), len(a[memo:m]) ) )

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

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

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

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

Solution (Python):


import sys






























def main():
    mod = 1000000007                
    inf = float('inf')              
    
    sys.setrecursionlimit(10**6)    
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, m, x = mi()
    L = [0] * (n+1)
    for i in lmi():
        L[i] = 1
    print(min(sum(L[x+1:]), sum(L[:x])))


if __name__ == "__main__":
    main()

Solution (Python):
def main():
    n, m, x = map(int, input().split())
    num_list = list(map(int, input().split()))
    
    square_list = [0] * (n + 1)
    
    for n in num_list:
        square_list[n-1] = 1
    
    left = sum(square_list[0:x-1])
    right = sum(square_list[x:])
    
    print(min(left, right))


if __name__ == '__main__':
    main()

Solution (Python):
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
A_a = [int(i) for i in A if i < x]
A_b = [int(i) for i in A if i > x]
L_a = len(A_a)
L_b = len(A_b)


if L_a >= L_b:
    print(L_b)
else:
    print(L_a)

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

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

for i in range(m):
    if a[i] < x:
        left += 1
    else:
        right += 1

print(min(right, left))

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

cost1 = 0
cost2 = 0

for a in range(n+1):
    if a == x:
        break
    for b in range(m):
        if a == charge[b]:
            cost1 += 1

for a in range(n+1, -1, -1):
    if a == x:
        break
    for b in range(m):
        if a == charge[b]:
            cost2 += 1

print(min(cost1, cost2))

Solution (Python):
def f10():
    N, M, X=map(int, input().split())
    A=[int(i)-1 for i in input().split()]
    X = X-1
    s=sum(A[i]<X for i in range(len(A)))
    print(min(s, M-s))

def main():
    f10()

main()

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

d=[0]*(N+1)
for i in range(M):
  d[A[i]]=1
print(min(sum(d[:X]),sum(d[X:])))

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a.sort()
num = a.index(x)
print(min(num, m-num))

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

cost = [0] * (N + 1)

for i in range(len(A)):
    cost[A[i]] = 1

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

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

print(min(bisect.bisect(a,x),m-bisect.bisect(a,x)))

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

Solution (Python):
n, m, x = [int(s) for s in input().split()]
a_list = [int(s) for s in input().split()]
for i in range(m):
    if a_list[i] > x:
        break
else:
    i += 1
print(min(i, m - i))

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


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

Solution (Python):
N,M,X = list(map(int,input().split()))
A = list(map(int,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())
A = list(map(int, input().split()))
cost_r = 0
for i in range(x):
    if i in A:
        cost_r += 1
cost_l = len(A) - cost_r
print(min(cost_l, cost_r))

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

Solution (Python):
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
b = a.index(x)
c = len(a) - b - 1
if b > c:
    print(c)
else:
    print(b)

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

a,b = 0,0
for i in A:
  if i>X:
    b+=1
  else:
    a+=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))