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



Sample input:
5 3 3
1 2 4


Sample output:
1

Submission status: Accepted

Solution code:


def main():


   N,M,X = map(int,input().split())
   tollList = list(map(int,input().split()))
   leftToll = [i for i in tollList if i < X]
   rightToll = [i for i in tollList if i > X]
   print(min(len(leftToll),len(rightToll)))




if __name__== "__main__":
    main()

Submission status: Accepted

Solution code:
#インポート
import sys

#入力用
def ILI(): return list(map(int, sys.stdin.readline().rstrip().split()))
def ISI(): return map(int, sys.stdin.readline().rstrip().split())
def II(): return int(sys.stdin.readline().rstrip())
def ISS(): return sys.stdin.readline().rstrip().split()
def IS(): return sys.stdin.readline().rstrip()

N, M, X = ISI()
A = ILI()
cost_a = 0
cost_b = 0

for x in A:
    if x < X:
        cost_a += 1
    else:
        cost_b += 1
print(min(cost_a, cost_b))

Submission status: Accepted

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

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

print(min(l, r))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
k, m, x = map(int, input().split())
src = list(map(int, input().split()))
big = len(list(filter(lambda l: l>x, src)))
small = len(list(filter(lambda l: l<x, src)))
print(min(big,small))

Submission status: Accepted

Solution code:
(n, m, x) = (int(tok) for tok in input().split())
left = 0
right = 0

for pos in [int(tok) for tok in input().split()]:
  left += (1 if pos < x else 0)
  right += (1 if pos > x else 0)

print(min(left, right))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=[int(i) for i in input().split()]
a=set(a)
ans=10**100
tmp=0
for i in range(x+1):
    if i in a:
        tmp+=1
ans=min(ans,tmp)
tmp=0
for i in range(x,n+1):
    if i in a:
        tmp+=1
ans=min(ans,tmp)
print(ans)

Submission status: Accepted

Solution code:
import bisect as b
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
tmp = b.bisect_left(a,x)

if tmp >= m-tmp:
  print(m-tmp)
else:
  print(tmp)

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
c = 0
d = m

for i in range(m):
  if a[i] < x:
    c += 1
    d -= 1

if c >= d:
  print(d)
else:
  print(c)

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

n, m, x = na()
aaa = na()
print(min(len([a for a in aaa if a < x]), len([a for a in aaa if a > x])))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
As = list(map(int, input().split()))
nl = len(list(filter(lambda A: A < X, As)))
nr = len(list(filter(lambda A: A > X, As)))
r = min(nl, nr)
print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
  N, M, X = map(int, input().split())
  a = list(map(int, input().split()))
  
  i = 0
  while i < M:
    if a[i] > X:
      break
    i += 1
  print(min(i, M - i))

if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
n,m,p = map(int,input().split())
a = list(map(int,input().split()))
up = len(list(filter(lambda x:x>p,a)))
down = len(list(filter(lambda x:x<p,a)))
print(min(up,down))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
cost=list(map(int,input().split()))
cost1=0
cost2=0
for i in cost:
  if i>X:
    cost2+=1
  elif i<X:
    cost1+=1
    
print(min(cost1,cost2))

Submission status: Accepted

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

cost_to_zero = sum([1 for A in A_list if 0 < A < X])
cost_to_n = sum([1 for A in A_list if X < A < N])

print(min(cost_to_zero, cost_to_n))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
cnt = 0
for x in A:
    if x<X:
        cnt += 1
print(min(cnt,M-cnt))

Submission status: Accepted

Solution code:
import bisect
n,m,x=map(int, input().split())
a=list(map(int, input().split()))
ind=bisect.bisect_right(a,x)
print(min(len(a[:ind]),len(a[ind:])))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
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]))))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
goalA = 0
goalB = 0
for i in range(1, X):
    goalA += A.count(i)
for j in range(X + 1, N):
    goalB += A.count(j)
print(min(goalA, goalB))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split())) # A_1からA_M

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

ans = min(l, r)
print(ans)

Submission status: Accepted

