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

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

print(min(sum(grids[0: X + 1]), sum(grids[X: N + 2])))

Submission status: Accepted

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

a.append(x)
a.sort()

print(min(len(a[:a.index(x)]),len(a[a.index(x)+1:])))

Submission status: Accepted

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

Submission status: Accepted

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

left = 0
right = 0

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

print(min(left, right))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
import itertools
#n = int(input())
#n, d = list(input().split())
N, M, X= list(map(int, input().split()))
A = list(map(int, input().split()))

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


print(min(total, total2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

answer = min(to_0, to_N)
print(answer)

Submission status: Accepted

Solution code:
import bisect

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

ind = bisect.bisect_left(A, X)
print(min(ind, len(A) - ind))

Submission status: Accepted

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

lower = list(filter(lambda num: num < x, a_list))
larger = list(filter(lambda num: num > x, a_list))

print(min(len(lower),len(larger)))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
N=[int(i) for i in range(n+1)]
a=[int(i) for i in input().split()]
min1=0
min2=0
for i in N[x:]:
    for j in a:
        if i==j:
            min1+=1
for k in N[:x]:
    for l in a:
        if k==l:
            min2+=1
print(min(min1,min2))

Submission status: Accepted

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

Submission status: Accepted

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

bigger = []
smaller = []
for t in tolls:
    if t > X :
        bigger.append(t)
    elif t < X :
        smaller.append(t)
        
print(min(len(bigger), len(smaller)))

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

ans=0
for i in range(M):
    if A[i]>=X:
        ans+=1
        
print(min(ans,M-ans))

Submission status: Accepted

Solution code:
N, M, X = map(int,input().split())
A = set(map(int,input().split()))
l = set()
r = set()
for i in range(X):
    l.add(i)
for i in range(X, N):
    r.add(i)
l_tall = l & A
r_tall = r & A
if len(l_tall) <= len(r_tall):
    print(len(l_tall))
else:
    print(len(r_tall))

Submission status: Accepted

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

a,b = 0,0
for i in range(m):
    if l[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()))

r1 = 0
r2 = 0
for i in range(m):
    if a[i] == x: continue
    if a[i] < x : r1 += 1
    if a[i] > x : r2 += 1

print(min(r1, r2))

Submission status: Accepted

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

fee1 = 0
fee2 = 0

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

print(min(fee1, fee2))

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())

A = list(map(int, input().split()))
t = 0
s = 0
for i in A:
    if i > c:
        t += 1
    if i < c:
        s += 1
print(min(s, t))

Submission status: Accepted

Solution code:
#Toll Gates
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
judge = 1
k = 0
n1 = 0; n2 = 0

for i in range(N+1):
    if i == A[k] and judge == 1:
        n1 += 1
        if k != M-1:
            k += 1
    if i == A[k] and judge == 2:
        n2 += 1
        if k != M-1:
            k += 1
    if i == X:
        judge = 2
print(min(n1,n2))

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:
def main():
    squares, tolls_number, start = map(int, input().split(" "))
    tolls = list(map(int, input().split(" ")))
    first_toll_index = 0
    for i in range(tolls_number):
        if tolls[i] > start:
            first_toll_index = i
            break
    print(min(len(tolls[:first_toll_index]), len(tolls[first_toll_index:])))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import bisect


def main():
    N, M, X = map(int, input().split())
    A = list(map(int, input().split()))
    index = bisect.bisect_left(A, X)
    print(min(index, M - index))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


def main():
    N, M, X = map(int, input().split())
    A = set(list(map(int, input().split())))
    X0 = set(list(range(0, X)))
    XN = set(list(range(X, N + 1)))
    print(min(len(X0 & set(A)), len(XN & set(A))))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    n,m,x=INTM()
    A=LIST()
    money=[0]*(n+1)
    for i in A:
        money[i]=1
    sum0 = sum(money[0:x+1])
    sumn = sum(money[x:n])
    print(min(sum0,sumn))
if __name__ == '__main__':
    do()

Submission status: Accepted

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

Submission status: Accepted

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

z = 0
k = 0

for i in a:
	if i < x:
		z += 1
	else:
		k += 1

