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:
#ABC094 B
n,m,x=map(int,input().split())
List=[int(i) for i in input().split()]
lcost=0
rcost=0
for i in range(x):
    for a in List:
        if a<i:
            lcost+=1

for k in range(x,n):
    for b in List:
        if b>i:
            rcost+=1

print(min(lcost,rcost))

Submission status: Wrong Answer

Solution code:

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

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

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

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:

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

#goal = N - X
A_goal = [i for i in A_list if X < i and i < N]
print(len(A_goal))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i, a in enumerate(A): # numerate オブジェクトを返します
    if X < a:
        break

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

print(answer)

Submission status: Wrong Answer

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

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

# ゴールするまでにかかるコストの最小値
print(min(sum(l[:X]), sum(l[X:])))

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

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

Submission status: Wrong Answer

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

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
if 1<m<=n:
    x-=1
print(min(abs(n-x-1),abs(x-1)))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 > M:
        right += 1
    else:
        left += 1
print(min(left, right))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 += 1
        if cnt > M - cnt:
            cnt = M - cnt

print (cnt)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
A=list(map(int,input().split()))
for i in range(m):
  if A[0]<x:
    ans=0
  elif A[i]>x:
    ans=min(i,m-i)
    break
  else:
    ans=0

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
A=list(map(int,input().split()))
for i in range(m):
  if A[i]>x:
    ans=min(i,m-i)
else:
  ans=0

print(ans)

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
A=list(map(int,input().split()))
for i in range(m):
  if A[i]>x:
    ans=min(i,m-i)
  else:
    ans=0

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a,b,c=map(int,input().split())
b=list(map(int,input().split()))
i=c
total=0
total2=0
while True:
    i+=1
    if i in b:
        total+=1
    if i==a:
        break
while True:
    i-=1
    if i in b:
        total2+=1
    if i==0:
        break
print(min(total,total2))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

for j in range(x-1):
    if j in a:
        cnt2 += 1

print(min(cnt1, cnt2))

Submission status: Wrong Answer

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

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

for j in range(x-1):
    if j in a:
        cnt2 += 1

print(min(cnt1, cnt2))

Submission status: Wrong Answer

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

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

for j in range(x-1):
    if j in a:
        cnt2 += 1

print(max(cnt1, cnt2))

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
a=[int(i)for i in input().split()]
res=0
if x==n/2:
    tmp=[0,0]
    for i in a:
        if i<x:
            tmp[0]+=1
        else:
            tmp[1]+=1
    res=min(tmp)
else:
    for i in a:
        if x>n/2 and i>x:
            res+=1
        if x<n/2 and i<x:
            res+=1
print(res)

Submission status: Wrong Answer

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

ans_N = N - bisect.bisect_left(A, X)
ans_0 = bisect.bisect_left(A,X)
print(min(ans_N,ans_0))

Submission status: Wrong Answer

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

ans_N = (N+1) - bisect.bisect_left(A, X)
ans_0 = bisect.bisect_left(A,X)
print(min(ans_N,ans_0))

Submission status: Wrong Answer

Solution code:
N,gate,start=list(map(int,input().split()))
W=list(map(int,input().split()))
le=0
ri=0
for i in range(start-1,N):
  if i in W:
    ri+=1
for k in range(start-1):
  if k in W:
    le+=1
print(min(ri,le))

Submission status: Wrong Answer

Solution code:
N,M,X = map(int, input().split())
li = list(map(int, input().split()))
flag = True
for i in range(X+1,N):
    if i in li:
        b = li.index(i)
        flag = False
        break
if flag:
    print(0)
else:
 a = b -1
 b = len(li) - b + 1
 if a > b:
    print(b)
 else:
    print(a)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if X <= 1:
    print(0)
    exit()

if X >= N-1:
    print(0)
    exit()

if N <= 2:
    print(0)
    exit()

def cost_right(A, X):
    cost = 0
    for a in A:
        if X <= a:
            cost += 1
    return cost

def cost_left(A, X):
    cost = 0
    for a in A:
        if X >= a:
            cost += 1
    return cost


