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:
from bisect import bisect_left
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
tmp = bisect_left(a, x)
print(min(tmp, m-tmp))

Submission status: Accepted

Solution code:
#ABC094-B
n,m,x = map(int,input().split())
a = set(list(map(int,input().split())))
masu = [i for i in range(n+1)]
a_left = masu[:x]
a_right = masu[x+1:]

#print(a_left)
#print(a_right)

c_l = 0
c_r = 0
for i in range(len(a_left)):
    if a_left[i] in a:
        c_l += 1
        
for j in range(len(a_right)):
    if a_right[j] in a:
        c_r += 1
        
print(min(c_l,c_r))

Submission status: Accepted

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

keep=0
hidari=a[0]
while hidari<x and keep<=m:
  keep+=1
  hidari=a[keep]
  
print(min(keep,m-keep))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
import sys
import math
def i():return int(sys.stdin.readline().replace("\n",""))
def i2():return map(int,sys.stdin.readline().replace("\n","").split())
def s():return str(sys.stdin.readline().replace("\n",""))
def l():return list(sys.stdin.readline().replace("\n",""))
def intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def lx():return list(map(lambda x:int(x)*-1,sys.stdin.readline().replace("\n","").split()))
def t():return tuple(map(int,sys.stdin.readline().replace("\n","").split()))

def main():
    n,m,x = i2()
    a = intl()
    c1,c2 = 0,0
    for i in range(x,n+1):
        #print(i)
        if i in a:
            c1 += 1
    for i in range(0,x+1):
        #print(i)
        if i in a:
            c2 += 1
    print(min(c1,c2))
if __name__ == "__main__":
    main()

Submission status: Accepted

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

li=0

for i in range(X):
  if i in A:
    li+=1
print(min(li,M-li))

Submission status: Accepted

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

li=0
ri=0

for i in range(X):
  if i in A:
    li+=1
for i in range(X,N):
  if i in A:
    ri+=1
print(min(li,ri))

Submission status: Accepted

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

dic=[]

cnt_r=0
cnt_l=0
for n in range(1,N):
  if n>X and n in A:
    cnt_r=cnt_r+1
  elif n<=X and n in A:
    cnt_l=cnt_l+1

print(min(cnt_r,cnt_l))

Submission status: Accepted

Solution code:
# ABC094B

n, m, x = map(int, input().split())
A = list(map(int, input().split()))
left_cost = right_cost = 0
for a in A:
    if a < x:
        left_cost += 1
    else:
        right_cost += 1
print(min(left_cost, right_cost))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
zero = 0
goal = 0
for i in A:
  if(i <= X):
    zero += 1
  else:
    goal += 1
print(str(min(zero,goal)))

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(X+1,N):
  if i in A:
    c+=1

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

print(min(c,d))

Submission status: Accepted

Solution code:
def multi_input():
    return map(int, input().split())

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

s = [1 if i in A else 0 for i in range(N+1)]
print(min(sum(s[:X]), sum(s[X:])))

Submission status: Accepted

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

Submission status: Accepted

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

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

print(min(cost0, costn))

Submission status: Accepted

Solution code:
import bisect

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

a,b = bisect.bisect_left(A,x),m-bisect.bisect_right(A,x)
print(min(a,b))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
if len([i for i in a if i < x]) < len([i for i in a if i > x]):
    print(len([i for i in a if i < x]))
