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:
def main():
  n,m,x = list(map(int,input().split()))
  a = list(map(int,input().split()))
  
  for i in range(0,m):
    if a[i]>x:
      if i<m-i:
        print(i)
      else:
        print(m-i)
      break
main()

Submission status: Accepted

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

Submission status: Accepted

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

l = [i for i in A if i > X]

l2 = [i for i in A if i < X]

print(min(len(l), len(l2)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from bisect import bisect_left
N,M,X = map(int, input().split())
A = [int(i) for i in input().split()]
print(min(bisect_left(A, X), len(A) - bisect_left(A, X)))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

if up > down :
  print(down)
else :
  print(up)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return map(int, sys.stdin.readline().split())
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res

N,M,X=LI()
AS=LI()

bef=0
aft=0
for i in AS:
    if i <= X:
        bef += 1
    else:
        aft += 1

print(min(bef, aft))

Submission status: Accepted

Solution code:
from bisect import bisect_left

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

y = bisect_left(a, x)
print(min(y, m-y))

Submission status: Accepted

Solution code:
from bisect import bisect_right

n, m, x = (int(x) for x in input().split())
A = list(int(x) for x in input().split())
index = bisect_right(A, x)
print(min(len(A[:index]), len(A[index:])))

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''
    N, M, X = [int(item) for item in input().split()]
    As = [int(item) for item in input().split()]

    low = [item for item in As if item < X]
    high = [item for item in As if item > X]

    print(min(len(low), len(high)))


if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
import sys
from bisect import bisect_left
def input(): return sys.stdin.readline().strip()


def main():
    n, m, x = map(int, input().split())
    A = list(map(int, input().split()))
    idx = bisect_left(A, x)
    print(min(idx, m - idx))


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
N,M,X = map(int,input().split())
array_gate = list(map(int,input().split()))
array_base = [0] * (N+1)

if not ( 1 <= N,M <= 100):
    sys.exit()
if not ( 1 <= X <= N -1 ):
    sys.exit()
if not ( 1 <= min(array_gate) <= max(array_gate) <= N - 1):
    sys.exit()

for I in range(len(array_base)):
    if I in array_gate:
        array_base[I] = 1

left = array_base[0:X]
right = array_base[X:-1]
if left.count(1) <= right.count(1):
    result = left.count(1)
else:
    result = right.count(1)

print(result)

Submission status: Accepted

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

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

Submission status: Accepted

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

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

print(min(cost[0],cost[1]))

Submission status: Accepted

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

cnt_down = 0
cnt_up = 0
for i in range(x, 0, -1):
    if i in A: cnt_down += 1

for j in range(x, n+1, 1):
    if j in A: cnt_up += 1

ans = min(cnt_down, cnt_up)
print(ans)

Submission status: Accepted

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

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

cost2 = 0
for i in range(X, 0, -1):
    if i in A:
        cost2 += 1
print(min(cost1, cost2))

Submission status: Accepted

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

Submission status: Accepted

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

toN =0
to0 =0

for i in range(X+1,N):
  if i in As:
    toN +=1
for i in range(X-1,0,-1):
  if i in As:
    to0 +=1
print(min(toN,to0))

Submission status: Accepted

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

count_a=0
for i in range(m):
    if a[i]<x:
        count_a+=1

count_b=m-count_a

print(min(count_a,count_b))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x, *aa = map(int, open(0).read().split())

print(min(len([a for a in aa if a<x]), len([a for a in aa if a>x])))

Submission status: Accepted

Solution code:
def actual(N, M, X, A):
    # マスXの左右それぞれにある料金所の数を調べればOK
    toll_gates_left = [a_i for a_i in A if a_i < X]
    toll_gates_right = [a_i for a_i in A if X < a_i]

    return min(len(toll_gates_left), len(toll_gates_right))

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

print(actual(N, M, X, A))

Submission status: Accepted

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

Submission status: Accepted

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

l = list(range(1, X))
r = list(range(X+1, N+1))

l_c = len(set(A)&set(l))
l_r = len(set(A)&set(r))

print(min(l_c, l_r))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

result = min(len([i for i in a if i > x]), len([i for i in a if i < x]))
print(result)

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:
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

n,m,x = nm()
a=nl()

left=0
right=0
for ai in a:
  if ai < x:
    left+=1
  if ai > x:
    right+=1
print(min(left,right))

Submission status: Accepted

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

print(min(len([w for w in a_li if 0 <= w <= x]),
          len([w for w in a_li if min(x, n) <= w <= max(x, n)])))

Submission status: Accepted

Solution code:
import bisect
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
#aa = sorted(a,reverse=True)

#print(bisect.bisect_left(a,x))
#print(bisect.bisect_left(aa,x))

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

Submission status: Accepted

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

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline

N, M, X = map(int, input().split())
list_A = list(map(int, input().split()))
l = 0
r = 0

for A in list_A:
    if A < X:
        l += 1
    else:
        r += 1

print(min(l, r))

Submission status: Accepted

Solution code:
import numpy as np

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

ans = 0
if N <= X:
    ans = np.intersect1d(A[A > N], A[A < X]).shape[0]
else:
    ans = min(
        np.intersect1d(A[A > 0], A[A < X]).shape[0],
        np.intersect1d(A[A < N], A[A > X]).shape[0],
    )

print(ans)

Submission status: Accepted

Solution code:
n,m,k = map(int, input().split())
a = list(map(int,input().split()))
cnt = 0
for i in a:
  if i < k :
  	cnt += 1
if(cnt < m-cnt):
  print(cnt)
else:
  print(m-cnt)

Submission status: Accepted

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

print(min(ans1,ans2))

Submission status: Accepted

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

Submission status: Accepted

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

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

nlis = [0]*(n+1)

for i in lis:
    nlis[i] = 1

ans = min(sum(nlis[:x]), sum(nlis[x:]))

print(ans)

Submission status: Accepted

Solution code:
a,b,c=map(int,input().split())
d=list(map(int,input().split()))
result1=list(range(0,c+1))
result2=list(range(c,a+1))
ans1=0
ans2=0
for i in result1:
  if i in d:
    ans1+=1
for i in result2:
  if i in d:
    ans2+=1
print(min(ans1,ans2))

Submission status: Accepted

Solution code:
N,M,X = map(int, input().split())
A = list(map(int, input().split()))
B = []
C = []
for i in range(0, X):
  if i in A:
    B.append(i)
for j in range(X, N):
  if j in A:
    C.append(j)
print(min(len(B), len(C)))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-06-25 22:12:11 +0900
# LastModified: 2020-06-25 22:33:48 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    n, m, x = map(int, input().split())
    a = list(map(int, input().split()))
    a.sort()
    if x<a[0] or a[-1]<x:
        print("0")
        return

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



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
C = [False] * (N + 1)
for a in A:
    C[a] = True
print(min(sum(C[:X]), sum(C[X:])))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
lst = list(map(int, input().split()))
import bisect
z = bisect.bisect_left(lst, x)
#print(z)
print(min(len(lst[:z]), len(lst[z:])))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
s=sum(int(i)<x for i in input().split())
print(min(s,m-s))

Submission status: Accepted

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

left=sum(B[:X])
right=M-left
print(min(left,right))

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
squares = [0 for _ in range(N+1)]

A = list(map(int, input().split()))
for a in A:
    squares[a] = 1

root_a = sum(squares[0: X])
root_b = sum(squares[X: N+1])

if root_a < root_b:
    print(root_a)
else:
    print(root_b)

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(m):
	if x<S[i]:
		F=S[:i]
		break

print(min(len(F), len(S)-len(F)))

Submission status: Accepted

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

c = 0
s = 0
for i in range(x,n):
	if i in a:
		c += 1
for i in range(x):
	if i in a:
		s += 1
print(min(s,c))

Submission status: Accepted

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

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

print(min(cnt, M - cnt))

Submission status: Accepted

Solution code:
#n + 1 = マスの数
#m = 料金所の数(a)
#x = 最初のマス
n,m,x = map(int,input().split())
#a = 料金所の場所
a = list(map(int,input().split()))

for i in range(m):
    if a[i] > x:
        p = i
        break

#p = xより右か左かを判別
i = p
j = m - p

print(min(i,j))

Submission status: Accepted

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

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

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

if sum(cost[:X]) > sum(cost[X:]):
    print(sum(cost[X:]))
else: print(sum(cost[:X]))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
au = []
at = []
for i in range(m):
  if a[i] < x:
    au.append(a[i])
  else:
    at.append(a[i])

auv = len(au)
atv = len(at)
print(min(auv,atv))

Submission status: Accepted

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

print(min(left,right))

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(x, n+1):
  if i in a:
    ans1 += 1
while x > 0:
  if x in a:
    ans2 += 1
  x-=1
print(min(ans1,ans2))

Submission status: Accepted

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

m_low =0

for a in A:
  if X < a:
    break
  m_low+=1
  
m_high = M - m_low

print(m_low if m_low<m_high else m_high)

Submission status: Accepted

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

# check
cost = min(len([a for a in A if a > X]), len([a for a in A if a < X]))
print(cost)

Submission status: Accepted

Solution code:
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()
def resolve():
    n, m, x = map(int, input().split())
    toll = [False] * (n + 1)
    for a in map(int, input().split()):
        toll[a] = True

    back = 0
    for i in range(x - 1, -1, -1):
        back += toll[i]
    forth = 0
    for i in range(x + 1, n + 1):
        forth += toll[i]
    print(min(back, forth))
resolve()

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
s=sum(int(i)<x for i in input().split())
print(min(s,m-s))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#n=int(input())
n,m,x=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

right=len([a for a in al if a <=x])
left=len([a for a in al if a>=x])

print(min(right,left))

Submission status: Accepted

Solution code:
def resolve():
    N, M, X = [int(i) for i in input().split()]
    A = [int(i) for i in input().split()]
    for i in range(M):
        if A[i] > X:
            break
    print(min(len(A[:i]), len(A[i:])))


resolve()

Submission status: Accepted

Solution code:
a = [input().split() for l in range(2)]

N = int(a[0][0]) 
M = int(a[0][1]) 
X = int(a[0][2]) # current place 

goal_len01 = N - X # end place
goal_len02 = X # start place

cost1 = 0
for i in range(goal_len01):
  if str(X+i+1) in a[1]:
    cost1 += 1

cost2 = 0
for i in range(goal_len02):
  if str(i+1) in a[1]:
    cost2 += 1

min_cost = 0
if cost1 >= cost2:
  min_cost = cost2
else:
  min_cost = cost1
  
print(min_cost)

Submission status: Accepted

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

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

L = []
for i in range(1, N):
    if i in A:
        L.append(True)
    else:
        L.append(False)

index = X - 1

ans1 = L[:index].count(True)
ans2 = L[index+1:].count(True)

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

Submission status: Accepted

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

print(min(left, right))

Submission status: Accepted

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

a = 0
b = 0
for i in range(M):
    if S[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 = list(map(int, input().split()))

l_cnt = 0
for a in A_list:
    l_cnt += 1 if a < X else 0
print(min(l_cnt, M-l_cnt))

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(m):
    if a[i]<x:
        cost1+=1
    else:
        cost2+=1
print(min(cost1,cost2))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
money=[False]*N
leftcount=0
rightcount=0
for i in A:
    money[i]=True
for i in range(X,0,-1):
    if money[i]==True:
        leftcount+=1
for i in range(X,N):
    if money[i]==True:
        rightcount+=1
if leftcount>rightcount:
    print(rightcount)
else:
    print(leftcount)

Submission status: Accepted

Solution code:
N, M, X = map(int, input().split())
*A, = map(int, input().split())
to_n = 0
for i in range(X, N+1):
    if i in A:
        to_n += 1
to_zero = 0
for i in range(X, 0, -1):
    if i in A:
        to_zero += 1
print(min(to_n, to_zero))

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M, X = lr()
A = lr()
left = sum(1 for y in A if y < X)
right = M - left
answer = min(left, right)
print(answer)

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:
    ans += 1
  else:
    break
    
print(min(ans, m-ans))

Submission status: Accepted

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

nums = [0] * (n + 1)
indices = list(map(int, input().split()))

for i in indices:
    nums[i] = 1

print(min(nums[:x].count(1), nums[x:].count(1)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

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

cos = [0]*(N+1)
for a in A:
    cos[a] += 1

toz = sum(cos[:X])
ton = sum(cos[X:])
print(min(toz, ton))

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(m):
  if a[i] > x:
    print(min(i,m-i))
    break

Submission status: Accepted

Solution code:
# template by 3xC and starkizard.
# contributors: 

#####################################################################################
from __future__ import division, print_function 

import sys
import os
from collections import Counter, deque, defaultdict
import itertools
import math
import io


"""Uncomment modules according to your need"""


# from bisect import bisect_left, bisect_right, insort
# from heapq import heappop, heapify, heappush
# from random import randint as rn
# from Queue import Queue as Q
# from copy import deepcopy
# from decimal import *
# import re
# import operator

#####################################################################################
# this enables you to write python3 code with PyPy2 (Python 2)
if sys.version_info[0] < 3:
    input = raw_input
    range = xrange

    filter = itertools.ifilter
    map = itertools.imap
    zip = itertools.izip

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

"""value of mod"""
MOD = 998244353
mod = 10**9 + 7

"""Uncomment next 4 lines if doing huge recursion"""
# import threading
# threading.stack_size(1<<27)
# sys.setrecursionlimit(10000

def prepare_factorial(mod=mod):
    """ returns two lists, factorial and inverse factorial modulo argument by default 10**9 +7 """
    # Comment code out when you don't need inverse factorial or vice versa
    fact = [1]
    for i in range(1, 200005):
        fact.append((fact[-1] * i) % mod)

    ifact = [0] * 200005
    ifact[200004] = pow(fact[200004], mod - 2, mod)
    for i in range(200004, 0, -1):
        ifact[i - 1] = (i * ifact[i]) % mod

    return fact, ifact

def modinv(n, p):
    """ returns N inverse modulo p """
    return pow(n, p - 2, p)

def ncr(n, r,  fact, ifact):
    """ takes 4 arguments: n , r and factorial and inverse factorial lists"""
    t = (fact[n] * (ifact[r]*ifact[n-r]) % MOD)% MOD
    return t


def get_n(Sum):    
    """this function returns the maximum n for which Summation(n) <= Sum"""
    ans = (-1 + sqrt(1 + 8*Sum))//2
    return ans

def sieve(n):
    """ returns a list of prime numbers till n """
    if n < 2: return list()
    prime = [True for _ in range(n + 1)]
    p = 3
    while p * p <= n:
        if prime[p]:
            for i in range(p * 2, n + 1, p):
                prime[i] = False
        p += 2
    r = [2]
    for p in range(3, n + 1, 2):
        if prime[p]:
            r.append(p)
    return r



def divs(n, start=1):
    """ returns a list of all divisors till n """
    divisors = []
    for i in range(start, int(math.sqrt(n) + 1)):
        if n % i == 0:
            if n / i == i:
                divisors.append(i)
            else:
                divisors.extend([i, n // i])
    return divisors



def divn(n, primes):
    """ returns the number of divisors, two arguments n and the sieve till n """
    divs_number = 1
    for i in primes:
        if n == 1:
            return divs_number
        t = 1
        while n % i == 0:
            t += 1
            n //= i
        divs_number *= t



def lrfind(d, x, default=-1):
    """ Takes 2 arguments an iterable and an element. returns a tuple (firstoccurence,lastoccurence) -1 if not found """
    left = right = -1
    for i in range(len(d)):
        if d[i] == x:
            if left == -1: left = i
            right = i
    if left == -1:
        return default, default
    else:
        return left, right

def gcd(x, y): # math.gcd is slower
    """ returns greatest common divisor of x and y """
    while y:
        x, y = y, x % y
    return x

def check_sorted(a):
    ''' returns True/False '''
    for i in range(len(a)-1):
        if a[i]>a[i+1]:
            return False
    return True
def ceil(n, k=1): return n // k + (n % k != 0) #returns math.ceil but protecting against floating inconsistencies
def input(): return sys.stdin.readline().strip()
def ii(): return int(input()) #inputs integer
def mi(): return map(int, input().split()) # inputting space seperated variables for example x,y,z
def li(): return list(map(int, input().split())) #inputting a space seperated list of integers
def lw(): return input().split() #inputting a space seperated list of strings
def lcm(a, b): return abs(a * b) // gcd(a, b) #returns LCM of two arguments
def prr(a, sep=' ', end='\n'): print(sep.join(map(str, a)), end=end) #For printing an iterable with seperator sep as optional second argument (default : " "), ending character (default: "\n") as optional third
def dd(): return defaultdict(int) #returns a dictionary with values defaulted to 0
def ddl(): return defaultdict(list) #returns a dictionary with values defaulted to []
def write(s): return sys.stdout.write(s)












###################################################################
def main():
    #CODE GOES HERE:
    n,m,x=mi()
    a=li()
    left=0
    right=0
    for i in a:
        if i<x:
            left+=1
        else:
            right+=1
    print(min(left,right))


















    
""" -------- Python 2 and 3 footer by Pajenegod and c1729 ---------"""

py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192

class FastIO(BytesIO):
    newlines = 0

    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
        return s

    def read(self):
        while self._fill(): pass
        return super(FastIO, self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill();
            self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)


class IOWrapper(IOBase):

    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s: self.buffer.write(s.encode('ascii'))
            self.read = lambda: self.buffer.read().decode('ascii')
            self.readline = lambda: self.buffer.readline().decode('ascii')


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')

""" main function"""

if __name__ == '__main__':
    main()
    # threading.Thread(target=main).start()

Submission status: Accepted

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

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:
    ans += 1
  else:
    break
    
print(min(ans, m-ans))

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:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(m):
    if a[i] > x:
        cnt = i
        break
print(min(cnt, m-cnt))