cost = 0

if (N+1) % 2 == 1:
    half = int((N+1)/2)
    if X == half:
        cost = min(cost_right(A, X),  cost_left(A, X))
    if X > half:
        cost = cost_right(A, X)
    elif X < half:
        cost = cost_left(A, X)
else:
    upper = int((N+1)/2)
    if X >= upper:
        cost = cost_right(A, X)
    elif X < upper:
        cost = cost_left(A, X)

print(cost)

Submission status: Wrong Answer

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

if X <= 1:
    print(0)
    exit()

if X >= N-1:
    print(0)
    exit()

if N <= 2:
    print(0)
    exit()

def cost_right(A, X):
    cost = 0
    for a in A:
        if X <= a:
            cost += 1
    return cost

def cost_left(A, X):
    cost = 0
    for a in A:
        if X >= a:
            cost += 1
    return cost


cost = 0

if (N+1) % 2 == 1:
    half = int((N+1)/2)
    if X == half:
        cost_r = cost_right(A, X)
        cost_l = cost_left(A, X)
        cost = min(cost_l,  cost_r)
    if X > half:
        cost = cost_right(A, X)
    elif X < half:
        cost = cost_left(A, X)
else:
    upper = int((N+1)/2)
    if X >= upper:
        cost = cost_right(A, X)
    elif X < upper:
        cost = cost_left(A, X)

print(cost)

Submission status: Wrong Answer

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

if X <= 1:
    print(0)
    exit()

if X >= N-1:
    print(0)
    exit()

if N <= 2:
    print(0)
    exit()

def cost_right(A, X):
    cost = 0
    for a in A:
        if X <= a:
            cost += 1
    return cost

def cost_left(A, X):
    cost = 0
    for a in A:
        if X >= a:
            cost += 1
    return cost


cost = 0

if (N+1) % 2 == 1:
    half = int((N+1)/2)
    if X == half:
        cost_r = cost_right(A, X)
        cost_l = cost_left(A, X)
        cost = min(cost_l,  cost_r)
    if X > half:
        cost = cost_right(A, X)
    elif X < half:
        cost = cost_right(A, X)
else:
    upper = int((N+1)/2)
    if X >= upper:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)

print(cost)

Submission status: Wrong Answer

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

if X <= 1:
    print(0)
    exit()

if X >= N-1:
    print(0)
    exit()

if N <= 2:
    print(0)
    exit()

def cost_right(A, X):
    cost = 0
    for a in A:
        if X <= a:
            cost += 1
    return cost

def cost_left(A, X):
    cost = 0
    for a in A:
        if X >= a:
            cost += 1
    return cost


cost = 0

if (N+1) % 2 == 1:
    half = int((N+1)/2)
    if X == half:
        cost_r = cost_right(A, X)
        cost_l = cost_left(A, X)
        cost = min(cost_l,  cost_r)
    if X > half:
        cost = cost_left(A, X)
    elif X < half:
        cost = cost_left(A, X)
else:
    upper = int((N+1)/2)
    if X >= upper:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)

print(cost)

Submission status: Wrong Answer

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

if X <= 1:
    print(0)
    exit()

if X >= N-1:
    print(0)
    exit()

if N <= 2:
    print(0)
    exit()

def cost_right(A, X):
    cost = 0
    for a in A:
        if X <= a:
            cost += 1
    return cost

def cost_left(A, X):
    cost = 0
    for a in A:
        if X >= a:
            cost += 1
    return cost


cost = 0

if (N+1) % 2 == 1:
    half = int((N+1)/2)
    if X == half:
        cost_r = cost_right(A, X)
        cost_l = cost_left(A, X)
        cost = cost_r
    if X > half:
        cost = cost_right(A, X)
    elif X < half:
        cost = cost_left(A, X)
else:
    upper = int((N+1)/2)
    if X >= upper:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)

print(cost)

Submission status: Wrong Answer

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

if X <= 1:
    print(0)
    exit()

