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 -*-

if __name__ == "__main__":
	N, M, X = list(map(int, input().split()))
	As = list(map(int, input().split()))
	cost = 0
	for A in As:
		if A > X:
			break
		cost += 1
	print(min(cost, M-cost))

Submission status: Accepted

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

go_0 = sum([ai < x for ai in a]) # goal=grid0
go_n = sum([ai > x for ai in a]) # goal=gridn
print(min(go_0, go_n))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
tolls = [int(i) for i in input().split()]
print(min(sum([1 for p in tolls if p < X]), sum([1 for p in tolls if p > X])))

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()))
i=0
cost=0
while a[i]<x:
  cost+=1
  i+=1
print(min(cost,len(a)-cost))

Submission status: Accepted

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

result = len(set(range(0,X))&A)
result = min(result, len(set(range(X,N))&A))

print(result)

Submission status: Accepted

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

w = 0
e = 0
for i in a:
    if i < x:
        w += 1
    elif x < i:
        e += 1
print(min(w, e))

Submission status: Accepted

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

to_zero = 0
to_N = 0
for A_i in A:
    if A_i < X:
        to_zero += 1
    elif N > A_i > X:
        to_N += 1
print(min(to_zero, to_N))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
toll_index = [int(i) for i in input().split() if int(i) not in [0,N,X]]
toll_array = [1 if j in toll_index else 0 for j in range(N+1)]
ZtoX, XtoN = sum(toll_array[0:X]),sum(toll_array[X:N])
print([ZtoX,XtoN][ZtoX>XtoN])

Submission status: Accepted

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

print(min(a,b))

Submission status: Accepted

Solution code:
from bisect import bisect_left

n, m, x = map(int, input().split())
axs = [int(x) for x in input().split()]

i = bisect_left(axs, x)
print(min(len(axs[:i]), len(axs[i:])))

Submission status: Accepted

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

t= [i for i in A if i> 0 and i< X]
s= [i for i in A if i> X and i<N]

print(min(len(t),len(s)))

Submission status: Accepted

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

Submission status: Accepted

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

cnt_b = 0
cnt_s = 0
for i in a:
    if i > X:
        cnt_b += 1
    else:
        cnt_s += 1
print(min(cnt_b, cnt_s))

Submission status: Accepted

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

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

t = [i for i in A if i<X and 0<i]
s = [i for i in A if i>X and i<N]