Solution code:
def test():
    n,m,x = map(int,input().split())
    a = list(map(int,input().split()))
    count1 = 0
    count2 = 0
    for i in range(x):
        if i in a:
            count1 += 1
    for i in range(x,n+1):
        if i in a:
            count2 += 1
    print(min(count1,count2))


if __name__ == "__main__":
    test()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
b=[0]*(n+1)
A=list(map(int,input().split()))
for a in A:
  b[a]=1
c=0
for i in range(x):
  c+=b[i]
print(m-c if c>=m-c else c)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,starts=map(int,input().split())
li = list(map(int,input().split()))
cnt=0
q=0
while li[q]<starts:
  cnt+=1
  q+=1
print(min(cnt,len(li)-cnt))

Submission status: Accepted

Solution code:
def resolve():
    n, m, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    ans = min(sum([1 for ai in a if ai >= x]), sum([1 for ai in a if ai < x]))
    print(ans)


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

cnt = 0
for i in range(X,N):
#  print (i, i in A, A,cnt)
  if i in A:
    cnt += 1
print (min(cnt, M-cnt))

Submission status: Accepted

Solution code:
#n is road /m is gate /x is start
n,m,x=map(int,input().split())

r=map(int,input().split())

toZero=0
for i in r:
  if i<x:toZero +=1 

print(min(toZero,m-toZero))

Submission status: Accepted

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

zero_cost = 0
N_cost = 0
for a in A:
    if X < a:
        N_cost += 1
    else:
        zero_cost +=1
        
print(min(zero_cost, N_cost))

Submission status: Accepted

Solution code:
n, m ,x =map(int, input().split())
a = list(map(int, input().split()))
ans_l = 0
ans_r = 0

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

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

print(min(ans_l, ans_r))

Submission status: Accepted

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

a.append(x)
a.sort()

i = a.index(x)

print(min(i, m - i))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
A.append(X)
A.sort()
idx = A.index(X)
print(idx if idx < M - idx else M - idx)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
count = len([1 for value in a if 0 < value < x])
print(min(count, m-count))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
As=list(map(int,input().split()))

way=[]
for i in range(n):
  way.append(i)
  
ans1,ans2=0,0
for i in range(x,n,1):
  if i in As:
    ans1+=1
for i in range(x,0,-1):
  if i in As:
    ans2+=1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
def main():
    N, M, X = map(int, input().split())
    A = [int(a) for a in input().split()]
    costL = 0
    for i in range(len(A)):
        if A[i] < X:
            costL += 1
    return min(costL, M-costL)
    
if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import copy

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

goal0 = 0
goaln = 0

X2 = copy(X)

#0へ
while True:
    if X-1 == 0:
        break
    else:
        if X-1 in A:
            goal0 += 1

        X -= 1

while True:
    if X2+1 == N:
        break
    else:
        if X2+1 in A:
            goaln += 1

        X2 += 1

print(min(goal0,goaln))

Submission status: Accepted

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

r = 0
l = 0

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

print(min(l,r))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

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

to0 = len([a for a in A if a < X])
toN = len(A) - to0

ans = min(to0, toN)
print(ans)

Submission status: Accepted

