Problem:


Score : 200 points

Problem Statement

There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right.

Initially, you are in Square X.
You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N.
However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1.
It is guaranteed that there is no toll gate in Square 0, Square X and Square N.

Find the minimum cost incurred before reaching the goal.

Constraints

1 \leq N \leq 100

1 \leq M \leq 100

1 \leq X \leq N - 1

1 \leq A_1 < A_2 < ... < A_M \leq N

A_i \neq X

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M X
A_1 A_2 ... A_M

Output

Print the minimum cost incurred before reaching the goal.

Sample Input 1

5 3 3
1 2 4

Sample Output 1

1

The optimal solution is as follows:

First, travel from Square 3 to Square 4. Here, there is a toll gate in Square 4, so the cost of 1 is incurred.

Then, travel from Square 4 to Square 5. This time, no cost is incurred.

Now, we are in Square 5 and we have reached the goal.

In this case, the total cost incurred is 1.

Sample Input 2

7 3 2
4 5 6

Sample Output 2

0

We may be able to reach the goal at no cost.

Sample Input 3

10 7 5
1 2 3 4 6 8 9

Sample Output 3

3



Sample input:
5 3 3
1 2 4


Sample output:
1

Submission status: Accepted

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

for b in a:
    c += 1
    if x < b:
        c -= 1
        if c < (m/2):
            print(c)
        else:
            print(m-c)
        break

Submission status: Accepted

Solution code:
s=list(map(lambda x:int(x), input().split()))
a=list(map(lambda x:int(x), input().split()))
cost=[len(list(filter(lambda x:x<s[2], a))),
      len(list(filter(lambda x:x>s[2], a)))]
print(min(cost))

Submission status: Accepted

Solution code:
n,m,x=[int(x) for x in input().split()]
arr=[int(x) for x in input().split()]
goLeft = 0
goRight = 0
for i in arr:
    if i < x:
        goLeft += 1
    else:
        goRight += 1
print(min(goLeft,goRight))

Submission status: Accepted

Solution code:
#abc094b

n,m,x=map(int,raw_input().split())
a=map(int,raw_input().split())
cnt0=0
cntn=0
for i in a:
 if i<x:
  cnt0+=1
 else:
  cntn+=1
print min(cnt0,cntn)

Submission status: Accepted

Solution code:
# coding=utf-8
n, m, x = map(int, input().split())
i = sum((1 for ai in map(int, input().split()) if ai < x))
print(min(i, m-i))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
 
a.append(x)
a = sorted(a)
 
index = a.index(x)
if index < len(a) - (index + 1):
    print(index)
else:
    print(len(a) - (index + 1))

Submission status: Accepted

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

# N,M,Xを取得
a, b, x = map(int, input().split())

cost_idxs = map(int, input().split())

count_low, count_high = [0, 0]

for i in cost_idxs:
    if i < x:
        count_low += 1
    elif i > x:
        count_high += 1

min_cost = min(count_low, count_high)

# 結果を出力
print("{}".format(min_cost))

Submission status: Accepted

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

a.append(x)
a = sorted(a)

index = a.index(x)
if index < len(a) - (index + 1):
    print(index)
else:
    print(len(a) - (index + 1))

Submission status: Accepted

Solution code:
l = list(int(i) for i in input().split())
A = list(int(i) for i in input().split())

left_cost = 0
right_cost = 0

for i in range(l[1]):
    if A[i] < l[2]:
        left_cost += 1
    else:
        right_cost += 1

if left_cost < right_cost:
    print("%d" % left_cost)
else:
    print("%d" % right_cost)

Submission status: Accepted

Solution code:
nmx = input().split()
n = int(nmx[0])
m = int(nmx[1])
x = int(nmx[2])

a = input().split()
numl = 0
numr = 0
a = [int(x) for x in a]

for i in range(m):
    if a[i] <= x:
        numl += 1
    else:
        numr += 1

if numl > numr:
    print("%d"%numr)
else:
    print("%d"%numl)

Submission status: Accepted

