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:
#
# Written by NoKnowledgeGG @YlePhan
# ('ω')
#
#import math
#mod = 10**9+7
#import itertools
#import fractions
#import numpy as np
#mod = 10**4 + 7
"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""
 
def main():
  n,m,x = map(int,input().split())
  a = list(map(int,input().split()))
  cost = 0
  for i in range(x+1,n):
    if a.count(i):
      cost += 1
  mi_ = cost
  cost = 0
  for i in range(1,x):
    if a.count(i):
      cost += 1
  mi_ = min(mi_, cost)
  
  print(mi_)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
from itertools import takewhile
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
#print(X,A)
lmt=len(list(takewhile(lambda x:x<X,A)))
#print(list(takewhile(lambda x:x<X,A)))
#print(lmt)
ans=min(lmt,M-lmt)
print(ans)

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 = list(map(int, input().split()))
A = set(map(int, input().split()))
back = 0
for num in range(0, X):
  if num in A:
    back += 1
forward = 0
for num in range(X+1, N+1):
  if num in A:
    forward += 1
print(min([back,forward]))

Submission status: Accepted

Solution code:

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

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

print(min(cnt, m - cnt))

Submission status: Accepted

Solution code:
# babc094_b.py
N, M, X = map(int,input().split())
A = list(map(int,input().split()))
cnt_pre=0
cnt_post=0
for i in A:
    if i<X:
        cnt_pre+=1
    else:
        cnt_post+=1
print(min(cnt_post,cnt_pre))

Submission status: Accepted

Solution code:
import numpy as np

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

ans = min(np.count_nonzero(A < X), np.count_nonzero(A > X))
print(ans)

Submission status: Accepted

Solution code:
def main():
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))
    right = list(filter(lambda y: y<x, a))
    left = list(filter(lambda y: y>x, a))
    print(min(len(right), len(left)))

if __name__ == "__main__":
    main()

Submission status: Accepted

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

    for i in range(m):
        array = [a<x for a in A]
    print(min(sum(array), m-sum(array)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
l=set(a)&set(list(range(1,x)))
r=set(a)&set(list(range(x+1,n)))
print(min(len(l),len(r)))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
l = list(map(int, input().split()))
l.append(x)
l.sort()
print(min(m - l.index(x), l.index(x)))

Submission status: Accepted

Solution code:
def ii():return int(input())
def iim():return map(int,input().split())
def iil():return list(map(int,input().split()))
def ism():return map(str,input().split())
def isl():return list(map(str,input().split()))

n,m,x = iim()
before = 0
after = 0
A = iil()
for i in A:
    if i < x:
        before += 1
    else:
        after += 1

print(min(before,after))

Submission status: Accepted

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

ans = 0

for i in a:
  if i < x:
    ans += 1

print(min(ans, m-ans))

Submission status: Accepted

Solution code:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
INF = 1 << 60
sys.setrecursionlimit(10 ** 6)

#ここから書き始める
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
left = 0
right = 0
for i in a:
    if i < x:
        left += 1
    elif i > x:
        right += 1
print(min(right, left))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for i in a:
    if i<x:
        ans+=1
    else:
        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 a:
  if i < x:
    cnt += 1

print(min(cnt, m-cnt))

Submission status: Accepted

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

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

cnt = 0
for a in A:
    if a > X:
        break
    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()))

go_left=sum(a > X for a in A)
go_right=sum(a < X for a in A)
print(min(go_left, go_right))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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):
    if i in A:
        ans1 = ans1 + 1

for i in range(x + 1, n + 1):
    if i in A:
        ans2 = ans2 + 1

print(min(ans1, ans2))

Submission status: Accepted

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

ans = float("inf")
# x -> n
t = 0
for i in range(x+1, n+1):
    t += cost[i]
ans = min(ans, t)

# x -> 0
t = 0
for i in range(x-1, -1, -1):
    t += cost[i]

ans = min(ans, t)

print(ans)

Submission status: Accepted

Solution code:
N, M, X = map(int,input().split())
An = map(int,input().split())
cost = [0]*N
for A in An: cost[A] = 1
costL = sum(cost[:X])
costR = sum(cost[X:])
print(costL if costL <= costR else costR)

Submission status: Accepted

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

for i in input().split():
    if int(i) < x:
        low += 1
    else:
        high += 1

print(min(low, high))

Submission status: Accepted

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

Submission status: Accepted

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

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+1:])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left
N, M, X = map(int, input().split())
A = sorted(list(map(int, input().split())))
index = bisect_left(A, X)
print(min(len(A[:index]), len(A[index:])))

Submission status: Accepted

