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

cost = [0, 0]

for i in A:
	if i < X:
		cost[0] += 1
	else:
		cost[1] += 1
print(min(cost))

Submission status: Accepted

Solution code:

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

N = A[0]
M = A[1]
X = A[2]
little = 0
large = 0

for i in range(M):
    if X > R[i]:
        little += 1
    else:
        large += 1

if little > large:
    ans = large
else:
    ans = little
    
print(ans)

Submission status: Accepted

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

right_cost = 0
left_cost = 0

for i in range(1,N):
	location = i + X

	if location in cost_spot:
		#print("ATACK",location)
		right_cost = right_cost + 1
	else:
		pass
		#print("NONOO",location)

	if location == N:
		break

for i in range(1,N):
	location = X - i

	if location in cost_spot:
		#print("ATACK",location)
		left_cost = left_cost + 1
	else:
		pass
		#print("NONOO",location)

	if location == 0:
		break

#print('right_cost  ',right_cost)
#print('left_cost   ',left_cost)
print(min(right_cost,left_cost))

Submission status: Accepted

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

X = int(X)
bef = [cost < X for cost in array]
aft = [cost > X for cost in array]

be = sum(bef)
af = sum(aft)

if be <= af:
    print(be)
else:
    print(af)

Submission status: Accepted

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

Submission status: Accepted

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

print(min(A,B))

Submission status: Accepted

Solution code:
import math

n, m, x = input().strip().split(' ')
N, M, X = [int(n), int(m), int(x)]
tollGates  = list(map(int, input().strip().split(' ')))
grids = [int(0)] * N
for i in tollGates:
    grids[i]=1
# print(min(sum(grids[0:X],grids[X+1:N-1])))
print(min(sum(grids[0:X]),sum(grids[X+1::])))

Submission status: Accepted

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

Submission status: Accepted

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

#leftto0
cost_left = 0
for i in range(x-1,0,-1):
    if i in a:
        cost_left+= 1
    
#right_to_N
cost_right = 0
for i in range(x+1, n):
    if i in a:
        cost_right+= 1
    
print(min(cost_left, cost_right))

Submission status: Accepted

Solution code:
length, _, position = [int(x) for x in input().split()]
fee_stations = [int(x) for x in input().split()]
former = 0
latter = 0
#cont fee_station
for station_place in fee_stations:
    if station_place < position:
        former += 1
    else:
        latter += 1
print(min(former, latter))

Submission status: Accepted

Solution code:
# coding : utf-8

import numpy as np

X = [int(i) for i in input().split()]
C = np.array([int(i) for i in input().split()])

high = np.sum(C > X[2])
low  = np.sum(C < X[2])

print(min(high,low))

Submission status: Accepted

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

ll = [0] * (N + 1)
for i in l:
    ll[i] = 1

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

Submission status: Accepted

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

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

# solve
right = 0
left = 0

for i in range(len(A)):
    if (A[i] > X):
        right += 1
    if (A[i] < X):
        left += 1

if (right < left):
    print(right)
else:
    print(left)

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
c = 0
for t in a:
  if t < x:
    c += 1

print([len(a)-c, c][c<len(a)-c])

Submission status: Accepted

Solution code:
NMX = list(int(i) for i in input().split())
A = list(int(i) for i in input().split())
ans0 = 0
ansN = 0
for j in range(0, NMX[2]):
    if j in A:
        ans0 += 1
for j in range(NMX[2], NMX[0]):
    if j in A:
        ansN += 1
anslist = [ans0, ansN]
ans = min(anslist)
print(ans)

Submission status: Accepted

Solution code:
N, M, X = map(int,input().split())
A = set(map(int,input().split()))
lat = {i for i in range(X+1,N)}
fwd = {i for i in range(1,X)}
print(min(len(A&lat),len(A&fwd)))

Submission status: Accepted

Solution code:
N,M,X=list(map(int,input().split()))
A=list(map(int,input().split()))
#print(A)
A.append(X)
#print(A)
C=sorted(A)
#print(C)

search=C.index(X)
length=len(C)
#print([search,length])
print(min(search,length-search-1))

Submission status: Accepted

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

N_more_count =0
N_less_count =0

for i in range (M):
    AM = int(A[i])
    if AM>X:
        N_more_count=N_more_count+1
    if AM<X:
        N_less_count=N_less_count+1
print(min(N_less_count,N_more_count))

Submission status: Accepted

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

