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

b = [0] * (n + 1)
for i in a:
    b[i] = 1
    
l_s = 0
r_s = 0
for i in range(x + 1):
    l_s += b[i]
    
for i in range(x, n + 1):
    r_s += b[i]
print(min(l_s, r_s))

Submission status: Accepted

Solution code:

if __name__ == '__main__':
    n, m,x = map(int, input().split())
    a = [int(i) for i in input().split()]
    count1=0
    count2=0
    for i in a:
        if i < x:
            count1+=1
        elif 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()))
a1=0
a2=0
tmp=x
while tmp<n:
    if tmp+1 in a:
        a1+=1
    tmp+=1
tmp=x
while tmp>0:
    if tmp-1 in a:
        a2+=1
    tmp-=1
print(min(a1,a2))

Submission status: Accepted

Solution code:
import sys

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

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


for i in range(M):
  if A[i] > X:
    AX_index = i
    break
cost_n = len(A) - AX_index
cost_0 = AX_index

print(min(cost_n,cost_0))

Submission status: Accepted

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

s=[0]*(n+1)
l=list(map(int,input().split()))
       
for i in range(m):
    s[l[i]]=1
       
       
if sum(s[0:x])>sum(s[x+1:]):
       print(sum(s[x+1:]))
else:
       print(sum(s[0:x]))

Submission status: Accepted

Solution code:

N, M, X = map(int, input().split())
A = list(map(int, input().split()))
ans1 = 0
ans2 = 0
for i in A:
    if i < X:
        ans1 += 1
    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()))
c1 = 0
c2 = 0
for i in range(0, x+1):
    if i in a:
        c1 += 1
for j in range(x, n+1):
    if j in a:
        c2 += 1
print(min(c1, c2))

Submission status: Accepted

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

for i in range(X, N+1):
    if i in FS:
        cost_N += 1

for i in range(1, X+1):
    if i in FS:
        cost_0 += 1

print(min(cost_N, cost_0))

Submission status: Accepted

Solution code:
import numpy as np
N, M, X = map(int,input().split())
A = [a for a in map(int,input().split())]

squares = np.zeros(N+1)
squares[A] = 1

cost0 = squares[:X].sum()
costN = squares[X+1:].sum()

if cost0 >= costN:
    print(int(costN))
else:
    print(int(cost0))

Submission status: Accepted

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

print(min(cost_for_0, cost_for_N))

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

arr = list(range(n + 1))

for i in arr:
    for j in a:
        if i == j:
            arr[i] = 1
            break
        else:
            arr[i] = 0

low = arr[:x]
high = arr[x:]
c = 0
d = 0
for i in low:
    c += i
for i in high:
    d += i
print(min(c, d))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
count = 0
for a in A:
    if x > a:
        count += 1

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
count = 0
for a in A:
    if x > a:
        count += 1

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

Submission status: Accepted

Solution code:
import bisect
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
b = bisect.bisect_left(A, X)
print(min(b, M-b))

Submission status: Accepted

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

# if max(a) <= x or min(a) >= x:
#     print(0)
#     exit(1)

for i in range(1, x):
    if i in a:
        cost_0 += 1

for i in range(x + 1, n):
    if i in a:
        cost_n += 1

print(min(cost_0, cost_n))

Submission status: Accepted

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

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 range(len(A)):
  if A[k] < x:
    i += 1
  elif A[k] > x:
    j += 1
    
print(min(i,j))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
A= list(map(int, input().split()))
cost1 = 0
cost2 = 0
now1 = x
now2 = x
while now1 < n:
    now1 += 1
    if now1 in A:
        cost1 += 1
while now2 > 0:
    now2 -= 1
    if now2 in A:
        cost2 += 1
print(min(cost1, cost2))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from builtins import int, map, list, print, len, min
    from bisect import bisect_right
    import sys
    sys.setrecursionlimit(10 ** 6)

    input = (lambda: (sys.stdin.readline()).rstrip())
    input_list = (lambda: input().split())
    input_number = (lambda: int(input()))
    input_number_list = (lambda: list(map(int, input_list())))

    N, M, X = input_number_list()
    A = input_number_list()
    A.sort()
    idx = bisect_right(A, X)
    l = len(A[:idx])
    r = len(A[idx:])
    print(min(l, r))


if __name__ == '__main__':
    main()

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 range(M):
    if A[i] < X:
        left += 1
    elif A[i] < N:
        right += 1
