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:
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())
# 長さNの配列を作成し、すべての要素に対して初期値を0に設定する。
tollList = [0] * (n + 1)
a = list(map(int, input().split()))
# 料金所がある場所の要素を0→1に変更
for num in a:
    tollList[num] = 1
ans = min(sum(tollList[0:x+1]), sum(tollList[x:]))
# この指定方法でもいける。
# ans = min(sum(tollList[0:x + 1]), sum(tollList[-1:x - 1:-1]))
print(ans)

Submission status: Accepted

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

masu = [0 for _ in range(N+1)]
for a in A:
  masu[a] = 1
answer = min(sum(masu[:X]), sum(masu[X:]))
print(answer)

Submission status: Accepted

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

print(Answer)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():

    N, M, X = map(int, input().split())
    A = list(map(int, input().split()))
    A.sort()
    count1 = 0
    for i in range(M):
        if A[i] < X: count1 += 1
    return min(count1, len(A)-count1)



if __name__ == '__main__':
    print(main())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int, input().split())
a = list(map(int, input().split()))
l = []
before = 0
after = 0
for i in range(n+1):
  l.append(i)

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

Submission status: Accepted

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

Submission status: Accepted

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

left=0
right=0
for ai in aa:
  if ai < x:
    left += 1
  elif ai > x:
    right += 1
print(min(left,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
  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()))


for i in range(M):
    if A[0] >= X:
        ans = 0
        break
    elif A[M-1] <= X:
        ans = 0
        break
    else:
        if A[i-1] < X and X < A[i]:
            ans = min(i,M-i)

print(ans)

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 X < i:
        left += 1
    elif X > i:
        right += 1

print(min(left, right))

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[0] >= X:
        ans = 0
        break
    elif A[M-1] <= X:
        ans = 0
        break
    else:
        if A[i] == X:
            ans = min(i, M-1-i)
        elif A[i-1] < X and X < A[i]:
            ans = min(i,M-i)

print(ans)

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 = sorted(list(map(int, input().split())))
f = len(list(filter(lambda y:y>x, a)))
b = len(a)-f
print(f if f < b else b)

Submission status: Accepted

Solution code:
n,m,x = map(int, input().split())
a = sorted(list(map(int, input().split())))
f = list(filter(lambda y:y>x, a))
if len(f) < len(a)-len(f):
  print(len(f))
else:
  print(len(a)-len(f))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = [int(x) for x in input().split()]
key1 = len(a)
key2 = 0
for i in range(key1):
    if a[i] <= x:
        key2 += 1
    else:
        break
print(min([key2, key1-key2]))

Submission status: Accepted

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

cnt = 0
for a in A:
    if a < x:
        cnt += 1
    else:
        break

print(min(cnt, len(A)-cnt))

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
  else:
    r+=1
print(min(l,r))

Submission status: Accepted

Solution code:
N,M,X = map(int, input().split())
H = list(map(int, input().split()))
left = 0
right = 0
for i in range(N):
    if i in H:
        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 = [int(j) for j in 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()))

cost = [0]*(N+1)
for idx in range(M):
    cost[A[idx]] = 1

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

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
array = list(map(int, input().split()))
index = [0] * (N+1)
tmp = 0
tmp2 = 0
for i in range(N):
    if i in array:
        index[i] = 1
for i in range(X,N+1):
    tmp += index[i]
for i in range(0,X+1):
    tmp2 += index[i]
if tmp <= tmp2:
    print(tmp)
else:
    print(tmp2)

Submission status: Accepted

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

Submission status: Accepted

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

tozero = len([i for i in a if i<x])
print(min(tozero,len(a)-tozero))

Submission status: Accepted

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

A_list = [int(e) for e in input().split()]

cost_to_zero = 0
cost_to_N = 0

for toll_gate in A_list:
    if toll_gate < X:
        cost_to_zero += 1
    elif toll_gate > X:
        cost_to_N += 1

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()))
backward = 0
forward = 0

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

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

print(min(forward, backward))

Submission status: Accepted

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

l = 0

for a in arr:
    if a < x:
        l += 1
r = m-l
print(min(l,r))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from bisect import *

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n,m,x=map(int, input().split())
    a=list(map(int, input().split()))
    i=bisect_left(a,x)
    print(min(i,m-i))

main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(min(l_cnt, M-l_cnt))

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
print(min(cnt,M-cnt))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#2019/09/30
std_input = open(0).readlines()
N, M, Q = map(int, std_input[0].split())
#print(N, M, Q)
A = list(map(int, std_input[1].split()))
#print(A)
cnt_up = 0
cnt_down = 0
Qup = Q
Qdown = Q
for i in range(N-Q):
    Qup += 1
    if Qup in A:
        cnt_up += 1
