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:
def main():
    N, M, X = map(int, input().split())
    A = list(map(int, input().split()))
    under_x, upper_x = 0, 0
    for a in A:
        if a < X:
            under_x += 1
        else:
            upper_x += 1
    print(min(under_x, upper_x))


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:
def root1():
    """Xから0までのルートでかかる費用を求める
    """
    cost = 0
    for fee_station in fee_station_list:
        if fee_station < X:
            cost += 1

    return cost


def root2():
    """XからNまでのルートでかかる費用を求める
    """
    cost = 0
    for fee_station in fee_station_list:
        if X < fee_station < N:
            cost += 1

    return cost


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

cost1 = root1()
cost2 = root2()

print(min(cost1, cost2))

Submission status: Accepted

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

map_list = [0 for i in range(n+1)]

for i in range(n+1):
    if i in a_inputs:
        map_list[i]=1

ans1,ans2=0,0
for i in range(x,n+1):
    ans1+=map_list[i]
for i in range(x,-1,-1):
    ans2+=map_list[i]
print(min(ans1,ans2))

Submission status: Accepted

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

I = [ a for a in A if a < X ]
if len(I) < len(A) - len(I):
    print(len(I))
else:
    print(len(A) - len(I))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(m):
    if al[i]>x:
        print(min(i, m-i))
        break

Submission status: Accepted

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

a_big = [i for i in a if i > x]
a_small = [i for i in a if i < x]

print(min(len(a_big), len(a_small)))

Submission status: Accepted

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

for i in range(x,n+1):
  if i in a:
    tn += 1
for i in range(x,0,-1):
  if i in a:
    t0 += 1
print(min(t0,tn))

Submission status: Accepted

Solution code:
# solution
import io

n,m,k=map(int,input().split())
j=sum(int(i)<k for i in input().split())
print(min(j,m-j))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=[int(i) for i in input().split()]
for i in range(len(A)):
    if A[i]>X:
        S1=A[0:i]
        S2=A[i:]
        break
    else:
        continue
print(min(len(S1),len(S2)))

Submission status: Accepted

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

Submission status: Accepted

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

for i in a:
  cost[i] = 1

cost_zero = cost[1:x]
cost_n = cost[x+1:]

ans = min(sum(cost_zero),sum(cost_n))

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

c1 = 0
c2 = 0

for a in A:
    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 = map(int, input().split())
 
left = 0
right = 0
 
for i in a:
	if i < x:
		left += 1
	else:
		right += 1
print(min(left, right))

Submission status: Accepted

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

Submission status: Accepted

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

for i in reversed(range(0, X+1)):
  if i-1 in A:
    cost_a += 1
  
for j in range(X, N+1):
  if j in A:
    cost_b += 1

print(min(cost_a, cost_b))

Submission status: Accepted

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

    # 左に移動したときと右に移動した時のコストを比較する
    left = 0
    right = 0

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

    for i in range(m):
        if a[i] > x:
            right += 1

    print(min([left, right]))

Submission status: Accepted

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

for i in a:
    if i < x:
        y += 1
    else:
        z += 1

print(min(y,z))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a = sorted(a)
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 = sum(int(i)<x for i in input().split())
print(min(a,m-a))

Submission status: Accepted

Solution code:
# ABC 094: B – Toll Gates
n, m, x = map(int, input().split())
a = [int(s) for s in input().split()]

if x < a[0] or x > a[m - 1]:
    print(0)
else:
    print(min(len([p for p in a if p < x]), len([q for q in a if q > x])))

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:
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
week=["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"]
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod_>0):A[a]%=mod_
    return A
def comb(n,r,mod_,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod_-2,mod_)*pow(fac[r],mod_-2,mod_))%mod_
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
#################################### ########
# coding: utf-8
import re
import math
import itertools
from copy import deepcopy
import random
from heapq import heappop,heappush
import time
import os
import queue
import sys
import datetime
from functools import lru_cache
readline=sys.stdin.readline
sys.setrecursionlimit(2000)
#import numpy as np
alphabet="abcdefghijklmnopqrstuvwxyz"
mod=int(10**9+7)
inf=int(10**20)
def yn(b):
    if b:
        print("yes")
    else:
        print("no")
def Yn(b):
    if b:
        print("Yes")
    else:
        print("No")
