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:
I=lambda:map(int,input().split());n,m,x=I();s=sum(a<x for a in I());print(min(s,m-s))

Submission status: Accepted

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

to_z = sum([1 for a in A if a < x])
to_n = sum([1 for a in A if a > x])

print(min(to_z, to_n))

Submission status: Accepted

Solution code:
import bisect as bi

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

k=bi.bisect_right(A,x)

print(min(k,m-k))

Submission status: Accepted

Solution code:
n,m,x,*a=map(int,open(0).read().split())
print(min(sum(1for i in a if i<x),sum(1for i in a if i>x)))

Submission status: Accepted

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

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

A.append(x)
A.sort()
idx=A.index(x)

a=A[:idx]
b=A[idx+1:]

print(min(len(a),len(b)))

Submission status: Accepted

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

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

lcost = m - rcost

print(min(lcost, rcost))

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 = [int(i) for i in input().split() if int(i) < x]
print(len(A) if m - len(A) > len(A)  else m - len(A))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

fee=[]

for i in range(n):
    fee.append('1' if i in a else '0')

print(min(fee[0:x].count('1'),fee[x::].count('1')))

Submission status: Accepted

Solution code:
int_n, int_m, int_x = map(int, input().split())

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


to_start = len([x for x in int_a_ar if x < int_x])

to_end = len([x for x in int_a_ar if x > int_x])


cost = to_start if to_start < to_end else to_end

print(cost)

Submission status: Accepted

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

c = 0
for i in range(len(A)):
    if A[i] < X:
        c += 1
cost.append(c)

c = 0
for i in range(len(A)):
    if X < A[i]:
        c += 1
cost.append(c)
#print(cost)
print(min(cost))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

cost0 = 0
costN = 0

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

print(min(cost0, costN))

Submission status: Accepted

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

xr = 0
xl = 0

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

Submission status: Accepted

Solution code:
n,m,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
before=0
after=0
for i in range(x):
    if i in a:
        before+=1
for j in range(x+1,n):
    if j in a:
        after+=1
print(min(before,after))

Submission status: Accepted

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

Submission status: Accepted

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

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:
# -*- coding: utf-8 -*-
import sys
# ----------------------------------------------------------------
# Use Solve Function

def solve(lines):
    N,M,X = map(int, lines.pop(0).split(' '))
    A = list(map(int, lines.pop(0).split(' ')))
    less = more = 0
    for i in A:
        if i < X:
            less += 1
        else:
            more += 1
    print(min(more, less))


#
# main
#
lines = [x.strip() for x in sys.stdin.readlines()]

#
# solve !!
#
solve(lines)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC094B
n,m,x = map(int,input().split())
aa = list(map(int,input().split()))
aa.append(x)
aa = sorted(aa)
# print(aa)
idx=aa.index(x)
print(min(idx, m-idx))

Submission status: Accepted

Solution code:
""" AtCoder """

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

A.append(X)
A.sort()

print(min(A.index(X), M - A.index(X)))

Submission status: Accepted

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

first = X
last = N+1-X
first_count = 0
last_count = 0

for a in range(len(A)):
    if X < A[a]:
        first_count += 1
    else:
        last_count += 1

if first_count > last_count:
    ans = last_count
else :
    ans = first_count

print(ans)

Submission status: Accepted

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

for i in range(m):
    if a[i]<x:
        o += 1
    elif a[i]>x:
        l += 1
print(min(o,l))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
A = [int(i) for i in input().split() if int(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()))
left = len([a for a in A if a <= X])
right = len([a for a in A if a >= X])
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:
N, M, X = map(int,input().split())
A = list(map(int,input().split()))
l, r = 0, 0
for a in A:
  if(X > a):
    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()))
count1=0
count2=0
t1=x
t2=x
while(t1>=0):
    if(t1 in a):
        count1+=1
    t1+=-1
while(t2<=n):
    if(t2 in a):
        count2+=1
    t2+=1
print(min(count1,count2))

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


main()

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
A=list(map(int,input().split()))
if x>A[m-1] or x<A[0]:
    print(0)
    exit()
    k=0
for i in range(m):
    if A[i]>x:
        k=i
        break
