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()))

l,r = 0,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()))
a = len(A)

count_low = 0
count_high = 0
for i in range(a):
  if A[i] > X:
    count_high +=1
  elif A[i] < X:
    count_low += 1
    
if count_low >= count_high:
  print(count_high)
elif count_low < count_high:
  print(count_low)

Solution (Python):
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
left, right = 0, 0
for i in a:
    if i < x:
        left += 1
    else:
        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()]
sorted(A)

a = len(list(filter(lambda a: X < a < N, A)))
b = len(list(filter(lambda a: 0 < a < X, A)))

print(min(a, b))

Solution (Python):

def inp():
    return(int(input()))



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



def instr():
    s = input()
    return(list(s[:len(s)]))



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


N, M, X = invr()

A = inlist()

l = 0
r = N
lef_gates = 0
right_gates = 0

for a in A:
    if a > X:
        right_gates += 1
    else:
        lef_gates += 1

print(min(lef_gates, right_gates))

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

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

smallList = [i for i in a if i < x]
largeList = [i for i in a if x < i]

s = len(smallList)
l = len(largeList)

print(min(s, l))

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

Solution (Python):






import sys
input = sys.stdin.readline

import math

import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache






MOD = 10**9+7
INF = float('inf')






def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]


def Yes(): print("Yes"); return
def No(): print("No"); return


def inv(n): return pow(n, MOD-2, MOD)


kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret


def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr


def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors


def lcm(a, b):
    return a * b // gcd (a, b)


def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count


def Base_10_to_n(X, n):
  if (int(X/n)):
    return Base_10_to_n(int(X/n), n)+[X%n]
  return [X%n]






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

p = bisect.bisect(A,X)
n = len(A)

print(min(p,n-p))

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

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


leftCost = len(a[0:x_index])
rightCost = len(a[x_index + 1:m+1])

print(min(rightCost, leftCost))

Solution (Python):
import math
from collections import deque
from collections import defaultdict


def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): 
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): 
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} 
def bitArr(n):
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): 
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq

n,m,x = readInts()
a = readInts()
forzero = len([i for i in a if i<x])
forend = len(a)-forzero

print(min(forzero,forend))

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

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

print(min(left,right))

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

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

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

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

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

if left<right:
  print(left)
else:
  print(right)

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

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

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

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

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

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

l = sum([1 if (i < x) else 0 for i in a])
print(min(l,m-l))

Solution (Python):
def resolve():
	n, m, x = map(int, input().split())
	a = list(map(int, input().split()))
	seq = [False]*(n+1)
	for i in a:
		seq[i] = True
	v = min(seq[:x+1].count(True), seq[x:].count(True))
	print(v)
resolve()

Solution (Python):
import sys

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

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

print(min(cnt, M - cnt))

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

left = 0
right = 0

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

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

to_0 = 0
if A[-1] < X:
    to_0 = M
    to_N = 0
elif A[0] < X < A[-1]:
    for i in A:
        if i < X:
            to_0 += 1
    to_N = M - to_0
elif X < A[0]:
    to_0 = 0
    to_N = M
print(min(to_0, to_N))

Solution (Python):
n,m,k = map(int,input().split())
a_list = list(map(int,input().split()))
check = [0]*(n+1)
for i in a_list:
    check[i-1] = 1
left = sum(check[0:k])
right = sum(check[k:n+1])
if left > right:
    print(right)
else:
    print(left)

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

Solution (Python):
import numpy as np

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


print(min(len(a[a<x]),len(a[a>x])))

Solution (Python):
a,b,c = map(int,input().split())
x = list(map(int, input().split()))
s = sum([x[i]<c for i in range(b)])

print(min(s, b-s))

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

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

a.append(x)
a.sort()

cut=0
for i in range(n):
    if a[i]==x:
        cut=i
        break

R=len(a[cut+1:])
L=len(a[:cut])

print(min(R, L))

Solution (Python):

def main():
    n, m, x = map(int, input().split())
    a = tuple(map(int, input().split()))
    a_low = [i for i in a if i < x]
    a_high = [i for i in a if i > x]
    r = min(len(a_low), len(a_high))
    print(r)

if __name__ == '__main__':
    main()

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

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,numpy,string
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def SS(): return map(str,sys.stdin.readline().rstrip().split())
def II(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())

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

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

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

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):
n, m, x = map(int, input().split())
A = map(int, input().split())
r = 0
l = 0
for a in A:
	if a > x:
		r += 1
	else:
		l += 1
print(min(r, l))

Solution (Python):
import numpy as np
N, M, X = map(int, input().split())
A = np.array(list(map(int, input().split())))

print(min(np.where(A>X)[0].shape[0], np.where(A<X)[0].shape[0]))

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

Solution (Python):
N,M,X = [int(hoge) for hoge in input().split()]
A = [int(hoge) for hoge in input().split()]
for n in range(M):
    if A[n] > X:
        print(min(n,M-n))
        exit()
