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:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
N,M,X = map(int,input().split()) #整数の入力
a = [int(i) for i in range(M)] #検問所の入力
b=[]
c=[]
for i in range(X,N): #XからNの範囲の整数について 
  if i in a is True: #ある整数が検問所の整数として存在する
    b.append(1)
for i in range(1,X): #1からX-1の範囲の整数について
  if i in a is True: #ある整数が検問所の整数として存在する
    c.append(1)
print(min(sum(b),sum(c)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import bisect
N, M, X = map(int, raw_input().split())
A = map(int, raw_input().split())
i = bisect.bisect_left(A, X)
if i == 0 or N - i == 0:
	print 0
elif i < N - i:
	print i - 1
else:
	print N - i - 1

Submission status: Wrong Answer

Solution code:
import bisect
N, M, X = map(int, raw_input().split())
A = map(int, raw_input().split())
i = bisect.bisect_left(A, X)
print 0 if i == 0 or N - i == 0 else \
      i - 1 if i < N - i else \
      N - i - 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from numpy import inf
n, m, x =map(int, input().split())
a = list(map(int, input().split()))
ans=inf
if x<a[0] or a[m-1]<x:
    print(0)
    exit()
for i in range(m-1):
    if a[i+1]<x<a[i+2]:
        ans=min(ans,min(i+1,m-i-1))
print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
idx=X
cnt_left=0
cnt_right=0
route_list=[i+1 for i in range(N)]
left=route_list[:idx-1]
right=route_list[idx:]
for i in range(len(left)):
    for c in A:
        if c==left[i]:
            if left[i]==1 or left[i]==N:
                cnt_left+=0
            else:
                cnt_left+=1
for i in range(len(right)):
    for c in A:
        if c==right[i]:
            if right[i]==1 or right[i]==N:
                cnt_right+=0
            else:
                cnt_right+=1

print(min(cnt_right,cnt_left))

Submission status: Wrong Answer

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
idx=X
cnt_left=0
cnt_right=0
route_list=[i+1 for i in range(N)]
left=route_list[:idx]
right=route_list[idx:]
for i in range(len(left)):
    for c in A:
        if c==left[i]:
            if left[i]==1 or left[i]==N:
                cnt_left+=0
            else:
                cnt_left+=1
for i in range(len(right)):
    for c in A:
        if c==right[i]:
            if right[i]==1 or right[i]==N:
                cnt_right+=0
            else:
                cnt_right+=1

print(min(cnt_right,cnt_left))

Submission status: Wrong Answer

Solution code:
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
idx=X
cnt_left=0
cnt_right=0
route_list=[i+1 for i in range(N)]
left=route_list[:idx]
right=route_list[idx:]
for i in range(len(left)):
    for c in A:
        if c==route_list[i]:
            if route_list[i]==1 or route_list[i]==N:
                cnt_left+=0
            else:
                cnt_left+=1
for i in range(len(right)):
    for c in A:
        if c==route_list[i]:
            if route_list[i]==1 or route_list[i]==N:
                cnt_right+=0
            else:
                cnt_right+=1

print(min(cnt_right,cnt_left))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a.sort()

s = sum(a)

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

Submission status: Wrong Answer

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

if __name__ == "__main__":
	N, M, X = list(map(int, input().split()))
	As = list(map(int, input().split()))
	cost = 0
	for A in As:
		if X > A:
			break
		cost += 1
	print(max(cost, M-cost))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

tax = list(map(int,input().split()))
alltax = len(tax)
atax = len(tax[:x])
btax = alltax-atax
if atax > btax:
    print(btax)
else:
    print(atax)

Submission status: Wrong Answer

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

t= [i for i in A if i> 0 and i< X]
s= [i for i in A if i> X and i >N]

print(min(len(t),len(s)))

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
if X < min(A):
	print(0)
else:
	cost_left = M - X + 1
	cost_right = M - cost_left
	print(min(cost_left, cost_right))

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
if X < min(A):
	print(0)
else:
	cost_left = len(A) - X + 1
	cost_right = len(A) - cost_left
	print(min(cost_left, cost_right))

Submission status: Wrong Answer

Solution code:
l = list(map(int,input().split()))
a = list(map(int,input().split()))
b = []
c = []
for n in a:
    if n > l[2]:
        b.append(n)
    else:
        c.append(n)
if l[2] - l[1] <= l[1]:
    print('{}'.format(len(c)))
else:
    print('{}'.format(len(b)))

Submission status: Wrong Answer

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:
    right = mid
  if A[mid] < X:
    left = mid

res = min(left, M - left)
print(res)

Submission status: Wrong Answer

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:
    right = mid
  if A[mid] < X:
    left = mid

mid = (left + right) // 2
res = min(mid, M - mid)
print(res)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input('N M X = ').split())
A = map(int, input('A_{i}(i=1,2,…,M)= ').split()) #int型で入力

setA = set(A) #list型をset型へ
s1 = range(0, X)
s2 = range(X, N+1)
a1 = set(s1) & (setA) #積集合
a2 = set(s2) & (setA)
cost1 = len(a1)
cost2 = len(a2)

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

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input('N M X = ').split())
A = map(int, input('A_{i}(i=1,2,…,M)= ').split()) 