print(min(len(t),len(s)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
l = map(int, raw_input().split())
n = l[0]
m = l[1]
x = l[2]

a = map(int, raw_input().split())

# print a

for i in xrange(0,m):
	if a[i] > x:
		if m - i < i:
			print m - i
			break
		else:
			print i
			break

Submission status: Accepted

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

Submission status: Accepted

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

cl = 0

for i in range(M):
  if A[i] < X:
    cl = cl + 1
cr = len(A) - cl

print(min(cl, cr))

Submission status: Accepted

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

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

countA=0
countB=0

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

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

print(min(countA,countB))

Submission status: Accepted

Solution code:
l = list(map(int,input().split()))
a = list(map(int,input().split()))
b = []
c = []
for n in a:
    if n > l[2]:
        b.append(n)
    else:
        c.append(n)
print('{}'.format(min(len(b),len(c))))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
arr = input().split()
list_fee = []

for i in range(N):
    if arr == []:
        break
    if int(arr[0]) == i+1:
        list_fee.append(1)
        arr.pop(0)
    else:
        list_fee.append(0)
    
a = list_fee[:X].count(1)
b = list_fee[X:].count(1)

print(min(a, b))

Submission status: Accepted

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

counterToN,counterToX = 0,0

for i in A:
    if i - 1 < X :
        counterToN += 1
    else :
        counterToX += 1

print(min([counterToN,counterToX]))

Submission status: Accepted

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

idx = 0

while idx < M:
    if A[idx] > X:
        break
    idx += 1

res = min(idx, M - idx)
print(res)

Submission status: Accepted

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

count = 0
for i in range(x):
  if i in fee_station:
    count += 1

print(count if count < len(fee_station) - count else len(fee_station) - count)

Submission status: Accepted

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

cost_0, cost_N = 0, 0

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

if cost_0 < cost_N:
    print(cost_0)
else:
    print(cost_N)

Submission status: Accepted

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

a = [i in A for i in range(1, N+1)]
print(min(sum(a[:X]), sum(a[X:])))

Submission status: Accepted

Solution code:
import bisect
_,m,x=map(int,input().split());*a,=map(int,input().split());i=bisect.bisect_left(a,x);print(min(i,m-i))

Submission status: Accepted

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

forward = 0
back = 0
for i in a:
    if i < x:
        back += 1
    elif i > x:
        forward += 1

print(min(back, forward))

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in a:
    for j in range(x):
        if i == j:
            to_0 += 1

    for k in range(x, n):
        if i == k:
            to_n += 1

if to_0 >= to_n:
    print(to_n)
else:
    print(to_0)

Submission status: Accepted

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

r = l = 0
for a in A:
    if a < X:
        r += 1
    elif a > X:
        l += 1
print(min(r, l))

Submission status: Accepted

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

setA = set(A) 
s1 = range(0, X)
s2 = range(X, N+1)
a1 = set(s1) & (setA)
a2 = set(s2) & (setA)
cost1 = len(a1)
cost2 = len(a2)

if cost1 >= cost2:
    print(cost2)
else:
    print(cost1)

Submission status: Accepted

Solution code:
l = input().split()
n = int(l[0])
m = int(l[1])
x = int(l[2])
a = input().split()
i = 0
while(1):
    if int(a[i]) > x:
        break
    i = i + 1
if i < m - i:
    print(i)
else:
    print(m - i)

Submission status: Accepted

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

l = len([a_i for a_i in a if a_i < x])
r = len([a_i for a_i in a if a_i > x])

ans = l
if r < ans:
    ans = r
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

cost1 = 0
for i in range(1, X):
    if i in Am:
        cost1+= 1

cost2 = 0
for i in range(X + 1, N):
    if i in Am:
        cost2 += 1
print(min(cost1, cost2))

Submission status: Accepted

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

a = [int(i) for i in input().rstrip().split(' ')]

c1 = len(list(filter(lambda i: i < x, a)))
c2 = len(list(filter(lambda i: i > x, a)))
print(min(c1, c2))

Submission status: Accepted

Solution code:
goal,num,start = map(int,input().split())
A = list(map(int,input().split()))
route = [0 for i in range(goal+1)]
for ind in A:
    route[ind] = 1
print(min(sum(route[start:goal]),sum(route[0:start+1])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#Toll Gates

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

#進む側
temp1 = X
cost1 = 0
while(1):
	if temp1 == N:
		break
	temp1 += 1
	for j in range(M):
		if temp1 == A[j]:
			cost1 += 1

#戻る側
temp2 = X
cost2 = 0
while(1):
	if temp2 == 0:
		break
	temp2 -= 1
	for j in range(M):
		if temp2 == A[j]:
			cost2 += 1

#出力
print(min(cost1,cost2))

Submission status: Accepted

Solution code:
N,M,X = (int(i) for i in input().split())
places = input()
placelistchar = places.split(" ")

placelist = []
for k in range(M):
    placelist.append(int(placelistchar[k]))


countbig = 0
countsmall = 0


for i in range(0,N):
    if(i in placelist):
        if i<X:
            countsmall += 1
        else:
            countbig += 1

print(min(countsmall,countbig))

Submission status: Accepted

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

Submission status: Accepted

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

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

big_A = list(filter(lambda x: x > X, A))#xより大きい成分だけ取り出す
len_min_A = len(A) - len(big_A)

if len(big_A) < len_min_A:
    print(len(big_A))
else:
    print(len_min_A)

Submission status: Accepted

Solution code:
from itertools import accumulate
N, M, X = map(int, input().split(' '))
Toll = list(map(int, input().split(' ')))
cost = [1 if i in Toll else 0 for i in range(N+1)]
cost_cum = list(accumulate(cost))
print(min(cost_cum[X]-cost_cum[0], cost_cum[N]-cost_cum[X]))

Submission status: Accepted

Solution code:
import numpy as np

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

    print(min(np.sum(arr_np < x) ,np.sum(arr_np > x)))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

row = [0]*(N+1)

for i in A:
    row[i]=1
    
print(min(sum(row[:X]),sum(row[X:])))

Submission status: Accepted

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

Submission status: Accepted

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


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

cntm = 0
cntp = 0

for i in range(M):
    if X < a[i]:
        cntm += 1

    else:
        cntp += 1


if cntm < cntp:
    print(cntm)

else:
    print(cntp)

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a = input()
a = a.rstrip().split(" ")
goal2 = int(a[0])
sekisyosuu = int(a[1])
start = int(a[2])

b = input()
sekisyo = b.rstrip().split(" ")

#print(sekisyo)

up=0
dn=0
for i in range(len(sekisyo)):
    if int(sekisyo[i])>=int(start):
        up = up+1
        i+=1
    else:
        dn = dn+1
        i +=1
    
#print(up)
#print(dn)

if int(up)<int(dn):
    print(up)
else:
    print(dn)

Submission status: Accepted

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

Submission status: Accepted

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

to_N = list(range(X,N))
to_0 = list(range(0,X))

to_N_count = 0
for i in to_N:
    for j in  A:
        if i == j:
            to_N_count += 1

to_0_count = 0
for i in to_0:
    for j in A:
        if i == j:
            to_0_count += 1

print(min(to_N_count,to_0_count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M, X = [int(x) for x in input().split(" ")]
arr = [0 for x in range(N+1)]
for i in [int(a) for a in input().split(" ")]:
	arr[i] = 1
kiri = arr[0:X].count(1)
kanan = arr[X+1:].count(1)
print(min(kiri, kanan))

Submission status: Accepted

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

for i in An:
    if i < X:
        count += 1
    else:
        pass

if count >= M - count:
    print (M - count)
else:
    print (count)

Submission status: Accepted

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

cost, left, right = {}, 0, 0

for i in a:
    cost[i] = True

for i in reversed(range(0, x)):
    left += (1 if i in cost else 0)

for i in range(x, n + 1):
    right += (1 if i in cost else 0)

print(min(left, right))

Submission status: Accepted

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

cost = {}

for i in a:
    cost[i] = True

left = right = 0

for i in reversed(range(0, x)):
    left += (1 if i in cost else 0)

for i in range(x, n + 1):
    right += (1 if i in cost else 0)

print(min(left, right))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(a)):
    if a[i] > x:
        over +=1
    else:
        under+=1
        
print(min(over,under))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
l = list(range(X+1))
r = list(range(X+1, N+1))
lc, rc = 0,0
for a in A:
    if a in l:
        lc += 1
    if a in r:
        rc += 1
print(min(lc, rc))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
import numpy as np
B = abs(np.array(A)-X)
i = np.where(B == min(B))[0][0]
if A[i]-X > 0:
    print(min(M-i,i))
else:
    print(min(i+1,M-i-1))

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

c1 = len([i for i in gates if i < X])
can = [c1, M - c1]

print(min(can))

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 A:
    if(i <= X):
        l += 1
    elif(i >= X):
        r += 1
print(min(l, r))

Submission status: Accepted

Solution code:
N, M, X = [int(i) for i in  input().split(" ")]
A = [int(i) for i in input().split(" ")]
r = len([ai for ai in A if ai < X])
l = len([ai for ai in A if ai > X])
print(min((r,l)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M, X = map(int, raw_input().split(" "))
A = map(int, raw_input().split(" "))
r = len([ai for ai in A if ai < X])
l = len([ai for ai in A if ai > X])
print(min((r,l)))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split(" "))
A = map(int, input().split(" "))
left, right = 0,0
for ai in A:
  if ai < X: left+=1
  else: right+=1
print(min(right, left))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ipt1 = [int(i) for i in input().split()]
a = [int(i) for i  in input().split()]
n = ipt1[0]
m = ipt1[1]
x = ipt1[2]
cost_0 = 0
cost_n = 0
for i in range(m):
    if a[i] < x:
        cost_0 += 1
    else:
        cost_n += 1

print(int(min(cost_0, cost_n)))

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]))
    break

Submission status: Accepted

Solution code:
import bisect

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

idx = bisect.bisect(A, X)
print(min(idx, M-idx))

Submission status: Accepted

Solution code:
route0 = 0
routeN = 0
N,M,X = map(int, input().split())
list = input().split(" ")
#print(list)
for i in range(0,M):
    if int(list[i]) <= X:
        route0 = route0 + 1
#print(route0)

for i in range(0,M):
    if int(list[i]) > X:
        routeN = routeN + 1
#print(routeN)
print(min(route0,routeN))

Submission status: Accepted

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

to0, toX = 0, 0
for m1 in m_list:
    if m1 > x:
        toX += 1
    else:
        to0 += 1
print(min(to0,toX))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# kakomon toku
import math
import sys
import itertools
import numpy as np

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

cost_r=0
cost_l=0
i=0
while i < m :
    if a[i] > x :
        cost_r += 1
    i += 1
i=m-1
while i >= 0 :
    if a[i] < x :
        cost_l += 1
    i -= 1
answer = cost_r
if cost_l < answer:
    answer = cost_l

print(answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M, X = map(int, raw_input().split())
A = map(int, raw_input().split())
p = len(filter(lambda a: a < X, A))
q = len(filter(lambda a: a > X, A))
print min(p, q)

Submission status: Accepted

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

Submission status: Accepted

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

print(min(len(left),len(right)))

Submission status: Accepted

Solution code:
def get_values():
    return [int(a) for a in input().split()]

N, M, X = get_values()
As = get_values()

left_cost = 0
for a in As:
    if a > X:
        break
    left_cost += 1
right_cost = len(As) - left_cost
print(min(left_cost, right_cost))

Submission status: Accepted

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

for i,a in enumerate(A):
    if a>X:
        print(min(i,M-i))
        break

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from bisect import bisect
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
pos = bisect(A, X)
ans = [len(A[:pos]), len(A[pos:])]
print(min(ans))

Submission status: Accepted

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

A = list(map(int,input().split()))[:M]

print(min([len(list(filter(lambda a:a>X,A))),len(list(filter(lambda a:a<X,A)))]))

Submission status: Accepted

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

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 range(M):
    if a[i] < X:
        b = b + 1
    else:
        c = c + 1
if b > c:
    print(c)
else:
    print(b)

Submission status: Accepted

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

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:
        break
print(min(i, M - i))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
count = 0
for i in a:
    if i<x:
        count = count + 1
    else:
        break

print(min(count,m-count))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
left = 0
for i in range(m):
    if x > a[i]:
        left += 1
    else:
        break
right = m - left
cost_min = left if left < right else right
print('{}'.format(cost_min))

Submission status: Accepted

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

for i in range(m+1):
    if a[i]==x:
        j=i
print(min(j,m-j))

Submission status: Accepted

Solution code:
def minimum_cost(N, M, X, gates):
    left = range(X, -1, -1)
    right = range(X, N + 1)

    left_cost = right_cost = 0
    for i in left:
        if i in gates:
            left_cost += 1
    
    for i in right:
        if i in gates:
            right_cost += 1

    min_cost = left_cost
    if min_cost > right_cost:
        min_cost = right_cost

    return min_cost


if __name__ == "__main__":
    N, M, X = list(map(int, input().rstrip().split(" ")))
    gates = [int(x) for x in input().rstrip().split(" ")]

    print(minimum_cost(N, M, X, gates))

Submission status: Accepted

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

# print(n, m, x)
# print(a)

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

# print(A)

cnt = 0
for i in range(x, n + 1):
    cnt += A[i]

cnt_ = 0
for i in range(x, -1, -1):
    cnt_ += A[i]
    # print(i, A[i])
# print(cnt_)

if cnt < cnt_:
    print(cnt)
else:
    print(cnt_)

Submission status: Accepted

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

print(count0 if count0 < countN else countN)

Submission status: Accepted

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

forward_cost = 0
backward_cost = 0

i = X
while i <= N:
    i += 1

    if i in A_list:
        forward_cost += 1

i = X
while i >= 0:
    i -= 1

    if i in A_list:
        backward_cost += 1

print(min(forward_cost, backward_cost))

Submission status: Accepted

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

for i in range(M):
  if X < A[i]:
    break
    
cost = min([len(A[0:i]), len(A[i:M])])

print(cost)

Submission status: Accepted

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

cost = 0
cost2 = 0

for i in range(X, N):
   if i in a:
       cost += 1

for i in range(X, 0, -1):
    if i in a:
        cost2 += 1

if cost < cost2:
    print(cost)
else:
    print(cost2)

Submission status: Accepted

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

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

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M,X = map(int, input().split())
n = list(map(int, input().split()))
Ni = list(range(N,X,-1))
Nk = list(range(0,X))
Ni_set = set(Ni)
Nk_set = set(Nk)
n_set = set(n)
Ni_ten = list(Ni_set & n_set)
Nk_ten = list(Nk_set & n_set)
if len(Ni_ten)< len(Nk_ten):
 print(len(Ni_ten))
else:
  print(len(Nk_ten))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
B - Toll Gates
https://beta.atcoder.jp/contests/abc094/tasks/abc094_b

"""
import sys
from sys import stdin
input = stdin.readline


def main(args):
    N, M, X = map(int, input().split())
    points = [0] * (N + 1)
    gates = [int(x) for x in input().split()]
    for g in gates:
        points[g] = 1

    ans_0 = sum(points[:X])
    ans_n = sum(points[X:N])
    print(min(ans_0, ans_n))


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a, b = 0, 0
t = list(map(int, input().split()))
for i in range(m):
    if t[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()))
countA=0
countB=0

for i in range(0,M):
    if A[int(i)] in range(0,X):
        countA += 1
for j in range(0,M):
    if A[int(j)] in range(X,N+1):
        countB += 1
if countA > countB:
    print(countB)
else:
    print(countA)

Submission status: Accepted

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

cost_l = 0
cost_r = 0

# left
for i in range(x-1, -1, -1):
    if i in a:
        cost_l += 1

#right
for i in range(x+1, n+1, 1):
    if i in a:
        cost_r += 1

print(min(cost_l, cost_r))

Submission status: Accepted

Solution code:


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

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

    print(min(sum(A[0:X]), sum(A[X:N])))



if __name__ == '__main__':
    main()

Submission status: Accepted

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

left=0
right=0

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

Submission status: Accepted

Solution code:
N, M, X = (int(_) for _ in input().split())
A = [int(_) for _ in input().split()]
cost = [0, 0]
for a in A:
    if a < X:
        cost[0] += 1
    else:
        cost[1] += 1

print(min(cost))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split(" "))
a = input().split(" ")
sum_zero = 0
sum_n = 0
for i in range(1, x):
    if str(i) in a:
        sum_zero += 1

for i in range(x+1, n):
    if str(i) in a:
        sum_n += 1
print(min(sum_zero, sum_n))

Submission status: Accepted

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

    cost_move_to_left = 0
    cost_move_to_right = 0
    for i in a:
        if i > x:
            cost_move_to_left += 1
        elif i < x:
            cost_move_to_right += 1

    print(cost_move_to_left if cost_move_to_left < cost_move_to_right else cost_move_to_right)



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# coding: utf-8

N, M, X = map(int, input().split())
cost0 = len([i for i in input().split() if int(i) < X])
if cost0 * 2 <= M:
    print(cost0)
else:
    print(M - cost0)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
fee = set(map(int, input().split()))
ls = list(range(n+1))
f, b = ls[:x], ls[x+1:]
print(min(len(fee & set(f)), len(fee & set(b))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def solve(x, a):
	low = 0
	high = len(a)-1
	while high >= low:
		t = (high+low)//2
		if x>a[t]:
			low = t+1
		else:
			high = t-1
	t = math.ceil((high+low)/2)
	return min(t, len(a)-t)
		
n,m,x = map(int, input().split())
a = list(map(int, input().split()))
print(solve(x,a))