Solution code:
from bisect import bisect_left
from bisect import bisect_right
N, M, X = map(int, input().split())
A = sorted(list(map(int, input().split())))
index = bisect_left(A, X)
s = len(A[:index])
g = len(A[index:])
print(min(s,g))

Submission status: Accepted

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

    line = [0 for _ in range(n+1)]
    for i in range(n+1):
        if i in As:
            line[i] += 1
    ans = min(sum(line[:x]), sum(line[x:]))
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

left=0
right=0

for i in range(0,N+1):
  if i in A:
    if i<X:
      left +=1
    else:
      right+=1

print(min(left,right))

Submission status: Accepted

Solution code:
import bisect

def Toll_Gates(n , m , x , al):

    al.sort()
    ans = 0

    left = bisect.bisect_left(al, x)
    right = m - left

    ans = min(left , right)

    return ans

def main():
    n , m , x = map(int , input().split())
    al = list(map(int, input().split()))
    print(Toll_Gates(n , m , x , al))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

A.sort()
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 i in range(x,n+1):
    if i in a:
        ans1+=1

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

print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=[int(i) for i in input().split()]
#print(A)
left=0
right=0
#通過した数をカウント
for i in A:
  if i>X:
    right+=1 #右端へ移動
  else:
    left+=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()))
S = sum(s < X for s in A)
print(min(S, M-S))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
P = list(filter(lambda x: x < X, A))
Q = list(filter(lambda x: x > X, A))
print(min(len(P), len(Q)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=input().split()
B=[int(a) for a in A if int(a)>X]
C=[int(b) for b in A if int(b)<X]
b=len(B)
c=len(C)
print(min(b,c))

Submission status: Accepted

Solution code:
import math
import string


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]

n, m, x = map(int, input().split())
a = map(int, input().split())
left = 0
right = 0
for aa in a:
    if aa < x:
        left += 1
    else:
        right += 1
print(min(left, right))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

up_a = [i for i in a if i < x]
down_a = [i for i in a if  x < i]

print(min(len(up_a), len(down_a)))

Submission status: Accepted

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

import bisect
ind = bisect.bisect(A,X)
ans = min(ind,M-ind)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#abc094 b
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
left=0
right=0
for i in a:
    if i>x:
        right+=1
    else:
        left+=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()))
c1=0
c2=0
for i in range(M):
  if N>A[i]>X:
    c1+=1
  if 0<A[i]<X:
    c2+=1

print(min(c1,c2))

Submission status: Accepted

Solution code:
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

    N, M, X =map(int, input().split())
    A = list(map(int, input().split()))
    res = 0
    for i in A:
        if i>=X:
            res += 1
    print(min(res, M-res))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

A_left = [a for a in A if a < X]
A_right = [a for a in A if a > X]
print(min(map(len, (A_left, A_right))))

Submission status: Accepted

Solution code:
# Author: cr4zjh0bp
# Created: Thu Mar 12 07:52:52 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

N, M, X = na()
X -= 1
a = na()
b = [0] * N
for i in range(M):
    b[a[i] - 1] = 1

l, r = 0, 0
for i in range(N):
    if i < X:
        l += b[i]
    else:
        r += b[i]

print(min(l, r))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
index = 0
f = 0
ans = [0,0]
for i in range(N+1):
    if (i == A[index]):
        ans[f] += 1
        index = min(index+1,M-1)
    if (i == X):
        f += 1

print(min(ans))

Submission status: Accepted

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

Submission status: Accepted

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

right = 0
for r in range(x, n+1):
    if r in a:
        right += 1

left = 0
for l in range(x):
    if l in a:
        left += 1

print(min(right, left))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import os


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

    N, M, X = list(map(int, sys.stdin.readline().split()))
    LINES = list(map(int, sys.stdin.readline().split()))
    s = [i for i in LINES if i > 0 and i < X]
    l = [i for i in LINES if i > X and i < N + 1]
    print(min(len(s), len(l)))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# import bisect
# import copy
# import fractions
# import math
# import numpy as np
# from collections import Counter, deque
# from itertools import accumulate,permutations, combinations,combinations_with_replacement,product

def resolve():
    n,m,x=map(int,input().split())
    A=list(map(int,input().split()))

    B=sorted(A+[x])
    print(min(B.index(x), m-B.index(x)))

resolve()

Submission status: Accepted

Solution code:
list = list(map(int,input().split()))
a = list[0]
p = list[1]
b = list[2]
c = 0
d = 0
tax = [int(i) for i in input().split()]
for i in range(p):
	t=tax[i]
	if t<b:
		c=c+1
	if t>b:
		d=d+1
if c>d:
	print(d)
