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:
# coding:utf-8

import sys


input = sys.stdin.readline


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


N, M, X = inpl()
A = inpl()

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

print(min(cnt, M - cnt))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
pre, fo = 0, 0
for i in A:
    if i < X:
        pre += 1
    else:
        fo += 1

print(min(pre, fo))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from sys import stdin


def main() -> None:
    n, m, x = [int(s) for s in input().split()]
    up = down = 0
    for i in range(m):
        ai = int(next_str())
        if ai < x:
            down += 1
        else:
            up += 1

    print(min(up, down))


def next_str() -> str:
    result = ""
    while True:
        tmp = stdin.read(1)
        if tmp.strip() != "":
            result += tmp
        elif tmp != '\r':
            break
    return result


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,_,x=map(int,input().split())
l=list(map(int,input().split()))
print(min(sum(a>x for a in l),sum(a<x for a in l)))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

l = r = 0
for a in aa:
    if a < x:
        l = l + 1
    else:
        r = r + 1
print(min(l, r))

Submission status: Accepted

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

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

hidari = [i for i in A if i<=X]
migi = [i for i in A if X<=i]
print(min(len(hidari), len(migi)))

Submission status: Accepted

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

if x >= max(a) or x <= min(a):
    print(0)
else:
    cnt = 0
    for i in range(m):
        if a[i] > x:
            cnt += 1
    print(min(cnt,len(a)-cnt))

Submission status: Accepted

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

x_more = [x < a_i for a_i in a]