print(min(left, right))

Submission status: Accepted

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

to_zero = len([i for i in a if i < x])
to_n = len([i for i in a if i > x])

print(min(to_n, to_zero))

Submission status: Accepted

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

print(min(cost_list[X], cost_list[-1] - cost_list[X]))

Submission status: Accepted

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

index = 0
for i in range(n+1):
    if i == A[index]:
        if i < x:
            cost_zero += 1
        else:
            cost_n += 1
        index = min(index+1, m-1) 
print(min(cost_zero, cost_n))

Submission status: Accepted

Solution code:
def resolve():
    N, M, X = list(map(int, input().split()))
    A = list(map(int, input().split()))
    cost1 = len([a for a in A if a > X])

    cost2 = len([a for a in A if a < X])
    print(min(cost1, cost2))

    return
 

resolve()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# B - Toll Gates
from bisect import bisect_left

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

a = bisect_left(A, X)
print(min(a, M-a))

Submission status: Accepted

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

Submission status: Accepted

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

cost = [0,0]
for i in list:
    if 0 < i < X:
        cost[0] += 1
    if X < i < N:
        cost[1] += 1

print(min(cost))

Submission status: Accepted

Solution code:
# N M X
# A1 A2 ... AM
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
print(min(sum(1 for a in A if a>X), sum(1 for a in A if a<X)))

Submission status: Accepted

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

costmigi=0
for i in range(X,N+1):
    if i in A:
        costmigi+=1
        
print(min(costmigi,len(A)-costmigi))

Submission status: Accepted

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

a.append(x)
newa = sorted(a)

y=newa.index(x)
ans=min(len(newa[:y]),len(newa[y+1:]))
print(ans)

Submission status: Accepted

Solution code:
def resolve():
    N,M,X = map(int,input().split())
    A = list(map(int,input().split()))
    sumLow = min((j for j in range(len(A)) if A[j] > X) , default=-1)
    ans = min(sumLow,M-sumLow)
    print(ans)
resolve()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

def simCost(n,a,c,direction,cost=0):
    if c == 0 or c == n:
        return cost
    elif c in a:
        return simCost(n,a,c+direction,direction,cost+1)
    else:
        return simCost(n,a,c+direction,direction,cost)

    

def solve(n,x,a):
    return min(simCost(n,a,x,+1),simCost(n,a,x,-1))

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




if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[6]:


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


# In[7]:


goal0_cost = sum(pos < X for pos in A)
goalN_cost = sum(pos > X for pos in A)
print(min(goal0_cost, goalN_cost))


# In[ ]:

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
A = [int(i) for i in input().split()]
cnt = 0
for e in A:
    if x > e:
        cnt += 1
    else:
        break

print(min(len(A[:cnt]), len(A[cnt:])))

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, n+1):
  if A.count(i) > 0:
    cost += 1
cost_nomal = cost
cost = 0 
for i in range(1, x+1):
  if A.count(i) > 0:
    cost += 1
cost_reverse = cost

print(min(cost_nomal,cost_reverse))

Submission status: Accepted

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

fee = 0
flist = []
for i in range(len(a)):
    if a[i] < x:
        fee += 1
    else:
        flist.append(fee)
        flist.append(len(a) - i)
        break

print(min(flist))

Submission status: Accepted

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

# xは最初の位置
# nは目的地
# aは料金所（コスト1）

cost = 0
cost2 = 0

for i in a:
  if i > x:
    cost += 1
  else:
    cost2 += 1
    
if cost < cost2:
  print(cost)
else:
  print(cost2)

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline


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

    cost_0 = 0
    cost_N = 0
    for a in A:
        if a < X:
            cost_0 += 1
        else:
            cost_N += 1

    ans = min(cost_0, cost_N)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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


def solve(N: int, M: int, X: int, A: "List[int]"):
    price = [1 if i in A else 0 for i in range(1, N)]
    X -= 1
    left = price[:X]
    right = price[X:]
    print(min(sum(left), sum(right)))
    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 = [int(a) for a in input().split()]
count = 0
for a in A:
    if a > X:
        count += 1
print(count if count < M - count else M - count)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
la=list(map(int,input().split()))
count1=0
count2=0
y=x
while y>=0:
    for i in la:
        if y==i:
            count1+=1
    y-=1