else:
	print(c)

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(len(A[A<X]),len(A[A>=X])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

x = bisect_left(A,X)
print(min(x,M-x))

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

s = 0
b = 0

for y in a:
    if y > x:
        b += 1
    elif y < x:
        s += 1
print(min(b,s))

Submission status: Accepted

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

count1 = 0

count2 = 0

for i in range(x,n+1):
    if i in t:
        count1 += 1

for j in range(x, 0, -1):
    if j in t:
        count2 += 1
print(min(count1,count2))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(min(sum(lower), sum(upper)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

#print(a[:a.index(x)])
#print(a[a.index(x)+1:])

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

Submission status: Accepted

Solution code:
#ABC084

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

Submission status: Accepted

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

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

r0=0
rn=0

for i in r:
    if i<x:
        r0=r0+1
    else:
        rn=rn+1


if r0<rn:
    print(r0)
else:
    print(rn)

Submission status: Accepted

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

for i in a:
  s=sum(int(i)<x for i in a)
print(min(s,m-s))

Submission status: Accepted

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

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

Submission status: Accepted

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

up=0
down=0
for i in range(M):
    if(a[i]<X):
        down+=1
    else:
        up+=1
print(min(down,up))

Submission status: Accepted

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

ans1 = 0
ans2 = 0

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

for j in range(x):
  if j in a:
    ans2 += 1
    
ans = min(ans1,ans2)
  
  
print(ans)

Submission status: Accepted

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


SQUARES = [0] * (n + 1)
for a in A:
    SQUARES[a] = 1


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

Submission status: Accepted

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

first_cnt,end_cnt=0,0

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

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A_list = list(map(int, input().split()))
min1 = 10000
cnt = 0
for i in range(X-1, 0, -1):
    for j in range(len(A_list)):
        if A_list[j] == i:
            cnt+=1
if cnt < min1:
    min1 = cnt
cnt= 0
for i in range(X+1, N):
    for j in range(len(A_list)):
        if A_list[j] == i:
            cnt+=1
if cnt < min1:
    min1 = cnt
print(min1)

Submission status: Accepted

Solution code:
import numpy as np
N, M, X=map(int, input().split())
A=list(map(int, input().split()))
x=np.searchsorted(A, X, side='left')
y=M-x
print(min(x, y))

Submission status: Accepted

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

A_before = [x for x in A if x<X]
A_after = [x for x in A if x>X]

print(min(len(A_before), len(A_after)))

Submission status: Accepted

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

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

print(min(a,b))

Submission status: Accepted

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

A_=[0]*(N+1)
for a in A:
    A_[a]=1
ans1=0
for a in A_[X+1:]:
    if a==1:
        ans1+=1
ans2=0
for a in reversed(A_[:X]):
    if a==1:
        ans2+=1

print(min(ans1,ans2))

Submission status: Accepted

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

cnt_1=0
cnt_2=0
for i in range(M):
    if A[i]<X:
        cnt_1+=1
    elif A[i]>X:
        cnt_2+=1
    else:
        pass
print(min(cnt_1,cnt_2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#094_B
n,m,x=map(int,input().split())
a=[int(p)<x for p in input().split()]
print(min(sum(a),len(a)-sum(a)))

Submission status: Accepted

Solution code:
from bisect import bisect

n,m,x=map(int,input().split())
a=sorted(list(map(int,input().split())))
z=bisect(a,x)
print(min(z,m-z))

Submission status: Accepted

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

left = sum(a[:x])
right = sum(a[x+1:])

print(min([left, right]))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
count1 = 0
count2 = 0
for a in map(int, input().split()):
  if a < x:
    count1 += 1
  else:
    count2 += 1

print(min(count1, count2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

left = len([v for v in alist if v < x])
right = len([v for v in alist if v > x])

print(min(left,right))

Submission status: Accepted

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

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

Submission status: Accepted

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

#----------
N,M,X = list(map(int, input().rstrip().split()))
A_list = list(map(int, input().rstrip().split()))
#----------
sum_L=0
sum_R=0
for a in A_list:
    if a < X:
        sum_L += 1
    elif a > X:
        sum_R += 1

print( min(sum_L,sum_R) )

Submission status: Accepted

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

len_left = len([i for i in A if i < X])
len_right = len([i for i in A if i > X])

ans = min(len_left,len_right)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Low=0
High=0

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

Submission status: Accepted

Solution code:
def solve():
    N, M, X = [int(_) for _ in input().split()]
    masu = [0] * (N + 1)
    A = [int(_) for _ in input().split()]
    for a in A:
        masu[a] = 1
    return min(sum(masu[0:X]), sum(masu[X:]))
if __name__ == '__main__':
    print(solve())