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, k = (map(int, input().split()))
a = list(map(int, input().split()))
f = lambda x:1 if x<k else 0
f2 = lambda x:1 if x>k else 0
y = list(map(f, a))
z = list(map(f2, a))
print(min(sum(y), sum(z)))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
a=[int(i) for i in input().split()]
l,r=[],[]
for i in a:
  if i<X:
    l.append(i)
  else:
    r.append(i)
print(min(len(l),len(r)))

Submission status: Accepted

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

Submission status: Accepted

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

to0 = list(range(n+1))[:x]
cost1 = len(set(to0) & set(a))

ton = list(range(n+1))[x:]
cost2 = len(set(ton) & set(a))

ans = min(cost1, cost2)
print(ans)

Submission status: Accepted

Solution code:
def get(S):
    return list(map(S, input().split()))

N, M, X = get(int)
A = get(int)

cost = [0 for _ in range(0, N + 2)]

for i in A:
    cost[i] = 1

L = sum(cost[0 : X + 1])
R = sum(cost[X : N + 1])
print(min(L, R))

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())
a = [int(i) for i in input().split()]

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

print(ans)

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

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]*(n+1)
for i in a:
    l[i-1]=1
print(min(sum(l[0:x-1]),sum(l[x-1:n])))

Submission status: Accepted

Solution code:
li = list(map(int,input().split()))
A=list(map(int,input().split()))
a=0
b=0
for i in range(len(A)):
    if A[i]<li[2]:
        a+=1
    else:
        b+=1
print(min(a,b))

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left as bi_l

n, m, x, *a = map(int, sys.stdin.read().split())

def main():
    left = bi_l(a, x)
    right = m - left
    return min(left, right)

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

Submission status: Accepted

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

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()))
cost=0
for i in range(m):
    if x<a[i]:
        break
    else:
        cost+=1
if cost<(m-cost):
    print(cost)
else:
    print(m-cost)

Submission status: Accepted

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

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

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

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

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

Submission status: Accepted

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

cost = 0
for i in range(N - X):
  if X + i + 1 in A:
    cost += 1

COST = 0
for i in range(X):
  if X - i - 1 in A:
    COST += 1

print(min(cost, COST))

Submission status: Accepted

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

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

costa=0
costb=0
for i in a:
    if i<x:
        costa+=1
    elif i>x:
        costb+=1

print(min(costa,costb))

"""


5 3 3
1 2 4

1


7 3 2
4 5 6

0

10 7 5
1 2 3 4 6 8 9

3
"""

Submission status: Accepted

Solution code:
a,b,c = (map(int, input().split())) 
n = list(map(int, input().split())) 
chargeA=0
chargeB=0

for i in range(b):
  if c<n[i]<a:
    chargeA+=1
  else:
    chargeB+=1
print(min(chargeA,chargeB))

Submission status: Accepted

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

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

import bisect

l = bisect.bisect_left(A, x)
ans = min(l, m-l)
print(ans)

Submission status: Accepted

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

import bisect

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
# xより小さい料金所と大きい料金所の数をかぞえたら終了
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:
import sys
n,m,x = map(int, sys.stdin.readline().split())
a = list(map(int, sys.stdin.readline().split()))

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

print(min(count, m-count))

Submission status: Accepted

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

print(min(len([i for i in range(1, X) if i in A]), len([i for i in range(X + 1, N) if i in A])))

Submission status: Accepted

Solution code:

cnt_min=0
cnt_max=0
ans=0
n,m,x=map(int,input().split())
lst=list(map(int,input().split()))

for i in lst:
    if i < x:
        cnt_min+=1
    else:
        cnt_max+=1
print(cnt_max if cnt_min>cnt_max else cnt_min)

Submission status: Accepted

Solution code:
NMX = list(map(int, input().split()))
A = list(map(int, input().split()))
masu = {}
for i in range(NMX[0]+1):
	if(i in A):
		masu[i] = 1
	else:
		masu[i] = 0
right=0
for i in reversed(range(0,NMX[2]+1)):
	right+=masu[i]
left=0
for i in reversed(range(NMX[2]+1,NMX[0]+1)):
	left+=masu[i]
if(right>left):
	print(left)
else:
	print(right)

Submission status: Accepted

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

left = 0
right = 0

for a in A:
    if a < x:
        left += 1
    elif x < a:
        right += 1

print(min(right, left))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
count = 0
B = []
if N == X:
  print(0)
else:
  for x in range(X,N+1):
    if x in A:
      count += 1
  B.append(count)
  count = 0
  for x in range(X,0,-1):
    if x in A:
      count += 1
  B.append(count)
  print(min(B))

Submission status: Accepted

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

left = 0
right = 0
for i in input_list:
    if i < x: left += 1
    elif i > 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()))

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

ans2 = 0
for i in reversed(range(X)):
  if i in A:
    ans2 += 1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
"""B - Toll Gates
https://atcoder.jp/contests/abc094/tasks/abc094_b
N M X
A_1 A_2 ... A_M

>>> main(5, 3, 3, [1, 2, 4])
1
>>> main(7, 3, 2, [4, 5, 6])
0
>>> main(10, 7, 5, [1, 2, 3, 4, 6, 8, 9])
3
"""