else:
    print(len([i for i in a if 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:
n,m,x=map(int,input().split())
list=list(map(int,input().split()))
cost0=0
costN=0
for num in list:
	if 0<num<x:
		cost0+=1
	if x<num<n:
		costN+=1
print(min(cost0,costN))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
L = 0
R = 0
for a in A:
    if a < X:
        L += 1
    elif a > 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()))

L_count = 0
R_count = 0

for i in a:
  if i<x:
    L_count += 1
  else:
    R_count += 1
    
print(min(L_count,R_count))

Submission status: Accepted

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

to_0_cost = len([A for A in A_list if A < X])
to_N_cost = len([A for A in A_list if A > X])

ans = min(to_0_cost, to_N_cost)

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_right

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

left = bisect_right(A,X)
right = len(A) - left

print(min(left,right))

Submission status: Accepted

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

Submission status: Accepted

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

s=0
l=0
for i in A:
    if i<X:
        s+=1
    else:
        l+=1
        
print(min(l,s))

Submission status: Accepted

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

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 range(m):
    if a[i] > x:
        break
    y = i+1
for i in range(m):
    if a[-1-i] < x:
        break
    z = i+1
print(min([m-y,m-z]))

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, M, X = MAP()
A = LIST()

cost = [0]*(N+1)

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

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

Submission status: Accepted

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

la.append(X)
la = sorted(la)
la.index(X)

print(min(la.index(X), int(M) - la.index(X)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def resolve():
    n,m,x=map(int, input().split())
    l=list(map(int, input().split()))
    right=0
    left=0
    for i in range(m):
        if l[i]<x:
            left+=1
        else:
            right+=1
    print(min(left,right))
resolve()

Submission status: Accepted

Solution code:
def resolve():
    n,m,x=map(int, input().split())
    l=list(map(int, input().split()))
    l.append(x)
    l.sort()
    if l[0]==x or l[-1]==x:
        print(0)
    else:
        for i in range(m+1):
            if l[i]==x:
                print(min(m-i,i))

resolve()

Submission status: Accepted

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

for i in range(m):
    if ls[i] < x:
        ls2 += [ls[i]]
    else:
        break

ls1 = list(set(ls) - set(ls2))
len1 = len(ls1)
len2 = len(ls2)
if len1 <= len2:
    print(len1)
else:
    print(len2)

Submission status: Accepted

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

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

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

print(min(ans0,ans1))

Submission status: Accepted

Solution code:
n, m, x = [int(n) for n in input().split(' ')]
a = [int(n) for n in input().split(' ')]
cost = [0] * (n + 1)

for i in range(0, m):
    cost[a[i]] = 1

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
ma = lambda : map(int,input().split())
ni = lambda : int(input())
n,m,x = ma()
A =list(ma())
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:
# -*- coding: utf-8 -*-

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
    else:
        break

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-1):
  if A[0] > X or A[M-1] < X:
    print(0)
    break
  elif A[i] < X < A[i+1]:
    print(min(i+1, M-i-1))
    break

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = [int(i) for i in input().split()]
ans = 0
for i in range(m):
    if a[i]>x:
        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()))

r1 = 0
r2 = 0
for a in A:
    if a < X:
        r1 += 1
    else:
        r2 += 1

print(min(r1,r2))

Submission status: Accepted

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

Submission status: Accepted

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

large = []
small = []
for i in a:
    if x < i:
        large.append(i)
    else:
        small.append(i)

print(len(small) if len(small) < len(large) else len(large))

Submission status: Accepted

Solution code:
import numpy as np
import sys

input = sys.stdin.readline


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

left = 0
right = 0
a = list(map(int,input().split()))

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()))
right = 0
left = 0
for a in A:
    if a > X:
        right += 1
    if a < X:
        left += 1

print(min(right, left))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

length = len(A)

for i in range(N+1):
    if A[i]<X:
        front +=1
    else:
        break

back = length - front

if front<back:
    print(front)
else:
    print(back)

Submission status: Accepted

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

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
# input = sys.stdin.readline

def readlines(n):
    for _ in range(n):
        yield map(int, input().split())


def main():
    n, m, x = map(int, input().split())
    a = set(map(int, input().split()))

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

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

    print(min(zeroside, nside))    

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 a:
    if i < x:
        down += 1
    elif i > x:
        up += 1
print(min(up, down))

Submission status: Accepted

Solution code:
def solve():
    N,M,X = map(int, input().split())
    A = list(map(int, input().split()))
    count = 0
    for i in range(M):
        if A[i] > X:
            break
        count += 1
    count2 = 0
    for j in range(count+1,M+1):
        count2 += 1
    print(min(count, count2))

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

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



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