Solution code:
n, m, x = map(int,input().split())
A = list(map(int,input().split()))
right = len(list(filter( lambda num : num < x , A)))
left = len(A) - right
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()))
b = sum([a > x for a in A])
print(min(b, m-b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
if __name__ == "__main__":
    n, m, x = map(int, input().split())
    factors = [ tmp for tmp in range(n+1) ]
    gateFlag = [ False for tmp in range(n+1) ]
    a = list(map(int, input().split()))
    for tmp in range(m):
        gateFlag[a[tmp]] = True
    ansFactor = 0
    ansFactor2 = 0
    pivot = x
    while pivot-1 > 0:
        if gateFlag[pivot-1]:
            ansFactor += 1
        else:
            pass
        pivot -= 1
    else:
        pivot = x
    while pivot+1 < n:
        if gateFlag[pivot+1]:
            ansFactor2 += 1
        else:
            pass
        pivot += 1
    print(min(ansFactor, ansFactor2))

Submission status: Accepted

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

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


former = sum(j<X for j in A)
later = M-former

if former <= later:
    print(former)
else:
    print(later)

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
s=sum(int(a)<x for a 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()))

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

print(min(p,q))

Submission status: Accepted

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

left = 0
right = 0
for item in a:
    if item < x:
        left += 1
    else:
        right += 1

print(min(left, right))

Submission status: Accepted

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

a = list(map(int, input().split()))
for i in range(m):
    if a[i] < x:
        cost_a += 1
    else:
        cost_b += 1
print(min(cost_a, cost_b))

Submission status: Accepted

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

cost = []
costA=0
costB=0
l=0



for i in range(n+1):
    if i==A[l]:
        cost.append(1)
        if l < len(A)-1:
            l+=1
    else:
        cost.append(0)

for j in range(x):
    if cost[j]==1:
        costA+=1

for k in range(x,n):
    if cost[k]==1:
        costB+=1

#print("{0},{1}".format(costA,costB))

print(min(costA,costB))

#if costA>costB:
#    print(costB)
#else:
#    print(costA)

Submission status: Accepted

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

pre=post=0

for i in range(x):
    if i in mlist:
        pre += 1

for i in range(x,n+1):
    if i in mlist:
        post += 1

print(min(pre,post))

Submission status: Accepted

Solution code:
import sys

l=input().split()
N=int(l[0])
M=int(l[1])
X=int(l[2])

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


migi=0
hidari=0
for item in l:
	if(item>X):
		migi+=1
	else:
		hidari+=1

if(migi>hidari):
	print(hidari)
else:
	print(migi)

Submission status: Accepted

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

pre = 0
post = 0
for ai in a:
	if ai < X:
		pre += 1
	else:
		post += 1

res = min(pre, post)

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

l = []

for c in a:
    if c < x:
        l.append(c)

if len(l) < m-len(l):
    print(len(l))
else:
    print(m-len(l))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N, M,X = list(map(int,raw_input().split()))
li = list(map(int,raw_input().split()))
right = len(list(filter(lambda x:x<X,li)))
left = len(list(filter(lambda x:x>X,li)))
print min(right,left)

Submission status: Accepted

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

ans1=int(0)
ans2=int(0)

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

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

print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

cost0 = costn = 0

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

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

print(min(cost0, costn))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, M, X = map(int, input().split())
    A = map(int, input().split())
    cost_map = {}
    for i in A:
        cost_map[i] = 1
    cost_to_0 = [0 for i in range(N+1)]
    cost_to_N = [0 for i in range(N+1)]
    for i in range(1, N+1):
        if i in cost_map:
            cost_to_0[i] = cost_to_0[i-1] + 1
        else:
            cost_to_0[i] = cost_to_0[i-1]

    for i in range(0, N)[::-1]:
        if i in cost_map:
            cost_to_N[i] = cost_to_N[i+1] + 1
        else:
            cost_to_N[i] = cost_to_N[i+1]
    print(min(cost_to_0[X], cost_to_N[X]))

Submission status: Accepted

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

cost = 0

for i in range(m):
  if a[i] < x:
    cost += 1
  else:
    break

print(min(cost, m - cost))

Submission status: Accepted

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

n, m, x = map(int, input().split())
a = list(map(int, input().split()))
to_zero = len([v for v in a if v > 0 and v < x])
to_n = len([v for v in a if v > x and v < n])
print(min(to_zero, to_n))

Submission status: Accepted

Solution code:
A,B,C = map(int,input().split())

List_one = [0]*B
List_one = list(map(int,input().split()))

List_one.append(C)
#LIst_one = List_one + [C]
#print (List_one)

List_one.sort()# List_two=List_one.sort()としたらNoneを返してしまう。
#print(List_one)

x = List_one.index(C)

if x>=B-x:
    print(B-x)
else:
    print(x)

Submission status: Accepted

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

num = 0
for i in places:
    if i > X:
        break
    num += 1

print(min([num,N-num]) )

Submission status: Accepted

Solution code:
#coding: utf-8                                  
                                                
NMX = [int(i) for i in input().split()]         
N, M, X = NMX[0],  NMX[1],  NMX[2]              
fee_station = [int(i) for i in input().split()] 
                                                
increase = 0                                    
decrease = 0                                    
                                                
for i in range(M):                              
  if fee_station[i] > X:                        
    increase += 1                               
  else:                                         
    decrease += 1                               
                                                
print(min(increase, decrease))

Submission status: Accepted

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

Submission status: Accepted

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

#print(N,M,X)

#A = [int(input()) for i in range(N)]
#A = [input() for i in range(N)]

#A = []
#for i in range(M):
#    A.append(input()) # ３度の入力に対して、1, 2, 3 と入力。
#print(A) # ['1', '2', '3']


A = [int(i) for i in input().split()]


S = np.zeros((N + 1))
for i in range(M):
    S[A[i]] = 1

#print(S)

ans1 = 0
ans2 = 0

for i in range(0 , X + 1):
    if S[i] == 1:
        ans1+=1

for i in range(X , N + 1):
    if S[i] == 1:
        ans2+=1
#print(ans1,ans2)
print(min(ans1,ans2))

Submission status: Accepted

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

pay_list= [0,0]

for i in range(x,n+1):
    if i in fee_list:
        pay_list[0] += 1

for j in range(x):
    if j in fee_list:
        pay_list[1] += 1

if pay_list[0] < pay_list[1]:
    print(pay_list[0])
else:
    print(pay_list[1])

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,m,x = LI()
    t = LI()
    a = collections.defaultdict(int)
    for c in t:
        a[c] = 1
    r = inf
    tr = 0
    for i in range(x+1,n):
        tr += a[i]
    r = tr
    tr = 0
    for i in range(x-1,-1,-1):
        tr += a[i]
    if r > tr:
         r = tr

    return r


print(main())

Submission status: Accepted

Solution code:
N, M, X = [int(i) for i in input().split()]
mass = [0 for i in range(N + 1)]
for i in input().split():
    mass[int(i)] = 1

r = 0
for i in range(X, N + 1):
    r += mass[i]
l = 0
for i in range(X, 0, -1):
    l += mass[i]

if r >= l:
    print(l)
else:
    print(r)

Submission status: Accepted

Solution code:
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []    
    data = input()
    array_result.append(data.split(" "))

    flg = True

    try:
        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = True

            else:

                flg = False
    finally:

        return array_result

arr_data = getinputdata()

#ますの数
n = int(arr_data[0][0])

#料金所の数
m = int(arr_data[0][1])

#最初の位置
x = int(arr_data[0][2])

arr=list(map(int, arr_data[1]))

#print(n,m,x,arr)

kingaku1=0
kingaku2=0

for i in range(1,x):
    
    if i in arr:
        
        kingaku1+=1

for j in range(x+1,n+1):
    
    if j in arr:
        
        kingaku2+=1

    
print(kingaku1 if kingaku1<=kingaku2 else kingaku2)

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
l = list(map(int, input().split()))
left = 0
right = 0
for i in l:
  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())