if X >= N-1:
    print(0)
    exit()

if N <= 2:
    print(0)
    exit()

def cost_right(A, X):
    cost = 0
    for a in A:
        if X <= a:
            cost += 1
    return cost

def cost_left(A, X):
    cost = 0
    for a in A:
        if X >= a:
            cost += 1
    return cost


cost = 0

if (N+1) % 2 == 1:
    half = int((N+1)/2)
    if X == half:
        cost_r = cost_right(A, X)
        cost_l = cost_left(A, X)
        cost = cost_l
    if X > half:
        cost = cost_right(A, X)
    elif X < half:
        cost = cost_left(A, X)
else:
    upper = int((N+1)/2)
    if X >= upper:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)

print(cost)

Submission status: Wrong Answer

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

if X <= 1:
    print(0)
    exit()

if X >= N-1:
    print(0)
    exit()

if N <= 2:
    print(0)
    exit()

def cost_right(A, X):
    cost = 0
    for a in A:
        if X <= a:
            cost += 1
    return cost

def cost_left(A, X):
    cost = 0
    for a in A:
        if X >= a:
            cost += 1
    return cost


cost = 0

if (N+1) % 2 == 1:
    half = int((N+1)/2)
    if X == half:
        cost_r = cost_right(A, X)
        cost_l = cost_left(A, X)
        cost = min(cost_l,  cost_r)
    if X > half:
        cost = cost_right(A, X)
    elif X < half:
        cost = cost_left(A, X)
else:
    upper = int((N+1)/2)
    if X >= upper:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)

print(cost)

Submission status: Wrong Answer

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

if X <= 1:
    print(0)
    exit()

if X >= N-1:
    print(0)
    exit()

if N <= 2:
    print(0)
    exit()

def cost_right(A, X):
    cost = 0
    for a in A:
        if X <= a:
            cost += 1
    return cost

def cost_left(A, X):
    cost = 0
    for a in A:
        if X >= a:
            cost += 1
    return cost


cost = 0

if (N+1) % 2 == 1:
    half = int((N+1)/2)
    if X == half:
        cost_r = cost_right(A, X)
        cost_l = cost_left(A, X)
        cost = min(cost_l,  cost_r)
    if X >= half:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)
else:
    upper = int((N+1)/2)
    if X >= upper:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)

print(cost)

Submission status: Wrong Answer

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

if X <= 1:
    print(0)
    exit()

if X >= N-1:
    print(0)
    exit()

if N <= 2:
    print(0)
    exit()

def cost_right(A, X):
    cost = 0
    for a in A:
        if X < a:
            cost += 1
    return cost

def cost_left(A, X):
    cost = 0
    for a in A:
        if X > a:
            cost += 1
    return cost


cost = 0

if (N+1) % 2 == 1:
    half = int((N+1)/2)
    if X == half:
        cost_r = cost_right(A, X)
        cost_l = cost_left(A, X)
        cost = min(cost_l,  cost_r)
    if X >= half:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)
else:
    upper = int((N+1)/2)
    if X >= upper:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)

print(cost)

Submission status: Wrong Answer

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

if X <= 1:
    print(0)
    exit()

if X >= N-1:
    print(0)
    exit()

def cost_right(A, X):
    cost = 0
    for a in A:
        if X < a:
            cost += 1
    return cost

def cost_left(A, X):
    cost = 0
    for a in A:
        if X > a:
            cost += 1
    return cost


cost = 0

if (N+1) % 2 == 1:
    half = int((N+1)/2)
    if X == half:
        cost_r = cost_right(A, X)
        cost_l = cost_left(A, X)
        cost = min(cost_l,  cost_r)
    if X >= half:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)
else:
    upper = int((N+1)/2)
    if X >= upper:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)

print(cost)

Submission status: Wrong Answer

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

def cost_right(A, X):
    cost = 0
    for a in A:
        if X < a:
            cost += 1
    return cost

def cost_left(A, X):
    cost = 0
    for a in A:
        if X > a:
            cost += 1
    return cost


cost = 0

