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: Wrong Answer

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

now = x

res1 = 0
for i in range(n - x - 1):
    now += 1
    if a.count(now):
        res1 += 1

res2 = 0
for i in range(x):
    now -= 1
    if a.count(now):
        res2 += 1

if res1 < res2:
    print(res1)
else:
    print(res2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m,x = map(int, raw_input().split())
list = []
list = map(int, raw_input().split())
ans = 0
if x <= n-m:
 for i in range(n-m,m):
  ans += list[i]
  print(ans)
else:
 print(0)

Submission status: Wrong Answer

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

C = [0 for i in range(N)]
for j in range(len(A)):
    C[A[j]] = 1
C_left = C[:X-1]
C_right = C[X:]
result = min(sum(C_left),sum(C_right))
print(result)

Submission status: Wrong Answer

Solution code:
l = input().split()
N = int(l[0])
M = int(l[1])
X = int(l[2])
cost1 = 0
cost2 = 0
j = 0
k = input().split()
for e in k:
    if int(e) >= X:
        j = k.index(e)
    cost1 = cost1 + 1

for i in range(j, M):
    cost2 = cost2 + 1
if cost1 > cost2:
    print(cost2)
else:
    print(cost1)

Submission status: Wrong Answer

Solution code:
x,y,z=[int(i) for i in input().split()]
tag_list=input().split()

tag_set=set(tag_list)

obj_list=[]
for i in range(0,x+1):
    obj_list.append(str(i))

result=[]

obj_set=set(obj_list[y+1:])
a=list(obj_set & tag_set)
result.append(len(a))

obj_set=set(obj_list[:y+1])
a=list(obj_set & tag_set)
result.append(len(a))

print(min(result))

Submission status: Wrong Answer

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

now = x
res = 0

if n - x < x:
    for i in range(n - x - 1):
        now += 1
        if a.count(now):
            res += 1
else:
    for i in range(x):
        now -= 1
        if a.count(now):
            res += 1

print(res)

Submission status: Wrong Answer

Solution code:
l = input().split()
N = int(l[0])
M = int(l[1])
X = int(l[2])
cost1 = 0
cost2 = 0
j = 0
k = input().split()
for e in k:
    if int(e) >= X:
        j = k.index(e)
    cost1 = cost1 + 1

for i in range(j, M):
    cost2 = cost2 + 1
if cost1 > cost2:
    print(cost1)
else:
    print(cost2)

Submission status: Wrong Answer

Solution code:
def main():
    N,M,X = list(map(int,input().split()))
    A = [0]
    A.extend(list(map(int,input().split())))
    for i in range(100):
        A.append(0)    
    Map = [0]
    for i in range(1,N+1):
        if i in A:
            Map.append(1)
        else:
            Map.append(0)
    right = Map[X:]
    left = Map[:X]
    if right < left:
        print(sum(right))
    else:
        print(sum(left))
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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 = right_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: Wrong Answer

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

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

cost_A = 0
cost_B = 0


i = X - 1
while True:
    if i in A:
        cost_A += 1
    elif i == 0:
        break  
    i -= 1

i = X + 1
while True:
    if i in A:
        cost_B += 1
    elif i == M:
        break
    i += 1
    
if cost_A > cost_B:
    print(cost_B)
else:
    print(cost_A)

Submission status: Wrong Answer

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

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

cost_A = 0
cost_B = 0


i = 1
while True:
    if i in A:
        cost_A += 1
    elif i > X:
        break  
    i += 1

i = X
while True:
    if i in A:
        cost_B += 1
    elif i > A[len(A)-1]:
        break
    i += 1
    
if cost_A > cost_B:
    print(cost_B)
else:
    print(cost_A)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
n,m,x = map(int, raw_input().split())
if x <= n-m:
 print(m-x)
else:
 print(0)

Submission status: Wrong Answer

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

A = map(int,raw_input().split())
costs = []

for i in range(N):
    if i in A:
        costs.append(1)
    else:
        costs.append(0)

#print costs
#print costs[0:X-1]
#print costs[X+1:N]

if sum(costs[0:X-1]) > sum(costs[X+1:N]):
    print sum(costs[X+1:N])
else:
    print sum(costs[0:X-1])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 + 1
        count_0 = idx - 1
        print(min(count_N, count_0))
        sys.exit()

Submission status: Wrong Answer

Solution code:
def solve(N, M, X, A):
    a = sum(A[0:X])
    b = sum(A[X-1:-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: Wrong Answer

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 + 1
        count_0 = idx - 1
        print(min(count_N, count_0))
        sys.exit()

Submission status: Wrong Answer

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

P = 0
Q = 0

for j in range(X-1):
    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: Wrong Answer

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

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

Submission status: Wrong Answer

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

P = 0
Q = 0

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

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

print(min(P, Q))

Submission status: Wrong Answer

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-1]),sum(cost[x-1:])))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