P = list(map(int,input().split()))
a, b = 0, 0

for i in range(m):
    if P[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()]
left = 0
for i in range(M):
    if A[i] < X:
        left += 1
right = M - left
print(min(left, right))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N,M,X = list(map(int,input().split()))
    A = [0]
    A.extend(list(map(int,input().split())))
    for i in range(100):
        A.append(0)    
    Map = [0]
    for i in range(1,N+1):
        if i in A:
            Map.append(1)
        else:
            Map.append(0)
    right = sum(Map[X+1:])
    left = sum(Map[:X])
    #print(left,right)
    if right < left:
        print(right)
    else:
        print(left)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans = len(list(filter(lambda i : A[i] < X, range(M))))
ans = min(ans, len(A)-ans)
print(ans)

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = list(map(lambda ai:0 if (int(ai) < x) else 1,input().split()))
print(min(sum(a),m-sum(a)))

Submission status: Accepted

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

for a in map(int, input().split()) :
    if a < x :
        down += 1
    elif x < a and x < n :
        up += 1

print(min(down, up))

Submission status: Accepted

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

to_zero = 0
to_N = 0

for a in A:
    if a < X:
        to_zero += 1
    elif a > X:
        to_N += 1

print(min(to_zero, to_N))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=sorted([int(i) for i in input().split()])
#len(A)=M
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()))