setA = set(A) 
s1 = range(0, X)
s2 = range(X, N+1)
a1 = set(s1) & (setA) 
a2 = set(s2) & (setA)
cost1 = len(a1)
cost2 = len(a2)

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

Submission status: Wrong Answer

Solution code:
l = input().split()
n = int(l[0])
m = int(l[1])
x = int(l[2])
a = input().split()
i = 1
while(1):
    if int(a[i]) > x:
        break
    i = i + 1
if i - 1 < m - i + 1:
    print(i - 1)
else:
    print(m - i + 1)

Submission status: Wrong Answer

Solution code:
#Toll Gates

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

#進む側
temp1 = X
cost1 = 0
for i in range(N-X+1):
	if temp1 == N:
		break
	temp1 += 1
	for j in range(M):
		if temp1 == A[j]:
			cost1 += 1

#戻る側
temp2 = X
cost2 = 0
for i in range(N-X+1):
	if temp2 == 0:
		break
	temp2 -= 1
	for j in range(M):
		if temp2 == A[j]:
			cost2 += 1

print(min(cost1,cost2))

Submission status: Wrong Answer

Solution code:
N,M,X = (int(i) for i in input().split())
places = input()
placelistchar = places.split(" ")

placelist = []
for k in range(M):
    placelist.append(int(placelistchar[k]))

print(placelist)


countbig = 0
countsmall = 0

#i = 5
#print(i in placelist)

for i in range(X+1,N):
    if (i in placelist == True):
        countbig = countbig +1
for j in range(0,X):
    if (j in placelist == True):
        countsmall = countsmall + 1

print(min(countsmall,countbig))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
N, M, X = map(int, input().split())
A = list(map(int, input().split()))
p = 0
for i in range(N+1):
    if A[i] > X:
        break
    p = i