P = 0
Q = 0

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

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

print(min(P, Q))

Submission status: Wrong Answer

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

cost1 = 0
cost2 = 0
for i in A_LIST:
    if i > 3:
        cost1 += 1
    else:
        cost2 += 1

print(min(cost1, cost2))

Submission status: Time Limit Exceeded

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

left, right = 0, M
while right - left > 1:
  mid = (left + right) // 2
  if A[mid] > X:
    mid = left
  if A[mid] < X:
    mid = right

res = max(mid, M - mid)
print(res)

Submission status: Accepted

Solution code:
N, M, X = map(int,input().split())
S = map(int,input().split())
Fees = list(S)
Goal1 = []
Goal2 = []
count1 = 0
count2 = 0
point0 = 0

for i in range(X):
    point0 += 1
    Goal1.append(point0)
# print(Goal1)

for j in range(N-X):
    X += 1
    Goal2.append(X)
# print(Goal2)

for fee in Fees:
    if fee in Goal1:
        count1 += 1
    if fee in Goal2:
        count2 += 1

if count1 >= count2:
    print(count2)
if count1 < count2:
    print(count1)
















# Fee = list(S)
# print(Fee)
# count1 = 0
# count2 = 0
# for i in range(N-X):
#     X += 1
#     if X in Fee:
#         count1 += 1
# print(X)
# for j in range(N):
#     X -= 1
#     if X in Fee:
#         count2 += 1
#
# if count1 <= count2:
#     print(count1)
# if count1 > count2:
#     print(count2)

Submission status: Accepted

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

for i in range(x,n):
    if a.count(i) == 1:
        count += 1
cost.append(count)
count = 0
c = range(0,x)
for i in reversed(c):
    if a.count(i) == 1:
        count += 1
cost.append(count)
print(min(cost))

Submission status: Accepted

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

l_cost = 0
g_cost = 0

for i in A:
    if i > X:
      l_cost += 1
    else:
        g_cost += 1
        
print(min(l_cost, g_cost))

Submission status: Accepted

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

Submission status: Accepted

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

a_cost = 0
b_cost = 0
for i in lst:
    if i > x:
        a_cost += 1
    else:
        b_cost += 1
print(min(a_cost, b_cost))

Submission status: Accepted

Solution code:
def tool_gate(now: int, gate_list: list) -> int:
    back_count = sum(i < now for i in gate_list)
    forward_count = sum(i > now for i in gate_list)
    return min(back_count, forward_count)


if __name__ == "__main__":
    n, m, now = map(int, input().split())
    gate_list = list(map(int, input().split()))
    print(tool_gate(now, gate_list))

Submission status: Accepted

Solution code:
lst = input().split()
N = int(lst[0])
M = int(lst[1])
X = int(lst[2])
L = input().split()

cost_0 = 0
for n in L:
   if 0 < int(n) < X:
      cost_0 += 1
   elif X < int(n):
      break

cost_N = 0
for n in L:
   if X < int(n) < N:
      cost_N += 1

print(min([cost_0, cost_N]))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
a_point = list(map(int,input().split()))
lg = 0
sl = 0
for i in range(len(a_point)):
    if X < a_point[i]:
        lg  += 1
    else:
        sl += 1

if lg > sl:
    print(sl)
else:
    print(lg)

Submission status: Accepted

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

cnt1 = 0
for i in range(0, X):
  if i in AS:
    cnt1 += 1

cnt2 = 0
for i in range(X+1, N+1):
  if i in AS:
    cnt2 += 1

print(cnt1 if cnt1 < cnt2 else cnt2)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def main():
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))
    for i in range(m):
        if a[i] > x:
            ans = min(i, len(a) - i)
            break
    else:
        ans = 0
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# 全体のマスを開始位置でスライス、料金所だけ抽出し、要素の個数で条件分岐
N, M, X = map(int, input().split())
A = list(map(int, input().split()))

square = list(range(0, N + 1))

a = square[:X + 1]
b = square[X:]

a_costs = []
b_costs = []