B=0
C=0

D=[]

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

D.append(B)
        
        
for i in range(X):
    if i in A:
        C=C+1

D.append(C)

print(min(D))

Submission status: Accepted

Solution code:
Cost0 = 0
CostN = 0
length = 0

listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
X = listA[0][2]

for x in listA:
   length += len(x)

for i in range(length - 3):
    if (listA[1][i] < X):
        Cost0 = Cost0 +1
    else:
        CostN = CostN +1

if (Cost0 < CostN):
    print(Cost0)
else:
    print(CostN)

Submission status: Accepted

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

a = input().split()
A = input().split()

for i in range(0, len(a)):
    a[i] = int(a[i])

for i in range(0, len(A)):
    A[i] = int(A[i])

count = 0
for i in range(0, len(A)):
    if(A[i] < a[2]):
        count = count + 1


if(count > (len(A) -  count)):
        count = len(A) -  count

print("{0}".format(count))

Submission status: Accepted

Solution code:
from collections import deque

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

Q = deque([(X, 1, 0), (X, -1, 0)])
R = []
while Q:
    P = Q.popleft()
    N1 = P[0] + P[1]
    if N1 == 0 or N1 == N:
        R.append(P[2])
        continue
    C = P[2] + (1 if N1 in A else 0)
    Q.append((N1, P[1], C))

print(min(R))

Submission status: Accepted

Solution code:
n, m, x = list(map(int, input().split()))
alist = list(map(int, input().split()))
leftcost = len(list(filter(lambda num: num < x, alist)))
rightcost = len(list(filter(lambda num: num > x, alist)))
print(leftcost if leftcost <= rightcost else rightcost)

Submission status: Accepted

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

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

flg = 0
costA = 0
costB = 0

for i in range(N+2):
    if i == X:
        flg = 1
    elif i in A:
        if flg == 0:
            costA += 1
        else:
            costB += 1
            

if costA > costB:
    print(costB)
else:
    print(costA)

Submission status: Accepted

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

small = 0
big = 0
for j in A:
    if j < X:
        continue
    else:
        small=small+1

for j in A:
    if j > X:
        continue
    else:
        big=big+1



if big>=small:
    print(small)
else:
    print(big)

Submission status: Accepted

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


counter = 0
for i in range(M):
	if X < M_list[i]:
		break
	counter += 1

if counter <= M - counter:
	print(counter)
else:
	print(M-counter)

Submission status: Accepted

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

sm = l[2]
la = l[2]
while(True):
    if sm == 0:
        print 0
    if la == l[0]:
        print 0
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2 + 0.5
        break
    if sm in A:
        ix = A.index(sm) + 0.5
	break
    if la in A:
	ix = A.index(la) - 0.5
	break
M = l[1] - ix - 1
if M > ix:
    print int(math.ceil(ix))
else:
    print int(math.ceil(M))

Submission status: Accepted