while x<=n:
    for i in la:
        if x==i:
            count2+=1
    x+=1
if count2>count1:
    print(count1)
else:
    print(count2)

Submission status: Accepted

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

B = [0 for _ in range(n+1)]
for a in A:
    B[a] = 1

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

Submission status: Accepted

Solution code:
n,m,x = map(int, input().split())
a = list(map(int, input().split()))
s = x
cost = 0
while s!=0:
    s-=1
    if s in a:
        cost+=1
ans = cost
cost = 0
s = x
while s!=n:
    s+=1
    if s in a:
        cost+=1 
ans = min(ans,cost)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
_,m,*a=map(int,open(0).read().split())
c=sorted(a).index(a[0])
print(min(c,m-c))

Submission status: Accepted

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

cnt = 0
for m in range(M):
    if A[m] < X:
        cnt += 1

print(min(cnt,M-cnt))

Submission status: Accepted

Solution code:
N,M,X=map(int,input().split())
AM=list(map(int,input().split()))
Ns=[0]*(N+1)
for a in AM:
  Ns[a]=1
  pass

i = X
mincost,cost=0,0
while i != 0:
  if Ns[i] == 1:cost+=1
  i-=1
  pass
mincost=cost
cost,i=0,X
while i != N:
  if Ns[i] == 1:cost+=1
  i+=1
  pass
mincost=min(mincost,cost)
print(mincost)

Submission status: Accepted

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

c = len([x for x in A if x <X])
print(min(c,M-c))

Submission status: Accepted

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

cnt_a = len([x for x in A if x < X])
cnt_b = len([x for x in A if x >= X])

print(min(cnt_a, cnt_b))

Submission status: Accepted

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

for i in A:
	cost[i-1] = 1

ans = min(sum(cost[0:X]), sum(cost[X:]))
print(ans)

Submission status: Accepted

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

cost =[0]*(N+1)

for i in A:
    cost[i] = 1

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

cost = 0
for i in range(X, N):
    if i in A:
        cost += 1
min_cost = min(cost, min_cost)
print(min_cost)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def li():
    return list(map(int, input().split()))


def mi():
    return map(int, input().split())


def ii():
    return int(input())


N, M, X = mi()
A = li()

filterdA = list(filter(lambda x: x <= X, A))

print(min(M - len(filterdA), len(filterdA)))

Submission status: Accepted

Solution code:
import bisect
n,m,x=map(int,input().split())
a=[int(i) for i in input().split()]
ind=bisect.bisect(a,x)
print(min(len(a[:ind]),len(a[ind:])))

Submission status: Accepted

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

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

print( min( len(a[0:memo]), len(a[memo:m]) ) )

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

import sys
# import time
# import math
# import numpy as np
# import scipy.sparse.csgraph as cs            # csgraph_from_dense(ndarray, null_value=inf), bellman_ford(G, return_predecessors=True), dijkstra, floyd_warshall
# import random                                # random, uniform, randint, randrange, shuffle, sample
# import string                                # ascii_lowercase, ascii_uppercase, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from datetime import date, datetime          # date.today(), date(year,month,day) => date obj; datetime.now(), datetime(year,month,day,hour,second,microsecond) => datetime obj; subtraction => timedelta obj
# from datetime.datetime import strptime       # strptime('2019/01/01 10:05:20', '%Y/%m/%d/ %H:%M:%S') returns datetime obj
# from datetime import timedelta               # td.days, td.seconds, td.microseconds, td.total_seconds(). abs function is also available.
# from copy import copy, deepcopy              # use deepcopy to copy multi-dimentional matrix without reference
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)



def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1             # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n, m, x = mi()
    L = [0] * (n+1)
    for i in lmi():
        L[i] = 1
    print(min(sum(L[x+1:]), sum(L[:x])))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
def main():
    n, m, x = map(int, input().split())
    num_list = list(map(int, input().split()))
    
    square_list = [0] * (n + 1)
    
    for n in num_list:
        square_list[n-1] = 1
    
    left = sum(square_list[0:x-1])
    right = sum(square_list[x:])
    
    print(min(left, right))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
A = list(map(int,input().split()))
A_a = [int(i) for i in A if i < x]
A_b = [int(i) for i in A if i > x]
L_a = len(A_a)
L_b = len(A_b)


if L_a >= L_b:
    print(L_b)
else:
    print(L_a)