a_behind = [elem for elem in a if elem < x]
a_front = [elem for elem in a if elem > x]

print(min(len(a_behind), len(a_front)))

Submission status: Accepted

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

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

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

if left < (M-left): print(left)
else: print(M-left)

Submission status: Accepted

Solution code:
import sys
  
l = map(int, raw_input().split())
N, M, X = l[0], l[1], l[2]
m = map(int, raw_input().split())
cost_N = 0
if m[0] > X or m[-1] < X:
    print(0)
    sys.exit()
for a in m:
    if a > X:
        idx = m.index(a)
        count_N = M - idx
        count_0 = idx
        print(min(count_N, count_0))
        sys.exit()

Submission status: Accepted

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

Rcost = 0
Lcost = 0
for i in array:
    if i <  X:
        Lcost += 1
    elif i > X:
        Rcost += 1
print(min(Rcost,Lcost))

Submission status: Accepted

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

road_list = [0] * (N + 1)
for i in A_list:
    road_list[i] = 1

right = sum(road_list[X:])
left = sum(road_list[:X])
print(min(right, left))

Submission status: Accepted

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

	p = x
	cost = 0
	while p > 0:
		if p in a:
			cost += 1
		p -= 1
	cost_left = cost

	p = x
	cost = 0
	while p < n:
		if p in a:
			cost += 1
		p += 1
	cost_right = cost

	print(min((cost_left, cost_right)))

Submission status: Accepted

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

cost = 0
for i in range(X-1):
    if i+1 in A:
        cost += 1

mincost = cost
cost = 0
for i in range(N-X-1):
    if X+1+i in A:
        cost += 1

if mincost < cost:
    print(mincost)
else:
    print(cost)

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
L = [0 for x in range(N+1)]
gate = list(map(int, input().split()))
p = X
c = 0
min_c = 2e9

for x in gate:
    L[x] = 1

while p != N:
    if L[p] == 1:
        c += 1

    p += 1

min_c = min(min_c, c)

p = X
c = 0

while p != 0:
    if L[p] == 1:
        c += 1

    p -= 1

min_c = min(min_c, c)

print(min_c)

Submission status: Accepted

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

cost_to_l = 0
cost_to_r = 0

for x in a:
    if(x < X):
        cost_to_l += 1
    else:
        cost_to_r += 1

print(min(cost_to_l, cost_to_r))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
da = list(map(int,input().split()))
ta = list(map(int,input().split()))

l1 = 0
l2 = 0

for i in range(da[2]):
  for j in range(da[1]):
    if i == ta[j]:
      l1 += 1
      
for i in range(da[0] - da[2]):
  for j in range(da[1]):
    if i + da[2] == ta[j]:
      l2 += 1
      
print(min(l1,l2))

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 range(M):
  if cost[i] < X:
    ans1 +=1
  else:
    ans2 +=1

print(min(ans1,ans2))

Submission status: Accepted

Solution code:
n,m,x=input().split()
N=int(n);M=int(m);X=int(x)
a=[int(x) for x in input().split()]

L=0
R=0
i=X
while i!=0:
    if i-1 in a:
        L+=1
    i-=1
i=X
while i!=N:
    if i+1 in a:
        R+=1
    i+=1
print(min(L,R))

Submission status: Accepted

Solution code:
def solve(N, M, X, A):
    a = sum(A[:X])
    if x == N:
        return 0
    b = sum(A[X+1:])
    return min(a, b)
if __name__ == "__main__":
    s = input()
    N, M, X = list(map(lambda x: int(x), s.split()))
    A = [0 for x in range(N)]
    for x in map(lambda x: int(x), input().split()):
        A[x] = 1 
    print(solve(M, N, X, A))

Submission status: Accepted

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

left=sum(num[:x+1])
right=sum(num[x:n+1])
print(min(left,right))

Submission status: Accepted

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

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

cost_l = 0
for i in range(1,X):
    if i in A:
        cost_l = cost_l + 1
    else:
        pass

cost_r = 0
for i in range(X+1,N):
    if i in A:
        cost_r = cost_r + 1
    else:
        pass
    
if cost_l < cost_r:
    print(cost_l)
else:
    print(cost_r)

Submission status: Accepted

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

r = (n+1)*[0]
for i in a:
    r[i] = 1

if(sum(r[0:x]) > sum(r[x:])):
    print(sum(r[x:]))
else:
    print(sum(r[0:x]))

Submission status: Accepted

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

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

counta = 0
countb = 0