if (N+1) % 2 == 1:
    half = int((N+1)/2)
    if X == half:
        cost_r = cost_right(A, X)
        cost_l = cost_left(A, X)
        cost = min(cost_l,  cost_r)
    if X >= half:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)
else:
    upper = int((N+1)/2)
    if X >= upper:
        cost = cost_right(A, X)
    else:
        cost = cost_left(A, X)

print(cost)

Submission status: Wrong Answer

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

pits = []

cost = 0

for i in range(0, N+1):
    pits.append(i)


half = int(len(pits)/2)

if X == half:
    cost_r = 0
    cost_l = 0
    for a in A:
        if X <= a:
            cost_r += 1
        else:
            cost_l += 1
    cost = min(cost_r, cost_l)
elif X >= half:
    for a in A:
        if X <= a:
            cost += 1
else:
    for a in A:
        if X >= a:
            cost += 1

print(cost)

Submission status: Wrong Answer

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

pits = []

cost = 0

for i in range(0, N+1):
    pits.append(i)

half = int(len(pits) / 2)

if X == half:
    cost_r = 0
    cost_l = 0
    for a in A:
        # 右側
        if X < a:
            cost_r += 1
        # 左側
        if X > a:
            cost_l += 1
    cost = min(cost_l, cost_r)
    
elif half < X:
    for a in A:
        if X < a:
            cost += 1
else:
    for a in A:
        if X > a:
            cost += 1

print(cost)

Submission status: Wrong Answer

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

pits = []

cost = 0

for i in range(0, N+1):
    pits.append(i)

half = int(len(pits) / 2)

if X == half:
    cost_r = 0
    cost_l = 0
    for a in A:
        # 右側
        if X < a:
            cost_r += 1
        # 左側
        if X > a:
            cost_l += 1
    cost = (cost_l, cost_r)
elif half < X:
    for a in A:
        if X < a:
            cost += 1
else:
    for a in A:
        if X > a:
            cost += 1

print(cost)

Submission status: Wrong Answer

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

pits = []

cost = 0

for i in range(0, N+1):
    pits.append(i)

half = int(len(pits) / 2)

if X == half:
    cost_r = 0
    cost_l = 0
    for a in A:
        # 右側
        if X < a:
            cost_r += 1
        # 左側
        if X > a:
            cost_l += 1
    cost = min(cost_l, cost_r)
elif half < X:
    for a in A:
        if X <= a:
            cost += 1
else:
    for a in A:
        if X >= a:
            cost += 1

print(cost)

Submission status: Wrong Answer

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

pits = []

cost = 0

for i in range(0, N+1):
    pits.append(i)

half = int(len(pits) / 2)

if X == half:
    cost_r = 0
    cost_l = 0
    for a in A:
        # 右側
        if X < a:
            cost_r += 1
        # 左側
        if X > a:
            cost_l += 1
    cost = min(cost_l, cost_r)
elif half < X:
    for a in A:
        if X < a:
            cost += 1
else:
    for a in A:
        if X > a:
            cost += 1

print(cost)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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, 1, -1):
    if i in A: cnt_down += 1

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

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

Submission status: Wrong Answer

Solution code:
N,M,X=map(int,input().split())
A=[int(x) for x in input().split()]
left=sum(x<X for x in A)
right=M-left
print(max(left,right))

Submission status: Wrong Answer

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

print(min(x-2,n-x-1))

Submission status: Wrong Answer

Solution code:
N,M,X = map(int,input().split())
A = list(map(int,input().split()))
cnt,cnt2 = 0,0
start,goal = abs(0-X),abs(N-X)
if start > goal:
	for s in range(goal):
		X = X + 1
		if X in A:
			cnt += 1
elif start == goal:
	for s in range(goal):
		X = X + 1
		if X in A:
			cnt += 1
	for g in range(start):
		X = X - 1
		if X in A:
			cnt2 += 1
	cnt = min(cnt,cnt2)
else:
	for g in range(start):
		X = X - 1
		if X in A:
			cnt += 1
print(cnt)