def main(n, m, x, a):
    line = [0 for _ in range(n)]

    for a in a:
        line[a - 1] = 1

    to_left = sum(line[x - 1:])
    to_right = sum(line[x - 1::-1])

    print(min(to_left, to_right))


if __name__ == '__main__':
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))

    main(n, m, x, a)

Submission status: Accepted

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

c=0
for i in range(x):
  if i==a[c]:
    c+=1
print(c if 2*c<m else m-c)

Submission status: Accepted

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

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,*a=map(int,open(0).read().split())
map=[0]*(n+1)
for i in a: map[i]=1
print(min(sum(map[0:x]),sum(map[x:n])))

Submission status: Accepted

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

cost1 = 0
for i in range(x, n+1):
    if i in a:
        cost1 += 1
    
cost2 = 0
for i in range(x):
    i = x-i
    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()))
C = [0 for _ in range(N)]
for a in A:
    C[a] = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=[int(i) for i in input().split()]
a=0
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:
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
# xより小さい料金所と大きい料金所の数をかぞえたら終了
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())
l=list(map(int,input().split()))
a=[]
b=[]
for i in range(m):
    if l[i]<x:
        a.append(l[i])
    else :
        b.append(l[i])
print(min(len(a),len(b)))

Submission status: Accepted

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

Submission status: Accepted

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

a2 = sum([1 for i in lst if i > x])
a1 = m - a2
print(min(a1, a2))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
for i,x in enumerate(A):
  if x > X:
    t = i
    break

print(min(t,M-t))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
ls_0=[e for e in ls if e<X]
ls_N=[e for e in ls if e>X]
print(min([len(ls_0),len(ls_N)]))

Submission status: Accepted

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

count0 = 0
countn = 0
for i in range(x):
    if i in a:
        count0 += 1
for i in range(x,n):
    if i in a:
        countn += 1
ans = min(count0,countn)
print(ans)

Submission status: Accepted

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

cst_0 = 0
cst_m = 0

for i in range(m):
    if ls_a[i] < x:
        cst_0 += 1
    elif ls_a[i] > x:
        cst_m += 1

print(min(cst_0, cst_m))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#094b
N,M,X = map(int, input().split())
A_list = [int(e) for e in input().split()]

#あなたは，最初マス X にいます． 
#隣り合うマスの間は自由に移動することができ，マス 0 またはマス N にたどり着くとゴールすることができます． 
#ただし，i=1,2,...,M について，マス Ai には料金所があり，そのためマス Ai に移動してくる際には 1 のコストがかかります．
#なお，マス 0，マス X，マス N には料金所がないことが保証されます．

#ゴールするまでにかかるコストの最小値を求めてください．

#X < N - 1

cost_to_0 = 0
cost_to_M = 0

for i in range(M):
    if A_list[i] < X:
        cost_to_0 += 1
    else:
        cost_to_M += 1
          
print(min(cost_to_M,cost_to_0))

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

l = [0]*n

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

f = sum(l[0:x])
g = sum(l[x:n])

print( f if f<g else g)

Submission status: Accepted

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

count_l = 0
count_r = 0

for a in A:
    if a > x:
        count_r += 1
    else:
        count_l += 1

ans = min(count_l, count_r)
print(ans)

Submission status: Accepted

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

left = sum(x<X for x in A)
right = sum(x>X for x in A)
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[i] > X:
        break
print(min(i , M - i))

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(a.index(X),len(a)-a.index(X)-1))

Submission status: Accepted

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

for i in range(0,X):
  if str(i) in A:
    count_bef += 1
for j in range(X,N+1):
  if str(j) in A:
    count_aft += 1
if count_bef<=count_aft:
  print(count_bef)
else:
  print(count_aft)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

