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

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


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

Solution (Python):
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

def main():
    n,m,x = i2()
    a = intl()
    c1,c2 = 0,0
    for i in range(x,n+1):
        
        if i in a:
            c1 += 1
    for i in range(0,x+1):
        
        if i in a:
            c2 += 1
    print(min(c1,c2))
if __name__ == "__main__":
    main()

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

li=0

for i in range(X):
  if i in A:
    li+=1
print(min(li,M-li))

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

li=0
ri=0

for i in range(X):
  if i in A:
    li+=1
for i in range(X,N):
  if i in A:
    ri+=1
print(min(li,ri))

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

dic=[]

cnt_r=0
cnt_l=0
for n in range(1,N):
  if n>X and n in A:
    cnt_r=cnt_r+1
  elif n<=X and n in A:
    cnt_l=cnt_l+1

print(min(cnt_r,cnt_l))

Solution (Python):


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

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

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

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

print(min(c,d))

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

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

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

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

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

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

print(min(cost0, costn))

Solution (Python):
import bisect

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

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

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

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()))
cnt=0
for i in range(m):
  if a[i]<x:
    cnt+=1
ans=min(cnt,m-cnt)
print(ans)

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())
list=list(map(int,input().split()))
cost0=0
costN=0
for num in list:
	if 0<num<x:
		cost0+=1
	if x<num<n:
		costN+=1
print(min(cost0,costN))

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

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

L_count = 0
R_count = 0

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

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

to_0_cost = len([A for A in A_list if A < X])
to_N_cost = len([A for A in A_list if A > X])

ans = min(to_0_cost, to_N_cost)

print(ans)

Solution (Python):
from bisect import bisect_right

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

left = bisect_right(A,X)
right = len(A) - left

print(min(left,right))

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

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

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

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

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

Solution (Python):
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M, X = MAP()
A = LIST()

cost = [0]*(N+1)

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

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

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

la.append(X)
la = sorted(la)
la.index(X)

print(min(la.index(X), int(M) - la.index(X)))

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

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

Solution (Python):
def resolve():
    n,m,x=map(int, input().split())
    l=list(map(int, input().split()))
    l.append(x)
    l.sort()
    if l[0]==x or l[-1]==x:
        print(0)
    else:
        for i in range(m+1):
            if l[i]==x:
                print(min(m-i,i))

resolve()

Solution (Python):
n, m, x = map(int, input().split())
ls = list(map(int, input().split()))
ls2 = []

for i in range(m):
    if ls[i] < x:
        ls2 += [ls[i]]
    else:
        break

ls1 = list(set(ls) - set(ls2))
len1 = len(ls1)
len2 = len(ls2)
if len1 <= len2:
    print(len1)
else:
    print(len2)

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

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

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

print(min(ans0,ans1))

Solution (Python):
n, m, x = [int(n) for n in input().split(' ')]
a = [int(n) for n in input().split(' ')]
cost = [0] * (n + 1)

for i in range(0, m):
    cost[a[i]] = 1

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

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

Solution (Python):
import sys
input = sys.stdin.readline
ma = lambda : map(int,input().split())
ni = lambda : int(input())
n,m,x = ma()
A =list(ma())
c1 = 0
c2 = 0
for a in A:
    if a>x:c1+=1
    else:c2+=1
print(min(c1,c2))

Solution (Python):


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

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

print(min(cnt,m-cnt))

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

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

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

r1 = 0
r2 = 0
for a in A:
    if a < X:
        r1 += 1
    else:
        r2 += 1

print(min(r1,r2))

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

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

large = []
small = []
for i in a:
    if x < i:
        large.append(i)
    else:
        small.append(i)

print(len(small) if len(small) < len(large) else len(large))

Solution (Python):
import numpy as np
import sys

input = sys.stdin.readline


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

left = 0
right = 0
a = list(map(int,input().split()))

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()))
right = 0
left = 0
for a in A:
    if a > X:
        right += 1
    if a < X:
        left += 1

print(min(right, left))

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

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

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

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

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

length = len(A)

for i in range(N+1):
    if A[i]<X:
        front +=1
    else:
        break

back = length - front

if front<back:
    print(front)
else:
    print(back)

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

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):
import sys


def readlines(n):
    for _ in range(n):
        yield map(int, input().split())


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

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

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

    print(min(zeroside, nside))    

main()

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

up = 0
down = 0

for i in a:
    if i < x:
        down += 1
    elif i > x:
        up += 1
print(min(up, down))

