Problem:


Score : 200 points

Problem Statement

There are N + 1 squares arranged in a row, numbered 0, 1, ..., N from left to right.

Initially, you are in Square X.
You can freely travel between adjacent squares. Your goal is to reach Square 0 or Square N.
However, for each i = 1, 2, ..., M, there is a toll gate in Square A_i, and traveling to Square A_i incurs a cost of 1.
It is guaranteed that there is no toll gate in Square 0, Square X and Square N.

Find the minimum cost incurred before reaching the goal.

Constraints

1 \leq N \leq 100

1 \leq M \leq 100

1 \leq X \leq N - 1

1 \leq A_1 < A_2 < ... < A_M \leq N

A_i \neq X

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M X
A_1 A_2 ... A_M

Output

Print the minimum cost incurred before reaching the goal.

Sample Input 1

5 3 3
1 2 4

Sample Output 1

1

The optimal solution is as follows:

First, travel from Square 3 to Square 4. Here, there is a toll gate in Square 4, so the cost of 1 is incurred.

Then, travel from Square 4 to Square 5. This time, no cost is incurred.

Now, we are in Square 5 and we have reached the goal.

In this case, the total cost incurred is 1.

Sample Input 2

7 3 2
4 5 6

Sample Output 2

0

We may be able to reach the goal at no cost.

Sample Input 3

10 7 5
1 2 3 4 6 8 9

Sample Output 3

3



Sample input:
5 3 3
1 2 4


Sample output:
1

Submission status: Accepted

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

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

for i in range(x+1, n):
    if a.count(i) == 1:
        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 = [i for i in A if i < X]
h = [i for i in A if i > X]
print(min(len(l), len(h)))

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

for i in reversed(range(X)):
    if i in A:
        cost2 += 1

print(min(cost1, cost2))

Submission status: Accepted

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

Submission status: Accepted

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

cost = 0
temp1 = 0
temp2 = 0
for i in range(M):
    if X < A[i] and N > A[i]:
        temp1 += 1
for i in reversed(range(M)):
    if X > A[i] and 0 < A[i]:
        temp2 += 1
cost = min(temp1, temp2)
print(cost)

Submission status: Accepted

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

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

print(min(M - num, num))

Submission status: Accepted

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

*l, = filter(lambda x:(x<X), A)
*r, = filter(lambda x:(X<x), A)

print(min(len(l), len(r)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
input_front = input().split(" ")
input_back = input().split(" ")
n, x = int(input_front[0]), int(input_front[2])


def problemB(n, x):
    masu_list = [0] * (n+1)
    adder = input_back

    for i in adder:
        masu_list[int(i)] = 1
    front = sum(masu_list[:x])
    back = sum(masu_list[x+1:])

    if front <= back:
        return print(front)

    else:
        return print(back)


problemB(n, x)

Submission status: Accepted

Solution code:
# coding: utf-8
N, M, X = map(int, input().split())
l = list(map(int, input().split()))
pre = len([i for i in l if i > X])
print(pre if pre < len(l) - pre else len(l) - pre)

Submission status: Accepted

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

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

print(c1 if c1 < c2 else c2)

Submission status: Accepted

Solution code:
n,m,x,*a=map(int,open(0).read().split());c=sum([0<=e<=x for e in a]);print(min(c,len(a)-c))

Submission status: Accepted

Solution code:
import sys


fin = sys.stdin.readline
N, M, X = [int(elem) for elem in fin().split()]
A_list = [int(elem) for elem in fin().split()]
is_cost_taken = [False] * N
for A in A_list:
    is_cost_taken[A] = True

min_total_cost = min(
    sum(is_cost_taken[i] for i in range(X)),
    sum(is_cost_taken[i] for i in range(X + 1, N))
)
print(min_total_cost)

Submission status: Accepted

Solution code:
import bisect

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

i=bisect.bisect_left(a,X)
print(min(i,M-i))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N,M,X=map(int, input().split())
l,r=0,0
for a in map(int, input().split()):
	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()))
a = sorted(a + [x])
ind = a.index(x)
print(min(len(a[:ind]), len(a[ind+1:])))

Submission status: Accepted

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

lower = len([a for a in As if a < X])
upper = len([a for a in As if X < a])

ans = min(lower, upper)
print(ans)

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
li = map(int, input().split())
l, r = 0, 0
for i in li:
  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()))

temp_res = 0
for a in A:
    if a > X:
        break
    temp_res += 1

res = min(temp_res, M - temp_res)
print(res)

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 a:
    if i >= x:
        c1 += 1
    else:
        c2 += 1