def YN(b):
    if b:
        print("YES")
    else:
        print("NO")
class union_find():
    def __init__(self,n):
        self.n=n
        self.P=[a for a in range(N)]
        self.rank=[0]*n
 
    def find(self,x):
        if(x!=self.P[x]):self.P[x]=self.find(self.P[x])
        return self.P[x]
 
    def same(self,x,y):
        return self.find(x)==self.find(y)
 
    def link(self,x,y):
        if self.rank[x]<self.rank[y]:
            self.P[x]=y
        elif self.rank[y]<self.rank[x]:
            self.P[y]=x
        else:
            self.P[x]=y
            self.rank[y]+=1
 
    def unite(self,x,y):
        self.link(self.find(x),self.find(y))
 
    def size(self):
        S=set()
        for a in range(self.n):
            S.add(self.find(a))
        return len(S)
def is_power(a,b):#aはbの累乗数か
    now=b
    while now<a:
        now*=b
    if now==a:return True
    else:return False
def bin_(num,size):
    A=[0]*size
    for a in range(size):
        if (num>>(size-a-1))&1==1:
            A[a]=1
        else:
            A[a]=0
    return A
def get_facs(n,mod_=0):
    A=[1]*(n+1)
    for a in range(2,len(A)):
        A[a]=A[a-1]*a
        if(mod>0):A[a]%=mod_
    return A
def comb(n,r,mod,fac):
    if(n-r<0):return 0
    return (fac[n]*pow(fac[n-r],mod-2,mod)*pow(fac[r],mod-2,mod))%mod
def next_comb(num,size):
    x=num&(-num)
    y=num+x
    z=num&(~y)
    z//=x
    z=z>>1
    num=(y|z)
    if(num>=(1<<size)):return False
    else:
        return num
def get_primes(n,type="int"):
    A=[True]*(n+1)
    A[0]=False
    A[1]=False
    for a in range(2,n+1):
        if A[a]:
            for b in range(a*2,n+1,a):
                A[b]=False
    if(type=="bool"):return A
    B=[]
    for a in range(n+1):
        if(A[a]):B.append(a)
    return B
def is_prime(num):
    if(num<=2):return False
    i=2
    while i*i<=num:
       if(num%i==0):return False
       i+=1
    return True
def ifelse(a,b,c):
    if a:return b
    else:return  c
def join(A,c=" "):
    n=len(A)
    A=list(map(str,A))
    s=""
    for a in range(n):
        s+=A[a]
        if(a<n-1):s+=c
    return s
def factorize(n,type_="dict"):
    b = 2
    list_ = []
    while b * b <= n:
        while n % b == 0:
            n //= b
            list_.append(b)
        b+=1
    if n > 1:list_.append(n)
    if type_=="dict":
        dic={}
        for a in list_:
            if a in dic:
                dic[a]+=1
            else:
                dic[a]=1
        return dic
    elif type_=="list":
        return list_
    else:
        return None
def floor_(n,x=1):
    return x*(n//x)
def ceil_(n,x=1):
    return x*((n+x-1)//x)
###################################################
def main():
    n,m,x=map(int,input().split())
    A=list(map(int,input().split()))
    ans=[0,0]
    for a in range(x,n+1):
      if a in A:
        ans[0]+=1
    for a in range(0,x+1):
      if a in A:
        ans[1]+=1
    print(min(ans))


main()

Submission status: Accepted

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

roots = [0] * (N+1)

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

ans_s = 0
for i in range(0,X):
    ans_s += roots[i]
ans_g = 0
for i in range(X+1,N+1):
    ans_g += roots[i]
print(min(ans_s,ans_g))

Submission status: Accepted

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

bef=0
aft=0
for i in range(m):
  if (a[i]<x):
    bef+=1
  else:
    aft+=1
print(min(bef,aft))

Submission status: Accepted

Solution code:
# from math import factorial,sqrt,ceil,gcd
# from itertools import permutations as permus
# from collections import deque,Counter
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
N,M,X = map(int,input().split())
arrA = list(map(int,input().split()))

lis = [0]*N
for i in arrA:
    lis[i]=1

ans = min(sum(lis[:X]),sum(lis[X:]))

print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))

Submission status: Accepted

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

Submission status: Accepted

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

count = 0