for i in range(N):
    Qdown -= 1
#    print(Qdown)
    if Qdown < 0:
        break
    if Qdown in A:
        cnt_down += 1
#print(cnt_up, cnt_down)
print(min(cnt_up,cnt_down))

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    n, m, x = list(map(int, input().rstrip('\n').split()))
    a = list(map(int, input().rstrip('\n').split()))
    ca = 0
    cb = 0
    for i in range(m):
        if a[i] < x:
            ca += 1
        else:
            cb += 1
    print(min(ca, cb))


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

print(min( len([a for a in an if a < x]), len([a for a in an if a > x])))

Submission status: Accepted

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    [N, M, X] = string_to_int(inputs[0])
    A = string_to_int(inputs[1])
    cost_0 = 0
    cost_n = 0
    for a in A:
        if a < X:
            cost_0 += 1
        elif a > X:
            cost_n += 1
    return min([cost_0, cost_n])


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Accepted

Solution code:
from bisect import bisect_left
N,M,X = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
b = bisect_left(A,X)
if b==0:
  print(0)
  exit()
print(min(b,M-b))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = set(map(int,input().split()))
Af = [1 for i in range(1,X) if i in A]
Al = [1 for i in range(X+1,N) if i in A]
print(min(sum(Af),sum(Al)))

Submission status: Accepted

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

Submission status: Accepted

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

    toz = 0
    for i in range(x, 0, -1):
        if am.count(i) == 1:
            toz += 1

    ton = 0
    for i in range(x, n, 1):
        if am.count(i) == 1:
            ton += 1

    print(min([toz, ton]))

bb094()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
L = list(map(int, input().split()))
print(min(len(set(L)&set(range(1,c))),len(set(L)&set(range(c+1,a)))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

c1 = 0
for i in a:
    if i < x:
        c1 += 1

c2 = 0
for i in a:
    if i > x:
        c2 += 1

print(min(c1, c2))

Submission status: Accepted

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

count_up = 0
for i in range(M):
    if X < charge_list[i]:
        count_up += 1
    else:
        pass


count_down = 0
for i in range(M):
    if charge_list[i] < X:
        count_down += 1
    else:
        pass


print(min(count_up, count_down))

Submission status: Accepted

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

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

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

print(min(p, q))

Submission status: Accepted

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

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

Submission status: Accepted

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

ans = 0
ans_ = 0
for i in range(m):
    if a[i] < x:
        ans += 1
    if a[i] > x:
        ans_ += 1
print(min(ans, ans_))

Submission status: Accepted

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

go,back = 0,0

for a in A:
    if a < x:
        go += 1
    else:
        back += 1

print(min(go,back))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
to_zero = sum([1 for a in A if a < X])
to_n = sum([1 for a in A if a > X])
if to_zero >= to_n:
    print(to_n)
else:
    print(to_zero)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

count_low = 0
count_high = 0

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

print(min(count_low, count_high))

Submission status: Accepted

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

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

# solve
cost = [0] * (N + 1)
for i in range(M):
    cost[A[i]] = 1

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

Submission status: Accepted

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

for i in range(m):
    if a[i]>x:
        R+=1
    else:
        L+=1
print(min(L,R))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Toll Gates
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
tmp = 0
for i in range(M):
    if X < A[i]:
        tmp = i
        break
    else:
        pass
if tmp > M/2:
    print(M-tmp)
else:
    print(tmp)

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

hot = [0] * N
for i in a:
    hot[i] = 1
ans = min(sum(hot[:X]), sum(hot[X + 1 :]))
print(ans)

Submission status: Accepted

Solution code:
x,m,x=map(int,input().split())
a=list(map(int,input().split()))
a.append(x)
a.sort()
start=len(a[:a.index(x)])
goal=len(a[a.index(x):])-1
print(min(start,goal))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*N

for i in A:
  B[i]=1
#print(B)

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

Submission status: Accepted

Solution code:
N,M,X = map(int,(input().split()))
AList = list(map(int,input().split()))
left = 0
right = 0
for a in AList:
    if a < X:
        left += 1
    elif a > X:
        right += 1
print(min(left,right))

Submission status: Accepted

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

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

to_0_cost = len(list(filter(lambda v: v < x, a)))
to_n_cost = len(list(filter(lambda v: v > x, a)))

print(min(to_0_cost, to_n_cost))

Submission status: Accepted

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

Submission status: Accepted

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

anslist=[0]*(n+1)
for i in a:
  anslist[i]=1
print(min(sum(anslist[:x]),sum(anslist[x:n])))

Submission status: Accepted

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

right = len([int(i) for i in a if x < i])
left = len([int(i) for i in a if x > i])

print(min(right, left))

Submission status: Accepted

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

right = [l for i in a if x < i]
left = [l for i in a if x > i]

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

Submission status: Accepted

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

cost_1 = 0

current = x
while current != n:
    current += 1
    if current in a_list:
        cost_1 += 1

cost_2 = 0
current = x
while current != 0:
    current -= 1
    if current in a_list:
        cost_2 += 1

print(min(cost_1, cost_2))

Submission status: Accepted

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

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

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

print(min(left, right))

Submission status: Accepted

Solution code:
n, m, x = list(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:
N,M,X = map(int, input().strip().split(' '))
A = list(map(int, input().strip().split(' ')))

to0 = len([a for a in A if a < X])
print(min(to0, M-to0))

Submission status: Accepted

Solution code:
import numpy as np

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

upper = np.sum((a_list > x))
lower = len(a_list) - upper

print(min(lower, upper))

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+1, n+1):
        if i in a:
                ans1 += 1

for i in range(x):
        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()))