ans = [len(A[:p]), len(A[p:])]
print(min(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
fee = set(input().split())
ls = list(range(n+1))
f, b = ls[:x], ls[x+1:]
print(min(len(fee & set(f)), len(fee & set(b))))

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
fee = map(int, input().split())
ls = list(range(n+1))
f, b = ls[:x], ls[x+1:]
print(min(len(set(fee) & set(f)), len(set(fee) & set(b))))

Submission status: Wrong Answer

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

for b in a:
    c += 1
    if x < b:
        if c < (m/2):
            print(c)
        else:
            print(m-c)
        break

Submission status: Wrong Answer

Solution code:
a=[int(x) for x in input().split()]
n = a[0]
m = a[1]
x = a[2]
arr = a[3:3+m]
goLeft = 0
goRight = 0
for i in arr:
    if i < x:
        goLeft += 1
    else:
        goRight += 1
if goLeft > goRight:
    print(goRight)
else:
    print(goLeft)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

B=0
C=0

D=[]

for i in range(N-X):
    if i in A:
        B=B+1

D.append(B)
        
        
for i in range(X):
    if i in A:
        C=C+1

D.append(C)

print(min(D))

Submission status: Wrong Answer

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

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

B=0
C=0

D=[]

for i in range(N-X):
    if i in A:
        B=B+1

D.append(B)
        
        
for i in range(X-1):
    if i in A:
        C=C+1

D.append(C)

print(min(D))

Submission status: Wrong Answer

Solution code:
inputs_ = [input().split() for i in range(2)]
N = int(inputs_[0][0])
M = int(inputs_[0][1])
X = int(inputs_[0][2])
A = list(map(int,inputs_[1][:]))
costs = [0]*(N)
for num in range(N):
    for i in range(M):
        if(num == A[i]):
            costs[num] = 1
leftcost = sum(costs[0:X-1])
rightcost = sum(costs[X+1:N])
print(min(leftcost,rightcost))

Submission status: Wrong Answer

Solution code:
inputs_ = [input().split() for i in range(2)]
N = int(inputs_[0][0])
M = int(inputs_[0][1])
X = int(inputs_[0][2])
A = list(map(int,inputs_[1][:]))
costs = [0]*(N+1)
for num in range(N):
    for i in range(M):
        if(num == A[i]):
            costs[num] = 1
leftcost = sum(costs[0:X-1])
rightcost = sum(costs[X+1:N])
print(min(leftcost,rightcost))

Submission status: Wrong Answer

Solution code:
inputs_ = [input().split() for i in range(2)]
N = int(inputs_[0][0])
M = int(inputs_[0][1])
X = int(inputs_[0][2])
A = list(map(int,inputs_[1][:]))
costs = [0]*(N+1)
for num in range(N):
    for i in range(M):
        if(num == A[i]):
            costs[num] = 1
leftcost = sum(costs[0:X-1])
rightcost = sum(costs[X+1:N])
print(leftcost,rightcost,costs)
print(min(leftcost,rightcost))

Submission status: Wrong Answer

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

for j in A:
    if j > X:
        continue
    else:
        big=big+1



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

Submission status: Wrong Answer

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

count_right=0
count_left=0
#print("right"+str(X+1)+":"+str(N+1))
#print("left"+str(0)+":"+str(X-1))
for i in range(X+1,N+1):
    if i in A:
#        print("mach:"+str(i))
        count_right=count_right+1
endpoint=max(0,X-1)
for i in range(endpoint):
    if i in A:
#        print("mach:"+str(i))
        count_left=count_left+1

print(min(count_right,count_left))

Submission status: Wrong Answer

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

sm = l[2]
la = l[2]
while(True):
    if sm == 0:
        print 0
    if la == l[0]:
        print 0
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2 + 0.5
        break
    if sm in A:
        ix = A.index(sm)
	break
    if la in A:
	ix = A.index(la)
	break
M = l[1] - ix - 1
if M > ix:
    print int(math.ceil(ix)) + 1
else:
    print int(math.ceil(M))

Submission status: Wrong Answer

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

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

corse_A = A[0:X-1]
corse_B = A[X:]

costA = len(corse_A) - 1
costB = len(corse_B) - 1

if costA < 0:
    print(costB)
elif costB < 0:
    print(costA)
elif costA == 0 or costB == 0:
    print(0)
elif costA < costB:
    print(costA)
else:
    print(costB)

Submission status: Wrong Answer

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

count_right=0
count_left=0
#print("right"+str(X+1)+":"+str(N+1))
#print("left"+str(0)+":"+str(X-1))
for i in range(X+1,N+1):
    if i in A:
#        print("mach:"+str(i))
        count_right=count_right+1
endpoint=min(0,X-1)
for i in range(endpoint):
    if i in A:
#        print("mach:"+str(i))
        count_left=count_left+1

print(min(count_right,count_left))

Submission status: Wrong Answer

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

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

corse_A = A[0:X-1]
corse_B = A[X:]

costA = len(corse_A) - 1
costB = len(corse_B) - 1

if costA <= 0:
    print(costB)
elif costB <= 0:
    print(costA)
elif costA < costB:
    print(costA)
else:
    print(costB)

Submission status: Wrong Answer

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

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

corse_A = A[0:X-1]
corse_B = A[X:]

costA = len(corse_A) - 1
costB = len(corse_B) - 1

if costA < 0:
    print(costB)
elif costB < 0:
    print(costA)
elif costA < costB:
    print(costA)
else:
    print(costB)

Submission status: Wrong Answer

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

sm = l[2]
la = l[2]
while(True):
    if sm == 0:
        print 0
    if la == l[0]:
        print 0
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2 + 0.5
        break
    if sm in A:
        ix = A.index(sm)
	break
    if la in A:
	ix = A.index(la)
	break
M = l[1] - ix - 1
if M > ix:
    print int(math.floor(ix))
else:
    print int(math.ceil(M))

Submission status: Wrong Answer

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

sm = l[2]
la = l[2]
while(True):
    if sm == 0:
        print 0
    if la == l[0]:
        print 0
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2 + 0.5
        break
    if sm in A:
        ix = A.index(sm)
	break
    if la in A:
	ix = A.index(la)
	break
M = l[1] - ix - 1
if M > ix:
    print int(math.ceil(ix))
else:
    print int(math.ceil(M))

Submission status: Wrong Answer

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

sm = l[2]
la = l[2]
while(True):
    sm = sm - 1
    la = la + 1
    if sm == 0:
        print 0
    if la == l[0]:
        print 0
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2 + 0.5
        break
    if sm in A:
        ix = A.index(sm)
	break
    if la in A:
	ix = A.index(la)
	break
M = l[1] - ix - 1
if M > ix:
    print int(math.ceil(ix))
else:
    print int(math.ceil(M))

Submission status: Wrong Answer

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

sm = l[2]
la = l[2]
while(True):
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2 + 0.5
        break
    if sm in A:
        ix = A.index(sm)
	break
    if la in A:
	ix = A.index(la)
	break
    if sm == 0:
        print 0
    if la == l[0]:
        print 0
M = l[1] - ix - 1
if M > ix:
    print int(math.ceil(ix))
else:
    print int(math.ceil(M))

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
N,M,X = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
A = np.array(A)
# print(A)
test = (N+1)/2
count1 = np.where(A >= test)
count2 = np.where(A <= test)
# print(count1)
# print(len(count2))
# print("test")

if count1[0][0] == 0 and len(count1[0]) == 1:
    print(0)
    sys.exit()
elif count2[0][0] == 0 and len(count2[0]) == 1:
    print(0)
    sys.exit()

if (X == N) or (X == 0):
    print(0)
    sys.exit()

temp = min(len(count1[0]),len(count2[0]))
print(temp)

Submission status: Wrong Answer

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

sm = l[2]
la = l[2]
while(True):
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2 + 0.5
        break
    if sm in A:
        ix = A.index(sm)
	break
    if la in A:
	ix = A.index(la)
	break
M = l[1] - ix - 1
if M > ix:
    print int(math.ceil(ix))
else:
    print int(math.ceil(M))

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 X == 0 or X == 1 or X == (N-1) or X == N:
    print 0
elif 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())
A = sorted([int(i) for i in input().split()])
a = 0
b = 0
paying_area = range(1, M+1)

for i in range(X, 0, -1):
    if i-1 in A and not i-1 in [0, X, N]:
        print(i)
        a += 1

for i in range(X, N):
    if i+1 in A and not i+1 in [0, X, N]:
        b += 1

print(min((a,b)))

Submission status: Wrong Answer

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

sm = l[2]
la = l[2]
while(True):
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2 + 0.5
        print ix
        break
    if sm in A:
        ix = A.index(sm)
	break
    if la in A:
	ix = A.index(la)
	break
M = l[1] - ix - 1
print M
if M > ix:
    print int(math.ceil(ix))
else:
    print int(math.ceil(M))

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A_list = [int(x) for x in input().split()]
minus_counter = 0
plus_counter = 0
for i in range(len(A_list)):
    if A_list[i+1] > M:
        break
    minus_counter += 1
for i in range(minus_counter, len(A_list)):
    plus_counter += 1
print(min(minus_counter, plus_counter))

Submission status: Wrong Answer

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

sm = l[2]
la = l[2]
while(True):
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2 + 0.5
        print ix
        break
    if sm in A:
        ix = A.index(sm)
	break
    if la in A:
	ix = A.index(la)
	break
M = l[1] - ix
if M > ix:
    print int(math.ceil(ix))
else:
    print int(math.ceil(M))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
N,M,X = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
A = np.array(A)
# print(A)
test = (N+1)/2
count1 = np.where(A >= test)
count2 = np.where(A <= test)
# print(count1)
# print(len(count2))
# print("test")

if count1[0][0] == 0 and len(count1[0]) == 1:
    print(0)
    sys.exit()
elif count2[0][0] == 0 and len(count2[0]) == 1:
    print(0)
    sys.exit()

# print(len(count1[0]))
# print(len(count2[0]))
# print(count1[0][0])
temp = min(len(count1[0]),len(count2[0]))
print(temp)

Submission status: Wrong Answer

Solution code:
import numpy as np
import sys
N,M,X = map(int,input().split(" "))
A = list(map(int,input().split(" ")))
A = np.array(A)
# print(A)
test = (N+1)/2
count1 = np.where(A >= test)
count2 = np.where(A <= test)
# print(count1)
# print(len(count2))
# print("test")

if count1[0][0] == 0 and len(count1[0]) == 1:
    print(0)
    sys.exit()
elif count2[0][0] == 0 and len(count2[0]) == 1:
    print(0)
    sys.exit()

Submission status: Wrong Answer

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

if l[2] in A:
    M = l[1] - A.index(l[2])
    if M > A.index(l[2]):
        print A.index(l[2])
    else:
        print M
sm = l[2]
la = l[2]
while(True):
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2
        break
    if sm in A:
        ix = A.index(sm)
	break
    if la in A:
	ix = A.index(la)
	break
M = l[1] - ix
if M > ix:
    print int(math.floor(ix))
else:
    print int(math.ceil(M))

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 X == 0 or X == N:
    print 0
elif 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())
A_list = [int(x) for x in input().split()]
minus_counter = 0
plus_counter = 0
for i in range(len(A_list)):
    if A_list[i] > M:
        break
    minus_counter += 1