Submission status: Accepted

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

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

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

print(min(right, left))

Submission status: Accepted

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

cost1 = 0
cost2 = 0

for a in range(n+1):
    if a == x:
        break
    for b in range(m):
        if a == charge[b]:
            cost1 += 1

for a in range(n+1, -1, -1):
    if a == x:
        break
    for b in range(m):
        if a == charge[b]:
            cost2 += 1

print(min(cost1, cost2))

Submission status: Accepted

Solution code:
def f10():
    N, M, X=map(int, input().split())
    A=[int(i)-1 for i in input().split()]
    X = X-1
    s=sum(A[i]<X for i in range(len(A)))
    print(min(s, M-s))

def main():
    f10()

main()

Submission status: Accepted

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

d=[0]*(N+1)
for i in range(M):
  d[A[i]]=1
print(min(sum(d[:X]),sum(d[X:])))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
a = list(map(int, input().split()))
a.append(x)
a.sort()
num = a.index(x)
print(min(num, m-num))

Submission status: Accepted

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

cost = [0] * (N + 1)

for i in range(len(A)):
    cost[A[i]] = 1

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

Submission status: Accepted

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

print(min(bisect.bisect(a,x),m-bisect.bisect(a,x)))

Submission status: Accepted

Solution code:
import bisect
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
d = bisect.bisect_left(A, X)
print(min(d, M - d))

Submission status: Accepted

Solution code:
n, m, x = [int(s) for s in input().split()]
a_list = [int(s) for s in input().split()]
for i in range(m):
    if a_list[i] > x:
        break
else:
    i += 1
print(min(i, m - i))

Submission status: Accepted

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

# Xから0かNかどちらに行くのがコストが安いか。
a = 0
b = 0
A = list(map(int, input().split()))
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 = list(map(int,input().split()))
A = list(map(int,input().split()))
left = 0
right = 0
for i in range(M):
    if A[i] < X:
        left += 1
    else:
        right += 1
print(min(left,right))

Submission status: Accepted

Solution code:
n, m, x = map(int, input().split())
A = list(map(int, input().split()))
cost_r = 0
for i in range(x):
    if i in A:
        cost_r += 1
cost_l = len(A) - cost_r
print(min(cost_l, cost_r))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
a.append(x)
a.sort()
b = a.index(x)
c = len(a) - b - 1
if b > c:
    print(c)
else:
    print(b)

Submission status: Accepted

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

a,b = 0,0
for i in A:
  if i>X:
    b+=1
  else:
    a+=1
print(min(a,b))

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


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

l,r = 0,0
for a in A:
    if a < X:
        l += 1
    else:
        r += 1

print(min(l,r))

Submission status: Accepted

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

count_low = 0
count_high = 0
for i in range(a):
  if A[i] > X:
    count_high +=1
  elif A[i] < X:
    count_low += 1
    
if count_low >= count_high:
  print(count_high)
elif count_low < count_high:
  print(count_low)

Submission status: Accepted

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

print(min(left, right))

Submission status: Accepted

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

a = len(list(filter(lambda a: X < a < N, A)))
b = len(list(filter(lambda a: 0 < a < X, A)))

print(min(a, b))

Submission status: Accepted

Solution code:
# For taking integer inputs.
def inp():
    return(int(input()))


# For taking List inputs.
def inlist():
    return(list(map(int, input().split())))


# For taking string inputs. Actually it returns a List of Characters, instead of a string, which is easier to use in Python, because in Python, Strings are Immutable.
def instr():
    s = input()
    return(list(s[:len(s)]))


# For taking space seperated integer variable inputs.
def invr():
    return(map(int, input().split()))


N, M, X = invr()

A = inlist()

l = 0
r = N
lef_gates = 0
right_gates = 0

for a in A:
    if a > X:
        right_gates += 1
    else:
        lef_gates += 1

print(min(lef_gates, right_gates))

Submission status: Accepted

Solution code:
n,m,x=map(int,input().split())
a=[int(k) for k in input().split()]
bigger=smaller=0
for i in range(len(a)):
    if a[i]>x:
        bigger+=1
    else:
        smaller+=1
print(min(bigger,smaller))

Submission status: Accepted

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

smallList = [i for i in a if i < x]
largeList = [i for i in a if x < i]

s = len(smallList)
l = len(largeList)

print(min(s, l))

Submission status: Accepted

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