print(min(x_more.count(True), x_more.count(False)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
B - Toll Gates
"""

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

value = []
for part in input().split():
    value.append(int(part))

left = 0
right = 0
for i in value:
    if 1 <= i and i < x:
        left += 1
    if x < i and i <= n:
        right += 1

print(min(left, right))

Submission status: Accepted

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

arr = [0]*(N+1)

for a in A:
    arr[a] = 1

ans = min(sum(arr[1:X]), sum(arr[X:-1]))

print(ans)

Submission status: Accepted

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

Y = X
S1 = []
while Y < N:
    Y += 1
    S1.append(Y)

Z = X
S2 = []
while Z > 0:
    Z -= 1
    S2.append(Z)

risuto = []
risuto.append(len(set(A) & set(S1)))
risuto.append(len(set(A) & set(S2)))
print(min(risuto))

Submission status: Accepted

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

result=0

if x>cost_list[m-1] or x<cost_list[0]:
    result=0
else:
    cost_larger_n=sum([1 for i in cost_list if i>x and i<n]) 
    if cost_larger_n <= m-cost_larger_n:
        result=cost_larger_n
    else:
        result=m-cost_larger_n

print(result)

Submission status: Accepted

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

ans1 = 0
ans2 = 0

for i in range(n + 1):
    if i in a:
        if i < x:
            ans1 += 1
        elif i > x:
            ans2 += 1


if ans1 <= ans2:
    print(ans1)
else:
    print(ans2)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
e = [[int(i) for i in input().split()] for i in range(2)]

r = 0
l = 0

for a in e[1]:
    if e[0][2] > a:
        l += 1
    elif e[0][2] < a:
        r += 1

if l <= r:
    print(l)
else:
    print(r)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding:utf-8

INF = float('inf')


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


N, M, X = inpl()
A = inpl()

ans = 0
for i in range(M):
    if X < A[i]:
        break
    ans += 1

if ans > M - ans: ans = M - ans

print(ans)

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=input().split()
a=list(map(int,list(a)))
arr1=list(y for y in a if 0<y<x)
arr2=list(y for y in a if x<y)
print(min(len(arr1),len(arr2)))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=input().split()
a=list(map(int,list(a)))
c=0
d=0
k=x
while (x<n):
    if x in a:
        c+=1
    x+=1
while (0<k):
    if k in a:
        d+=1
    k-=1
print(min(c,d))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
Input = sys.stdin.readline
#Input = input

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

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

Submission status: Accepted

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

fee_st.append(x)
fee_st.sort()
p = fee_st.index(x)

if p < m/2:
    print(p)
else:
    print(m-p)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int, input().split())
fee_list = list(map(int, input().split()))
count = 0
while fee_list[count] <= x:
  count += 1
fee_0 = count
fee_n = m-count
  
ans_0 = fee_0
ans_n = fee_n

print(min(ans_0,ans_n))

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
    else:
        r += 1

print(min(l,r))

Submission status: Accepted

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

ans_l = 0
ans_r = 0
for a in A:
    if a<X:
        ans_l += 1
    else:
        ans_r += 1
        
print(min(ans_l,ans_r))

Submission status: Accepted

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

ans = 0
for i in range(m):
    if x < a[i]:
        ans = min(i, m-i)
        break

print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect
n, m, p = map(int, input().split())
a = list(map(int, input().split()))
print(min(abs(bisect(a, n, 0, len(a))-bisect(a, p, 0, len(a))),
          abs(bisect(a, 0, 0, len(a))-bisect(a, p, 0, len(a)))))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
A.append(X)
A.sort()
flag = False
for i in range(N+1):
  if (A[i] == X):
    flag = True
    break
if flag:
  print(min(len(A[i+1:]),len(A[:i])))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=list(map(int,input().split()))
p=0;q=0
for i in range(x):
  p+=a.count(i)
for j in range(x,n):
  q+=a.count(j)
print(min(p,q))

Submission status: Accepted

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

arr = [0 for _ in range(N+1)]
for x in list(map(int,input().split())):
    arr[x] = 1

print(min(sum(arr[0:X]),sum(arr[X+1:N])))

Submission status: Accepted

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
A.append(X)
A.sort()
m = A.index(X)
n = len(A) - 1 - A.index(X)
if n == 0:
  print(0)
elif m < n:
  print(m)
elif m >= n:
  print(n)

Submission status: Accepted

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

left_a_list = [a for a in a_list if a < x]
right_a_list = [a for a in a_list if a > x]
min_cost = min(len(left_a_list), len(right_a_list))

print(min_cost)

Submission status: Accepted

Solution code:
import numpy as np
N, M, X = map(int, input().split())
fare_arr = np.array(list(map(int, input().split())))
print(min(len(fare_arr[fare_arr<X]), len(N-fare_arr[fare_arr>X])))

Submission status: Accepted

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

count=0
listA.sort()
index=0
while True:
    if listA[index]<x and index<len(listA):
        count+=1
        index+=1
    else:
        break

print(min([count, len(listA)-count]))

Submission status: Accepted

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

Submission status: Accepted

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

cost = 9999999

pass

left_cost = len([a for a in A if a < X])

right_cost = len([a for a in A if a > X])

print(min(left_cost, right_cost))

Submission status: Accepted

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

Submission status: Accepted

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

# 左方向(1からX-1間)のコストを求める
left_cost = 0
for i in range(1, X):
    if i in A:
        left_cost += 1

# 右方向（X+1からN-1間）のコストを求める
right_cost = 0
for i in range(X+1, N):
    if i in A:
        right_cost += 1

if left_cost <= right_cost:
    print(left_cost)
else:
    print(right_cost)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import defaultdict,deque
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inp(): return int(input())
def inpl(): return list(map(int, input().split()))
def inpl_s(): return list(input().split())

N,M,X = inpl()
aa = inpl()
ind = bisect.bisect_left(aa,X)
print(min(ind,M-ind))

Submission status: Accepted

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

leftCost = 0
for place in a:
	if place > x:
		break
	else:
		leftCost += 1

rightCost = m - leftCost

if rightCost > leftCost:
	print(leftCost)
else:
	print(rightCost)

Submission status: Accepted

Solution code:
def smaller(x, y):
	if x < y: return x
	else: 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, M):
	if A[i] < X: left = left + 1
	if A[i] > X: right = right + 1

print smaller(left, right)

Submission status: Accepted

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

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

masu = [0 for _ in range(N+1)]

for i in A:
    masu[i] = 1

L = sum(masu[:X])
R = sum(masu[X+1:N+1])

print(min(L, R))

Submission status: Accepted

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

Submission status: Accepted

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

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

A_0 = [a for a in A if a < X ]
A_N = [a for a in A if a > X ]

print(min(len(A_0), len(A_N)))

Submission status: Accepted

Solution code:
def main17():
    buf = input("");
    bufs = buf.split();
    hai = [];
    for i in range(len(bufs)):
        hai.append(int(bufs[i]));
    buf = input("");
    bufs = buf.split();
    hai2 = [];
    pen = 0;
    for i in range(len(bufs)):
        hai2.append(int(bufs[i]));
    for i in range(len(hai2)):
        if hai[2] < hai2[i]:
            break;
        else:
            pen = pen + 1;
    if pen < len(hai2) / 2:
        print(pen);
    else:
        print((len(hai2) - pen));




if __name__ == '__main__':
    main17()

Submission status: Accepted

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

Submission status: Accepted

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

up=0
down=0

for i in a:
    if i>x:
        up+=1
    else:
        down+=1
print(min(up,down))

Submission status: Accepted

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

up = 0
down = 0

for a in a_s:
    if a > x:
        up += 1
    else:
        down += 1

print(min(up, down))

Submission status: Accepted

Solution code:
from numpy import inf
n, m, x =map(int, input().split())
a = list(map(int, input().split()))
ans=inf
if x<a[0] or a[m-1]<x:
    print(0)
    exit()
for i in range(m-1):
    if a[i]<x<a[i+1]:
        ans=min(ans,min(i+1,m-i-1))
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(M):
  if A[i] < X:
    cnt1 += 1
  else:
    cnt2 += 1

print(min(cnt1,cnt2))

Submission status: Accepted

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

sm = 0
la = 0
for a in A:
  if(int(a) < X):
    sm += 1
  else:
    la += 1

print(min(sm, la))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(X+1):
    count += A.count(i)

ans = min(count, len(A)-count)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


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
        else:
            r += 1

    print(min(l, r))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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


print(min(sum(1 for a in A if a < X), sum(1 for a in A if a > X)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(10000)

# Debug output


def chkprint(*args):
    names = {id(v): k for k, v in inspect.currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg), '???')+' = '+repr(arg) for arg in args))

# Binary converter


def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]

# --------------------------------------------


dp = None


def main():
    N, M, X = li_input()
    A = li_input()

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

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


main()

Submission status: Accepted

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

to_0_count = 0
to_N_count = 0
for i in range(0, X):
    if i in a_list:
        to_0_count +=1
for i in range(X+1, N+1):
    if i in a_list:
        to_N_count +=1
print(min([to_0_count, to_N_count]))

Submission status: Accepted

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

ans1 = len([a for a in A if a < x])
ans2 = len([a for a in A if a > x])
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
cnt=0
for c in map(int,input().split()):cnt+=c>x
print(min(cnt,m-cnt))

Submission status: Accepted

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

Submission status: Accepted

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


to_0 = 0
to_N = 0
for a in A:
    if a<X:
        to_0 += 1
    else:
        to_N += 1

print(min(to_0,to_N))

Submission status: Accepted

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

ans1 = len([a for a in A if a<X])
ans2 = len([a for a in A if a>X])
print(min(ans1,ans2))

Submission status: Accepted

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

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
    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()))
b=[0 for _ in range(n+1)]
for i in a:
    b[i] += 1
print(min(sum(b[:x]),sum(b[x:])))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left

n, m, x = map(int, input().split())
axs = [int(x) for x in input().split()]

i = bisect_left(axs, x)
print(min(i, len(axs) - i))

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
i = list(map(int,input().split()))
cs = []
cl = []    
for j in range(m):
    if x > i[j]:
        cs.append(i[j])
    else:
        cl.append(i[j])
print(min(len(cs),len(cl)))

Submission status: Accepted

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

Submission status: Accepted

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

a.append(X)
b=sorted(a)
print(min(len(b)-b.index(X)-1,b.index(X)))

Submission status: Accepted

Solution code:
#coding:utf-8
n=[int(i) for i in input().split()]
Ad=0
Au=0
A=[int(i) for i in input().split()]
for i in range(n[1]):
  if(A[i]>n[2]):
    Au+=1
  else:
    Ad+=1
if(Au>=Ad):
  print(Ad)
else:
  print(Au)

Submission status: Accepted

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

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

    #前半を調べる
    for i in range(X):
        if i in A:
            cnt_first += 1

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

    if cnt_first < cnt_last:
        print(cnt_first)
    else:
        print(cnt_last)




if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

costa = 0
costb = 0
n = 0


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


for i in range(X,-1,-1):
    j = A.count(i)
    if j == 1:
        costa = costa + 1

for n in range(X,N+1):
    k = A.count(n)
    if k == 1:
        costb = costb + 1

if costa > costb:
    print(costb)
else:
    print(costa)

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
idx=X
cnt_left=0
cnt_right=0
cost_list=[0 for _ in range(N)]
for c in A:
    cost_list[c]=1
    
left=sum(cost_list[:idx])
right=sum(cost_list[idx:])
    
print(min(right,left))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a_tmp = input().split()
a = []
for _ in a_tmp:
    a.append(int(_))
cost_l = 0
cost_r = 0
j = 0
for i in range(n+1):
    if i < x:
        if i == a[j]:
            cost_l += 1
            j += 1
            if j >= len(a):
                break
    elif x < i:
        if i == a[j]:
            cost_r += 1
            j += 1
            if j >= len(a):
                break
    else:
        continue
print(min(cost_l, cost_r))

Submission status: Accepted

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

xt = 0
for i in a:
    if x < i:
        xt = a.index(i)
        break;

print(min(len(a[:xt]), len(a[xt:])))

Submission status: Accepted

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

def main():
    list = [0] * (N + 1)
    for _ in range(M):
        a = A.pop()
        list[a] = 1
    left = list[:X + 1]
    right = list[X:]
    ans = min(sum(left), sum(right))
    print(ans)

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# your code goes here
n,m,x= map(int,input().split())
l = list(map(int,input().split()))

l.append(x)
l.sort()

print(min(l.index(x),m-l.index(x)))

Submission status: Accepted

Solution code:
N, M, X = list(map(int,input().strip().split(' ')))
A = list(map(int,input().strip().split(' ')))
costV = [0 for i in range(N)]
for a in A:
    costV[a] = 1 

left_cost = sum(costV[:X])
right_cost = sum(costV[X+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()))
B = [0]*(N+1)
for x in A:
    B[x] = 1
for i in range(N):
    B[i+1] += B[i]
print( min(B[X]-B[0],B[N]-B[X]))

Submission status: Accepted

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

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

d=0
e=0

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

print(min([d,e]))

Submission status: Accepted

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

a.sort()

s = len(a)

cnt = 0
for v in a:
    if v > x:
        cnt += 1
print(min(s - cnt, cnt))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
https://abc094.contest.atcoder.jp/tasks/abc094_b
"""
[n,m,x]=[int(i) for i in input().split()]
a=[int(i) for i in input().split()]
b=0
c=0
for i in a:
    if 0<i and i<x:
        b=b+1
    if x<i and i<n:
        c=c+1
print(min(b,c))

Submission status: Accepted

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

for i in range(len(a)):
  #数直線上で初期の場所ｘの左側にある料金所をチェックする
  if a[i] < x < a[i+1]:
    st = a[i]

#振り返ってみてみるとこんなことはしなくていい。上と同様に回すのが正解。
for i in range(n+1):
  #例外処理…xが両端にあるとき０を出力する
  if st == 0:
    print("0")
    break

  if i in a:
    num += 1
  #i番目の数が与えられた配列に含まれていたら、料金所を通ったことになるのでnumに1加算
  if i == st:
    #iがstまでたどり着いた時、ｘ地点にたどり着いたことになるので探索を終了する。
    res_l = num
    #左側の料金所の数
    res_r = m - num
    #同様に右側
    print(min(res_l,res_r))
    #右左をmin()関数によって比較。小さい方を出力する。
    break
    #for文を抜ける。ちょっと軽くなるかなって…

#いい例ではないのであまり参考にしないでください。
#少なくともの改良点として、11行目の言葉そのままです。
#ｎの全探索をする必要はないです

Submission status: Accepted

Solution code:
n,m,x = input().split()
N = int(n)
M = int(m)
X = int(x)
left = []
right = []

A = input().split()
A = list(map(int,A))
for i in range(len(A)):
	if(A[i]<X):
		left.append(A[i])
	elif(A[i]>X):
		right.append(A[i])

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
cost = list(map(int, input().split()))
n = len(list(filter(lambda x: x>X, cost)))
m = len(list(filter(lambda x: x<X, cost)))
print(m if n>=m else n)

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
cost_mas = list(map(int, input().split()))
cost = 0
n = len(list(filter(lambda x: x>X, cost_mas)))
m = len(list(filter(lambda x: x<X, cost_mas)))
print(cost+m if n>=m else cost+n)

Submission status: Accepted

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

    ans = min(len([v for v in a if 0 < v and v < x]),
              len([v for v in a if x < v and v <= n]))
        
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
Ai = list(map(int, input().split()))
m = [i for i in Ai if i < X]
M = [o for o in Ai if o > X]
a = len(m)
b = len(M)
if a > b:
  print(b)
if b > a:
  print(a)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

ct1 = 0
ct2 = 0

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

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

print(min(ct1, ct2))