for i in range(minus_counter, len(A_list)):
    plus_counter += 1
print(min(minus_counter, plus_counter))

Submission status: Wrong Answer

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

if l[2] in A:
    M = l[1] - A.index(l[2])
    if M > A.index(l[2]):
        print A.index(l[2])
    else:
        print M
sm = l[2]
la = l[2]
while(True):
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2
        break
    if sm in A:
        ix = A.index(sm)
	break
    if la in A:
	ix = A.index(la)
	break
M = l[1] - ix
if M > ix:
    print int(math.ceil(ix))
else:
    print int(math.ceil(M))

Submission status: Wrong Answer

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

import math

l = map(int, raw_input().split())
A = map(int, raw_input().split())

if l[2] in A:
    M = l[1] - A.index(l[2])
    if M > A.index(l[2]):
        print A.index(l[2])
    else:
        print M
sm = l[2]
la = l[2]
while(True):
    sm = sm - 1
    la = la + 1
    if sm in A and la in A:
    	ix = A.index(sm) + A.index(la)
        ix = ix / 2
        break
    if sm in A:
        ix = A.index(sm)
	break
    if la in A:
	ix = A.index(la)
	break
M = l[1] - ix
if M > ix:
    print math.ceil(ix)
else:
    print math.ceil(M)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A = sorted([int(i) for i in input().split()] + [X])