if x == 0 or x == n :
    print(0)
else:
    print(min(c1,c2))

Submission status: Accepted

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

Submission status: Accepted

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

import bisect

idx = bisect.bisect_right(A, X)


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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#094 B
N,M,X= map(int,input().split())
A = [int(j) for j in input().split()]
left =0
right = 0

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

Submission status: Accepted

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

Submission status: Accepted

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

M = [0]*101
ans1 = 0
ans2 = 0
for a in A:
    M[a] = 1
for i in range(x,n+1):
    ans1 += M[i]
for j in range(x,-1,-1):
    ans2 += M[j]
print(min(ans1,ans2))

Submission status: Accepted

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

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

ans = []

c = 0

for i in range(N):
  if i == X:
    ans.append(c)
    c = 0
    continue
  if i in A:
    c += 1
  if i == N-1:
    ans.append(c)
print(min(ans))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
cnt = 0
min = 0
cnt_2 = 0
lists = list(range(N + 1))
for i in range(X, N + 1):
    for j in range(len(A)):
        if i == 0 or i == N or i == X:
            continue
        elif i == A[j]:
            cnt += 1
for m in range(X, -1, -1):
    for n in range(len(A)):
        if m == 0 or m == N or m == X:
            continue
        elif m == A[n]:
            cnt_2 += 1
if cnt > cnt_2:
    min = cnt_2
elif cnt_2 > cnt:
    min = cnt
print(min)

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = [int(i) for i in input().split()]
n_1 = sum(X > x for x in A)
n_2 = sum((N - x) * (X - x) < 0 for x in A)
ans = min(n_1, n_2)
print(ans)

Submission status: Accepted

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

num = 0
for i in A:
    if i<X:
        num += 1
    else: break

print(min(num, M-num))

Submission status: Accepted

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

l = [0]*(N+1)
A = list(map(int, input().split()))
for a in A:
    l[a] = 1

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = [ int(i) for i in input().split() ]
import bisect
a = sorted(a)
cn1 = bisect.bisect_left(a,x)
cn2 = len(a) - cn1
print(min(cn1,cn2))

Submission status: Accepted

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

l = 0
r = 0

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
lst = [0]*(N+1)
cost_idx = map(int, input().split())
for i in cost_idx:
    lst[i] = 1
left = sum(lst[:X+1])
right = sum(lst[X:])
print(min(left, right))

Submission status: Accepted

Solution code:
N, M, X = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
lower = 0
higher = 0
for a in A:
    lower += 1 if a < X else 0
    higher += 1 if a > X else 0
print(min(lower, higher))

Submission status: Accepted

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

lower = 0
higher = 0
for i in range(0, N):
    lower += Z[i] if i < X else 0
    higher += Z[i] if i > X else 0
print(min(lower, higher))

Submission status: Accepted

Solution code:
N, M, X = (int(x) for x in input().split())
A = [int(x) for x in input().split()]
Z = [0] * N
for a in A:
    Z[a] = 1
lower = 0
for i in range(0, X+1):
    lower += Z[i]
higher = 0
for i in range(X, N):
    higher += Z[i]
print(min(lower,higher))

Submission status: Accepted

Solution code:
import bisect
n,m,x=map(int,input().split())
A=[int(x) for x in input().split()]
i=bisect.bisect_left(A,x)
j=bisect.bisect_right(A,x)
print(min(i,m-j))

Submission status: Accepted

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

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

import bisect

l = bisect.bisect_left(a, x)

print(min(l, m-l))

Submission status: Accepted

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

Submission status: Accepted

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

As = list(map(int,input().strip().split()))

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

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

Submission status: Accepted

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

c1 = 0
c2 = 0

for i in a:
	if x < i:c1+=1
	if i < x:c2+=1

print(min(c1,c2))

Submission status: Accepted

Solution code:
from sys import stdin
N,M,X=[int(x) for x in stdin.readline().rstrip().split()]
data=[int(x) for x in stdin.readline().rstrip().split()]
cost_l=0
cost_r=0
for i in data:
    if i < X:
        cost_l+=1
    else:
        cost_r+=1
print(min(cost_l,cost_r))

Submission status: Accepted

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

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 range(X):
  for j in A:
    if i == j:
      S+=1

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

print(S if S <= L else L)

Submission status: Accepted

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

l1 = [x for x in range(1, X) if x in A]
l2 = [x for x in range(X + 1, N + 1) if x in A]
print(min(len(l1), len(l2)))