for i in range(0,x+1):
    counta += a.count(i)
for i in range(x+1,n):
    countb += a.count(i)

print(min(counta,countb))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = map(int, input().split())
n1 = 0
n2 = 0
for a in A:
    if a < X:
        n1 += 1
    else:
        n2 += 1
if n1 <= n2:
    print(n1)
else:
    print(n2)

Submission status: Accepted

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

for i in A:
    if X<i:
        ue+=1
    else:
        sita+=1

print(min(ue,sita))

Submission status: Accepted

Solution code:
#coding:utf-8

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

a = map(int, raw_input().split())

p1 = 0
p2 = 0
for i in a:
    if X > i:
        p1 += 1
    else:
        p2 += 1

print min(p1, p2)

Submission status: Accepted

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

cnt_l = 0
for i in range(x-1,0,-1):
    for j in range(len(A)):
        if i==A[j]:
            cnt_l+=1
cnt_r = 0
for i in range(x+1,n):
    for j in range(len(A)):
        if i==A[j]:
            cnt_r+=1
print(min(cnt_l,cnt_r))

Submission status: Accepted

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

#print(a)

nl = 0
nu = 0
for i in range(m):
    if a[i] < x:
        nl += 1
    elif a[i] > x:
        nu += 1
if nl <= nu:
    print(nl)
else:
    print(nu)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = [int(i) for i in input().split()]
l = sum([1 for i in A if i < X])
r = sum([1 for i in A if i > X])
print(l if l < r else r)

Submission status: Accepted

Solution code:
import collections


n, m, x = map(int, input().split())
c = collections.defaultdict(int)
for key in map(int, input().split()):
    key = int(key)
    c[key] += 1

forward = 0
backword = 0
touch_x = False

for i in range(n):
    if i == x:
        touch_x = True

    if not touch_x and c[i]:
        forward += 1

    else:
        if c[i]:
            backword += 1


print(min(forward, backword))

Submission status: Accepted

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

# 2.count the fee
# check 1 to (x-1)
ans = 0
for i in range(1,x):
    if i in a:
        ans += 1

# if it is greater than half, change
if ans > (m/2):
    ans = m-ans
    
print(ans)

Submission status: Accepted

Solution code:
l = list(map(int, input().split()))
N, M, X = l[0], l[1], l[2]

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

import numpy as np
fee = np.array(fee)
left = np.sum(fee < X)
right = np.sum(fee > X)

if left > right:
    print(right)
else:
    print(left)

Submission status: Accepted

Solution code:
from sys import stdin


def main():
    N, M, X = [int(x) for x in stdin.readline().rstrip().split()]
    Ai = [int(x) for x in stdin.readline().rstrip().split()]
    spam = [1 if i in Ai else 0 for i in range(N + 1)]
    print(min(sum(spam[:X]), sum(spam[X + 1:])))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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().split())
B=0
C=0
L=list(map(int,input().split()))
for I in L:
	if I<X:
		B+=1
	else:
		C+=1
print(min(B,C))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# 整数の入力
N, M, X = map(int, input().split())
# スペース区切りの整数の入力
A = list(map(int, input().split()))

Y = [0 for i in range(N)]
for j in range(M):
    Y[A[j]] = 1

rightSideCost = sum(Y[0:X])
leftSideCost = sum(Y[X:N])

print(min(rightSideCost,leftSideCost))

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

print(min([cost1,cost2]))

Submission status: Accepted

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

sum_0 = 0
sum_N = 0

for i in range(len(a)):
    if a[i]<x:
        sum_0 +=1
    if a[i]>x:
        sum_N+=1
print(min(sum_0, sum_N))

Submission status: Accepted

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

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

if count >= (M / 2):
    answer = M - count
else:
    answer = count

print(answer)

Submission status: Accepted

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

for i in range(x, 0, -1):
    for j in range(len(a)):
        if a[j] == i:
            cost0 += 1

for i in range(x, n+1):
    for j in range(len(a)):
        if a[j] == i:
            costN += 1

if cost0 <= costN:
    print(cost0)

else:
    print(costN)

Submission status: Accepted

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

Z=0
for j in range(0,X):
    if j in A:
        Z+=1
print(min(Y,Z))

Submission status: Accepted

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

c1 = 0
for i in range(x, n+1):
    if i in r:
        c1 += 1

c2 = 0
for i in range(x, 0, -1):
    if i in r:
        c2 += 1

print(min(c1, c2))

Submission status: Accepted