print(min(k,m-k))

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([j for j in a if j>x])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
left=0;right=0
for i in range(m):
  if a[i]<x: left += 1
  else: right += 1
#print(left,right)#
print(min(left,right))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
gate=list(map(int,input().split()))
#print(N,M,X,gate)
l_even = [i for i in gate if i < X]
print(min(len(l_even),M-len(l_even)))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=[int(i) for i in input().split()]
be=0
af=0
for i in range(m):
    if a[i]<x:
        be+=1
    elif a[i]>x:
        af+=1
print(be if be<af else af)

Submission status: Accepted

Solution code:

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

A = [i for i in map(int, input().split())]
squares=[i for i in range(N+1)]
V=squares[X]
lowest=[]
highest =[]
for i in range(len(A)):
    if A[i]<V:
        lowest.append(A[i])
    else:
        highest.append(A[i])
if len(lowest)>len(highest):
    cost = len(highest)
else:
    cost = len(lowest)

print(cost)

Submission status: Accepted

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

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

    print(min(l, r))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

    p1 = 0
    for i in range(x, 0, -1):
        if i in a_:
            p1 += 1

    p2 = 0
    for i in range(x, n):
        if i in a_:
            p2 += 1

    print(min([p1, p2]))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

    p1 = 0
    for i in range(x - 1, -1, -1):
        if i in a_:
            p1 += 1

    p2 = 0
    for i in range(x + 1, n):
        if i in a_:
            p2 += 1

    print(min([p1, p2]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M, X, = map(int,input().split())
L = list(map(int,input().split()))
cnt1 = 0
cnt2 = 0
for x in L:
    if x < X:
        cnt1 += 1
    else :
        cnt2 += 1

print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
from bisect import bisect_right

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

i = bisect_right(As, X)
print(min(i, M-i))

Submission status: Accepted

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

ans1,ans2 = 0,0
for i in range(X,N):
    if i in A:
        ans1 += 1
for i in range(X,-1,-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()))
i=0
while a[i]<=x:
    i+=1
print(min(i,m-i))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
s=0
i=0
while a[i]<=x:
    s+=1
    i+=1
print(min(s,m-s))

Submission status: Accepted

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

Submission status: Accepted

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

count_left=0
count_right=0

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

print(min(count_left,count_right))

Submission status: Accepted

Solution code:
n, m, x = (int(y) for y in input().split())
A_lis = [int(y) for y in input().split()]
res = 0

for i in A_lis:
    if (i>x):
        res +=1

print(min(res,m-res))

Submission status: Accepted

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

A.append(x)
A.sort()
idx = A.index(x)

l = len(A[:idx])
r = len(A[idx:]) - 1
if l < r:
    print(l)
else:
    print(r)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(min(s,d))

Submission status: Accepted

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

def main():
    na = list(map(int, input().split()))
    N, M, X = na[0], na[1],na[2]
    A = list(map(int, input().split()))

    i = bisect.bisect_left(A, X)

    print(min(i, M - i))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
l = list(map(int, input().split()))
a = {}
for t in l:
    a[t] = 1

total1 = 0
i = x
while i >= 0:
    i -= 1
    total1 += a.get(i, 0)

total2 = 0
i = x
while i <= n:
    i += 1
    total2 += a.get(i, 0)

print(min(total1, total2))

Submission status: Accepted

Solution code:
a,b,k=map(int,input().split())
p=[i for i in list(map(int,input().split()))if i<k]
print(min(b-len(p),len(p)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
b=[]
c=[]
for i in a:
  if i<x:
    b.append(i)
  else:
    c.append(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()))
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())
s=sum(int(_)<x for _ 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, right = X, X
left_cost, right_cost = 0, 0
for i in range(N+1):
  left -= 1
  right += 1
  if(left in A):
    left_cost += 1
  if(right in A):
    right_cost += 1
print(min(left_cost, right_cost))

Submission status: Accepted

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

L = list(filter(lambda x:x<X,A))
R = list(filter(lambda x:x>X,A))

print(min(len(L),len(R)))

Submission status: Accepted

Solution code:
n,b,sta=map(int,input().split())
A=list(map(int,input().split()))
Z=["F" for i in range(n+1)]
for i in A:
  Z[i]="B"
fi=Z[:sta:]
se=Z[sta+1::]
print(min(fi.count("B"),se.count("B")))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
input = sys.stdin.readline

N, M, start = map(int, input().split())
lst_gate = map(int, input().split())

left = 0
right = 0
for gate in lst_gate:
    if gate < start:
        left += 1
    else:
        right += 1
print(min(left, right))

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
input = sys.stdin.readline

N, M, start = map(int, input().split())
lst_station = input().split()

cost2zero = sum(1 for i in range(start) if str(i) in lst_station)
cost2N = sum(1 for i in range(start+1, N+1) if str(i) in lst_station)

print(min(cost2zero, cost2N))

Submission status: Accepted

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

for i in range(len(A_LIST)):
    A_LIST[i]=int(A_LIST[i])

left_counter=0
right_counter=0

for i in A_LIST:
    if i<X:
        left_counter+=1
    else:
        right_counter+=1

print(left_counter if left_counter<right_counter else right_counter)

Submission status: Accepted

Solution code:
a,b,c= map(int, input().split())
p = list(map(int, input().split()))
k = 0
for i in range(b):
    if p[i] < c:
        k+=1
print(min(k,b-k))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
A,B,X = list(map(int,input().split()))
l = list(map(int,input().split()))

print(min(bisect.bisect_left(l,X),(len(l)-bisect.bisect_left(l,X))))

Submission status: Accepted

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

countmax=0
count0=0

for i in range(M):
    if(A[i]<X):
        count0+=1
    elif(A[i]>X):
        countmax+=1
    else:
        count0+=1
        countmax+=1

if(count0>countmax):
    print(countmax)
else:
    print(count0)

Submission status: Accepted

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


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

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

    for i in range(n - x):
        temp = x + i + 1
        if temp in a:
            right += 1

    print(min(left, right))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

count = 0
for i in input().split():
    if int(i) > X:
        break
    count += 1

print(min(count , M-count))

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)
a1=[i for i in a if i < x]
a2=[i for i in a if i > x]
print(min(len(a1), len(a2)))

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)
r = M - l