Submission status: Accepted

Solution code:

# -*- coding: utf-8 -*-

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

cost1 = 0
cost2 = 0

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

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

print(min(cost1,cost2))

Submission status: Accepted

Solution code:
import bisect
N, M, X = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
 
index = bisect.bisect_right(A, X)
if X in A:
  print(max(0, min(index - 1, len(A) - index)))
else:
  print(max(0, min(index, len(A) - index)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

lft = 0
rgt = 0

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

Submission status: Accepted

Solution code:
import bisect
n, m, x = map(int, input().split())
a = [int(i) for i in input().split()]
print(min(len(a[bisect.bisect_right(a, x):]), len(a[:bisect.bisect_right(a, x)])))

Submission status: Accepted

Solution code:
import bisect

n, m, x = [int(item) for item in input().split()]
a = [int(item) for item in input().split()]

index = bisect.bisect(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()))
c = 0
for i in range(M):
    if A[i] < X:
        c += 1
print(min((len(A) - c),c))

Submission status: Accepted

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

ans = count_right if count_left > count_right else count_left
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin
n,m,x = [int(_) for _ in stdin.readline().rstrip().split()]
data = [int(_) for _ in stdin.readline().rstrip().split()]
blocks=[0]*(n+1)
for i in data:
    blocks[i]=1
print(min(sum(blocks[:x]), sum(blocks[x:])))

Submission status: Accepted

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

c1 = len(list(filter(lambda A: A < X, As)))
c2 = len(list(filter(lambda A: A > X, As)))
ans = min(c1, c2)

print(ans)

Submission status: Accepted

Solution code:
a = list(map(int,input().split()))
N = a[0]
M = a[1]
X = a[2]
cost = 0
line = list(map(int,input().split()))
for i in range(M):
    if X <= line[i]:
        cost = i
        break
print(str(min(cost, len(line) - cost)))

Submission status: Accepted

Solution code:
def solve(string):
    n, m, x, *a = map(int, string.split())
    lows = sum([_a < x for _a in a])
    return str(min(lows, m - lows))


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

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
print(min(count,m-count))

Submission status: Accepted

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

Submission status: Accepted

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

b = len(set(range(0, x)) & set(a))

print(min(b, m-b))

Submission status: Accepted

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

left = len(set(range(0, x)) & set(a))
right = len(set(range(x, n)) & set(a))

print(min(left, right))

Submission status: Accepted

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

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

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

print(min(left, right))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
ma=[i for i in A if i<X]
Ma=list(set(A)^set(ma))
cost=min(len(ma),len(Ma))
print(cost)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

As = list(map(int, input().split()))
A_set = set(As)

def count(f, t, A_set):
    ret = 0
    for i in range(f, t + 1):
        ret += i in A_set
    return ret

ans1 = count(0, X, A_set)
ans2 = count(X, N, A_set)
print(min(ans1, ans2))

Submission status: Accepted

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

Submission status: Accepted

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

l = [0] * (n + 1)
for i in range(m):
    l[a[i]] = 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()))
for i in range(M):
    if A[i] > X: break
print(min(i,len(A)-i))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
Al=list(map(int,input().split()))
Al.append(X)
i=sorted(Al).index(X)
print(i if i<M-i else M-i)

Submission status: Accepted

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

for i in range(X):
    if i in A:
        cnt0 += 1

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

print(min(cnt0, cntN))

Submission status: Accepted

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

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

Submission status: Accepted

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

left = 0
right = 0
for a in Ai:
    if a < X:
        left += 1
    if a > X:
        right += 1

print(min(left, right))

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import sys


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

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

Submission status: Accepted

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

Submission status: Accepted

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

arr = []
for i in range(n + 1):
    if i not in A:
        arr.append(0)
    else:
        arr.append(1)

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

Submission status: Accepted

Solution code:
def solve():
    N,M,X=map(int,input().split())
    A=list(map(int,input().split()))
    c1 = len(list(filter(lambda e:e<X, A)))
    c2 = len(list(filter(lambda e:e>X, A)))
    return min(c1,c2)

print(solve())

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
c1,c2=0,0
for i in a:
  if 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()))
answer = 0

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

print(min(answer, m-answer))

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)+1:]), len(a[:a.index(x)])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

y = bisect.bisect_left(a,x)
print(min(y,len(a)-y))

Submission status: Accepted

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

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

grid = [0] * n

for i in range(1,n+1):
	if i in A:
		grid[i-1] = 1
        
x_0 = grid[:x].count(1)
x_n = grid[x:].count(1)

