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

G_0 = 0
G_N = 0
for a in A:
    if a < X:
        G_0 += 1
    else:
        G_N += 1

print(min(G_0,G_N))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
lst=[0]*(n+1)

for i in a:
    lst[i]+=1

print(min(sum(lst[:x]),sum(lst[x:])))

Submission status: Accepted

Solution code:
def toll(n, x, tolls):
	rcount = 0
	lcount = 0
	for i in range(x, n):
		if i in tolls:
			rcount += 1
	for i in range(1, x):
		if i in tolls:
			lcount += 1
	return min(rcount, lcount)
n, m, x = map(int, input().split())
tolls = list(map(int, input().split()))
print(toll(n, x, tolls))

Submission status: Accepted

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

go_left = 0
go_right = 0

for i in range(x, n+1):
    if a.count(i) == 1:
        go_right += 1

for j in range(0, x):
    if a.count(j) == 1:
        go_left += 1

print(min(go_left, go_right))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
n=[*range(1,n+1)];maxN=max(n)
a=list(map(int,input().split()))
count1,count2=0,0
for i in range(x,maxN+1):
  if i in a:
    count1+=1
for i in range(x,0,-1):
  if i in a:
    count2+=1
print(min(count1,count2))

Submission status: Accepted

Solution code:
def main():
    N, M, X = map(int, input().split())
    a = list(map(int, input().split()))
    if X < a[0] or a[M-1] < X:
        print(0)
        return
    else:
        for i in range(M):
            if X < a[i]:
                t = i
                break
        b = M - t
        f = t
        print(min(f, b))
main()

Submission status: Accepted

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

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

count1 = count2 = 0

for i in p:
    if 0 < i <= x:
        count1 += 1
    elif x <= i <= n:
        count2 += 1
    
print(min(count1,count2))

Submission status: Accepted

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

ans_N = M - bisect.bisect_left(A,X)
ans_0 = bisect.bisect_left(A,X)
print(min(ans_N,ans_0))

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np
from functools import reduce

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m, x = rm()
a = rl()
li = [0] * (n+1)
for i in a:
    li[i] += 1