for i in A:
    if i > X:
        break
    count += 1

if count < M/2:
    print(count)
else:
    print(M-count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a_list = map(int, input().split())
less_a = 0
larger_a = 0
for a in a_list:
    if a < x:
        less_a += 1
    else:
        larger_a += 1
print(min(less_a, larger_a))

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    n, m, x = MII()
    aa = MII()
    l_c = sum([1 for a in aa if a < x])
    r_c = sum([1 for a in aa if a > x])
    print(min(l_c, r_c))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

p = 0
mi = 0
for ai in a:
  if x < ai:
    p += 1
  else:
    mi += 1
print(min(mi, p))

Submission status: Accepted

Solution code:
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools
import math

n,m,x = map(int,input().split())
a = list(map(int,input().split()))
flag = [False]*(n+1)
for i in range(len(a)):
    flag[a[i]] = True
cnt1 = 0
cnt2 = 0
for i in range(x):
    if flag[i] == True:
        cnt2 += 1
for i in range(x+1,n+1):
    if flag[i] == True:
        cnt1 += 1
print(min(cnt1,cnt2))

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:
import bisect

N, M, X = map(int, input().split())
A = list(map(int, input().split()))
index = bisect.bisect_right(A, X)
print(min(index, len(A) - index))

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
	n,m,x = MI()
	a = LI()
	for i,aa in enumerate(a):
		if(aa>x):
			print(min(i, m-i))
			exit()

if __name__ == '__main__':
	main()

Submission status: Accepted

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

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
ans = min(cnt,m-cnt)
print(ans)

Submission status: Accepted

Solution code:
#coding:utf-8
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
right = 0
left = 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()))
count = 0
for i in range(m):
    if a[i] > x:
        count += 1
print(min(count,m-count))

Submission status: Accepted

Solution code:
import numpy as np
N,M,X,*A = map(int,open(0).read().split()) 
A = np.array(A)
print(min((A>X).sum(),(A<X).sum()))

Submission status: Accepted

Solution code:

url = "https://atcoder.jp//contests/abc094/tasks/abc094_b"

def main():
    N, M, X = list(map(int, input().split()))
    Ms = list(map(int, input().split()))
    count = 0
    for i in range(0, X + 1):
        if i in Ms:
            count += 1
    ans = count
    count = 0
    for i in range(X, N):
        if i in Ms:
            count += 1
    ans = count if ans > count else ans
    print(ans)
if __name__ == '__main__':
    main()

Submission status: Accepted

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

N=[]
for i in range(n+1):
    N.append(i*0)

for i in range(len(a)):
    N[a[i]]=1

print(min(sum(N[0:x+1]),sum(N[x+1:-1])))

Submission status: Accepted

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

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

ans = len(right) if len(right) < len(left) else len(left)

print(ans)

Submission status: Accepted

Solution code:
def myAnswer(N:int,M:int,X:int,A:list) -> int:
   masu =[]
   for i in range(N+1):
      if(i in A):
         masu.append(1)
      else:
         masu.append(0)
   return min(sum(masu[:X]),sum(masu[X+1:]))


def modelAnswer():
   tmp=1
def main():
   N,M,X =map(int,input().split())
   A =list(map(int,input().split()))
   print(myAnswer(N,M,X,A[:]))

if __name__ == '__main__':
   main()

Submission status: Accepted

Solution code:
import itertools
import copy
N ,M,X = (map(int,input().split(" ")))
nums = list((map(int,input().split(" "))))
a1 = sum([ num > X for num in nums])
a2 = sum([ num < X for num in nums])
print(min(a1,a2))

Submission status: Accepted

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

Submission status: Accepted

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

a1list=[]
a2list=[]
for a in alist:
  if a<X:
    a1list.append(a)
  else:
    a2list.append(a)
    
print(min(len(a1list),len(a2list)))

Submission status: Accepted

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

cost_a, cost_b = 0, 0

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

Submission status: Accepted

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

print(min(len(A[:index]), len(A[index:])))

Submission status: Accepted

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

Submission status: Accepted

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

left_cost = len([a for a in A if a < X])
right_cost = len([a for a in A if X < a])
print(min(left_cost, right_cost))

Submission status: Accepted

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

Submission status: Accepted

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