Solution (Python):
def solve():
    N,M,X = map(int, input().split())
    A = list(map(int, input().split()))
    count = 0
    for i in range(M):
        if A[i] > X:
            break
        count += 1
    count2 = 0
    for j in range(count+1,M+1):
        count2 += 1
    print(min(count, count2))

if __name__ == '__main__':
    solve()

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

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



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


print(min(cnt_1,cnt_2))

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

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

Solution (Python):

import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,M,X=map(int,input().split())
    A=list(map(int,input().split()))
    print(min(bisect_right(A,X),len(A)-bisect_right(A,X)))

if __name__ == '__main__':
    main()

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

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

    low_count = 0
    high_count = 0
    for i in num_list:
        if i < x:
            low_count += 1
        elif i > x:
            high_count += 1

    print(min(low_count, high_count))

if __name__ == '__main__':
    main()

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

Solution (Python):
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m, x = nm()
    a = nl()

    price = [1 if i in a else 0 for i in range(n)]

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


if __name__ == '__main__':
    main()

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

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

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

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

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

    return 0

if __name__ == "__main__":
    solve()

Solution (Python):
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
cnt_r = 0
cnt_l = 0
road = [True]*(n+1)
for i in a:
    road[i] = False
for i in range(x,n+1):
    if not road[i]:
        cnt_r += 1
for i in range(x,-1,-1):
    if not road[i]:
        cnt_l += 1
ans = min(cnt_r,cnt_l)
print(ans)

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

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

Solution (Python):


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

Solution (Python):
import sys
sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

def main():
    N,M,X=MI()
    A=LI()
    temp=0
    import bisect 
    num=bisect.bisect_left(A,X)
    print(min(num,M-num))
        
    


main()

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

if __name__ == "__main__":
  resolve()

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

Solution (Python):
n,m,x = map(int, input().split())
a = list(map(int, input().split()))
X = x
Y = x
A,B = 0, 0
while X != n:
  X += 1
  if X in a: A += 1

while Y != 0:
  Y -= 1
  if Y in a: B += 1
print(min(A,B))

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

for i in range(M):
    if A[i] > X:
        r = M-i
        l = i - (1 if i>0 and A[i-1]==X else 0)
        print(min(l,r))
        exit()
print(0)

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

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

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

x -= 1
l = 0
for i in range(x+1):
    if i in A:
        l += 1
r = 0
for i in range(x, n):
    if i in A:
        r += 1
print(min(l, r))

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):
def main():
    n, m, x = map(int, input().split())
    a = [int(x) - 1 for x in input().split()]
    count = [0 for _ in range(n)]
    for aa in a:
        count[aa] += 1
    for i in range(1, n):
        count[i] += count[i - 1]
    print(min(count[x - 1], count[n - 1] - count[x - 1]))


if __name__ == '__main__':
    main()

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

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

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
print(min(sum(l[0:x+1]),sum(l[x:n+1])))

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

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

cst = 0
for a in A:
    if a < X:
        cst += 1
if cst < M - cst:
    print(cst)
else:
    print(M-cst)

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

mainasu = 0
purasu = 0
for i in range(M):
    if (A[i] < X):
        mainasu += 1
    if(A[i] > X):
        purasu += 1

if (mainasu > purasu):
    print(purasu)
elif(mainasu <= purasu):
    print(mainasu)

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

Solution (Python):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, m, x = MAP()
a = LIST()
ans1 = 0
for i in range(x, n + 1):
    ans1 += 1 if i in a else 0
ans2 = 0
for i in range(x + 1):
    ans2 += 1 if i in a else 0
print(min(ans1, ans2))

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]), sum(b[x:])))

Solution (Python):
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, M, X = map(int, readline().split())
    A = list(map(int, readline().split()))
    cost = [0] * (N+1)
    for i in range(M):
        cost[A[i]] += 1
    ans = min(sum(cost[:X]), sum(cost[X+1:]))
    print(ans)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

sumn = sum(aa[x+1:])
sum0 = sum(aa[:x])

print(min(sumn,sum0))

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

R = [0] * (N + 1)
for i in A:
    R[i] = 1

for i in range(0,X + 1):
    S1 += R[i]

for i in range(X + 1,N + 1):
    S2 += R[i]

print(min(S1,S2))

Solution (Python):

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

boxes = [0] * (n + 1)
nums = [int(i) for i in input().split()]
for num in nums:
    boxes[num] = 1

left = sum(boxes[:x])
right = sum(boxes[x:])
ans = min(left, right)
print(ans)

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

