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:
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    n,m,x = map(int,input().split())
    maps=[]
    maps=list(map(int,input().split()))
    dp=[0]*(n+1)
    left=0
    right=0

    for i in maps:
        dp[i]=1

    left = sum(dp[x:])
    right = sum(dp[:x])

    print(min(left,right))

if __name__=="__main__":
    main()

Submission status: Accepted

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

for i, a in enumerate(a_l):
    if x < a:
        break
if i > len(a_l)/2:
    ans = len(a_l[i:])
else:
    ans = len(a_l[:i])
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left
n, m, x, *a = map(int, open(0).read().split())

b = bisect_left(a, x)
print(min(m - b, b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

x = int(input().split()[2])
a = list(map(int, input().split()))
i = bisect.bisect(a, x)

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

Submission status: Accepted

Solution code:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,M,X = MI()
A = LI()
a = sum(A[i] < X for i in range(M))
print(min(a,M-a))

Submission status: Accepted

Solution code:
from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,m,x=nii()
a=lnii()

ans1=0
ans2=0
for i in a:
  if i<x:
    ans1+=1
  else:
    ans2+=1

print(min(ans1,ans2))

Submission status: Accepted

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

cnt1, cnt2 = 0, 0
for a in A:
    if a < x:
        cnt1 += 1
    if a > x:
        cnt2 += 1
        
ans = min(cnt1, cnt2)
print(ans)

Submission status: Accepted

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

cost = [0]*(N+1)

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

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

print(ans)

Submission status: Accepted

Solution code:
def main():
    N,M,X = map(int,input().split())
    A = list(map(int,input().split()))
    left = 0
    right = 0
    for i in range(N):
        if i == X:
            continue
        elif i < X and i in A:
            left += 1
        elif i > X and i in A:
            right += 1

    ans = min(left,right)
    return ans

print(main())

Submission status: Accepted

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

b = sum(1 for i in range(m) if a[i] <= x)

print(min(b, m - b))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
A = list(map(int, input().split()))
start = 0
end = 0
for i in range(x):
    if i in A:
        start += 1

for i in range(x,n+1):
    if i in A:
        end += 1

print(min(start, end))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N, M, X = mapint()
As = set(list(mapint()))
to_zero = 0
for i in range(X, 0, -1):
    if i in As:
        to_zero += 1

to_N = 0
for i in range(X, N+1):
    if i in As:
        to_N += 1
print(min(to_zero, to_N))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left

n, m, x = map(int, input().split())
alst = list(map(int, input().split()))
pos = bisect_left(alst, x)
print(min(pos, m - pos))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


N,M,X = MI()
A = LI()
a = sum(A[i] < X for i in range(M))
print(min(a,M-a))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n,m,X = inpl()
a = inpl()
f = [False] * n
for x in a:
    f[x] = True
print(min(sum(f[:X]), sum(f[X:])))

Submission status: Accepted

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

Submission status: Accepted

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

mae = [i for i in A if i > X]
ushiro = [i for i in A if i < X]
m = len(mae)
u = len(ushiro)

if m > u:
    print(u)
else:
    print(m)

Submission status: Accepted

Solution code:
import bisect
N,M,X = map(int,input().split())
a = list(map(int, input().split()))
l = bisect.bisect_left(a, X)
print(min(l, M-l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int, input().split())
line = list(map(int, input().split()))
a = 0
b = 0
for i in line:
  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()))
#初期化
L = [0]*(N+1)
for i in range(M):
  L[A[i]] = 1
#分断
left = L[:X]
right = L[X:]

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
i = x
ans = 0
while i > 0:
    i -= 1
    if i in a:
        ans += 1
c = 0
i = x
while i < n:
    i += 1
    if i in a:
        c += 1
ans = min(ans,c)
print(ans)

Submission status: Accepted

Solution code:
N, M, X = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
x = [0 for i in range(N+1)]
for i in range(M):
  x[A[i]] = 1
ans1 = 0
for i in range(0,X):
  ans1 += x[i]
ans2 = 0
for i in range(X,N):
  ans2 += x[i]
print(min(ans1, ans2))

Submission status: Accepted

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

tmp = bisect(s, x)
print(min(tmp, m - tmp))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    n, m, x = map(int, input().split())
    a_list = list(map(int, input().split()))
    cnt = 0

    for a in a_list:
        if a < x:
            cnt += 1
        if x < a:
            break

    print(min(cnt, m - cnt))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
n, m, x = (int(i) for i in input().split())
list_a = [int(i) for i in input().split()]
list_toll = []
for i in range(0, n + 1):
    if i in list_a: list_toll.append(1)
    else: list_toll.append(0)
print(min(sum(list_toll[:x]), sum(list_toll[x:])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Toll Gates
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
l = len([a for a in A if a<X])
print(min(l,M-l))

Submission status: Accepted

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

cost = [0] * (N + 1)

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

Submission status: Accepted

Solution code:
from bisect import bisect
_, 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,X = map(int,input().split())
S = list(map(int,input().split()))
path = [0 for _ in range(N+1)]
for n in S:
  path[n] = 1
  
left = sum(path[1:X])
right = sum(path[X:-1])

print(min(left,right))

Submission status: Accepted

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


left = 0
right = 0

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

Submission status: Accepted

Solution code:
def count_fee_station(a, n_list):
    cost = 0
    for i in n_list:
        if i in a:
            cost += 1
    return cost


def main():
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))
    n_list_a = list(range(0, x + 1))
    n_list_b = list(range(x, n + 1))
    cost_a = count_fee_station(a, n_list_a)
    cost_b = count_fee_station(a, n_list_b)
    print(min(cost_a, cost_b))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def count_fee_station(a, n_list):
    cost = 0
    for i in n_list:
        if i in a:
            cost += 1
    return cost


def main():
    n , m , x  = map(int,input().split())
    a = list(map(int, input().split()))
    # if n in a:
    #     a.remove(n)
    n_list_a = list(range(0,x+1))
    n_list_b = list(range(x,n+1))
    cost_a = count_fee_station(a,n_list_a)
    cost_b = count_fee_station(a,n_list_b)
    print(min(cost_a,cost_b))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def count_fee_station(a, n_list):
    cost = 0
    for i in n_list:
        if i in a:
            cost += 1
    return cost


def main():
    n , m , x  = map(int,input().split())
    a = list(map(int, input().split()))
    if n in a:
        a.remove(n)
    n_list_a = list(range(0,x+1))
    n_list_b = list(range(x,n+1))
    cost_a = count_fee_station(a,n_list_a)
    cost_b = count_fee_station(a,n_list_b)
    print(min(cost_a,cost_b))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    a = 0
    b = 0

    for x in A:
        if x <= X:
            a += 1
        if X <= x:
            b += 1

    print(min(a, b))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
c = [0 for i in range(N+1)]
for a in A:
  c[a] = 1
ans = sum(c[:X+1])
print(min(ans, M-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(M):
    if a[i] < X:
        cnt += 1
    else:
        break
if cnt > M - cnt:
    cnt = M - cnt

print (cnt)

Submission status: Accepted

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

to_z, to_n = 0, 0
for i in a:
    if i > x:  to_n += 1
    else:  to_z += 1

print(min(to_z, to_n))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m,x = map(int, input().split())
a = list(map(int, input().split()))
l = [0 for l in range(n+1)]
for i in a:
    l[i] = 1
print(min(sum(l[x:]),sum(l[: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(X):
    if i in A:
        ans1+=1

for j in range(X,N+1):
    if j in A:
        ans2+=1

if ans1<ans2:
    print(ans1)
else:
    print(ans2)

Submission status: Accepted

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

print(min(costright,costleft))

Submission status: Accepted

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

A.append(X)
A.sort()

front = []
back = []

while len(A) > 0:
    pop = A.pop(0)
    if pop == X:
        while len(A) > 0:
            back.append(A.pop(0))
    else:
        front.append(pop)

print(min(len(front), len(back)))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
b=list(map(int,input().split()))
i=c
total=0
total2=0
while True:
    i+=1
    if i in b:
        total+=1
    if i==a:
        break
i=c
while True:
    i-=1
    if i in b:
        total2+=1
    if i==0:
        break
print(min(total,total2))

Submission status: Accepted

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

tin=lambda : map(int, input().split())
lin=lambda : list(tin())
mod=1000000007

#+++++

def main():
	#a = int(input())
	n, m, x = tin()
	#s = input()
	al = lin()
	pre = sum([1 for v in al if v < x])
	post = len(al)-pre
	return min(pre, post)
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
s = list(map(int, input().split()))
l, r = 0, 0
for i in s:
  if i < c:
    l += 1
  else:
    r += 1
print(min(l, r))

Submission status: Accepted

Solution code:
def resolve():
    n, m, x = map(int, input().split())
    al = list(map(int, input().split()))
    al = sorted(al)
    ans = [0, 0]
    for i in al:
        if i < x:
            ans[0] += 1
        elif x < i:
            ans[1] += 1
    ans = sorted(ans)
    print(ans[0])
resolve()

Submission status: Accepted

Solution code:
def main():
    l = [int(_) for _ in input().split()]
    n = l[0]
    m = l[1]
    x = l[2]
    a = [int(_) for _ in input().split()]

    cost_to_zero = 0
    cost_to_m = 0

    for i in range(len(a)):
        if a[i] > x:
            cost_to_m += 1
        else:
            cost_to_zero += 1

    answer = min([cost_to_zero, cost_to_m])
    print(answer)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
counter = 0
for i in range(m):
    if a[i] > x:
        break
    counter += 1

res = min(counter, m-counter)
print(res)

Submission status: Accepted

Solution code:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def main():
    n, m, x = nm()
    A = nl()
    cost = [0] * 101
    for a in A:
        cost[a] = 1
    ans_1 = 0
    ans_2 = 0
    for i in range(x):
        ans_1 += cost[i]
    for i in range(x, n + 1):
        ans_2 += cost[i]
    print(min(ans_1, ans_2))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int, input().split())
a = list(map(int, input().split()))
set0 = len(set(i for i in a if i < x))
setn = len(set(j for j in a if j > x))
print(min(set0,setn))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from collections import deque
#import numpy as np
import math
#sys.setrecursionlimit(10**6)
def S(): return sys.stdin.readline().rstrip()
def SL(): return map(str,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def IL(): return map(int,sys.stdin.readline().rstrip().split())

def solve():
    l = r = 0
    for i in range(0,x+1):
        if i in a:
            l += 1
    sign = 1 if x<n else -1
    for i in range(x,n+sign,sign):
        if i in a:
            r += 1
    ans = min(l,r)
    print(ans)
    return

if __name__=='__main__':
    n,m,x = IL()
    a = set(IL())
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    _, m, x = map(int, input().split())
    a = {int(an) for an in input().split()}
    cnt_smaller = sum(an < x for an in a)
    print(min(cnt_smaller, m - cnt_smaller))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

box = [0]*(N+1)

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

cost_l = 0
for i in range(X+1):
    cost_l += box[i]
cost_r = 0
for i in range(X,N+1):
    cost_r += box[i]

print(min(cost_l,cost_r))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=[int(i) for i in input().split()]
cost=0
for i in range(x,n):
    if i in a:
        cost+=1
cost2=0
for i in range(0,x+1)[::-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()))

u = []
l = []

for i in range(m):
    if a[i] < x:
        l.append(a[i])
    elif a[i] > x:
        u.append(a[i])

print(min(len(u), len(l)))

Submission status: Accepted

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

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

cost = [0,0]

for i in a:
    if i < x:
        cost[0] += 1
    else:
        cost[1] += 1
print(min(cost))

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 i in range(M):
    if A[i]<X:
        cnt_1+=1
    else:
        cnt_2+=1
print(min(cnt_1,cnt_2))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

g1, g2 = 0, 0
for i in range(x):
  if i in lst:
    g1 += 1
    
for i in range(x+1, n):
  if i in lst:
    g2 += 1
    
print(min(g1, g2))

Submission status: Accepted

Solution code:
import sys
import numpy as np
import numba
from numba import jit

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

@jit
def main(n ,m ,x, a):
  ans = 0
  right = (x > a).sum()
  left = (x < a).sum()
  return min(right, left)
  
n, m, x = map(int, readline().split())
a = np.array(readline().split(), np.int64)
print(main(n, m, x, a))

Submission status: Accepted

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

low=sum(i>x for i in l)
hight=sum(i<x for i in l)

print(min(low,hight))

Submission status: Accepted

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

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

lst = [len(A[:A.index(X)]), len(A[A.index(X)+1:])]

print(min(lst))

Submission status: Accepted

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

left_gates = [i for i in gate if i < x]
right_gates = [j for j in gate if x < j]

ans = min(len(left_gates), len(right_gates))

print(ans)

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:
		if i < m - i:
			print(i)
		else:
			print(m-i)
		exit()

Submission status: Accepted

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

cnt_lower=0
cnt_higher=0

for i in a:
    if i>x:
        cnt_lower+=1
    elif i<x:
        cnt_higher+=1
    else:
        continue
        
ans = min(cnt_lower, cnt_higher)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

s=len(a)

ans=0

for i in a:
  if i<x:
    ans+=1
    
print(min(ans,s-ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

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

index = bisect.bisect_left(a, x)

ans = min(len(a[:index]), len(a[index:]))

print(ans)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N, M, X = map(int, input().split())
a = list(map(int, input().split()))
x = bl(a, X)
print(min(x, M - x))

Submission status: Accepted

Solution code:
from sys import stdin

n,m,x = [int(x) for x in stdin.readline().split()]
a_lst = [int(x) for x in stdin.readline().split()]

cost_left = sum([1 for i in range(0, x) if i in a_lst])
cost_right = sum([1 for i in range(x+1, n+1) if i in a_lst])

print(min(cost_left, cost_right))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
B=[]
C=[]
for i in range(M):
    if A[i]>X:
        B.append(A[i])
    elif A[i]<X:
        C.append(A[i])
print(min(len(B),len(C)))

Submission status: Accepted

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

i = 0
j = 0
while 1:
  if j in A and j < X:
    i = j
    j += 1
  elif j < X:
    j += 1
  else:
    break
    
smaller = 0
bigger = 0
if i == 0:
  print(0)
else:
  for k in range(A.index(i) + 1):
    smaller += 1
  
  for k in range(A.index(i) + 1, M, 1):
    bigger += 1

  print(min(smaller, bigger))

Submission status: Accepted

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

former = []
latter = []

for i in range(len(a_list)):
    if a_list[i] < x:
        former.append(a_list[i])
    else:
        latter.append(a_list[i])
print(min(len(former), len(latter)))

Submission status: Accepted

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

for i in a:
    if i > x:
        cnt1 += 1
    else:
        cnt2 += 1
        
print(min(cnt1, cnt2))

Submission status: Accepted

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

s=[0 for i in range(N)]
for i in range(M):
    s[A[i]]=1
    
for i in range(X):
    cnt_0=sum(s[:X])

for j in range(N-X):
    cnt_N=sum(s[X:])

print(min(cnt_0,cnt_N))

Submission status: Accepted

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

P = [0] * (N + 1)

for A in A:
    P[A] = 1

a = P[:X].count(1)
b = P[X - N:].count(1)

# print(P[:X])
# print(P[X - N:])
print(min(a, b))

Submission status: Accepted

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

ans = 0
for i in A:
	ans += X>i
	
ans_N = 0
for i in A:
	ans_N += X<i

print(min(ans,ans_N))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
count0=0; countN=0;
for i in range(X,0,-1) :
  for j in range(M) :
    if i==A[j] :
      count0+=1
for i in range(X,N+1) :
  for j in range(M) :
    if i==A[j] :
      countN+=1
print(min(count0,countN))

Submission status: Accepted

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

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

print(min(ans,m-ans))

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

u = [i for i in L if i < X]
o = [i for i in L if i > X]
print(min(len(u), len(o)))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
l = list(map(int,input().split()))
num = X
ans1 = 0
ans2 = 0
while num <= N:
  if num in l:
    ans1 += 1
  num += 1
num = X
while num >= 0:
  if num in l:
    ans2 += 1
  num -= 1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

i = bisect_left(A, X)
print(min(i, len(A) - i))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
r=[0]*n
for i in range(m):
    r[a[i]-1]+=1
cnt_1=0
cnt_2=0
for i in range(x-1):
    cnt_1+=r[i]
for j in range(x,n):
    cnt_2+=r[j]
print(min(cnt_1,cnt_2))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
d=[0]*(N+1)
j=0
for i in range(A[0],N+A[0]):
  try:
    if i==A[j]:
      d[i]+=1
      j+=1
  except:
    pass
#print(d)
print(min(sum(d[:X]),sum(d[X:])))