Solution code:
N,M,X=list(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(min([c1,c2]))

Submission status: Accepted

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

left = len([p for p in data if p < x])
right = len([p for p in data if p > x])

print(min([left,right]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect


def get_next_int():
    return int(float(input()))


def get_next_ints(delim=" "):
    return tuple([int(float(x)) for x in input().split(delim)])


def get_next_str():
    return input()


def get_next_strs(delim=" "):
    return tuple(input().split(delim))


def get_next_by_types(*value_types, delim=" "):
    return tuple([t(x) for t, x in zip(value_types, input().split(delim))])


def solve():
    N, M, X = get_next_ints()
    costs = get_next_ints()
    costs = sorted(costs)
    x_index = bisect.bisect(costs, X)
    left_cost = len(costs[0:x_index])
    right_cost = len(costs[x_index:])
    if left_cost < right_cost:
        print(left_cost)
    else:
        print(right_cost)
solve()

Submission status: Accepted

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

while(A[i] < X):
    SUM += 1
    i += 1

print(min(SUM, M - SUM))

Submission status: Accepted

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

tmp = 0
tmp2 = 0
for i in range(1, x+1):
    if i in array:
        tmp +=1

for j in range(x, a+x):
    if j in array:
        tmp2 += 1

print(min(tmp, tmp2))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
a = list(map(int, input().split()))
c = 0
for x in range(X, N):
    if x in a:
        c += 1
if c >= M / 2:
    print(M - c)
else:
    print(c)

Submission status: Accepted

Solution code:
a, b, c = map(int, input().split())
a = [int(i) for i in input().split()]

small = 0
large = 0

for i in range(len(a)):
	if c > a[i]:
		small += 1
	if c < a[i]:
		large += 1

if small >= large:
	print(large)
else:
	print(small)

Submission status: Accepted

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

Submission status: Accepted

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

P = 0
Q = 0

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

for k in range(N-X):
    if k + X + 1  in A:
        Q += 1

print(min(P, Q))

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:
line = list(map(int,input().split()))
cost = list(map(int,input().split()))
costl = 0
costr = 0
for i in range(line[1]):
    if cost[i] < line[2]:
        costl += 1
    if cost[i] > line[2]:
        costr += 1
print(min(costr,costl))

Submission status: Accepted

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

k = sum(ai<x for ai in a)
j = sum(ai>x for ai in a)
print(min(k,j))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
#マス0かNに行きたい、M個料金所がある、いまマスXにいる
#問題文が読みづらすぎる
chkptList = list(map(int,input().split()))
TollToOrigin = 0
TollToN = 0
for i in range(X):
    TollToOrigin += chkptList.count(i)
for i in range(X,N):
    TollToN += chkptList.count(i)

print(min(TollToOrigin, TollToN))

Submission status: Accepted

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

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

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

cost_0 = 0
cost_n = 0

for i in a:
    if i < x:
        cost_0 += 1
    if i > x:
        cost_n += 1

print(min(cost_0, cost_n))

Submission status: Accepted

Solution code:
import sys
import copy

def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N, M, X] = [int(input_raw[0]), int(input_raw[1]), int(input_raw[2])]
    input_raw = read_func().strip().split()
    A = set([])
    for i in range(M):
        A.add(int(input_raw[i]))
    to_zero_cost = 0
    for i in range(X , -1, -1):
        if i in A:
            to_zero_cost += 1
    to_N_cost = 0
    for i in range(X , N + 1):
        if i in A:
            to_N_cost += 1
    print min(to_N_cost, to_zero_cost)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

totalUp = 0
i = x


while i!=n:
    if i in a:
        totalUp+=1
    i+=1

totalDown = 0

i = x
while i!=0:
    if i in a:
        totalDown+=1
    i-=1

print(min(totalUp,totalDown))

Submission status: Accepted

Solution code:
def min_toll(x, n, tolls):
    toll_to_0 = toll_to_n = 0
    for i in range(1, x):
        toll_to_0 += i in tolls
    for i in range(x + 1, n + 1):
        toll_to_n += i in tolls
    return min(toll_to_0, toll_to_n)


if __name__ == '__main__':
    n, _, x = map(int, input().split())
    tolls = list(map(int, input().split()))
    print(min_toll(x, n, tolls))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    from bisect import bisect_left

    n, m, x = list(map(int, input().split()))
    a = list(map(int, input().split()))
    low = bisect_left(a, x)
    print(min(len(a[:low]), len(a[low:])))

Submission status: Accepted

Solution code:
n, m, x = map(int, raw_input().split())
a = map(int, raw_input().split())
l = map(lambda i: 1 if i in a else 0, xrange(n+1))
print min(sum(l[:x]), sum(l[x:]))

Submission status: Accepted

Solution code:
import bisect

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

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

main()

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=[None]*M
A=list(map(int,input().split()))
lowNum=sum(x>X for x in A)
cost=min(lowNum, M - lowNum)
print(cost)

Submission status: Accepted

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

Submission status: Accepted

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

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

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()]
    
    upside_cost = sum(i > X for i in A)
    downside_cost = sum(i < X for i in A)
    
    if(upside_cost < downside_cost):
        print(upside_cost)
    else:
        print(downside_cost)
        
if __name__=="__main__":
    main()

Submission status: Accepted

Solution code:
import sys
if __name__ == "__main__":
    N, M, X = list(map(int, (input().split(' '))))
    A = list(map(int, (input().split(' '))))
    cost = [0 for i in range(N+1)]
    ans1 = 0
    ans2 = 0
    for i in range(N+1):
        if i in A:
           cost[i] = 1
    for i in range(X, -1, -1):
        ans1 += cost[i]
    for i in range(X, N+1):
        ans2 += cost[i]
    if ans1 < ans2:
        print(ans1)
    else:
        print(ans2)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
j = m
for i in a:
    if i > x:
        j = a.index(i)
        break
c = min(j, m-j)

print(c)

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
li = list(map(int,input().split()))
costto0=0
costton=0
for an in li:
    if  an < x:
        costto0 = costto0+1
    else:
        costton = costton+1
print(min(costto0,costton))

Submission status: Accepted

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

bi = bisect_left(a, x)
ci = m - bisect_left(a, x)
if bi < ci:
    print(bi)
else:
    print(ci)

Submission status: Accepted

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

cnt=0
i=0

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

if cnt>=M-cnt:
    print(M-cnt)
else:
    print(cnt)

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
print(min(sum(c[:x]), sum(c[(x+1):])))

Submission status: Accepted

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

b = sum(i < x for i in a)

if  b <= m - b:
    print(b)
else:
    print(m - b)

Submission status: Accepted

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

cost1=0
for i in range(X,N+1):
	if i in cost:
		cost1+=1


cost2=0
for i in range(X,-1,-1):
	if i in cost:
		cost2+=1

print min(cost1,cost2)

Submission status: Accepted

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

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

if count * 2 > M:
    print(M-count)
else:
    print(count)

Submission status: Accepted

Solution code:
M , N ,X = map(int,input().split())
l = list(map(int, input().split()))
c1 , c2 = 0,0
for i in l :
    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()))