print(min(cnt_1,cnt_2))

Submission status: Accepted

Solution code:
N,M,X = map(int, input().split())
cost = [0] * (N + 1)
A = [int(i) for i in input().split()]
for a in A:
    cost[a] = 1

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_left,bisect_right
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N,M,X=map(int,input().split())
    A=list(map(int,input().split()))
    print(min(bisect_right(A,X),len(A)-bisect_right(A,X)))

if __name__ == '__main__':
    main()

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:
        count += 1
    else:
        break
    
print(min(count, m - count))

Submission status: Accepted

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

    low_count = 0
    high_count = 0
    for i in num_list:
        if i < x:
            low_count += 1
        elif i > x:
            high_count += 1

    print(min(low_count, high_count))

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

def main():
    n, m, x = nm()
    a = nl()

    price = [1 if i in a else 0 for i in range(n)]

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


if __name__ == '__main__':
    main()

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

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

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
k = [x for x in range(X+1,N)]
b = [x for x in range(0,X)]
right = 0
left = 0
for i in range(len(A)):
  if A[i] in k:
    right += 1
  elif A[i] in b:
    left += 1
print(min(right,left))

Submission status: Accepted

Solution code:
def solve():
    N, M, X = map(int, input().split())
    A = [int(a) for a in input().split()]
    left = 0
    right = 0
    for i, a in enumerate(A):
        if a < X: left += 1
        else: right += 1
    print(min(left, right))

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
cnt_r = 0
cnt_l = 0
road = [True]*(n+1)
for i in a:
    road[i] = False
for i in range(x,n+1):
    if not road[i]:
        cnt_r += 1
for i in range(x,-1,-1):
    if not road[i]:
        cnt_l += 1
ans = min(cnt_r,cnt_l)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc094/tasks/abc094_b

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

Submission status: Accepted

Solution code:
import sys
sys.stdin.readline
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
mod=10**9+7

def main():
    N,M,X=MI()
    A=LI()
    temp=0
    import bisect 
    num=bisect.bisect_left(A,X)
    print(min(num,M-num))
        
    


main()

Submission status: Accepted

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

if __name__ == "__main__":
  resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int, input().split())
a = list(map(int, input().split()))
X = x
Y = x
A,B = 0, 0
while X != n:
  X += 1
  if X in a: A += 1

while Y != 0:
  Y -= 1
  if Y in a: B += 1
print(min(A,B))

Submission status: Accepted

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

for i in range(M):
    if A[i] > X:
        r = M-i
        l = i - (1 if i>0 and A[i-1]==X else 0)
        print(min(l,r))
        exit()
print(0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def solve():
    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+1:])))
if __name__=='__main__':
    solve()

Submission status: Accepted

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

x -= 1
l = 0
for i in range(x+1):
    if i in A:
        l += 1
r = 0
for i in range(x, n):
    if i in A:
        r += 1
print(min(l, r))

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

Submission status: Accepted

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

t = 0
for i in range(X+1,N):
    if i in A:
        t += 1
s = 0
for i in range(X-1,-1,-1):
    if i in A:
        s += 1
print(min(t,s))

Submission status: Accepted

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

Submission status: Accepted

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

cst = 0
for a in A:
    if a < X:
        cst += 1
if cst < M - cst:
    print(cst)
else:
    print(M-cst)

Submission status: Accepted

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

mainasu = 0
purasu = 0
for i in range(M):
    if (A[i] < X):
        mainasu += 1
    if(A[i] > X):
        purasu += 1

if (mainasu > purasu):
    print(purasu)
elif(mainasu <= purasu):
    print(mainasu)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 1, 0, -1, 1, -1, -1, 1]
dy = [1, 0, -1, 0, 1, -1, 1, -1]
debugmode = True

n, m, x = MAP()
a = LIST()
ans1 = 0
for i in range(x, n + 1):
    ans1 += 1 if i in a else 0