print(min(z,k))

Submission status: Accepted

Solution code:
N,M,X = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
L, R = [], []
for i in a:
    if i < X:
        L.append(i)
    elif X < i:
        R.append(i)

if len(L) > len(R):
    print(len(R))
else:
    print(len(L))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split())) # list()でリスト化、それを変数に代入。
cost = 0
for i in range(m):
    if(a[i]<x):
        cost = 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()))

cnt1 = 0
cnt2 = 0

for a in A:
    if a < X:
        cnt1 += 1
    else:
        cnt2 += 1
print(min(cnt1, cnt2))

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

a.sort()

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

cr = 0
for i in range(len(a)):
    if a[i] >= x:
        cr += 1
print(min(cl,cr))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
N,M,X=map(int,input().split())
L=list(map(int,input().split()))
num=bisect.bisect(L,X)
print(min(len(L[num:]),len(L[:num])))

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 a:
  c[i] = 1
  
print(min(sum(c[:x]), sum(c[x:])))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from itertools import product, permutations, combinations
from bisect import bisect_right,bisect_left
INF = float('inf')

N,M,X=map(int, input().split())
A=list(map(int, input().split()))
low = 0
high = 0
for a in A:
    if a < 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()))


d1 = len([i for i in a if i < x])
d2 = len([i for i in a if i > x])

print(min(d1, d2))

Submission status: Accepted

Solution code:

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

print (min(len(a[:r]),len(a[r:])))

Submission status: Accepted

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

cx = 0
cy = 0
xy = 0
for i in a:
	if i >= x:
		cy += 1
	else:
		cx += 1
print (min(cx,cy))

Submission status: Accepted

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

right_route = 0
for i in range(x, n+1):
    if i in al:
        right_route += 1

left_route = 0
for i in reversed(range(1, x+1)):
    if i in al:
        left_route += 1

print(min(right_route, left_route))

Submission status: Accepted

Solution code:
from bisect import bisect

n, m, x = map(int, input().split())
aaa = list(map(int, input().split()))
l = bisect(aaa, 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())
r = 0
l = 0
for i in a:
    if i < x:
        l+=1
    else:
        r+=1
print(min(l,r))

Submission status: Accepted

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

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

for aa in a:
    mas[aa-1]=1

l1=mas[0:x]
l2=mas[x:n]

print(min(sum(l1),sum(l2)))

Submission status: Accepted

Solution code:
f = lambda:map(int,input().split())
_,m,x = f()
l = list(f())
c = len([i for i in l if i<x])
print(min(c, m-c))

Submission status: Accepted

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

former = sum(x > i for i in a)
later = sum(x < i for i in a)

print(min(former, later))

Submission status: Accepted

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

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  x <A[i] < n:
             B += 1
         if  0 < A[i] < x:
             C +=1