print(min(sum(i<x for i in a), sum(i>x for i in a)))

Submission status: Accepted

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

back,go = 0,0

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

N,M,X=map(int,input().split())
Mlist=list(map(int,input().split()))
Nlist=[0]*N
for a in Mlist:
  Nlist[a]=1

a=sum(Nlist[X:])
b=sum(Nlist[:X])
print(min([a,b]))

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N, M, X = map(int, input().split())
    N, M, X = N - 1, M - 1, X - 1
    A = [A_i - 1 for A_i in map(int, input().split())]

    to_zero = len([A_i for A_i in A if A_i < X])
    to_N = len([A_i for A_i in A if X < A_i])

    print(min(to_zero, to_N))

Submission status: Accepted

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

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

lower_count = 0
larger_count = 0
for a in A:
    if a > x:
        larger_count += 1
    elif a < x:
        lower_count += 1
if lower_count < larger_count:
    print(lower_count)
else:
    print(larger_count)

Submission status: Accepted

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

for a in A:
    if a > x:
        break
    count += 1
    
print(min(count,len(A)-count))

Submission status: Accepted

Solution code:
N, M, X = (int(x) for x in input().split())
A = tuple(int(x) for x in input().split())
count = 0
for a in A:
 if a > X:
  break
 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()))

cost_l = 0
cost_r = 0
left = True

for ai in A:
    if left:
        if ai > X:
            left = False
            cost_r += 1
            continue
        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())
masu = list(map(int, input().split()))
max1 = 0
max2 = 0
for i in masu:
    if(i < x):
        max1 += 1
for i in masu:
    if(i > x):
        max2 += 1
if max1 >= max2:
    print(max2)
else:
    print(max1)