Problem:


Score : 200 points

Problem Statement

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

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

Find the minimum cost incurred before reaching the goal.

Constraints

1 \leq N \leq 100

1 \leq M \leq 100

1 \leq X \leq N - 1

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

A_i \neq X

All values in input are integers.

Input

Input is given from Standard Input in the following format:

N M X
A_1 A_2 ... A_M

Output

Print the minimum cost incurred before reaching the goal.

Sample Input 1

5 3 3
1 2 4

Sample Output 1

1

The optimal solution is as follows:

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

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

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

In this case, the total cost incurred is 1.

Sample Input 2

7 3 2
4 5 6

Sample Output 2

0

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

Sample Input 3

10 7 5
1 2 3 4 6 8 9

Sample Output 3

3



Sample input:
5 3 3
1 2 4


Sample output:
1

Submission status: Accepted

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

if N == X or 0 == X:
    print(0)

else:
    s_cost = 0
    e_cost = 0
    for i in range(0,X):
        if i in A:
            s_cost += 1
    for i in range(X,N):
        if i in A:
            e_cost += 1
    print(min(s_cost,e_cost))

Submission status: Accepted

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

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

Submission status: Accepted

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

g=list(map(int, input().split()))
r=0
l=0
for i in range(m):
    if g[i]<x:
        l+=1
    else:
        r+=1