ans2 = 0
for i in range(x + 1):
    ans2 += 1 if i in a else 0
print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    N, M, X = map(int, readline().split())
    A = list(map(int, readline().split()))
    cost = [0] * (N+1)
    for i in range(M):
        cost[A[i]] += 1
    ans = min(sum(cost[:X]), sum(cost[X+1:]))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

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

sumn = sum(aa[x+1:])
sum0 = sum(aa[:x])

print(min(sumn,sum0))

Submission status: Accepted

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

R = [0] * (N + 1)
for i in A:
    R[i] = 1

for i in range(0,X + 1):
    S1 += R[i]

for i in range(X + 1,N + 1):
    S2 += R[i]

print(min(S1,S2))

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc094/tasks/abc094_b
n, m, x = map(int, input().split())

boxes = [0] * (n + 1)
nums = [int(i) for i in input().split()]
for num in nums:
    boxes[num] = 1

left = sum(boxes[:x])
right = sum(boxes[x:])
ans = min(left, right)
print(ans)

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
l=[]
r=[]
if x<a[0] or x>a[m-1]:
  print(0)
else:
  for i in range(m):
    if a[i]<x:
      l.append(a[i])
    else:
      r.append(a[i])
  print(min(len(l),len(r)))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
s = input().rstrip().split(' ')
counta = 0
countb = 0
for i in range(M):
  if int(s[i]) > X and int(s[i]) < N:
    counta += 1
for j in range(M):
  if int(s[j]) < X:
    countb += 1
count = min(counta, countb)
print(count)

Submission status: Accepted

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

Submission status: Accepted

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

fullSet = []
for i in range(N + 1):
    if i in A:
        fullSet.append(1)
    else:
        fullSet.append(0)

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, math
sys.setrecursionlimit(10 ** 6)
from collections import deque, defaultdict, Counter
from operator import itemgetter

def main():
    N, M, X = map(int, sys.stdin.readline().rstrip().split())
    A = list(map(int, sys.stdin.readline().rstrip().split()))
    
    idx = -1
    for i in range(M+1):
        if A[i] < X:
            idx = i
        else:
            break
    
    print(min(len(A[:idx+1]), len(A[idx+1:])))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split(" "))
A = [int(i) for i in input().split(" ")]
low = [0]*(N+1)

for i in A:
    low[i]=1

count1 = 0
count2 = 0

x=X
while(x!=0):
    count1+=low[x]
    x-=1
x=X
while(x!=N):
    count2+=low[x]
    x+=1
if count1<count2:
    print(count1)
else:
    print(count2)

Submission status: Accepted

Solution code:
a,b,c = map(int,input().split())
n_list = list(map(int,input().split()))
ans_1 = 0
ans_2 = 0

for i in n_list:
  if i >=c and i <=a:
    ans_1+=1
    
for i in n_list:
  if i >=0 and i <=c:
    ans_2+=1

print(min(ans_1,ans_2))

Submission status: Accepted

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

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

P0 = 0

for i in A:
    if i < x:
        P0 += 1
    else:
        break

ans = min(P0, m - P0)
print(ans)

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+1, n):
    if i in A:
        cnt1 += 1
for j in range(x-1, 0, -1):
    if j in A:
        cnt2 += 1
print(min(cnt1, cnt2))

Submission status: Accepted

Solution code:
N,M,X,*A=map(int,open(0).read().split())

I=lambda p,q:p.index(q)

if X in A:
    print(min(I(A,X),M-I(A,X)-1))
else:
    A.append(X)
    A=sorted(A)
    print(min(I(A,X),M-I(A,X)))

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

print(min(l,r))

Submission status: Accepted

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

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

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

print(min(count1, count2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
icase=0
if icase==0:
    from bisect import bisect
    n,m,x=map(int,input().split()) 
    a=list(map(int,input().split()))
    i=bisect(a,x)
    print(min(i,m-i))