Solution (Python):
N,M,X=map(int,input().split())
s = input().rstrip().split(' ')
counta = 0
countb = 0
for i in range(M):
  if int(s[i]) > X and int(s[i]) < N:
    counta += 1
for j in range(M):
  if int(s[j]) < X:
    countb += 1
count = min(counta, countb)
print(count)

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

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

fullSet = []
for i in range(N + 1):
    if i in A:
        fullSet.append(1)
    else:
        fullSet.append(0)

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

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

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

Solution (Python):
import sys, math
sys.setrecursionlimit(10 ** 6)
from collections import deque, defaultdict, Counter
from operator import itemgetter

def main():
    N, M, X = map(int, sys.stdin.readline().rstrip().split())
    A = list(map(int, sys.stdin.readline().rstrip().split()))
    
    idx = -1
    for i in range(M+1):
        if A[i] < X:
            idx = i
        else:
            break
    
    print(min(len(A[:idx+1]), len(A[idx+1:])))


if __name__ == '__main__':
    main()

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

for i in A:
    low[i]=1

count1 = 0
count2 = 0

x=X
while(x!=0):
    count1+=low[x]
    x-=1
x=X
while(x!=N):
    count2+=low[x]
    x+=1
if count1<count2:
    print(count1)
else:
    print(count2)

Solution (Python):
a,b,c = map(int,input().split())
n_list = list(map(int,input().split()))
ans_1 = 0
ans_2 = 0

for i in n_list:
  if i >=c and i <=a:
    ans_1+=1
    
for i in n_list:
  if i >=0 and i <=c:
    ans_2+=1

print(min(ans_1,ans_2))

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

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

P0 = 0

for i in A:
    if i < x:
        P0 += 1
    else:
        break

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

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

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

I=lambda p,q:p.index(q)

if X in A:
    print(min(I(A,X),M-I(A,X)-1))
else:
    A.append(X)
    A=sorted(A)
    print(min(I(A,X),M-I(A,X)))

Solution (Python):

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

for i in range(len(a)):
    if a[i] < x:
        l += 1
r = m-l

print(min(l,r))

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

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

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

print(min(count1, count2))

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

Solution (Python):
icase=0
if icase==0:
    from bisect import bisect
    n,m,x=map(int,input().split()) 
    a=list(map(int,input().split()))
    i=bisect(a,x)
    print(min(i,m-i))

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


if __name__ == '__main__':
    main()

Solution (Python):
from bisect import bisect_left

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

left = bisect_left(A,X)
right = M - left

print(min(left,right))

Solution (Python):
def root1():
    """Xから0までのルートでかかる費用を求める
    """
    cost = 0
    for fee_station in fee_station_list:
        if fee_station < X:
            cost += 1

    return cost


def root2():
    """XからNまでのルートでかかる費用を求める
    """
    cost = 0
    for fee_station in fee_station_list:
        if X < fee_station < N:
            cost += 1

    return cost


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

cost1 = root1()
cost2 = root2()

print(min(cost1, cost2))

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

map_list = [0 for i in range(n+1)]

for i in range(n+1):
    if i in a_inputs:
        map_list[i]=1

ans1,ans2=0,0
for i in range(x,n+1):
    ans1+=map_list[i]
for i in range(x,-1,-1):
    ans2+=map_list[i]
print(min(ans1,ans2))

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

I = [ a for a in A if a < X ]
if len(I) < len(A) - len(I):
    print(len(I))
else:
    print(len(A) - len(I))

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

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

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

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

a_big = [i for i in a if i > x]
a_small = [i for i in a if i < x]

print(min(len(a_big), len(a_small)))

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

for i in range(x,n+1):
  if i in a:
    tn += 1
for i in range(x,0,-1):
  if i in a:
    t0 += 1
print(min(t0,tn))

Solution (Python):

import io

n,m,k=map(int,input().split())
j=sum(int(i)<k for i in input().split())
print(min(j,m-j))

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

Solution (Python):
N,M,X=map(int,input().split())
A=[int(i) for i in input().split()]
for i in range(len(A)):
    if A[i]>X:
        S1=A[0:i]
        S2=A[i:]
        break
    else:
        continue
print(min(len(S1),len(S2)))

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

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

for i in a:
  cost[i] = 1

cost_zero = cost[1:x]
cost_n = cost[x+1:]

ans = min(sum(cost_zero),sum(cost_n))

print(ans)

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

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

c1 = 0
c2 = 0

for a in A:
    if a < X:
        c1 += 1
    else:
        c2 += 1
print(min(c1,c2))

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