for i in a:
    if i in A:
        a_costs.append(i)
for i in b:
    if i in A:
        b_costs.append(i)

a_cost = len(a_costs)
b_cost = len(b_costs)

if a_cost > b_cost:
    print(b_cost)
else:
    print(a_cost)

Submission status: Accepted

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

for i in A:
    if X > i:
        l1.append(i)
    else:
        l2.append(i)

print(min(len(l1), len(l2)))

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

Submission status: Accepted

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

low = 0
high = 0
for i in range(m):
  if a[i] < s:
    low += 1
  else:
    high += 1
print(min(low,high))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
cnt1 = 0
cnt2 = 0
x1 = x
x2 = x

while x1 < n+1:
    x1 += 1
    if x1 in a:
        cnt1 += 1

while x2 > 0:
    x2 -= 1
    if x2 in a:
        cnt2 += 1



if cnt1 < cnt2:
    ans = cnt1
else:
    ans = cnt2

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a,b,c=input().split()
a=int(a)
b=int(b)
c=int(c)
d=list(map(int,input().split()))
e=0
f=0
for i in range(b):
  if d[i]>c:
    e=e+1
  if d[i]<c:
    f=f+1
if e>f:
  print(f)
else:
  print(e)

Submission status: Accepted

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

Submission status: Accepted

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

mn = 0
l_cost = 0
r_cost = 0

# Calculate left cost
for i in range(x):
    if i in arr:
        l_cost += 1

# Calculate right cost
for i in range(x, n + 1):
    if i in arr:
        r_cost += 1

print(min(l_cost, r_cost))

Submission status: Accepted

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

Submission status: Accepted

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


def solve(N: int, M: int, X: int, A: "List[int]"):
    ans = 0
    for i in range(X-1, 0, -1):
        if i in A:
            ans += 1
    c = 0
    for i in range(X+1, N):
        if i in A:
            c += 1
    if ans > c:
        ans = c
    print(ans)


    return


# Generated by 1.1.7.1 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())
A = list(map(int, input().split()))

X_high = 0
X_low = 0

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

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

print(min(X_high, X_low))

Submission status: Accepted

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


goto_goal_0 = 0 # 0までのコスト
goto_goal_n = 0 # nまでのコスト

# x から 0 へ向かうコストを計算
for i in range(x - 1, 0, -1):   # x-1 番目から順番にデクリメントしながらforループ
    if i in a:
        goto_goal_0 += 1
        # print("0 is {}".format(goto_goal_0))

# x から n へ向かうコストを計算
for i in range(x, n + 1):   # x 番目から順番にインクリメントしながらforループ
    if i in a:
        goto_goal_n += 1
        # print("n is {}".format(goto_goal_n))

if goto_goal_0 < goto_goal_n:
    print(goto_goal_0)
else:
    print(goto_goal_n)

Submission status: Accepted

Solution code:

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

goto_goal_0 = 0 # 0までのコスト
goto_goal_n = 0 # nまでのコスト

# x から 0 へ向かうコストを計算
for i in range(x - 1, 0, -1):   # x-1 番目から順番にデクリメントしながらforループ
    if i in a:
        goto_goal_0 += 1
        # print("0 is {}".format(goto_goal_0))

# x から n へ向かうコストを計算
for i in range(x, n + 1):   # x 番目から順番にインクリメントしながらforループ
    if i in a:
        goto_goal_n += 1
        # print("n is {}".format(goto_goal_n))

if goto_goal_0 < goto_goal_n:
    print(goto_goal_0)
else:
    print(goto_goal_n)

Submission status: Accepted

Solution code:
# -*- coding:utf-8 -*-
N,M,X = map(int,input().split())
A = list(map(int,input().split()))

A.append(X)
A.sort()

A_index = A.index(X)

len_bef = len(A[0:A_index])
len_aft = len(A[A_index+1:])
ans = len_bef

if len_bef > len_aft:
    ans = len_aft

print(ans)

Submission status: Accepted

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

goal_N = 0
goal_0 = 0

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

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

min_cost = min(goal_N,goal_0)

print(min_cost)

Submission status: Accepted

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

goto_0=0
goto_N=0

for i in range(X,0,-1):
    if i in Ai:
        goto_0 += 1

for i in range(X,N):
    if i in Ai:
        goto_N += 1

print(min(goto_0,goto_N))

Submission status: Accepted

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

goto_0=0
goto_N=0

for i in range(0,X):
    if i in Ai:
        goto_0 += 1