start = A.index(X)
a = 0
b = 0
paying_area = range(1, M+1)
for i in range(start, -1, -1):
    if i in paying_area and not i in [0, X, N]:
        a += 1

for i in range(start, N+1):
    if i in paying_area and not i in [0, X, N]:
        b += 1

print(min((a,b)))

Submission status: Wrong Answer

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

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

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

print(min(count_right,count_left))

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A = sorted([int(i) for i in input().split()] + [X])
start = A.index(X)
a = 0
b = 0
paying_area = range(1, M+1)
for i in range(start, 0, -1):
    if i in paying_area and not i in [0, X, N]:
        a += 1

for i in range(start, N):
    if i in paying_area and not i in [0, X, N]:
        b += 1

print(min((a,b)))

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
for i in range(m):
 if x < list[i]:
  ans += 1
print(ans)

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A = sorted([int(i) for i in input().split()] + [X])
start = A.index(X)
print(min((len(range(start, M+1, -1)), len(range(start, M+1)))))

Submission status: Wrong Answer

Solution code:
N, M, X = map(int, input().split())
A = sorted([int(i) for i in input().split()] + [X])
start = A.index(X)
print(min((len(range(start-1, 0, -1)), len(range(start, N)))))

Submission status: Wrong Answer

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

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

print(min(ansn,ans0))

Submission status: Wrong Answer

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

print(ans)