cost = (n+1)*[0]
for i in range(len(a)):
    cost[a[i]] = 1

c1 = cost[0:x]
c2 = cost[x+1:n+1]
print(min(sum(c1),sum(c2)))

Submission status: Accepted

Solution code:


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

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

A.append(X)

# print(A)


A.sort()

X_index = int(A.index(X))
# print(X_index)

t = len(A)


# print(t)
# print(A)
diff_s = X_index
diff_b = t - X_index - 1

# print(diff_s)
# print(diff_b)


if diff_b == 0 or diff_s == 0:
  print(0)
elif diff_b < diff_s:
  print(diff_b)
else:
  print(diff_s)

  # 2 4 7 9 14

Submission status: Accepted

Solution code:
# ABC094B - Toll Gates
from bisect import bisect_left


def main():
    N, M, X, *A = map(int, open(0).read().split())
    A.sort()
    cur = bisect_left(A, X)
    ans = min(cur, M - cur)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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:
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:
import bisect

n, m, x = map(int, input().split())
ls = list(map(int, input().split()))
l = bisect.bisect(ls, x)
print(min(l, m - l))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np
N, M, X = map(int, input().split())
*A,     = map(int, input().split())



sum_right = 0
sum_left  = 0

I         = np.zeros((1, N+1))
I[0][0]   = 0
I[0][N]   = 0
I[0][X]   = 0

for i in A:
    I[0][i] = 1

print(int(min(np.sum(I[0][0:X]), np.sum(I[0][X:N+1]))))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC094b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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(left, right))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = map(int, input().split())
cnt = sum( x < i for i in a)
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()))
t = bisect.bisect(a, x)
print(min(len(a[:t]), len(a[t:])))

Submission status: Accepted

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

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())
n = sum(int(i) < X for i in list(map(int, input().split())))
print(min(n, M - n))

Submission status: Accepted

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

lst = [0] * (N+1)
for a in A:
    lst[a] = 1
print(min(sum(lst[:X]), sum(lst[X:])))

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
    sys.stdin=open('input_file.txt')
    
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
cnt=0
cntt=0

for i in a:
	if i<x:
		cnt+=1
	if i>x:
		cntt+=1
		
print(min(cnt,cntt))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
As = list(map(int, input().split()))
count1 = 0
count2 = 0
for i in range(x, n + 2):
    if i in As and i != n and i != 0 and i != x:
        count1 += 1
for i in range(0, x):
    if i in As and i != n and i != 0 and i != x:
        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]*N
for i in A: cost[i] = 1
print(min(sum(cost[X:]),sum(cost[:X+1])))

Submission status: Accepted

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

Submission status: Accepted

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

cost_0 = 0
cost_n = 0
for num in A:
  if num < x:
    cost_0 += 1
  else:
    cost_n += 1
  
print(min(cost_0, cost_n))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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 range(m):
    if a[i] < x:
        left += 1
    else:
        right += 1

print(min(left, right))

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

left = sum(i < x for i in a)
right = sum(i > x for i in a)

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 i in a:
    if i<x:
        left+=1
    else:
        right+=1
print(min(left,right))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Tue Sep  3 23:09:02 2019

@author: Yamazaki Kenichi
"""

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

A.sort()
map_ = [0 for i in range(N+1)]

for a in A:
    map_[a] = 1

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