print(min(sum(li[:x]), sum(li[x:])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#k = int(input())
#s = input()
#a, b = map(int, input().split())
#s, t = map(str, input().split())
#l = list(map(int, input().split()))
#l = [list(map(int,input().split())) for i in range(n)]
#a = [list(input()) for _ in range(n)]
#a = [int(input()) for _ in range(n)]

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

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


print(min(ans1, ans2))

Submission status: Accepted

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

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())
Als = list(map(int,input().split()))
cost1 = sum(1 for x in Als if x>X) 
cost2 = sum(1 for x in Als if x<X) 
print(min(cost1,cost2))

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(X-1, -1, -1):
    if i in A:
        left += 1
for i in range(X+1, N+1):
    if i in A:
        right += 1
print(min(left, right))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,gate,start=list(map(int,input().split()))
W=list(map(int,input().split()))
le=0
ri=0
for i in range(start,N+1):
  if i in W:
    ri+=1
for k in range(start+1):
  if k in W:
    le+=1
print(min(ri,le))

Submission status: Accepted

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

G = sum([a < X for a in A])

print(min(G, M-G))

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, M, X, *A = map(int, read().split())
    
    v = 0
    for a in A:
        if a < X:
            v += 1
        else:
            break
    
    print(min(v, M - v))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
f=lambda:[*map(int,input().split())]
n,m,x=f()
a=f()
l=r=0
for i in a:
  if i<x: l+=1
  elif i<n: r+=1
print(min(l,r))

Submission status: Accepted

Solution code:
import math


def resolve():
    import sys
    input = sys.stdin.readline
    # row = [int(x) for x in input().rstrip().split(" ")]
    # n = int(input().rstrip())
    nmx = [int(x) for x in input().rstrip().split(" ")]
    x = nmx[2]
    a_list = [int(x) for x in input().rstrip().split(" ")]


    left_cost = sum(1 for a in a_list if a < x)
    right_cost = len(a_list) - left_cost

    ans = left_cost if left_cost < right_cost else right_cost

    print(ans)




if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
N_masu, M_exp, X_pos = map(int, input().split())
exp_pos = list(map(int, input().split()))

cos_1 = 0
cos_2 = 0

for i in range(M_exp):
    pos = exp_pos[i]
    
    if (pos <= X_pos):
        cos_1 += 1
    else:
        cos_2 += 1

print(min(cos_1,cos_2))

Submission status: Accepted

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

c1 = 0
c2 = 0
for a in aa:
    if a < x:
        c1 += 1
    if a > x:
        c2 += 1
print(min(c1, c2))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a.sort()
print(min(len(a[:a.index(x)]), len(a[a.index(x)+1:])))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n, m, x = inintm()
A = inintl()

h = 0
l = 0

for a in A:
    if a < x:
        l += 1
    else:
        h += 1

print(min(h, l))

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=[False]*(n+1)
A=list(map(int,input().split()))
for i in range(m):
	s = A[i]
	a[s] = True

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

import bisect

t = bisect.bisect_left(A, X)
ans = min(t, M - t)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

N, M, X = map(int, input().split())
A = np.array(list(map(int, input().split())))
if len(A[A < X]) > len(A[A > X]):
    print(len(A[A > X]))
else:
    print(len(A[A < X]))

Submission status: Accepted

Solution code:

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

dammy = [0]*(N+1)

for i in A:
    dammy[i]=1
    if i==X:
        dammy[i]=0
# print(dammy)


left = sum(dammy[0:X+1])
right = sum(dammy[X+1:N+1])
# print(left,right)

print(min(left,right))

Submission status: Accepted

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

left = sum(x<X for x in A) 
right = sum(x>X for x in A)  

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

Submission status: Accepted

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

print(min(len(list(filter(lambda x:x<X,A))), len(list(filter(lambda x:x>X,A)))))

Submission status: Accepted

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

distance_to_head = len([i for i in A if i < X])
distance_to_tail = len([i for i in A if X < i])
print(min(distance_to_head, distance_to_tail))

Submission status: Accepted

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

distance_to_head = len(list(filter(lambda x: X < x, A)))
distance_to_tail = len(list(filter(lambda x: x < X, A)))
print(min(distance_to_head, distance_to_tail))

Submission status: Accepted

Solution code:
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# 約数生成
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,m,x = lr()
a = [0 for i in range(n+1)]
l = lr()
for num in l:
    a[num] = 1
a1 = [0]
for num in a:
    a1.append(num+a1[-1])
print(min(a1[x+1]-a1[0], a1[n+1]-a1[x+1]))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in a_list:
    r_list[i] = 1

zahyo = x
a = 0

while zahyo != 0:
    zahyo -= 1
    if r_list[zahyo] == 1:
        a += 1
zahyo = x
b = 0

while zahyo != n:
    zahyo += 1
    if r_list[zahyo] == 1:
        b += 1

print(min(a,b))

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

Submission status: Accepted

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

res1 = 0
res2 = 0

for a in A:
    if a < X:
        res1 += 1
    else:
        res2 += 1

print(min(res1, res2))

Submission status: Accepted

Solution code:
import bisect
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
t = bisect.bisect_left(A, X)
print(min(t, M-t))

Submission status: Accepted

Solution code:
import bisect
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
t = bisect.bisect_left(A, X)
print(min(t, M-t))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

# print(f"{n} {m} {x}")
# print(a_list)

n_list = [0] * (n + 1)
# print(n_list)

n_list[x] = 'X'
for i in range(m):
    n_list[a_list[i]] = 1
# print(n_list)

# print(n_list[:x])
# print(n_list[x + 1:])
print(min(sum(n_list[:x]), sum(n_list[x + 1:])))

Submission status: Accepted

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

Submission status: Accepted

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

l = len([a for a in A if a < X])
print(min([l, M - l]))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
List = list(map(int, input().split()))
pattern1 = 0
pattern2 = 0
setCost = set(List)
for i in range(N):
  if i in setCost:
    pattern1 += 1
  if i == X:
    break
for j in range(N,0,-1):
  if j in setCost:
    pattern2 += 1
  if j == X:
    break
if pattern1 < pattern2:
  print(pattern1)
else:
  print(pattern2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,*a=map(int,open(0).read().split());print(min(c:=sorted(a).index(a[0]),m-c))

Submission status: Accepted

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

cost = [0 for _ in range(N+1)]
for a in A:
    cost[a] = 1

cost_1 = 0
cost_2 = 0
for i in range(N+1):
    if i < X:
        cost_1 += cost[i]
    elif i > X:
        cost_2 += cost[i]

print(min(cost_1,cost_2))

Submission status: Accepted

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

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

B = [0] * (N+1)

for a in A:
    B[a] = 1

print(min(B[:X].count(1), B[X+1:].count(1)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

masu = [0]*(N+1)
for i in range(M):
    masu[A[i]]=1

ans = min(sum(masu[0:X]),sum(masu[X:N+1]))
print(ans)

Submission status: Accepted

Solution code:
MM = input().split()
N = int(MM[0])
M = int(MM[1])
X = int(MM[2])
LL = input().split()
a = 0
b = 0
for i in LL:
  if int(i) <X:
    a +=1
  else:
    b +=1
if a <= b:
  print(a)
else:
  print(b)

Submission status: Accepted

Solution code:
N, M, X = map(int,input().split())
A = list(map(int,input().split()))
ans = []
z = 0
y = 0
for i in range(X + 1, N + 1):
    if  i in A:
        z += 1
ans.append(z)
for i in range(1,X):
    if  i in A:
        y += 1
ans.append(y)
ans = sorted(ans)
print(ans[0])

Submission status: Accepted

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

import numpy as np
A_np = np.array(A)

cost_R = sum(X < A_np)
cost_L = sum(X > A_np)

print(min(cost_R, cost_L))

Submission status: Accepted

Solution code:
_, m, x = map(int, input().split())
(*a,) = map(int, input().split())
r = sum(x < i for i in a)
print(min(r, m - r))

Submission status: Accepted

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

masu = []
for i in range(n + 1):
    masu.append(False)

v = input().split()
for i in range(m):
    z = int(v[i])
    masu[z] = True

left = 0
right = 0

for i in range(x):
    if masu[i]:
        left += 1

for i in range(x, len(masu)):
    if masu[i]:
        right += 1



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

Submission status: Accepted

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

r_count = 0
l_count = 0

tmp_1 = X
tmp_2 = X


while tmp_1 != N:
    tmp_1 += 1
    if tmp_1 in A:
        r_count += 1

while tmp_2 != 0:
    tmp_2 -= 1
    if tmp_2 in A:
        l_count += 1


res = min(l_count, r_count)
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# その22 B - Toll Gates
# N：N+1個のマス 0~N
# M：料金所の数
# X：最初のマス
# A：料金所の場所

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

for i in range(len(A)):
    if X < A[i]:
        p+=1

for j in range(len(A)):
    if X > A[j]:
        s+=1

if p>=s:
    print(s)
else:
    print(p)

Submission status: Accepted

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

B = [i for i in A if i < X]
C = [i for i in A if i > X]

print( min(len(B), len(C)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

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

ans = min(ans1, ans2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n, m, x, *a = map(int, read().split())
left_cost = len([i for i in a if 0 < i < x])
right_cost = len([i for i in a if x < i < n])

print(min(left_cost, right_cost))

Submission status: Accepted

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

cost1 = 0

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

cost2 = 0

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

print(min(cost1, cost2))

Submission status: Accepted

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

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

m = [0]*(n+1)

for i in r:
    m[i] = 1
    
print(min(sum(m[:x]),sum(m[x:])))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import collections
from decimal import Decimal # 10進数で考慮できる

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

d = collections.deque()
def LI(): return list(map(int, sys.stdin.readline().split()))

N, M, X = LI()
A = LI()

left = 0
right = 0

cs = [0 for i in range(N)]
for a in A:
    cs[a] = 1
for i in range(X):
    if cs[i]:
        left += 1

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

Submission status: Accepted

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

res = sum(y < x for y in al)  # 真偽値リストを作って True の数を合計する方法
ress = m-res

print(min(res,ress))

Submission status: Accepted

Solution code:
N, M, X  = map(int, input().split())
a=[]
for i in input().split():
  a.append(int(i) < X)
  c = a.count(True)
print(min(c, M-c))

Submission status: Accepted

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

lst = [0]*(N+1)

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

left = sum(lst[0:X])
right = sum(lst[X:N+1])
ans = min(left, right)
print(ans)

Submission status: Accepted

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

print(min(sum(ans[:x]), sum(ans[x:])))

Submission status: Accepted

Solution code:
def solve():
    N, M, X = map(int, input().split())
    A = map(int, input().split())
    squares = [0 for _ in range(0, N+1)]
    for a in A:
        squares[a] = 1
    print(min(squares[:X].count(1), squares[X+1:].count(1)))


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N,M,X = LI()
A =LI()
cost = 0
go_right = N-X
go_left = X
cost_right = 0
cost_left = 0
for i in range(X+1, N):
    if i in A:
        cost_right += 1

for j in range(1,X):
    if j in A:
        cost_left += 1

print(min(cost_left,cost_right))

Submission status: Accepted

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

#~ゴール
cnt_g = 0
for i in range(X+1, N):
    if i in A: cnt_g+= 1

#~スタート
cnt_s = 0
for i in range(X-1, 0, -1):
    if i in A: cnt_s += 1

print(min(cnt_g, cnt_s))

Submission status: Accepted

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

ans=sum([a[i]>x for i in range(m)])
ans=min(ans,m-ans)
print(ans)

Submission status: Accepted

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

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

ans_l = 0 # 左に進んだ場合の答え
ans_r = 0 # 右に進んだ場合の答え

# 左に進んだ場合のコストの算出
for i in range(X, 0, -1):
    if i in A:
        ans_l += 1

# 右に進んだ場合のコストの算出
for i in range(X, N, 1):
    if i in A:
        ans_r += 1

# 最小値の算出
min_cost = min(ans_l, ans_r)

print(min_cost)

Submission status: Accepted

Solution code:
import bisect

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

num = bisect.bisect_left(A, X)

result = min(M-num, num)

print(result)

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
pr = 0 ; pl = 0
for i in range(x,n+1) :
    if i in a :
        pr += 1
for j in range(x,-1,-1) :
    if j in a :
        pl += 1
mn = min(pr, pl)
print(mn)

Submission status: Accepted

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

Submission status: Accepted

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

c1 = [i for i in range(x)]
c2 = [i for i in range(x,n+1)]
y=0
z=0
for i in c1:
  if i in a:
    y += 1
for i in c2:
  if i in a:
    z += 1
print(min(y,z))

Submission status: Accepted

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

count = [i for i in a if i > X]
print(min(len(count), len(a)-len(count)))

Submission status: Accepted

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

for a in A:
  L[a]+=1

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

Submission status: Accepted

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


cost = 0
for i in range(x,m+1):
  if i in al:
    cost += 1

cost2 = 0
for i in range(x,0,-1):
  if i in al:
    cost2 += 1
    
print(min(cost, cost2))

Submission status: Accepted

Solution code:
#19
N,M,X = map(int,input().split())
a = list(map(int,input().split()))
sum1 = 0
sum2 = 0

for i in range(M):
    if a[i] < X:
        sum1 += 1
    elif a[i] > X:
        sum2 += 1
    
if sum1 >=sum2 :
    print(sum2)
else:
    print(sum1)

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())
L=list(map(int,input().split()))
K=[i for i in L if i>X]
T=[i for i in L if i<X]
print(min(len(K),len(T)))

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

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 X > A[i]:
        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()))

for i in range(m):
    if a[i] >= x:
        idx = i
        break

print(min(i, m-i))

Submission status: Accepted

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

s1 = 0
s2 = 0
for num in a:
    if num < x:
        s1 += 1
    elif num > x:
        s2 += 1
print(min(s1, s2))

Submission status: Accepted

Solution code:
N, M, X = input().split()
N = int(N)
M = int(M)
X = int(X)
A = input().split()
A = [int(A[i]) for i in range(M)]
A.append(X)
A = sorted(A)
if M/2 > A.index(X):
  print(A.index(X))

elif  M/2 < A.index(X):
  print(int(M-A.index(X)))

Submission status: Accepted

Solution code:
import bisect
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
cost=bisect.bisect_left(A,X)
print(min(cost,M-cost))

Submission status: Accepted

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

Submission status: Accepted

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