for i in range(X,N):
    if i in Ai:
        goto_N += 1

print(min(goto_0,goto_N))

Submission status: Accepted

Solution code:
S_list = [input() for i in range(2)]
N, M, X= map(int,S_list[0].split())    
A_list = list(map(int,S_list[1].split()))

A_goal_N = [i for i in A_list if X < i and i < N]
A_goal_0 = [i for i in A_list if 0 < i and i < X]
result = min(len(A_goal_N),len(A_goal_0))
print(result)

Submission status: Accepted

Solution code:
import sys
lines = [s.rstrip("\n") for s in sys.stdin.readlines()]
n, m, x = [int(num) for num in lines.pop(0).split(" ")]
a_list = [int(num) for num in lines.pop(0).split(" ")]

for i in range(m):
    if a_list[i] > x:
        break

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

Submission status: Accepted

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

L = 0
R = 0

for ai in A:
    if ai < X:
        L = L + 1
    else:
        R = R + 1
print(min(L, R))

Submission status: Accepted

Solution code:
N, M, X = map(int,input().split())
fee = list(map(int,input().split()))
result_1 = []
result_2 = []

for i in fee:
    if i > X:
        result_1.append(i)
    else:
        result_2.append(i)

result = (min(len(result_1) ,len(result_2)))
print(result)

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
k = n-1
for i in range(m):
    if a[i] > x:
        k = i
        break
if k==0 or k==n-1:
    print('0')
    exit()
else:
    print(min(k,m-k))

Submission status: Accepted

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

s=0
b=0
for i in a:
    if i<x:
        s+=1
    if i>x:
        b+=1
print(min(s,b))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
total_square, total_toll_gate, current_square = map(int, input().split())
toll_gate_square = list(map(int, input().split()))
route1 = 0
route2 = 0
for i in range(total_toll_gate):
    if toll_gate_square[i] < current_square:
        route1 += 1
    else:
        route2 += 1