Solution code:
n, m, x = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
ans = 0
from bisect import bisect
i = bisect(a,x)
print(min(len(a[:i]),len(a[i:])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
import numpy as np

 
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
s = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

n, m, x = na()
a = np.array(na())

left = sum(a < x)
right = sum(a > x)
print(left if left < right else right)

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
A.append(X)
A.sort()
print(min(len(A[:A.index(X)]), len(A[A.index(X) + 1:])))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
*a, = map(int,input().split())

s = sum(i<X for i in a)

print(min(s,M-s))

Submission status: Accepted

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

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

Submission status: Accepted

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

print(min(sum(i > x for i in a), sum(i < x for i in a)))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
l = list(map(int, input().split()))
left = 0
right = 0
i = 0
while i < x:
    if i in l:
        left += 1
    i += 1
j = n-1
while j > x:
    if j in l:
        right += 1
    j -= 1

print(min(left, right))

Submission status: Accepted

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

A.sort()

index = A.index(X)

print(len(A[0:index]) if len(A[0:index]) <= len(A[index+1:len(A)]) else len(A[index+1:len(A)]))

Submission status: Accepted

Solution code:
N,M,X=(map(int, input().split(" ")))
S= sum(int(i)<X for i in input().split(" "))
print(min(S, M-S))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
L = 0
R = 0
for a in A: L += a < X
for a in A: R += a > X
print(min(L, R))

Submission status: Accepted

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

Submission status: Accepted

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

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

mas=[0]*(n+1)

for i in range(len(a)):
    mas[a[i]-1]=1

left_count=mas[:x].count(1)
right_count=mas[x:].count(1)

print(min(left_count,right_count))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
b=0
c=0
a=list(map(int,input().split()))
for i in range(X):
  if i in a:
    b+=1
for j in range(X,N+1):
  if j in a:
    c+=1
print(min(b,c))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
sum_list = []
count = 0

for i in range(n+1):
    if i in a:
        count += 1
    sum_list.append(count)

sum_front = sum_list[x] - sum_list[0]
sum_rear = sum_list[n] - sum_list[x]

print(min(sum_front, sum_rear))

Submission status: Accepted

Solution code:
n,m,x,*a=list(map(int,open(0).read().split()))
arr=[0]*(n+1)
for i in a:
  arr[i]=1
print(min(sum(arr[:x]), sum(arr[x+1:])))

Submission status: Accepted

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

cnt = sum(a[i] < x for i in range(m))

print(min(cnt, m - cnt))

Submission status: Accepted

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

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

print(min(cnt, m - cnt))

Submission status: Accepted

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

route=[0]*n
for i in a:
  route[i-1]=1
ans=min(sum(route[:x]),sum(route[x:]))
print(ans)

Submission status: Accepted

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

c0 = 0
c1 = 0

for i in range(M):
    if A[i] < X:
        c0 += 1
    elif A[i] > X:
        c1 += 1
print(min(c0, c1))

Submission status: Accepted

Solution code:
N, M, X = [int(x) for x in input().split()]
AN = [int(x) for x in input().split()]
print(min(len([i for i in AN if i < X]),len([i for i in AN if i > X])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
m_list = list(map(int,input().split()))
under_list = list(filter(lambda a:a<x,m_list))
over_list = list(filter(lambda a:a>x,m_list))
print(min(len(under_list),len(over_list)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
grid = [0]*(n+1)
a = list(map(int, input().split()))

for i in a:
    grid[i-1] = 1

if sum(grid[0:x]) >= sum(grid[x:n]):
    print(sum(grid[x:n]))
else:
    print(sum(grid[0:x]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

countx=0
county=0
for i in range(0,M):
    if X > A[i]:
        countx+=1
    elif X < A[i]:
        county+=1
print(min(countx,county))

Submission status: Accepted

Solution code:
import bisect

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

left = bisect.bisect_left(A, X)
right = len(A) - left
ans = min(left, right)
print(ans)

Submission status: Accepted

Solution code:
_, _, x = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
cost_lower = 0
cost_upper = 0
for ai in a:
    if ai < x:
        cost_lower += 1
    else:
        cost_upper += 1
print(min(cost_lower, cost_upper))

Submission status: Accepted

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

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

Submission status: Accepted

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

a1=input().split()
a2=[]
for i in range(n+1):
    if str(i) in a1:
        a2.append(1)
    else:
        a2.append(0)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
N_cost=len(list(filter(lambda x:x >X, A)))
Z_cost=len(list(filter(lambda x:x <X, A)))
print(min(N_cost,Z_cost))

Submission status: Accepted

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

s_count = 0
b_count = 0

for i in range(m):
    if List[i] < x:
        s_count += 1
    elif List[i] > x:
        b_count += 1

print(s_count if s_count < b_count else b_count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:


n, _, x = [int(x) for x in input().split()]
an = list(map(int,input().split()))
print(min(len([a for a in an if x < a]),len([a for a in an if a < x])))

Submission status: Accepted

Solution code:
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))
    exit()

Submission status: Accepted

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

l = sum(1 if i < x else 0 for i in a)
r = m -l

print(min(l,r))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
lef = 0
rig = 0
for ai in a:
    if ai < x:
        lef += 1
    else:
        rig += 1
print(min(lef, rig))

Submission status: Accepted

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

right_cost = len([ai for ai in a if ai > x])
left_cost =  len([ai for ai in a if ai < x])

print(min(right_cost, left_cost))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

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

print(min(cost0,costN))

Submission status: Accepted

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

left=0
right=0

for i in a:
  if x > int(i):
    left += 1
  elif x < int(i):
    right += 1
print(min(left,right))

Submission status: Accepted

Solution code:
n,m,x,*l=map(int,open(0).read().split())
s=sum(i in l for i in range(x))
print(min(s,m-s))

Submission status: Accepted

Solution code:
n,m,x,*l=map(int,open(0).read().split())
s=sum(1 for i in range(x) if i in l)
print(min(s,m-s))

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
cnt_1 = 0
cnt_2 = 0
for a in A:
    if a < x:
        cnt_1 += 1

cnt_2 = m - cnt_1
print(min(cnt_1,cnt_2))

Submission status: Accepted

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

    lower_cnt = 0
    upper_cnt = 0

    for a in A:
        if a < X:
            lower_cnt += 1
        elif a > X:
            upper_cnt += 1

    print(min(upper_cnt, lower_cnt))

main()

Submission status: Accepted

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

A.append(X)
idx = sorted(A).index(X)

print(min(idx, M-idx))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
l = list(map(int, input().split()))
c = sum(1 if y < x else 0 for y in l)
print(c if c < len(l)-c else len(l)-c)

Submission status: Accepted

Solution code:

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

right = 0
left = 0
for i in range(X, N+1):
    if i in A:
        right += 1

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

print(min(left, right))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
cost=0
for i in range(x,n+1):
    if i in a:
        cost+=1
ans=cost
cost2=0
for i in range(x,0,-1):
    if i in a:
        cost2+=1
ans=min(ans,cost2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

A_left =[]
A_right = []

for i in A:
  if i < X:
    A_left.append(i)
  elif i > X:
    A_right.append(i)
print(min(len(A_left),len(A_right)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a = sorted(a)
a = list(map(str,a))
b = a.index(str(x))
if b+1 <= len(a)/2:
  print(b)
else:
  print(m-b)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

l = list(range(0, n+1))
former = l[:x]
latter = l[x+1:]

print(min(len(set(former) & set(a)), len(set(latter) & set(a))))

Submission status: Accepted

Solution code:

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

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

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right

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

a = bisect_left(A, X)
b = bisect_right(A, X)
c = min([a, M-a, b, M-b])
print(c)

Submission status: Accepted

Solution code:
n,m,x = map(int, input().split())
a = set(map(int, input().split()))

line = list(range(0,n+1))
routeA = set(line[:x])
routeB = set(line[x+1:])

print(min(len(a & routeA),len(a & routeB)))

Submission status: Accepted

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

l = len(list(filter(lambda a: a < X, A)))
r = len(list(filter(lambda a: a > X, A)))
print(min(l, r))

Submission status: Accepted

Solution code:
import bisect

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

left = bisect.bisect_left(A,X)
right = M - bisect.bisect_right(A,X)
print(min(left,right))

Submission status: Accepted

Solution code:
N,M,X= map(int,input().split())
gates = [int(i) for i in input().split()]
# X to N
count1 = 0
for i in range(X,N):
    if i in set(gates):
        count1 += 1
    
# X to 0
count2 = 0
for i in range(0,X):
    if i in set(gates):
        count2+= 1
print(min(count1,count2))

Submission status: Accepted

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

cost = 0
for i in range(0,x):
    if i in a:
        cost += 1
cost2 = 0
for i in range(x+1,n+1):
    if i in a:
        cost2 +=1
print(min(cost,cost2))

Submission status: Accepted

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

ans_tmp1 = 0
ans_tmp2 = 0

for j in range(M):
    if A[j] > X and N > A[j]:
        ans_tmp1 += 1
    elif A[j] > N:
        break
    elif A[j] < X:
        ans_tmp2 += 1 

ans = min(ans_tmp1,ans_tmp2)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from bisect import bisect
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

print(bisect(A, X)) if bisect(A, X) < M - bisect(A, X) else print(M - bisect(A, X))

Submission status: Accepted

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