print(min(r,l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
list = input().split()
N = int(list[0])
M = int(list[1])
X = int(list[2])
A = input().split()
A = [int(i) for i in A]

cnt_left,cnt_right = 0,0
for i in range(X,N+1):
    for j in A:
        if j == i:
            cnt_right += 1
for i in range(0,X):
    for j in A:
        if j == i:
            cnt_left += 1
print(min(cnt_left,cnt_right))

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 x<A[i]:
    count+=1
print(min(count,len(A)-count))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
a=list(map(int,input().split()))
k=0
x=X
y=N-X
c=0
for i in range(M):
    if X<a[i]:
        k+=1
    elif X>a[i]:
        c+=1
print(min(c,k))

Submission status: Accepted

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

xaxis = [1 if i in ag else 0 for i in range(n+1)]
print(min(sum(xaxis[:x+1]), sum(xaxis[x:])))

Submission status: Accepted

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

x_large = len([i for i in range(len(toll)) if toll[i] > x])
x_small = len([i for i in range(len(toll)) if toll[i] < x])

print(min(x_large, x_small))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
i = 0
while a[i] < x and i < m:
    i += 1
print(min(i, m-i))

Submission status: Accepted

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

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

cnt0 = 0

cntn = 0

for i in a:
    if i>x:
        cntn += 1
    else:
        cnt0 += 1

print(min(cnt0,cntn))

Submission status: Accepted

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

cnt = 0
while a[cnt] < x and cnt != m-1:
    cnt += 1
cnt2 = 0
while a[m - 1 - cnt2] > x and m - 1 - cnt2 != 0:
    cnt2 += 1
print(min(cnt,cnt2))

Submission status: Accepted

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

cost_to_reach_0 = len([i for i in A if i < X])
cost_to_reach_N = len([i for i in A if i > X])

print(min(cost_to_reach_0, cost_to_reach_N))

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 a:
    if i < x:
        cost0 += 1
    else:
        costN += 1

print(min(cost0, costN))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = [int(i) for i in input().split()]
loc = 0
for i, j in enumerate(a):
    while j < x:
        loc += 1
        break
print(min(loc, m-loc))

Submission status: Accepted

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

cell = [0] * (N+1)

for a in A:
    cell[a] = 1
print(min(sum(cell[:X]), sum(cell[X:])))

Submission status: Accepted

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

l = [0] * n
for c in a:
  l[c] = 1

print(sum(l[x:]) if sum(l[:x]) > sum(l[x:]) else sum(l[:x]))

Submission status: Accepted

Solution code:
n,m,x=map(int, input().split())
a=[int(i) for i in input().split()]
b=[]
for i in a:
    if i>x:
        b.append(0)
    else:
        b.append(1)
print(min(b.count(1),b.count(0)))

Submission status: Accepted

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


def solve(N: int, M: int, X: int, A: "List[int]"):
    L = [0] * (N+1)
    for a in A:
        L[a] = 1
    print(min(sum(L[0:X]),sum(L[X+1:])))

    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, X, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
list_a = list(map(int,input().split()))
goal_0 = 0
goal_N = 0
for i in list_a:
    if i > X:
        break
    goal_0 += 1
for i in list_a[::-1]:
    if i < X:
        break
    goal_N += 1
print(min(goal_0,goal_N))

Submission status: Accepted

Solution code:
def smaller(x, y):
	if x < y: return x
	return y

N, M, X = map(int, raw_input().split())
A = map(int, raw_input().split())
left = 0
right = 0
for i in range(0, X):
	if i in A: left += 1
for i in range(X+1, N+1):
	if i in A: right += 1
print smaller(left, right)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=[int(i) for i in 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:
n,m,x=map(int,input().split())
l=list(map(int,input().split()))+[x]
l1=sorted(l)
i=l1.index(x)
print(min(i,m-i))

Submission status: Accepted

Solution code:
n, m, x = [ int(v) for v in input().split() ]
point_list = [ int(v) for v in input().split() ]
point_left = [ v for v in point_list if v < x ]
point_right = [ v for v in point_list if v > x ]
print(min(len(point_left),len(point_right)))

Submission status: Accepted

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

costs = [0] * (N + 1)

for val in A:
    costs[val] = 1

print(min(sum(costs[0:X]), sum(costs[X:-1])))

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

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

print(min(a, b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

a = 0
b = 0
for i in lst:
    if i < X:
        a += 1
    else:
        b += 1

print (min(a, b))

Submission status: Accepted

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

for i in range(M):
    if X > A[i]:
        number1 += 1
    else:
        number2 += 1

if number1 > number2:
    print(number2)
else:
    print(number1)

Submission status: Accepted

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

'''
for i,c in enumerate(a):
    if X < c:
        print(min(i,M-i))
        break
'''
import bisect
i = bisect.bisect_left(a,X)
print(min(i,M-i))

Submission status: Accepted

Solution code:
_,M,X = list(map(int,input().split()))
a = list(map(int,input().split()))
for i,c in enumerate(a):
    if X < c:
        print(min(i,M-i))
        break

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+1,n+1):
    if i in a:
        right+=1
for j in range(x):
    if j in a:
        left+=1
if right < left:
    print(right)
else:
    print(left)

Submission status: Accepted

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

# 現在位置
_X=X

# コスト
c1=c2=0

# 目的地に向かって1ずつ動かす（X->N）
for i in range(N-X):
  # 移動
  _X+=1

  # 料金所があればコストを加算
  if l.count(_X)>0:
    c1+=1

# 現在位置をリセット
_X=X

# 目的地に向かって1ずつ動かす（X->0）
for i in range(X-0):
  # 移動
  _X-=1

  # 料金所があればコストを加算
  if l.count(_X)>0:
    c2+=1

# コストが小さい方を出力
print(min(c1,c2))

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 A:
    if i < X:
        cost0 += 1
    else:
        costN += 1
print(min(cost0, costN))

Submission status: Accepted

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


def solve(N: int, M: int, X: int, A: "List[int]"):
    l, r = 0, 0
    for a in A:
        if a < X:
            l += 1
        else:
            r += 1
    ret = min(l, r)
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    M = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(M) ]  # type: "List[int]"
    solve(N, M, X, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
i = 0
cnt = 0
while A[i] < X:
	cnt += 1
	i += 1
if A[i] == X:
	opp = M - cnt -1
else:
	opp = M - cnt
print(min(cnt, opp))

Submission status: Accepted

Solution code:
###############################################################################

from sys import stdout
from bisect import bisect_left as binl
from copy import copy, deepcopy
from collections import defaultdict


mod = 1


def intin():
    input_tuple = input().split()
    if len(input_tuple) <= 1:
        return int(input_tuple[0])
    return tuple(map(int, input_tuple))


def intina():
    return [int(i) for i in input().split()]


def intinl(count):
    return [intin() for _ in range(count)]


def modadd(x, y):
    global mod
    return (x + y) % mod


def modmlt(x, y):
    global mod
    return (x * y) % mod


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


def combination(x, y):
    assert(x >= y)

    if y > x // 2:
        y = x - y

    ret = 1

    for i in range(0, y):
        j = x - i
        i = i + 1

        ret = ret * j
        ret = ret // i

    return ret


def get_divisors(x):
    retlist = []
    for i in range(1, int(x**0.5) + 3):
        if x % i == 0:
            retlist.append(i)
            retlist.append(x // i)
    return retlist


def get_factors(x):
    retlist = []
    for i in range(2, int(x**0.5) + 3):
        while x % i == 0:
            retlist.append(i)
            x = x // i
    retlist.append(x)
    return retlist


def make_linklist(xylist):
    linklist = {}
    for a, b in xylist:
        linklist.setdefault(a, [])
        linklist.setdefault(b, [])
        linklist[a].append(b)
        linklist[b].append(a)
    return linklist


def calc_longest_distance(linklist, v=1):
    distance_list = {}
    distance_count = 0
    distance = 0
    vlist_previous = []
    vlist = [v]
    nodecount = len(linklist)

    while distance_count < nodecount:
        vlist_next = []
        for v in vlist:
            distance_list[v] = distance
            distance_count += 1
            vlist_next.extend(linklist[v])
        distance += 1
        vlist_to_del = vlist_previous
        vlist_previous = vlist
        vlist = list(set(vlist_next) - set(vlist_to_del))

    max_distance = -1
    max_v = None
    for v, distance in distance_list.items():
        if distance > max_distance:
            max_distance = distance
            max_v = v

    return (max_distance, max_v)


def calc_tree_diameter(linklist, v=1):
    _, u = calc_longest_distance(linklist, v)
    distance, _ = calc_longest_distance(linklist, u)
    return distance


class UnionFind:

    def __init__(self, n):
        self.parent = [i for i in range(n)]

    def root(self, i):
        if self.parent[i] == i:
            return i
        self.parent[i] = self.root(self.parent[i])
        return self.parent[i]

    def unite(self, i, j):
        rooti = self.root(i)
        rootj = self.root(j)
        if rooti == rootj:
            return
        if rooti < rootj:
            self.parent[rootj] = rooti
        else:
            self.parent[rooti] = rootj

    def same(self, i, j):
        return self.root(i) == self.root(j)


###############################################################################


def main():
    n, m, x = intin()
    alist = intina()

    left = 0
    right = 0

    for a in alist:
        if a < x:
            left += 1
        else:
            right += 1

    print(min(left, right))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
print(min(len(list(filter(lambda m:0<=m<=x, a))),len(list(filter(lambda m:x<=m<=n, a)))))

Submission status: Accepted

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

List = list(map(int, input().split()))
List.append(x)

List.sort()

cnt = List.index(x)

print(cnt if cnt < m-cnt else m-cnt)

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([j for j in a if j > x])))

Submission status: Accepted

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

Submission status: Accepted

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

B = [0]*(N+1)
for i in range(N+1):
    if i in A:
        B[i] += 1
cost = min(sum(B[:X]),sum(B[X:]))

print(cost)

Submission status: Accepted

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

Submission status: Accepted

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

cnt0 = 0
cntn = 0
for item in lst:
    if item < x:
        cnt0 += 1
    elif item > x:
        cntn += 1
print(min(cnt0, cntn))

Submission status: Accepted

Solution code:
a, b, c = (int(i) for i in input().split())  
l = [int(i) for i in input().split()] 
print(min(sum([1 for i in l if i > c]),sum([1 for i in l if i < c])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

S=n[0:X]
B=n[X:]
print(min(sum(S),sum(B)))

Submission status: Accepted

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

Submission status: Accepted

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

print(min(a,b))

Submission status: Accepted

Solution code:
from collections import defaultdict
import math


def kari():
    map(int, input().split())
    list(map(int, input().split()))
    math.ceil()

def main():
    num, coust_num, start = map(int, input().split())
    data = set(list(map(int, input().split())))

    left = 0
    for i in range(1, start):
        if i in data:
            left += 1


    right = 0
    for i in range(start + 1, num):
        if i in data:
            right += 1

    print(min(right, left))








if __name__ == '__main__':
    main()

Submission status: Accepted

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

fee_to_head = len(list(filter(lambda n: n < X, A)))
fee_to_tail = len(list(filter(lambda n: n > X, A)))
print(min(fee_to_head, fee_to_tail))

Submission status: Accepted

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

for i in l:
    a[i] = 1

print(min(sum(a[0:x]),sum(a[x+1:n])))

Submission status: Accepted

Solution code:
import sys, os
import bisect

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    n,m,x = f()
    a = f()

    idx = bisect.bisect_left(a, x)
    print(min(idx, m - idx))

solve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
here = 0
if x < a[0] or a[m-1] < x:
  ans = 0
else:
  for i in range(m-1):
    if a[i] < x < a[i+1]:
      here = i
      ans = min(len(a[:here+1]),len(a[here+1:]))
print(ans)

Submission status: Accepted

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

for i in a:
    A[i]+=1
print(min(sum(A[:x]),sum(A[x+1:])))

Submission status: Accepted

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

Submission status: Accepted

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

print(min(Lcnt,Rcnt))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
box_l, _, start = map(int, input().split())
cost_arr = list(map(int, input().split()))
left = len([num for num in cost_arr if num < start])
right = len([num for num in cost_arr if num > start])
print(min(left, right))

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:
        p=i
        break
if x<a[0]:
    p=0
print(min(p,m-p))

Submission status: Accepted

Solution code:
def main():
  N, M, X = [int(x) for x in input().split()]
  costs = [0] * (N + 1)
  for x in [int(x) for x in input().split()]:
    costs[x] = 1

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


if __name__ == "__main__":
  main()

Submission status: Accepted

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

a.append(x)
a.sort()
y=a.index(x)

print(min(len(a[:y]),len(a[y+1:])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:

def read_input():
    n, m, x = map(int, input().split())
    costs = [0] * (n + 1)

    alist = map(int, input().split())
    for a in alist:
        costs[a] = 1

    return n, m, x, costs


def submit():
    n, m, x, costs = read_input()


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


if __name__ == '__main__':
    submit()

Submission status: Accepted

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

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

x = 0
y = 0
for a in range(0,N):
  if a in A and a < X:
    x += 1
  elif a in A and X < a:
    y += 1
  else:
    continue

print(x if x < y else y)

Submission status: Accepted

Solution code:
# 2019/05/02
# AtCoder Beginner Contest 094 - B

# Input 
n, m, x = map(int,input().split())
a = list(map(int, input().split()))
l = 0
r = 0
for i in range(m):
    if x > a[i]:
        l += 1
    else:
        r += 1

# Output
print(min(l, r))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = [int(i) for i in input().split()]
A.sort()
i = 0
while A[i] < X:
    i += 1
if i > M-i:
    print(M-i)
else:
    print(i)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# ABC094B - Toll Gates
n, m, x = list(map(int, input().rstrip().split()))
lst = list(map(int, input().rstrip().split()))
lst.append(x)
lst = sorted(lst)
print(min(len(lst[: lst.index(x)]), len(lst[lst.index(x) + 1 :])))

Submission status: Accepted

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

l, r = 0, 0
for ai in a:
    if ai < 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()))
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()))
count=0
for a in A:
    if a<X:
        count+=1
print(min(count,M-count))

Submission status: Accepted

Solution code:
import sys
from collections import Counter

n, m, x = map(int, input().split())
a_list = list(map(int, input().split()))
math_list = []

for i in range(n):
    if i in a_list:
        math_list.append(1)
    else:
        math_list.append(0)
#print(n, x, a_list, math_list)
print(min(sum(math_list[0:x]), sum(math_list[x+1::])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N,M,X = map(int, input().split())
A = list(map(int, input().split()))
sorted_A = sorted(A)
for i in range(M):
    if A[i]>=X:
        cnt = i
        break
ans1 = len(A[cnt:])
ans2 = len(A[:cnt])
ans = min(ans1,ans2)
print(ans)

Submission status: Accepted

Solution code:
def main():
	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
		elif a > X:
			r += 1
	print(min(l, r))


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
a_list = [int(i) for i in input().split()]
result1 = 0
result2 = 0
for item in a_list:
	if item >X:
		result1+=1
	elif item <X:
		result2+=1
print(min(result1,result2))

Submission status: Accepted

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

Submission status: Accepted

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

temp1, temp2 = 0, 0
for i in A:
    if 0 < i < X:
        temp1 += 1
    elif X < i < N:
        temp2 += 1
print(min(temp1, temp2))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np
input = sys.stdin.readline

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

a = np.array(a)


print(min(sum(a>x), sum(a<x)))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
less = list(filter(lambda l:l<x, a))
more = list(filter(lambda l:l>x, a))
print(min(len(less), len(more)))

Submission status: Accepted

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

goal_0 = 0
goal_N = 0

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

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

if goal_0 >= goal_N:
    print(goal_N)
else:
    print(goal_0)

Submission status: Accepted

Solution code:
N,M,X = map(int, input().split())
A = list(map(int, input().split()))
sorted_A = sorted(A)
for i in range(M):
    if A[i]>=X:
        cnt = i
        break
ans1 = len(A[cnt:])
ans2 = len(A[:cnt])
ans = min(ans1,ans2)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

b = a
for i in range(1,x,1):
  b = b - {i}

c = a
for i in range(x+1,n,1):
  c = c - {i}

print(min(len(b),len(c)))

Submission status: Accepted

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

Submission status: Accepted

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

for i in a:
    if i < x:
        to_0 += 1
    else:
        to_n += 1

ans = min(to_0, to_n)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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