print(min(len(A[A<X]),len(A[A>X])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
numbers = list(map(int,input().split()))
y = x
z = x
x0 = 0
xn = 0
for i in range (0,x):
  y -= 1
  if y in numbers:
    x0 += 1
  else:
    continue
for j in range(x,n):
  z += 1
  if z in numbers:
    xn += 1
  else:
    continue
print(min(x0,xn))
#print(n,m,x)

Submission status: Accepted

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

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



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

    

print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys, math, itertools, heapq, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
sys.setrecursionlimit(10**8)
inf = float('inf')
ans = count = 0

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

Submission status: Accepted

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

a = bisect.bisect_left(lst, X)
print(min(M-a, a))

Submission status: Accepted

Solution code:
def examB():
    N, M, X = LI()
    A = LI()
    L0 = bisect.bisect_left(A,X)
    L1 = M-L0
    ans = min(L0,L1)
    print(ans)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examB()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M, X = MAP()
A = LIST()
idx = bisect(A, X)
print(min(idx, M-idx))

Submission status: Accepted

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

a = [1 for i in al if i > x]
b = [1 for i in al if i < x]

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()]
tall = [0] * (N+1)
for a in A:
    tall[a] = 1
print(min(sum(tall[:X]),sum(tall[X+1:])))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
gatedict = {i : 0 for i in range(n + 1)}
for i in range(m) :
    gatedict[a[i]] = 1
before = 0
for p in range(x) :
    before += gatedict[p]
after = 0
for q in range(x+1,n+1) :
    after += gatedict[q]
print(min(before, after))

Submission status: Accepted

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

Submission status: Accepted

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

right_cost = 0
pos = X
for i in range(N-X):
    pos += 1
    if pos in A:
        right_cost += 1
        
left_cost = 0
pos = X
for i in range(X):
    pos -= 1
    if pos in A:
        left_cost += 1

print(min(right_cost, left_cost))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np
n,m,x= [int(x) for x in stdin.readline().rstrip().split()]
li = list(map(int,stdin.readline().rstrip().split()))

lin= [0]*(n+1)

for i in li:
    lin[i] = 1
print(min(sum(lin[:x]),sum(lin[x+1:])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
list_a = list(map(int, input().split()))
count = sum([1 for one_a in list_a if one_a < x])
print(min(count, len(list_a)-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(min(len([ai for ai in a if ai < x]), len([ai for ai in a if ai > x])))

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:
# ABC 094: B – Toll Gates
n, m, x = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]

squares = [0] * (n + 1)

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

print(min(squares[:x].count(1), squares[x + 1:].count(1)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

n, m, x = map(int, input().split())
A = list(map(int, input().split()))
r = bisect.bisect_right(A, x)
if 2*r <= m:
  print(r)
else:
  print(m-r)

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 in range(0,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())
l = list(map(int, input().split()))
l_big = [i for i in l if i > x]
l_small = [i for i in l if i < x]
print(min(len(l_big), len(l_small)))

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

G0, GN = 0, 0

for i in range(X):
  if i in l:
    G0 += 1

for i in range(X, N):
  if i in l:
    GN += 1
    
print(min(G0, GN))

Submission status: Accepted

Solution code:
#6
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
ans1=0
for i in range(x):
    if i in a:
        ans+=1
    
for j in range(x+1,n+2):
    if j in a:
        ans1+=1
        
print(min(ans,ans1))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
import numpy as np
a = np.array(list(map(int,input().split())))
print(min(np.sum((0<a) & (a<x)),np.sum((x<a) & (a<n))))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()

def main():
    n,m,x=map(int,input().split())
    aa=list(map(int,input().split()))
    print(min([sum(1 for a in aa if a < x),sum(1 for a in aa if a > x)]))

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n,m,x = inpl()
a = inpl()
for i in range(m):
    if a[i] >= x:
        break
print(min(i,m-i))

Submission status: Accepted

Solution code:
#                         author:  kagemeka 
#                         created: 2019-11-07 11:52:43(JST)
import sys
# import collections
# import math
# import string
import bisect
# import re
# import itertools
# import statistics
# import functools
# import operator

def main():
    n, m, x, *a = (int(i) for i in sys.stdin.read().split())
    th_x  = bisect.bisect_left(a, x)
    cost = min(th_x, m - th_x)
    print(cost)
    


if __name__ == "__main__":
    # execute only if run as a script
    main()

Submission status: Accepted

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

zero_g = 0
n_g = 0

for i in range(len(A)):
    if A[i] < x:
        zero_g += 1
    else:
        n_g += 1
print(min(n_g, zero_g))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = [0] * N
for i in [int(a) for a in input().split()]:
    A[i] += 1
B = [0] * (N+1)
C = [0] * (N+1)
for i in range(N):
    B[i+1] = B[i] + A[i]
for i in range(N)[::-1]:
    C[i] = C[i+1] + A[i]

print(M - max(B[X+1], C[X]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect
import sys
input = sys.stdin.readline


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

    x = bisect.bisect_left(A, X)
    ans = min(len(A[:x]), len(A[x:]))

    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect

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

index = bisect.bisect(a, x)
print(min(len(a[:index]), len(a[index:])))

Submission status: Accepted

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

import numpy as np
A=np.array(A)
print(min(np.count_nonzero(A > X),np.count_nonzero(A < X)))

Submission status: Accepted

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

A = [int(i) for i in input().split()]
couA = 0
couB  =0
for i in range(x,n):
    if A.count(i):
        couA +=1
for j in range(x,0,-1):
    if A.count(j):
        couB +=1
print(min(couA,couB))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
a=0
b=0
for m in range(M):
    if A[m]<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()))

right = 0
left = 0
for a in A:
  if a < X:
    left += 1
  else:
    right = len(A) - left
    break

print(min(left, right))

Submission status: Accepted

Solution code:
import bisect

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

l2 = bisect.bisect(l,x)

print(min(len(l)-l2,l2))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
tmp1 = list(range(X))
tmp2 = list(range(X+1,N))
ans = []
count = 0
for i in range(len(tmp1)):
    if tmp1[i] in A:
        count += 1
ans.append(count)
count = 0
for j in range(len(tmp2)):
    if tmp2[j] in A:
        count += 1
ans.append(count)
print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect as bi

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

i=bi.bisect_left(A,X)

print(min(i,M-i))