print(min(route1, route2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a = sorted(a)
print(len(a[:a.index(x)]) if len(a[:a.index(x)+1]) <= len(a[a.index(x)+1:]) else len(a[a.index(x)+1:]))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(m):
    if a[i] > x:
        if i < m-i: ans = i
        else      : ans = m-i
        break
print(ans)

Submission status: Accepted

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

acc = [0] * (n + 1)
for i in a:
    acc[i] = 1
print(min(sum(acc[:x]), sum(acc[x:])))

Submission status: Accepted

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

def answer(n: int, m: int, x: int, a:list) -> int:
    left = 0
    right = 0
    for i in a:
        if i < x:
            left += 1
        else:
            right += 1
    return min(left, right)

print(answer(n, m, x, a))

Submission status: Accepted

Solution code:
n, m, x = input().split()
list01 = input().split()
list02 = [int(a) for a in list01]
b = sum(c > int(x) for c in list02)
d = sum(e < int(x) for e in list02)
print(min(b, d))

Submission status: Accepted

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

for i in A:
    if X > i:
        l1.append(i)
    else:
        l2.append(i)

print(min(len(l1), len(l2)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a=input().split()
N=int(a[0])
M=int(a[1])
X=int(a[2])
ryokinjo=[]
b=input().split()
for i in range(len(b)):
  ryokinjo.append(int(b[i]))
count1=0
count2=0
for i in range(len(ryokinjo)):
  if ryokinjo[i]<X:
    count1+=1
  if ryokinjo[i]>X:
    count2+=1
print(min([count1,count2]))

Submission status: Accepted

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

cost_0 = 0
cost_last = 0

for n in A:
  if n > X:
    cost_last += 1
  elif n < X:
    cost_0 += 1


if cost_0 >= cost_last:
  print(cost_last)
elif cost_0 < cost_last:
  print(cost_0)

Submission status: Accepted

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

goal_N = 0
goal_0 = 0

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

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

min_cost = min(goal_N,goal_0)

print(min_cost)

Submission status: Accepted

Solution code:
# B - Toll Gates

# N M X
N, M, X = map(int, input().split())
my_list = list(map(int, input().split(maxsplit=M)))
count_start = 0
count_goal = 0

# 0へ行くパターン
for i in range(1, X):
    if i in my_list:
        count_start += 1

for i in range(X, N):
    if i in my_list:
        count_goal += 1

if count_start >= count_goal:
    answer = count_goal
else:
    answer = count_start

print(answer)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(m):
    if a[i] > x:
        less = len(a[:i])
        more = len(a[i:])
        print(min(less, more))
        break

Submission status: Accepted

Solution code:
# 数値の取得
last,fee,cur = map(int,input().split())
feesqu = list(map(int,input().split()))
total = len(feesqu)

# コストの最小値を出力
tcost = 0
gcost = 0
for cnt in range(0,total,1):
    if feesqu[cnt] < cur:
        tcost += 1
gcost = total - tcost
print(min(tcost,gcost))

Submission status: Accepted

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

Submission status: Accepted

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

cost_ToZero = cost_ToEnd = 0

for cost_mass in cost_masses:
    if X < cost_mass:
        cost_ToEnd = cost_ToEnd + 1
    elif X > cost_mass:
        cost_ToZero = cost_ToZero + 1
else:
  print(min([cost_ToZero, cost_ToEnd]))

Submission status: Accepted

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

left_cost = 0
right_cost = 0
for square in squares:
    if square < x:
        left_cost = left_cost + 1
    else:
        right_cost = right_cost + 1

print(min(right_cost, left_cost))

Submission status: Accepted

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

# 小さいほうの料金所の数
small_cost = 0
# 大きい方の料金所の数
big_cost = 0

# リストaの値とｘを比較して
for i in a:
    # ｘより小さいものをカウント
    if x > i:
        small_cost += 1
    # ｘより大きいものをカウント
    elif x < i:
        big_cost += 1
# 少ない方のカウントを出力
if small_cost <= big_cost:
    print(small_cost)
else:
    print(big_cost)

Submission status: Accepted

Solution code:
# 094b

def atc_094b(NMX: str, Ai_input: str) -> int:
    N, M, X = map(int, NMX.split(" "))
    Ai = [int(ai) for ai in Ai_input.split(" ")]

    up_cost = 0
    down_cost = 0

    for i in range(X + 1, N + 1):
        if i in Ai:
            up_cost += 1
    for i in range(X - 1, 0, -1):
        if i in Ai:
            down_cost += 1
    return min(up_cost, down_cost)


NMX_input_value = input()
Ai_input_value = input()
print(atc_094b(NMX_input_value, Ai_input_value))

Submission status: Accepted

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

if s >= b:
    print(b)
else:
    print(s)

Submission status: Accepted

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

right = [int(i) for i in A if i > X]
left = [int(i) for i in A if i < X]

r = len(right)
l = len(left)

if r < l:
    print(r)

else:
    print(l)

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
num, count_station, my_position = map(int, input().split())
a = map(int, input().split())
station_list = list(a)
space = num + 1
first_me_cost = 0
last_me_cost = 0

distance_me_first = my_position
distance_me_last = num - my_position

for i in station_list:
    if 1 <= i <= my_position - 1:
        first_me_cost += 1

for i in station_list:
    if my_position + 1 <= i < num:
        last_me_cost += 1

if first_me_cost > last_me_cost:
    print(last_me_cost)
elif last_me_cost > first_me_cost:
    print(first_me_cost)
elif last_me_cost == first_me_cost:
    print(first_me_cost)

Submission status: Accepted

Solution code:
a = [int(c) for c in input().split()]
N=a[0]
M=a[1]
X=a[2]
A = [int(c) for c in input().split()]
A2 = [0]*(N+1)
for i in range(M):
    A2[A[i]] = 1

cnt = X
cost1 = 0
while cnt < N+1:
    cost1+=A2[cnt]
    cnt+=1

cnt = X
cost2 = 0
while cnt > 0:
    cost2+=A2[cnt]
    cnt-=1

if cost1<cost2:
    print(cost1)
else:
    print(cost2)

Submission status: Accepted

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

l = [0] * N
for a in A:
    l[a-1] = 1

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

Submission status: Accepted

Solution code:
import bisect


def answer(n: int, m: int, x: int, a: []) -> int:
    i = bisect.bisect_left(a, x)
    return min(i, len(a) - i)


def main():
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))
    print(answer(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()))
b = 0
c = 0
for a in A:
  if a < X:
    b += 1
  else:
    c += 1
print(min(b, c))

Submission status: Accepted

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

for i , a in enumerate(A):
    if X < a:
        break

if i > len(A) / 2:
    ans = len(A[i:])
else:
    ans = len(A[:i])

print(ans)

Submission status: Accepted

Solution code:
import bisect

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

index = bisect.bisect_left(A,X)
ans = min(M-index,index)
print(ans)