print(0)

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):
import math
def py():
    print("Yes")
def pn():
    print("No")
def iin():
    x = int(input())
    return x

neko = 0
nya = 0
nuko = 0

n,m,x = map(int,input().split())
a = [int(x) for x in input().split()]
for i in range(m):
    if a[i] > x:
        break
if i > m-i:
    i = m -i
print(i)

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

Solution (Python):

"""
Created on Mon May 11 16:30:15 2020

@author: shinba
"""

import bisect

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

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

a = bisect.bisect(A, x)

print(min(a,m-a))

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

Solution (Python):
import sys
import bisect

readline = sys.stdin.readline

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

    leftcost = len(A[:bisect.bisect_left(A, X)])
    rightcost = len(A[bisect.bisect_left(A, X):])

    ans = min(leftcost, rightcost)
    print(ans)

if __name__ == "__main__":
    main()

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10**9)
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))


def resolve():
    N,M,X=pin()
    A=lispin()
    ans=0
    x=X
    for i in range(N):
        
        if x==N:break
        if x in A:ans+=1
        x+=1
    bns=0
    x=X
    for i in range(N):
        
        if x==0:break
        if x in A:bns+=1
        x-=1
    print(min(bns,ans))    
            


resolve()

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

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

for i in range(M):
    if X < A[i]:
        break

print(min(i, M-i))

Solution (Python):
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
AS=[]
cost1=0
cost2=0
for i in range(X,N+1):
	for j in range(len(A)):
		if i==A[j]:
			cost1+=1
for i in range(0,X+1):
	for j in range(len(A)):
		if i==A[j]:
			cost2+=1
if cost1<=cost2:
	print(cost1)
else:
	print(cost2)

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

Solution (Python):

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

A = list(map(int,input().split()))
b=0
s=0
for i in A:
    if i>X:
        b+=1
    else:
        s+=1
if b>=s:
    print(s)
else:
    print(b)

Solution (Python):
import sys

input = sys.stdin.readline

def main():
    ans = 0
    n, m ,x = map(int, input().split())
    a = list(map(int, input().split()))
    l = [0]*(n+1)
    for ai in a:
        l[ai] = 1
    ans = min(sum(l[:x]), sum(l[x:]))
    print(ans)

if __name__ == '__main__':
    main()

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

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

a = 0
b = 0

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

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

Solution (Python):

import sys


def solve(N: int, M: int, X: int, A: "List[int]"):
    from bisect import bisect
    i = bisect(A, X)
    return min(len(A)-i, i)



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)]  
    print(solve(N, M, X, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

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

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

S = [i for i in range(N + 1)]

l = len(set(S[: X]) & set(A))
r = len(set(S[X + 1 : N + 1]) & set(A))

print(l if l <= r else r)

Solution (Python):
N,M,X=map(int,input().split())
a=list(map(int,input().split()))
b=list()
for i in range(M):
  if a[i]<X:
    b.append(a[i])
c=len(a)-len(b)
print(min(len(b),c))

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

cost1 = 0
for a in A:
    if a < X:
        cost1 += 1

cost2 = M - cost1

print(min(cost1, cost2))

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

li = [0]*(n+1)

for i in a:
    li[i] += 1

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

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

left_sum = 0
right_sum = 0
for a in a_list:
    if a < x:
        left_sum += 1
    elif a > x:
        right_sum += 1

print(min(left_sum, right_sum))

Solution (Python):

N, M, X = map(int, input().split())
A = list(map(int, input().split()))
lst = [1 if (i in A) else 0 for i in range(1, N+2)]
lst2 = lst[:X]
lst3 = lst[X-1:]
print(min(sum(lst2),sum(lst3)))

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

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

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

left_cost = 0
right_cost = 0
for a in A:
  if a < X:
    left_cost += 1
  elif a > X:
    right_cost += 1

if left_cost < right_cost:
  print(left_cost)
else:
  print(right_cost)

Solution (Python):
n,m,x = map(int,input().split())
a_list = list(map(int,input().split()))
n_to_0 = 0
n_to_n = 0
t = x
while t > 0:
  if t in a_list:
    n_to_0 += 1
  t -= 1
u = x
while u < n:
  if u in a_list:
    n_to_n += 1
  u += 1
print(min(n_to_n, n_to_0))

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

gate = [0]*(n+1)

for a_i in a:
  gate[a_i]+=1

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

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

n = 0
for i in range(M):
  if A[i] > X:
    n = i
    break

print(min(n,M-n))

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

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

first = sum(a[i]>x for i in range(len(a)))
last  = sum(a[i]<x for i in range(len(a)))

print(min(first,last))

Solution (Python):

import sys
import math
from bisect import bisect_left, bisect_right, insort_left, insort_right
from collections import defaultdict, deque, Counter
from copy import deepcopy
from fractions import gcd
from functools import lru_cache, reduce
from heapq import heappop, heappush
from itertools import accumulate, groupby, product, permutations, combinations, combinations_with_replacement
from math import ceil, floor, factorial, log, sqrt, sin, cos
from operator import itemgetter
from string import ascii_lowercase, ascii_uppercase, digits
sys.setrecursionlimit(10**7)
rs = lambda: sys.stdin.readline().rstrip()
ri = lambda: int(rs())
rf = lambda: float(rs())
rs_ = lambda: [_ for _ in rs().split()]
ri_ = lambda: [int(_) for _ in rs().split()]
rf_ = lambda: [float(_) for _ in rs().split()]
INF = float('inf')
MOD = 10 ** 9 + 7
PI = math.pi

N, M, X = ri_()
A = ri_()
i = bisect_left(A, X)
print(min(len(A[:i]), len(A[i:])))

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
print(min(s,m-s))

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

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

print(min(total , m - total))

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

resolve()

Solution (Python):
import sys
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
read = sys.stdin.buffer.read
sys.setrecursionlimit(10 ** 7)

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

masu = [0] * N
for a in A:
    masu[a] += 1

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

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

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

Solution (Python):
n, m, x = map(int, input().split())
A = list(map(int, input().split()))
res1, res2 = 0, 0
for i in range(len(A)):
    if A[i] > x:
        res1 += 1
    else:
        res2 += 1

if res1 < res2:
    print(res1)
else:
    print(res2)

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

if left < right:
    print(left)
else:
    print(right)

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

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

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

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

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

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

i = 0
while A[i]<X:
    i += 1

print(len(A[i:]) if len(A[i:]) <len(A[:i]) else len(A[:i]))

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

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

right = 0
left = 0
for a in A:
  if a > 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()))