Solution code:
import numpy as np
import sys
N,M,X = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
temp = []
ans1 = 0
ans2 = 0
for i in range(N+1):
    if (i == 0) or (i==N):
        temp.append(0)
    elif i in A:
        temp.append(1)
    # elif (i == 0) or (i==N):
    #     temp.append(0)
    else:
        temp.append(0)
for i in range(X,N+1):
    ans1 += temp[i]

for i in range(X):
    ans2 += temp[i]

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*
n,m,x = map(int, raw_input().split())
list =[]
list = map(int, raw_input().split())
r_sum = 0
h_sum =0
for i in range(m):
 if list[i] < x:
  r_sum += 1
 if list[i] > x:
  h_sum += 1

if h_sum > r_sum:
 print(r_sum)
else:
 print(h_sum)

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
n = [int(x) for x in input().split()]
num1 = 0
for i in n:
    if i < X:
        num1 += 1
num2 = M - num1
smaller = lambda y, z: z if z < y else y
smaller_num = smaller(num1, num2)
print(smaller_num)

Submission status: Accepted

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

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

l = 0
r = 0

for a in aes:
    if a <= (x-1):
        l+=1
    elif x < a:
        r+=1

print(min([l, r]))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A_list = [int(x) for x in input().split()]
minus_counter = 0
plus_counter = 0
for i in range(len(A_list)):
    if A_list[i] > X:
        break
    minus_counter += 1
for i in range(minus_counter, len(A_list)):
    plus_counter += 1
print(min(minus_counter, plus_counter))

Submission status: Accepted

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

small,big=0,0
for i in range(X):
    if i in A:
        small+=1
for i in range(X+1,N+1):
    if i in A:
        big+=1
print(min(small,big))

Submission status: Accepted

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

for i in range(x):
    if i in a:
        cntF +=1
for i in range(x+1, n+1):
    if i in a:
        cntL +=1
print(min(cntF, cntL))

Submission status: Accepted

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

# 入力を各変数に格納(N,M,X)
cell_size, toll_size, start_cell = map(int, input().split())
# 数字が文字列リストなので数値リストに変換
toll_list = [int(i) for i in input().split()]

# 0からX
zero_to_start = 0
for i in range(0, start_cell):
	
	if i in toll_list:
		zero_to_start += 1

# XからN
start_to_end = 0
for i in range(start_cell, cell_size):

	if i in toll_list:
		start_to_end += 1

# 小さい方を出力
if zero_to_start <= start_to_end:
	print(zero_to_start)
else:
	print(start_to_end)

Submission status: Accepted

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

Submission status: Accepted

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

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

counta=0;
countb=0;

for i in a:
    if (n<i and i<x) or (x<i and i<n):
        counta+=1

for i in a:
    if (0<i and i<x):
        countb+=1


if (counta<countb):
    ans = counta
else:
    ans = countb

print(ans)

Submission status: Accepted

Solution code:

n, m, x = map(int, input().split())
a = list(map(int, input().split()))
a1 = [aa for aa in a if aa > x]
a2 = [aa for aa in a if aa < x]
if len(a1) > len(a2):
    print(len(a2))
else:
    print(len(a1))

Submission status: Accepted

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

Submission status: Accepted

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

if __name__ == '__main__':
    N,M,X = map(int,input().split())
    C = [0] * N
    A = list(int(i) for i in input().split())
 
    for i in range(N):
        if i in A:
            C[i] = 1

    cost = min(sum(C[X:N]),sum(C[0:X]))
    
    print(cost)

Submission status: Accepted

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

C = [0 for i in range(N)]
for j in range(len(A)):
    C[A[j]-1] = 1
C_left = C[:X-1]
C_right = C[X:]
result = min(sum(C_left),sum(C_right))
print(result)

Submission status: Accepted

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

cfee = 0 # left
for a in A:
  if a < X:
    cfee += 1
print (min(cfee, M-cfee))

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()
position = a.index(x)+1

if position == 0 or position == m+1:
	print(0)
else:
	if (m+1)-position <= (m+1)/2:
		print(m+1-position)
	else:
		print(position-1)

Submission status: Accepted

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