dicts = {i:0 for i in range(1, n)}
for i in range(m):
    dicts[a[i]] += 1

a, b = 0, 0

for i in range(1,n):
    if i < x:
        a += dicts[i]
    if i > x:
        b += dicts[i]

print(min(a, b))

Submission status: Accepted

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

l = [a for a in A if a < X]
r = [a for a in A if a > X]

print(len(l) if len(l) < len(r) else len(r))

Submission status: Accepted

Solution code:
from bisect import bisect_left as bl,bisect_right as br
n,m,now=map(int,input().split())
l=list(map(int,input().split()))
print(min(bl(l,now),m-bl(l,now)))

Submission status: Accepted

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

sum=len(a)
cost=100
costL=0
for i in range(M):
  if a[i]!=0 and a[i]<X:
    costL=costL+1
if min(costL,sum-costL)<cost:
  cost=min(costL,sum-costL)
print(cost)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(m+1):
  if A[i] > x:
    print(min(i,m-i))
    exit()

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

Submission status: Accepted

Solution code:
import sys

def resolve():
    N, M, X = list(map(int, input().split(" ")))
    A = list(map(int, input().split(" ")))
    pos = X
    costN = 0
    while True:
        if pos == N: 
            break
        pos += 1
        if pos in A:
            costN += 1
    pos = X
    cost0 = 0
    while True:
        if pos == 0: 
            break
        pos -= 1
        if pos in A:
            cost0 += 1
    print(min(cost0, costN))

if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
A = sorted(map(int, input().split()))
cost_0, cost_n = 0, 0
for a in A:
  if a < x: cost_0 += 1
  else: cost_n += 1
ans = min(cost_0, cost_n)
print(ans)

Submission status: Accepted

Solution code:
from __future__ import print_function

import sys

import re
import array
import copy
import functools
import operator

import math
import string
import fractions
from fractions import Fraction
from fractions import gcd
# fractions.gcd() を用いること
# math.log2()はatcoderでは対応していない．留意せよ．

import collections
import itertools
import bisect

import random
import time

import heapq
from heapq import heappush
from heapq import heappop
from heapq import heappushpop
from heapq import heapify
from heapq import heapreplace
from queue import PriorityQueue as pq
from queue import Queue

from itertools import accumulate

from collections import deque
from collections import Counter

from operator import mul
from functools import reduce

input = sys.stdin.readline


def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)
    return


def lcm(n, m):
    return int(n * m / gcd(n, m))


def coprimize(p, q):
    common = fractions.gcd(p, q)
    return (p // common, q // common)


def combinations_count(n, r):
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom


def find_gcd(list_l):
    x = reduce(gcd, list_l)
    return x


def main():
    n, m, x = map(int,input().strip().split())
    temp = list(map(int, input().strip().split()))
    a = ["none" for _ in range(n+1)]
    for i in temp:
        a[i] = "isCharge"

    ans1=0
    ans2=0
    for i in range(x, n+1):
        if a[i] == "isCharge":
            ans1+=1
    for i in range(0, x+1)[::-1]:
        if a[i] == "isCharge":
            ans2+=1
    print(min(ans1,ans2))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m,x=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
a.sort()
one=0
while a:
    check=a.pop()
    if check>x:
        one+=1
    else:
        a.append(check)
        break
two=len(a)

print(min(one,two))

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
low = 0
high  = 0
 
for i in input().split():
    if int(i) < c:
        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()))

import bisect

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

tolls = [0] * (N+1)

for item in A:
    tolls[item] = 1

print(min(sum(tolls[:X]), sum(tolls[X:])))

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 a > X:
    ans1 += 1
  else:
    ans2 += 1

print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(0,x):
  if a[cnt]==i:
    count1+=1
    if cnt==len(a)-1:
      pass
    else:
      cnt+=1
    
for j in range(x+1,n+1):
  if a[cnt]==j:
    count2+=1
    if cnt==len(a)-1:
      pass
    else:
      cnt+=1
      
print(count1 if count1<=count2 else count2)

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
list_A = list(map(int, input().split()))
left = 0
right = 0
for num in list_A:
    if num < x:
        left += 1
    if num > x:
        right += 1

print(min(left, right))

Submission status: Accepted

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

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

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

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

print(min(ctr, M - ctr))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(min(ans1, ans2))