Submission status: Wrong Answer

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

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

Solution code:
n,m,x=map(int,input().split())
l=list(map(int,input().split()))
ans=0
if n-x<x:
    for i in range(x+1,n):
        for j in range(m):
            if l[j]==i:
                ans+=1
    print(ans)
elif n-x>x:
    for i in range(0,x):
        for j in range(m):
            if l[j]==i:
                ans+=1
    print(ans)
else:
    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: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
l=list(map(int,input().split()))
ans=0
if n-x<x:
    for i in range(x+1,n):
        for j in range(m):
            if l[j]==i:
                ans+=1
    print(ans)
elif n-x>x:
    for i in range(x-1,0,-1):
        for j in range(m):
            if l[j]==i:
                ans+=1
    print(ans)
else:
    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(x-1,0,-1):
        for j in range(m):
            if l[j]==i:
                ans2+=1
    print(min(ans1,ans2))

Submission status: Wrong Answer

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,x-count)
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n,m,x=map(int,input().split())
la=list(map(int,input().split()))
count=0
if n%2==0:
    if n//2>x:
        while x>=0:
            for i in la:
                if x==i:
                    count+=1
            x-=1
    else:
        while x<=n:
            for i in la:
                if x==i:
                    count+=1
            x+=1
else:
    if n//2+1>x:
        while x>=0:
            for i in la:
                if x==i:
                    count+=1
            x-=1
    else:
        while x<=n:
            for i in la:
                if x==i:
                    count+=1
            x+=1
print(count)

Submission status: Wrong Answer

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-1,M-X+1))
        exit()
    ans += 1
print(min(ans-1,M-X+1))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

i = 1
c =0


while True:
  if A[i] < X and A[i+1] > X:
    break
  else:
    i +=1
    if i ==M:
      i = 0
      break


c = min(i, M-i)
print(c)

Submission status: Wrong Answer

Solution code:
l = list(map(int,input().split()))
r = input().split()
x = l[2]
n = l[0]

a = [int(i) for i in r]
c = 0
#print("x",x)
if(x<=n):
  for i in range(x,n+1):
    #print("x",i)
    if(x in a):
      c = c + 1
    x = x + 1
else:
  for i in range(x,n+1,-1):
    #print("x",i)
    if(x in a):
      c = c + 1
    x = x + 1  
print(c)

Submission status: Wrong Answer

Solution code:
l = list(map(int,input().split()))
r = input().split()
x = l[2]
n = l[0]

a = [int(i) for i in r]
c = 0
#print("x",x)
for i in range(x,n+1):
  #print("x",i)
  if(x in a):
    c = c + 1
  x = x + 1

print(c)

Submission status: Wrong Answer

Solution code:
n, m, x = map(int, input().split())
A = map(int, input().split())
r = 0
l = 0
for a in A:
	if a > x:
		r += 1
	else:
		l += 1
print(max(r, l))

Submission status: Wrong Answer

Solution code:
n,m,x = map(int,input().split())
a = list(map(int,input().split()))
abs1 = abs(n-x)
abs0 = abs(x)-1
print(min((abs1-1),(abs0-1)))

Submission status: Wrong Answer

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

for i in range(0,x-1):
 t += 1

print(min(t,m-t))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

keep=0
hidari=1
while keep<x:
  keep=a[hidari]
  hidari+=1

keep=10*100
migi=-1
while keep>x and migi>=-m+1:
  keep=a[migi]
  migi-=1
  
print(min([hidari-1,-migi-2]))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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

left = bisect_right(A,X)
right = len(A) - left

l = X - left
r = N - X - right
print(min(l,r))

Submission status: Wrong Answer

Solution code:
from bisect import bisect_right

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

left = bisect_right(A,X)
right = N - left

l = X - left
r = N - X - right
print(min(l,r))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(m):
    y = i
    if a[i] > x:
        break
for i in range(m):
    z = i+1
    if a[-1-i] < x:
        break
print(min([m-y,m-z]))

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+1):
    if i in A:
        ans += 1
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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