print(min(l, r))

Submission status: Accepted

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

A = map(int, input().split())
count0=0
count1=0
for i in A:
    if(i<X):
        count0+=1
    else:
        count1+=1
print(min(count0, count1))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
N,M,X = map(int,input().split()) #整数の入力
a = list(map(int,input().split()))
#検問所の入力
b=[]
c=[]
for i in range(X+1,N): #X+1からNの範囲の整数について 
  if i in a: #ある整数が検問所の整数として存在する
    b.append(1)
for i in range(1,X): #1からX-1の範囲の整数について
  if i in a: #ある整数が検問所の整数として存在する
    c.append(1)
print(min(sum(b),sum(c)))

Submission status: Accepted

Solution code:
def main():
    n, m, x = map(int, input().split())
    aa = list(map(int, input().split()))
    c0 = len([a for a in aa if a < x])
    cn = len([a for a in aa if a > x])
    print(min(c0, cn))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import sys
import math
import fractions
def j(a):
    if a==1: print("Yes")
    else :print("No")


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())

#x = ip()                              #入力整数1つ
#x,y = (int(i) for i in input().split())      #入力整数横2つ
x,y,z = (int(i) for i in input().split())    #入力整数横3つ
#a,b,c,k = (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
c = z
a.append(c)
a.sort()
p = a.index(c)
print(min(len(a)-p-1,p))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
 
n, m, x = map(int, input().split())
gates = list(set(map(int, input().split())))
costs = [0]*n

for gate in gates:
    costs[gate] = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

fare = 0

# 減少方向
for i in range(X) :
    if (i in gates) :
        fare += 1

min_fare = fare
fare = 0
for i in range(X,N+1) :
    if (i in gates) :
        fare += 1

if (min_fare > fare) :
    min_fare = fare

print(min_fare)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
a=[int(i) for i in input().split()]
n=X
for i in  range(M):
    if a[i]>X:
        n=i
        break
print(min(n,M-n))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split(" "))
ar = list(map(int,input().split(" ")))
br = []
count = 0
for i in range(X,N+1):
    if i in ar:
        count += 1
br.append(count)
count = 0
for i in range(X,-1,-1):
    if i in ar:
        count += 1