import numpy as np

def main():
    a = np.array(A)
    print(min(sum(a < X), sum(a > X)))

if __name__ == "__main__":
    main()

Solution (Python):




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

def main():
    cnt_1 = 0
    for i in range(1, 1000):
        if X + i in A:
            cnt_1 += 1
        if X + i == N:
            break
    cnt_2 = 0
    for i in range(1, 1000):
        if X - i in A:
            cnt_2 += 1
        if X - i == 0:
            break
    print(min(cnt_1, cnt_2))

if __name__ == "__main__":
    main()

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

cost_to_l = 0
x_to_l = x
while x_to_l > 0:
    x_to_l -= 1
    if x_to_l in a_l:
        cost_to_l += 1

cost_to_r = 0
x_to_r = x
while x_to_r < n:
    x_to_r += 1
    if x_to_r in a_l:
        cost_to_r += 1

print(min(cost_to_l,cost_to_r))

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

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

for ai in a:
 if ai < x:
  t += 1

print(min(t,m-t))

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

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


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


def solve(N, M, X, A):
    l, r = 0, 0
    for a in A:
        if a < X:
            l += 1
        elif a > X:
            r += 1
    return min(l, r)


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7


n,m,x=MI()
tolls=LI()
left,right=0,0
for i in range(x):
    if i in tolls:
        left+=1
for j in range(x,n):
    if j in tolls:
        right+=1
print(min(left,right))

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

for i in range(M):
    if int(gate[i]) < X:
        back += 1
    else:
        go += 1

print(min(back, go))

Solution (Python):
N,M,X=[int(i) for i in input().split(" ")]
A=[int(i) for i in input().split(" ")]
A.sort()
for i,a,b in zip(range(len(A)-1),A[:len(A)-1],A[1:]):
    if a<X and X<b:
        print(min(len(A[:i+1]),len(A[i+1:])))
        break
else:
    print(0)

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

ryokins = [0] * (n + 1)
res_left = 0
res_right = 0

for a in a_m:
    ryokins[a] = 1
for i in range(x, n, 1):
    res_left = res_left + ryokins[i]
for i in range(0, x, 1):
    res_right = res_right + ryokins[i]

print(min(res_left, res_right))

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

mov = [0]*n
for a in al:
    mov[a-1] = 1

print(min(sum(mov[:x]), sum(mov[x-1:])))

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

left = cost[:x + 1]
right = cost[x:]

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

Solution (Python):
from bisect import bisect_left

N,M,X=map(int, input().split())
A=list(map(int, input().split()))
i=bisect_left(A, X)
print(min(i, len(A) - i))

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

Solution (Python):

n,m,x = map(int,input().split())
a = set(list(map(int,input().split())))
masu = [i for i in range(n+1)]
a_left = masu[:x]
a_right = masu[x+1:]




c_l = 0
c_r = 0
for i in range(len(a_left)):
    if a_left[i] in a:
        c_l += 1
        
for j in range(len(a_right)):
    if a_right[j] in a:
        c_r += 1
        
print(min(c_l,c_r))

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

keep=0
hidari=a[0]
while hidari<x and keep<=m:
  keep+=1
  hidari=a[keep]
  
print(min(keep,m-keep))

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

cnt_left = 0
cnt_right = 0
for i in a:
    if i <x:
        cnt_left += 1
    else:
        cnt_right+=1
print(min(cnt_left,cnt_right))

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