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(' '))
fee_points = [x for x in map(int, input().split(' '))]
root = []
for i in range(0, n):
    if i in fee_points:
        root.append(1)
    else:
        root.append(0)

if sum(root[:x]) >= sum(root[x:]):
    print(sum(root[x:]))
else:
    print(sum(root[:x]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
'''
X:スタート地点
0, N:ゴール地点
m は料金所の個数。aを料金所とする
## 入力１
5 3 3
1 2 4
↓
0 1 2 3 4 5
  a a   a
0     X   N

## 考え方
Xより左にあるaの数と、右にあるaの数を比較して小さい方の数を出力

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

# print(A)

# マスを初期化
cells = [0]*(n+1)
# マスにaを代入
for a in A:
    cells[a] = 1

# xからみて左右のa数をカウント
l_count = sum(cells[:x])
r_count = sum(cells[x+1:])
# print(l_count, r_count) # debug
# a数が小さい方を出力
print(min(l_count, r_count))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
d = list(map(int, input().split()))
e = 0
f = 0
for i in d:
    if i < c:
        e += 1
    elif i > c:
        f += 1
print(min(e, f))

Submission status: Accepted

Solution code:
Tmp = []
Tmp = input().rstrip().split(' ')

nN = int(Tmp[0])
nM = int(Tmp[1])
nX = int(Tmp[2])

nAns1 = 0
nAns2 = 0
Tmp = input().rstrip().split(' ')
for i in range(nM):
  nTmp = int(Tmp[i])
  if nTmp < nX:
    nAns1 += 1
  else:
    nAns2 += 1

if nAns1 < nAns2:
  print(nAns1)
else:
  print(nAns2)

Submission status: Accepted

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

left, right = 0, 0
for i in range(M):
    if A[i] < X:
        left += 1
    if A[i] > X:
        right += 1

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

Submission status: Accepted

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


N, M, X = map(int, input().split(' '))
AM = list(map(int, input().split(' ')))
cost = len(list(filter(lambda x: x < X, AM)))
print(min(cost, len(AM) - cost))

Submission status: Accepted

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

print(sumL) if sumL < sumR else print(sumR)

Submission status: Accepted

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

left_cost = 0
for toleft in range(x-1, 0, -1):
    if toleft in a:
        left_cost += 1

right_cost = 0
for toright in range(x, n+1):
    if toright in a:
        right_cost += 1

print(min(left_cost, right_cost))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = [int(x) for x in input().split()]
left = sum(1 if x < X else 0 for x in A)
right = M-left
answer = min(left,right)
print(answer)

Submission status: Accepted

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

modori_cost,iki_cost = 0,0 

for i in A:
  if i<X:
    modori_cost +=1
  else:
    iki_cost +=1
    

print(min(modori_cost,iki_cost))

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(m):
	if a[i]>=x:
		r+=1
	else:
		l+=1
print(min(r,l))

Submission status: Accepted

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

array = [int(i) for i in input().split()]
cnta = 0
cntb = 0

for i in range(m):
  if array[i] < x:
    cnta +=1
  else:
    cntb +=1
    
print(min([cnta,cntb]))

Submission status: Accepted

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

Submission status: Accepted

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

cost_right=0
cost_left=0

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

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

print(min(cost_right,cost_left))

Submission status: Accepted

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

li = [1 if i in li else 0 for i in range(1, n+1)]

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

Submission status: Accepted

Solution code:
# ABC 94, B - toll gates
n, m, x = map(int, input().split(' '))
A = [int(el) for el in input().split(' ')]

B = [1 if i in A else 0 for i in range(n)]
print(min(sum(B[:x+1]), sum(B[x:])))

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 i in A:
    if i <= X:
        count_l += 1
    elif i >= X:
        count_r += 1
print(min(count_l, count_r))

Submission status: Accepted

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

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 0 < a[i] < x:
        b += 1
    elif x < a[i] < n:
        c += 1
print(min(b,c))

Submission status: Accepted

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

Submission status: Accepted

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


ans = []

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

ans.append(tmp)

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

ans.append(tmp)

print(min(ans))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = [int(s) for s in input().split()]
l = [v < X for v in A].count(True)
print(min(l, M - l))

Submission status: Accepted

Solution code:
import math

#x = int(input())
#a = int(input())
n,m,x = list(map(int,input().split(" ")))
#ls = list(input().split(" "))
ls = list(map(int,input().split(" ")))
#a,b,c = list(input().split())
#string = input()
#ls = [int(input()) for i in range(n)]

left = [i for i in ls if i < x]
right = [i for i in ls if i > x]
print(min([len(left),len(right)]))

Submission status: Accepted

Solution code:

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

a = len(list(filter(lambda s: s > x, xs)))
b = len(list(filter(lambda s: s < x, xs)))

print(min(a, b))

Submission status: Accepted

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

Submission status: Accepted

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

goal1 = 0
goal2 = 0

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

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

print(min(goal1, goal2))

Submission status: Accepted

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

lCnt = 0
rCnt = 0
for i in sList:
    if X < i:
        lCnt += 1
    elif X > i:
        rCnt += 1

ans = min(lCnt, rCnt)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from copy import *
from sys import *
from math import *
import queue
from collections import defaultdict,Counter,deque

setrecursionlimit(1000000)

#location: w,hで記載
def main():
	n,m,x = map(int,input().split())
	a = list(map(int,input().split()))
	ans = 0
	sna = 0
	for i in a:
		if(i<x):
			ans+=1
		if(i>x):
			sna+=1
	print(min(ans,sna))

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(m,n):
	x = max(m,n)
	y = min(m,n)
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	return y

class Queue():
	#競プロ用のQueue
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)

class Stack():
	#怯プロ用のStack
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)

main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
li = list(map(int, input().split()))
count_b = 0
count_s = 0

for i in li:
    if x<=i: count_b += 1 
    else: count_s += 1

if count_b < count_s: last_count = count_b
else: last_count = count_s 

print(last_count)

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
tolls = list(map(int, input().split()))
gate_l = 0
for toll in tolls:
  if toll > X:
    break
  gate_l += 1
print(min(gate_l, M-gate_l))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007

#A
def A():
    a, b, x = LI()
    if a <= x <= a + b:
        print("YES")
    else:
        print("NO")
    return

#B
def B():
    n, m, x = LI()
    a = LI()
    print(min(bisect.bisect_left(a, x), m - bisect.bisect_right(a, x)))
    return

#C
def C():
    n = II()
    x = LI()
    xb = x[::1]
    xb.sort()
    a = xb[n // 2 - 1]
    b = xb[n // 2]
    for i in range(n):
        if x[i] <= a:
            print(b)
        elif x[i] >= b:
            print(a)
        
    return

#D
def D():
    return


#Solve
if __name__ == '__main__':
    B()

Submission status: Accepted

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

Submission status: Accepted

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

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

c1 = c2 = 0

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = tuple(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())
l=sorted(list(map(int,input().split()))+[x])
a=l.index(x)
print(min(len(l[:a]),len(l[a+1:])))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
l=list(map(int,input().split()))
j=0;k=0
for i in l:
    if i < x:
        j+=1
    else:k+=1
print(min(j,k))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
a = {int(i) for i in input().split()}
l = set(range(0, X+1))
r = set(range(X, N+1))
print(min([len(a.intersection(l)) , len(a.intersection(r))]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

left = 0
for i in range(1, x):
    if i in As:
        left += 1

right = 0
for i in range(x+1, n):
    if i in As:
        right += 1

if left < right:
    print(left)
else:
    print(right)

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
d = list(map(int, input().split()))
e = 0
f = 0
for i in range(b):
    if d[i] > c:
        e += 1
    else:
        f += 1
print(min(e, f))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
B = [False]*(N+1)
for a in A: B[a] = True
print(min(B[:X].count(True),B[X:].count(True)))

Submission status: Accepted

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

Submission status: Accepted

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

ans = []
xx = X
num = 0
for i in range(1, 101):
    X += 1
    if A.count(X) == 1:
        num += 1

ans.append(num)
num = 0
for i in range(1, 101):
    xx -= 1
    if A.count(xx) == 1:
        num += 1

ans.append(num)
ans.sort()
print(ans[0])

Submission status: Accepted

Solution code:
import math
n,m,x = map(int,input().split(' '))
a = list(map(int,input().split(' ')))
pos = 0
ans1 = 0
ans2 = 0
for i in range(0,m):
    if a[i] > x:
        pos = i
        break
for i in range (0,pos):
    ans1+=1
for i in range (pos,m):
    ans2+=1

print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

l=[]

for i in range(n):
    if i in a:
        l.append(1)
    else:
        l.append(0)
l.append(0)
        
ans=min(sum(l[:x+1]),sum(l[x:]))
print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import numpy as np
import statistics
from statistics import mean, median,variance,stdev
import math

def main():
	N, M, X = map(int, input().split(" "))
	A = input().split(" ")
	A = [int(s) for s in A]
	
	p = bisect_left(A,X)
	
	aa = len(A)-p
	bb = p
	
	print(min(aa,bb))
	
if __name__ == "__main__":
	main()

Submission status: Accepted

Solution code:
def smaller(x, y):
	if x < y: return x
	return y

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC94 B

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

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

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

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = []
d = 0

for i in range(a[2]):
  if i in b:
    d+=1
else:
  c.append(d)
  d = 0

for i in range(a[0]-a[2]):
  if i+a[2] in b:
    d+=1
else:
  c.append(d)
  print(min(c))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

b = bisect_left(a, x)
print(min(b, m-b))

Submission status: Accepted

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

ans = 0
for a in A:
    if a < X:
        ans += 1

print(min(ans, M-ans))

Submission status: Accepted

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

lower = 0
upper = 0
for i in a:
    if i < x: lower += 1
    else: upper += 1
print(min(lower, upper))

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
l = list(map(int,input().split()))
tmp = len([i for i in l if i>x])
print(min(tmp,m-tmp))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
listA=list(map(int,input().split()))
for i in range(M-1):
  if listA[i]<X<listA[i+1]:
    ans=min(i+1,M-i-1)
  elif listA[i]==0:
    ans=min(i,M-i-1)
if X<listA[0] or listA[M-1]<X:
  ans=0
print(ans)

Submission status: Accepted

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

L = len([a for a in A if a < X ])
R = len(A) - L

print(min(L, R))

Submission status: Accepted

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

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

cnt1=0
cnt2=0

for j in a:
    if x>j:
        cnt1+=1

    else:
        cnt2+=1
print(min(cnt1,cnt2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=map(int, input().split())
a=list(map(int, input().split()))
v=0
for i in range(m):
    if x<a[0]:
        print(0)
        exit()
    if x<a[i]:
        v=i
        break

print(min(v,len(a)-v))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

def input():
    return sys.stdin.readline().rstrip()

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

    left = 0
    right = 0
    for i in al:
        if i < x:
            left += 1
        elif x < i:
            right += 1

    print(min(left, right))

Submission status: Accepted

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

mass = [0] * N
for i in A:
    mass[i] = 1

right = sum(mass[X:])
left = sum(mass[:X])

print(min(right, left))

Submission status: Accepted

Solution code:
from functools import reduce
import math

def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    N, M, X = (int(_) for _ in input().split())
    A = list(int(_) for _ in input().split())
    print(min(len([i for i in A if i < X]),len([i for i in A if i > X])))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
A = [int(i) for i in input().split()]
###nはマス目の数、mは料金所の数、xは自分がいるマス目
count_l = 0
count_r = 0

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

print(min(count_l, count_r))

Submission status: Accepted

Solution code:
def resolve():
	n,m,x=map(int,input().split())
	a=list(map(int,input().split()))
	t=sum([1 for i in a if i<x])
	b=m-t
	print(min(t,b))
resolve()

Submission status: Accepted

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


def main():
    n, m, x = list(map(int, input().rstrip().split()))
    lst = sorted(list(map(int, input().rstrip().split())))
    cur = bisect_left(lst, x)
    print(min(cur, m - cur))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# ABC094B - Toll Gates
n, m, x = list(map(int, input().rstrip().split()))
lst = sorted(list(map(int, input().rstrip().split())) + [x])
print(min(lst.index(x), m - lst.index(x)))

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N, M, X = map(int, input().split())
toll = [int(i) for i in input().split()]
counter1 = 0
counter2 = 0

for i in range(X - 1, 0, -1):
    for j in range(len(toll)):
        if toll[j] == i:
            counter1 += 1

for k in range(X, N):
    for l in range(len(toll)):
        if toll[l] == k:
            counter2 += 1

if counter1 <= counter2:
    print(counter1)
else:
    print(counter2)

Submission status: Accepted

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

left = 0
right = 0
for ai in input().split():
    ai = int(ai)
    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()))

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:
nl = lambda: list(map(int, input().split()))
sl = lambda: input().split()
n = lambda: int(input())
s = lambda: input()

N, M, X = nl()
As = nl()

before = 0
after = 0
for i in range(M):
    if As[i] < X:
        before += 1
    if X < As[i]:
        after += 1
print(min(before, after))

Submission status: Accepted

Solution code:

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

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

fr = 0
bh = 0

for i in A:

    if i < X:
        fr += 1

    else:
        bh += 1

print (min(fr,bh))

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(1, N + 1):
  if i in A:
    if i < X:
      ans1 += 1
    else:
      ans2 += 1
print(min(ans1, ans2))

Submission status: Accepted

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


abc()

Submission status: Accepted

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

mn = 0
cnt = 0
for a in A:
    if a < X:
        cnt += 1
for a in A:
    if a > X:
        mn += 1
print(min(mn, cnt))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

if left >= right:
    print(right)
else:
    print(left)

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, M, X = map(int, input().split())
    A_list = list(map(int, input().split()))

    answer1 = 0
    answer2 = 0
    for i in range(M):
        if X < A_list[i]:
            answer1 += 1
        if X > A_list[i]:
            answer2 += 1
    print(min(answer1, answer2))

Submission status: Accepted

Solution code:
n=input().split()
M,X=int(n[1]),int(n[2])
A=input().split()
p=0
for i in range(M):
    if int(A[i])>X:
        p+=1
if p>M/2:
    print(M-p)
else:
    print(p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M, X = [int(nmx) for nmx in input().split()]
A = [int(a) for a in input().split()]
A.append(X)
A.sort()
idx_X = A.index(X)
if len(A)//2 < idx_X+1:
  ans = len(A)- (idx_X+1)
else:
  ans = (idx_X+1) - 1
print(ans)

Submission status: Accepted

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

left = 0
right = 0

for i in lst:
    if i < x:
        left += 1
    else:
        right += 1

print(min(left,right))

Submission status: Accepted

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

left = sum(1 if x < X else 0 for x in A)
right = M-left

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

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")

N, M, X = list(map(int, sys.stdin.readline().split()))
A = np.array(list(map(int, sys.stdin.readline().split())))

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

Submission status: Accepted

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

cnt1 = len([i for i in lia if i<x])
cnt2 = m - cnt1
print(min(cnt1,cnt2))

Submission status: Accepted

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

left = list(filter(lambda el: el < x, a))
right = list(filter(lambda el: el > x, a))

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

Submission status: Accepted

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

right = 0
left = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
nmx = list(map(int, input().split()))
toll = list(map(int, input().split()))
s = 0
lng = len(toll)
for i in range(lng):
    if toll[i] < nmx[2]:
        s = s + 1
    else:
        break

if s < nmx[1] - s:
    print(s)
else:
    print(nmx[1] - s)

Submission status: Accepted

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

Submission status: Accepted

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

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

ar = list(range(1,x))

cnt = 0

for i in range(len(ar)):
    cnt += a.count(ar[i])

print(min(cnt, 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 X > a:
        ans1 +=1
    else:
        ans2 +=1 
print(min(ans1,ans2))

Submission status: Accepted

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

s=0
for i in range(M):
    if tg[i]<=X:
        s+=1


print(min(s,M-s))

Submission status: Accepted

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