print(min(B, 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:
        l += 1
    else:
        r += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in a:
    if(i >= x):
        cnt += 1
    else:
        cnt1 += 1

print(min(cnt, cnt1))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import bisect
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
cnt=0
for i in A:
    if i<=X:
        cnt+=1
    else:
        break

if (M/2)>=cnt:
    print(cnt)
else:
    print(M-cnt)

Submission status: Accepted

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

ans1 = 0
ans2 = 0
for a in A:
    if a < x:
        ans1 += 1
    else:
        ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

Solution code:
# coding: utf-8
N,M,X=map(int,input().split())
A=list(map(int,input().split()))

f=[0 for i in range(N+1)]

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
route = [0 for i in range(N+1)]
for i in range(M):
    route[A[i]] = 1
print(min(sum(route[:X]), sum(route[X:])))

Submission status: Accepted

Solution code:
a,b,c = map(int, input().split())
l = list(map(int, input().split()))
cost = [0] * (a+1)
for i in range(a):
  if i in l:
    cost[i] = 1

sum1 = sum(cost[0:c:])
sum2 = sum(cost[c::])
print(min(sum1,sum2))

Submission status: Accepted

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

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

print(min(r_cou,l_cou))

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

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, n):
    if i in a:
        ans1 += 1
for i in range(1, x):
    if i in a:
        ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

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

print(min(uppercost,lowercost))

Submission status: Accepted

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

a1 = 0
a2 = 0
for b in arr:
    if b <x:
        a1 += 1
    elif b > x:
        a2 +=1
print min(a1, a2)

Submission status: Accepted

Solution code:
import bisect

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

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 range(X):
    for j in range(M):
        if A[j] == i:
            a = a+1

print(min(a, M-a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
#!/usr/bin/env python3
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
less_x = 0
for i in range(m):
    if a[i] < x: less_x += 1
print(min(less_x,m - less_x))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
author : halo2halo
date : 24, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

N, M, *A = map(int, read().split())
X = A[0]
A.append(N)
A.sort()
num = A.index(X)

print(min(len(A[:num]), len(A[num+1:-1])))

Submission status: Accepted

Solution code:
n,m,x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a.sort()
if a.index(x) <= m//2:
    print(a.index(x))
else:
    print(m-a.index(x))

Submission status: Accepted

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

s1 = 0
s2 = 0
for a in arr:
    if a < x:
        s1 += 1
    elif a > x:
        s2 += 1

print min(s1, s2)

Submission status: Accepted

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

ans = 100000000000
now = 0
for i in range(0, x):
    now += v[i]
ans = min(ans, now)

now = 0
for i in range(x, n):
    now += v[i]
ans = min(ans, now)

print(ans)

Submission status: Accepted

Solution code:
#python3

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

Submission status: Accepted

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

to_0 = set(range(0, X))
to_N = set(range(X, N+1))

print(min(len(a & to_0), len(a & to_N)))

Submission status: Accepted

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

for i in input().split():
    k = int(i)
    a[k] = 1

left = right = 0
for i in range(n+1):
    if i < x:
        left += a[i]
    else:
        right += a[i]

ans = min(left, right)
print(ans)

Submission status: Accepted

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

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

cost1 = 0
cost2 = 0

for i in range(len(List)):
    if List[i] < x:
        cost1+=1
    else: cost2+=1

print(min(cost1,cost2))

Submission status: Accepted

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

to_0 = sum([1 for a in A if a < X])
to_N = sum([1 for a in A if a > X])
ans = min(to_0, to_N)

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n, m, x = map(int,input().split())
a = [int(i) for i in input().split()]

ans1 = 0
tmp1 = []
for i in range(x):
    tmp1.append(i)
for j in range(m):
    if a[j] in tmp1:
        ans1 += 1

ans2 = 0
tmp2 = []
for i in range(x, n + 1):
    tmp2.append(i)
for j in range(m):
    if a[j] in tmp2:
        ans2 += 1
print(min(ans1,ans2))

Submission status: Accepted

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

mass =[0]*n

for i in lst1:
    mass[i-1] = 1

x -= 1
print(min(sum(mass[:x]),sum(mass[x:])))

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:
import sys
input = sys.stdin.readline

def main():
	#N = int(input())
	#S = input().rstrip()
	N,M,X = map(int,input().split())
	vA = set(map(int,input().split()))
	#N = int(input())
	
	L1 = sum(i in vA for i in range(0,X))
	L2 = sum(i in vA for i in range(X,N))
	res = min(L1,L2)
	print(res)
	
main()

Submission status: Accepted

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

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

pList = []
s = aList.pop(0)
for i in range(n+1):
  if i == s:
    pList.append(1)
    if not(len(aList) == 0):
      s = aList.pop(0)
  else:
    pList.append(0)

resultS = 0
resultG = 0
for i in range(0,x+1):
  resultS += pList[i]
for i in range(x,n+1):
  resultG += pList[i]

if resultS<= resultG:
  print(resultS)
else:
  print(resultG)

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
C = sum(a < X for a in A)
print(min(C,len(A)-C))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = [int(a) for a in 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 = map(int,input().split())
A = list(map(int,input().split()))
cost = float("inf")
lis = [0]*(N+1)
for a in A:
    lis[a] += 1
print(min(sum(lis[X:]),sum(lis[:X])))

Submission status: Accepted

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

back=999
foward=999

for i in range(M):
    if A[i]==X:
        back=i
        foward=M-i+1
        break
    if A[i]>X:
        back=i
        foward=M-i
        break
    
print(min(back,foward))

Submission status: Accepted

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

Submission status: Accepted

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

tolls = [1 if i in As else 0 for i in range(N)]

print(min(sum(tolls[X-1:0:-1]), sum(tolls[X+1:])))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

if (c1 <= c2):
   print(c1)
else:
   print(c2)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(min(sum(to_left), M-sum(to_left)))

Submission status: Accepted

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

to_left =[1 for i in range(X-1, 0, -1) if i in A] 
to_right =[1 for i in range(X+1, N, 1) if i in A]
print(min(sum(to_left), sum(to_right)))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N,M,X = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
r = 0
l = 0
for i in range(M) :
    if X - A[i] > 0 :
        l+=1
    else :
        r+=1
print(min(r,l))

Submission status: Accepted

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

l = list(map(int,input().split()))
ll = [0 for _ in range(n+1)]

for i in l:
    ll[i] = 1

mae = ll[:x + 1]
ato = ll[x + 1:]

print(min(sum(mae),sum(ato)))

Submission status: Accepted

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

l = len([aa for aa in a if aa < x])

print(min(l, m - l))

Submission status: Accepted

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

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

cost_l = 0

for i in range(m):
    if a[i] <= x:
        cost_l += 1
    else:
        break
cost_r = m - cost_l
print(min(cost_l, cost_r))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n,m,x=map(int,input().split())
A=list(map(int,input().split()))
from bisect import bisect_left as bl
a=bl(A,x)
#print(a)
print(min(a,m-a))

Submission status: Accepted

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

l = list(range(n))[:x]
r = list(range(n))[x+1:]
lcost = 0
rcost = 0

for i in range(len(l)):
    if l[i] in a:
        lcost += 1

for i in range(len(r)):
    if r[i] in a:
        rcost += 1

print(min(lcost, rcost))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
cnt1 = 0
cnt2 = 0
i = X
j = X
while i <= N:
  if i in A:
    cnt1 += 1
  i += 1
while j >= 0:
  if j in A:
    cnt2 += 1
  j -= 1
print(min(cnt1, cnt2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
N, M, X = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]
import numpy as np
A = np.array(A)
right = np.count_nonzero(A > X)
left = np.count_nonzero(A < X)
print(min(left, right))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Thu Jan  2 17:08:37 2020

@author: student2
"""
potrn = 0
potrnn = 0
n,m,x = map(int,input().split())
v = [0 for i in range(n)]
for y in map(int,input().split()):
    v[y-1]=1
for z in range(x):
    if v[z] == 1:
        potrn +=1
for g in range(x,n):
    if v[g] == 1:
        potrnn +=1
print (min(potrn,potrnn))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split(" "))
li=list(input().split(" "))
for g in range(m):
    li[g]=int(li[g])
br=0
br2=0
k=x
pp=x
for i in range(pp):
    x-=1
    for z in range(m):
        if x==li[z]:
            br+=1
for i in range(n-pp):
    k+=1
    for z in range(m):
        if k==li[z]:
            br2+=1
print(min(br,br2))

Submission status: Accepted

Solution code:
from bisect import bisect_left
n, m, x = map(int, input().split())
A = list(map(int, input().split()))
idx = bisect_left(A, x)
print(min(len(A[:idx]), len(A[idx:])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

dis_l = 0
dis_r = 0

l = [0]*(n+1)
for i in range(m):
    l[a[i]] += 1

e = l[:x]
f = l[x+1:n+1]

if e.count(1) < f.count(1):
    print(e.count(1))
else:
    print(f.count(1))

Submission status: Accepted

Solution code:
"""
Created on Wed Jan  1 14:22:42 2020
"""

n, m, x = map(int, input().split())
has = [0] * (n + 1)
v = list(map(int, input().split()))
for i in range(m):
    has[v[i]] = 1
res1 = 0
res2 = 0
for i in range(n + 1):
    if has[i] == 1:
        if i <= x:
            res1 += 1
        else:
            res2 += 1
print(min(res1, res2))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = sorted(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))