print(min(x_0,x_n))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
#print(N)
num = list(map(int, input().split()))
#print(str_)
s = [i for i in num if i > X]
p = len(s)
q = M-p
if p >q:
    print(q)
else:
    print(p)

Submission status: Accepted

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

print(min(cost1,cost2))

Submission status: Accepted

Solution code:
def toll_gates(N: int, M: int, X: int, A: list) -> int:
    to0 = sum(1 for a in A if a < X)
    toN = sum(1 for a in A if a > X)
    return min(to0, toN)


if __name__ == "__main__":
    N, M, X = map(int, input().split())
    A = list(map(int, input().split()))
    ans = toll_gates(N, M, X, A)
    print(ans)

Submission status: Accepted

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

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:
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(len(A[x:]), len(A[:x])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
a = input().split()
cost1 = 0
cost2 = 0
sum_cost = 0

for i in range(M):
  a[i] = int(a[i])
  sum_cost += 1
  if(0< a[i] <X):
   cost1 += 1
 
cost2 = sum_cost - cost1
if(cost1 < cost2):
  print(cost1)
else:
  print(cost2)

Submission status: Accepted

Solution code:
# coding: utf-8
N, M, X = map(int, input().split())
A = sorted(list(map(int, input().split())))
cst = [0, 0]
for a in A:
    if a < X:
        cst[0] += 1
    else:
        cst[1] += 1
print(min(cst))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
ri = lambda: int(input())
rl = lambda: list(map(int,input().split()))
rr = lambda N: [ri() for _ in range(N)]
YN = lambda b: print('YES') if b else print('NO')
yn = lambda b: print('Yes') if b else print('No')
OE = lambda x: print('Odd') if x%2 else print('Even')
INF = 10**18

N,M,X=rl()
A=rl()
import bisect
ind = bisect.bisect_left(A,X)
print(min(ind,M-ind))

Submission status: Accepted

Solution code:
_,M,X = map(int,input().split())
As = [x for x in map(int,input().split()) if x>X]
l = len(As)
print(min(M-l,l))

Submission status: Accepted

Solution code:
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N, M, X = map(int, input().split())
    A = list(map(int, input().split()))
    tmp = len(list(filter(lambda x: x < X, A)))
    print(min(tmp, M-tmp))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc094/tasks/abc094_b
n, m, x = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
masu = [0] * (n + 1)
for r in a:
    masu[r] = 1
print(min(sum(masu[0:x + 1]), sum(masu[-n - 1 + x:])))

Submission status: Accepted

Solution code:
N,M,X=(int(i) for i in input().split())
L=[int(i) for i in input().split()]
a=0
b=0
for i in range(M):
  if L[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(i) for i in input().split()]
count = 0
for i in range(M):
    count += 1 if A[i] < X else 0
print(min(count, len(A) - count))

Submission status: Accepted

Solution code:
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))

Submission status: Accepted

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

import itertools
import collections
import bisect

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

    pos = bisect.bisect_left(A, X)
    # print(A[:pos])
    # print(A[pos:])
    print(min(len(A[:pos]), len(A[pos:])))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect

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

median = m/2
point = bisect.bisect_right(A, x)

if point >= median:
    print(m - point)
else:
    print(point)

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_right

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


if __name__ == '__main__':
  main()

Submission status: Accepted

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

while A[i] < X:
    i += 1

answer = min(i,len(A) - i)

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

ans=min(sum(c[0:x]),sum(c[x:n]))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
A = list(map(int,input().split()))
left = []
right = []
for i in A:
    if i <= x:
        left.append(i)
    else:
        right.append(i)
print(min(len(left),len(right)))

Submission status: Accepted

Solution code:
# encoding:utf-8
import copy
import numpy as np
import random

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

a = [int(i) for i in input().split()]



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

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

print(min(cost_l,cost_r))

Submission status: Accepted

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

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

#print(N, M, X)
#print(A)
num_left = len(list(filter(lambda a: X > a, A)))
num_right = len(list(filter(lambda a: X < a, A)))
#print(num_left)
#print(num_right)
result = num_left if num_left < num_right else num_right

print(result)

Submission status: Accepted

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

T = [0]*(N+1)
for a in A:
  T[a] = 1
print min(sum(T[:X]), sum(T[X:]))

Submission status: Accepted

Solution code:
_, m, x = map(int, input().split())
a = list(map(int, input().split()))
count = 0
for i in a:
    if i > x:
        break
    count += 1
print(min(count, m - count))