arr = [ 0 for i in range(N) ]
for p in A:
    arr[p] = 1

x2r = sum(arr[X:N])
x2l = sum(arr[0:X])

print(min([x2r, x2l]))

Submission status: Accepted

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

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

print(min(ansn,ans0))

Submission status: Accepted

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

now = x

res1 = 0
for i in range(n - x - 1):
    now += 1
    if a.count(now):
        res1 += 1

now = x
res2 = 0
for i in range(x):
    now -= 1
    if a.count(now):
        res2 += 1

if res1 < res2:
    print(res1)
else:
    print(res2)

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split(" "))
nums = list(map(int, input().split(" ")))
lefts = [t for t in nums if t < x]
rights = [t for t in nums if t > x]

if len(lefts) > len(rights):
	print(len(rights))
else:
	print(len(lefts))

Submission status: Accepted

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

a=list(map(int,input().split()))
lc=0
rc=0
for i in a:
    lc+=(1 if i<x else 0)
    rc+=(1 if i>x else 0)
print(min(lc,rc))

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

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

A = 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:
x,y,z=[int(i) for i in input().split()]
tag_list=input().split()

tag_set=set(tag_list)

obj_list=[]
for i in range(0,x+1):
    obj_list.append(str(i))

result=[]

obj_set=set(obj_list[z+1:])
a=list(obj_set & tag_set)
result.append(len(a))

obj_set=set(obj_list[:z+1])
a=list(obj_set & tag_set)

result.append(len(a))

print(min(result))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
c = 0
list1=input().split()
N = int(list1[0])
M = int(list1[1])
X = int(list1[2]) 
list2 = list(map(int, input().split()))
for i in range(M):
    if list2[i] < X:
        c+=1
if c<=M-c:
    print(c)
else:
    print(M-c)

Submission status: Accepted

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

a=0
b=0
for i in range(N+1):
    if i in Ms:
        if i > X :
            a+=1 
        elif X > i :
            b+=1

print(min(a,b))

Submission status: Accepted

Solution code:
def main():
    N, M, X = (int(i) for i in input().split())
    a = [int(i) for i in input().split()]
    route = [None for i in range(N+1)]
    route = []
    for i in range(N+1):
        if (i == 0) or (i == N) or (i == X):
            ret = False
        elif i in a:
            ret = True
        else:
            ret = None
        route.append(ret)
    min_0 = route[:X].count(True)
    min_N = route[X:].count(True)
    print(min(min_0, min_N))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
l = input().split()
N = int(l[0])
M = int(l[1])
X = int(l[2])
cost1 = 0
cost2 = 0
j = 0
k = input().split()
for e in k:
    if int(e) >= X:
        j = k.index(e)
        break
    cost1 = cost1 + 1

for i in range(j, M):
    cost2 = cost2 + 1
if cost1 > cost2:
    print(cost2)
else:
    print(cost1)

Submission status: Accepted

Solution code:
n,m,x =map(int, input().split())
Ain = list(map(int,input().split()))
A=[0 for i in range(n+1)]
for i in Ain:
    A[i] = 1
ans1=0
ans2=0
for i in range(x):
    ans1 += A[i]

for i in range(x,n):
    ans2 += A[i]

print(min(ans1, ans2))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
list = list(map(int, input().split()))
A = sum(n > X for n in list)
B = sum(n < X for n in list)
if A >= B:
  print(B)
else:
  print(A)

Submission status: Accepted

Solution code:
def m():
    N, M, X = map(int, input().split())
    A = [int(i) for i in input().split()]
    B = [0 for _ in range(N)]
    for a in A:
        B[a] = 1
    cost = min(sum(B[X:]), sum(B[:X]))
    return cost


print(m())

Submission status: Accepted

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

main()

Submission status: Accepted

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

list_A = [int(A) for A in input().split(' ')]

left, right = 0, 0

if X > list_A[len(list_A) - 1]:
    print(0)
    exit()

if X < list_A[0]:
    print(0)
    exit()

for A in list_A:
    if X > A:
        left += 1
        continue
    right += 1

print(min(left, right))