br.append(count)
print(min(br))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
clist = list(map(int,input().split()))
lroot = 0
rroot = 0

for item in clist:
    if item<x:
        lroot += 1
    else:
        rroot += 1

print(min(lroot,rroot))

Submission status: Accepted

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

Submission status: Accepted

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

res = min(sum([True for _ in a if _<x]), sum([True for _ in a if _>x]))
print(res)

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
d=[int(i) for i in input().split()]
#print(c)
e=[]
f=[]
for i in range(b):
	if d[i]<c:
		e.append(d[i])
	else:
		f.append(d[i])
#print(e)
#print(f)
g=len(e)
h=len(f)
if g<=h:
	print(g)
else:
	print(h)

Submission status: Accepted

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

Submission status: Accepted

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

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

s = [c for c in a if c<x]
l = [c for c in a if c>x]

print(min(len(s),len(l)))

Submission status: Accepted

Solution code:
# https://beta.atcoder.jp/contests/abc094/tasks/abc094_b


def solve():
    N, M, X = map(int, input().split())
    A = [0 for _ in range(N + 1)]
    cost = list(map(int, input().split()))
    for i in cost:
        A[i] = 1

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

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

Submission status: Accepted

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

    c1 = 0
    c2 = 0
    for a in A:
        if a < x:
            c1 += 1
        else:
            c2 += 1

    print(min(c1, c2))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

result = min(sum(a < X for a in A), sum(a > X for a in A))
print(result)

Submission status: Accepted

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

Submission status: Accepted

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


left, right = 0, 0
for a in A:
    if a < X:
        left += 1
    else:
        right += 1

print(min(left, right))

Submission status: Accepted

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


left, right = 0, 0
for a in A:
    if a < X:
        left += 1
    else:
        right += 1

print(min(left, right))

Submission status: Accepted

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

Submission status: Accepted

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

sum0 = 0
sumn = 0

route = [0] * (n+1)

for i in m_index:
    route[i] = 1

for i in range(x, n+1):
    sumn += route[i]
for i in range(x+1):
    sum0 += route[i]

print(min(sumn,sum0))

Submission status: Accepted

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

left_toll, right_toll = 0, 0
for a_i in A_m:
    if a_i < X:
        left_toll += 1
    else:
        right_toll += 1

print(left_toll if left_toll < right_toll else right_toll)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=(int(i) for i in input().split(' '))
a=[int(i) for i in input().split(' ')]
a+=[x]
a.sort()
print(min(a.index(x),m-a.index(x)))

Submission status: Accepted

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

Submission status: Accepted

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

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

print( min( [total,m-total] ))

Submission status: Accepted

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

former = len([a for a in A_list if a < X])
later = len([a for a in A_list if X < a])

print min(former, later)

Submission status: Accepted

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

from bisect import *

p = bisect_left(A, X)
l = p
r = M - p
print(min(l, r))

Submission status: Accepted

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

c1 = 0
c2 = 0

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

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

print(min(c1,c2))

Submission status: Accepted

Solution code:
import bisect
N, M, X = map(int, raw_input().split())
A = map(int, raw_input().split())
i = bisect.bisect_left(A, X)
if i == 0 or M - i == 0:
	print 0
elif i < M - i:
	print i
else:
	print M - i

Submission status: Accepted

Solution code:
n,m,x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
rn = [i for i in a if n>=i>=x]
r0 = [i for i in a if x>=i>=0]
print(len(rn)) if len(rn)<len(r0) else print(len(r0))

Submission status: Accepted

Solution code:
import bisect

n, m, x = map(int, input().split())
a = [int(s) for s in input().split()]
idx = bisect.bisect(a, x)
print(min(idx, m - idx))

Submission status: Accepted

Solution code:
nmx = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in a:
    if i > nmx[2]:
        print(min(a.index(i),nmx[1]-a.index(i)))
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

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

i = bisect.bisect_right(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()))

ans = 0
for x in range(X,N+1):
    if x in A:
        ans += 1
ans2 = M - ans

print(min(ans, ans2))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

n,m,x = li()
a = list(li())
small = 0
large = 0
for ai in a:
    if ai < x:
        small += 1
    else:
        large += 1

print(min(small, large))