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: Runtime Error

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(len(m)):
    if a[i]<x:
      print(min(i+1,m-i-1))
      break

Submission status: Runtime Error

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

Submission status: Runtime Error

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

if x==n:
    print(0)
else:
    print(min(sum(ans[:x+1]),sum(ans[-x:])))

Submission status: Runtime Error

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

for i in range(m):
    if a[i+1]<x<a[i+2]:
        ans=min(ans,min(i+1,m-i-1))
print(ans)

Submission status: Runtime Error

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

for i in range(X+1)
    count += A.count(i)

ans = min(count, len(A)-count)
print(ans)

Submission status: Runtime Error

Solution code:
#coding:utf-8
n=[int(i) for i in input().split()]
Ad=0
Au=0
A=[int(i) for i in input().split()]
for i in range(n[1]):
  if(A[i]>n[3]):
    Au+=1
  else:
    Ad+=1
if(Au>=Ad):
  print(Ad)
else:
  print(Au)

Submission status: Runtime Error

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

tax = [input() for i in range(m)]
alltax = len(tax)
atax = len(tax[:x])
btax = alltax-atax
if atax > btax:
    print(btax)
else:
    print(atax)

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
arr = input().split()
list_fee = []

for i in range(N):
    if int(arr[0]) == i:
        list_fee.append(1)
        arr.pop(0)
    else:
        list_fee.append(0)
    
a = list_fee[:X].count(1)
b = list_fee[X:].count(1)

print(min(a, b))

Submission status: Runtime Error

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

can = [len([i for i in gates if i > X]), len([i for i in gates if i < X])]

print(min(can))

Submission status: Runtime Error

Solution code:
N, M, X = map(int, raw_input().split(" "))
A = map(int, raw_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: Runtime Error

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

Submission status: Runtime Error

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

Solution code:
def main():
    n = int(input())
    a = sorted(map(int, input().split()))

    c = n // 2
    for i in range(n):
        if i < c:
            print(a[c])
        else:
            print(a[c - 1])


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n,m,x = map(int, input().split(' '))
ai = map(int, input().split(' '))
lcost = 0
rcost = 0
for gate in ai:
  if gate < x:
    lcost + = 1
  else:
    rcost += 1

print(min(lcost, rcost))

Submission status: Runtime Error

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

ai = map(int, input().split(' '))
lcost, rcost = 0, 0
for gate in ai:
  if gate < x:
    lcost = += 1
  else:
    rcost = += 1

 print(min(lcost, rcost))

Submission status: Runtime Error

Solution code:
 n, m, x = map(int, input().split(' '))
 ai = map(int, input().split(' '))
lcost, rcost = 0, 0
for gate in ai:
  if gate < x:
    lcost = lcost + 1
  else:
    rcost = rcost + 1

print(min(lcost, rcost))

Submission status: Runtime Error

Solution code:
 n, m, x = map(int, input().split(' '))
 ai = list(map(int, input().split(' ')))
lcost, rcost = 0, 0

for gate in ai:
  if gate < x:
    lcost = lcost + 1
  else:
    rcost = rcost + 1

 print(min(lcost, rcost))

Submission status: Runtime Error

Solution code:
,B,C = map(int,input().split())

List_one = [0]*B
List_one = list(map(int,input().split()))

List_one.append(C)
#LIst_one = List_one + [C]
#print (List_one)

List_one.sort()# List_two=List_one.sort()としたらNoneを返してしまう。
#print(List_one)

x = List_one.index(C)

if x>=B-x:
    print(B-x)
else:
    print(x)

Submission status: Runtime Error

Solution code:
A,,B,C = map(int,input().split())

List_one = [0]*B
List_one = list(map(int,input().split()))

List_one.append(C)
#LIst_one = List_one + [C]
#print (List_one)

List_one.sort()# List_two=List_one.sort()としたらNoneを返してしまう。
#print(List_one)

x = List_one.index(C)

if x+1>=B-x:
    print(B-x)
else:
    print(x+1)

Submission status: Runtime Error

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

for i in range(m):
    if P[i]  > x:
        a += 1
    else:
        b += 1
print(min(a, b))

Submission status: Runtime Error

Solution code:
Cost0 = 0
CostN = 0

listA=[]
while True:
    try:
        listA.append(list(map(int,input().split())))

    except:
        break;
X = listA[0][2]

for x in listA:
   length += len(x)

for i in range(length - 3):
    if (listA[1][i] < X):
        Cost0 = Cost0 +1
    else:
        CostN = CostN +1

if (Cost0 < CostN):
    print(Cost0)
else:
    print(CostN)

Submission status: Runtime Error

Solution code:
N,X,M = map(int,input().split())
i = input().split()
x=0
array = [0]*(N+1)
for a in range(N):
    if int(i[x])==a:
        x=x+1
        array[a]=1
r=0
l=0
for a in range(X-1):
    r+=array[a]
for a in range(X+1,N,1):
    l+=array[a]

if r<l:
    print(r)
elif r>l:
    print(l)
else:
    print(r)

Submission status: Runtime Error

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

a = input().split()
A = input().split()

for i in range(0, len(a)):
    a[i] = int(a[i])

for i in range(0, len(A)):
    A[i] = int(A[i])

count = 0
for i in range(0, a[2]):
    if(A[i] < a[2]):
        count = count + 1


if(count > (len(A) -  count)):
        count = len(A) -  count

print("{0}".format(count))

Submission status: Runtime Error

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


a = input().split()
A = input().split()

for i in range(0, len(a)):
    a[i] = int(a[i])

for i in range(0, len(A)):
    A[i] = int(A[i])

count = 0
for i in range(0, a[2]):
    if(A[i] < a[2]):
        count = count + 1


if(count > (len(A) -  count)):
        count = len(A) -  count

print("{0}".format(count))

Submission status: Runtime Error

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

import matplotlib

a = input().split()
A = input().split()

for i in range(0, len(a)):
    a[i] = int(a[i])

for i in range(0, len(A)):
    A[i] = int(A[i])

count = 0
for i in range(0, a[2]):
    if(A[i] < a[2]):
        count = count + 1


if(count > (len(A) -  count)):
        count = len(A) -  count

print("{0}".format(count))

Submission status: Runtime Error

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

import matplotlib

a = input().split()
A = input().split()

for i in range(0, len(a)):
    a[i] = int(a[i])

for i in range(0, len(A)):
    A[i] = int(A[i])

count = 0
for i in range(0, a[2]):
    if(A[i] < a[2]):
        count = count + 1


if(count > (len(A) -  count)):
        count = len(A) -  count

print(count)

Submission status: Runtime Error

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

import matplotlib

a = list(input().split())
A = list(input().split())

count = 0
for i in range(0, a[2]):
    if(A[i] < a[2]):
        count = count + 1


if(count > (A.shape[0] -  count)):
        count = A.shape[0] -  count

print(count)

Submission status: Runtime Error

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: Runtime Error

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: Runtime Error

Solution code:
list = map(int, raw_input().split())
List = map(int, raw_input().split())

countLatter = 0
countFormer = 0

for i in range(list[2] + 1, list[0]):
    if i in List :
        countLatter += 1
for i in range(0, list[2] - 1):
    if i in List :
        countFormer += 1

print(min(countLatter, countFormer))

Submission status: Runtime Error

Solution code:
N, M, X = map(int, input().split())
A = sorted([int(i) for i in input().split()])
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: Runtime Error

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.floor(ix)
else:
    print M

Submission status: Runtime Error

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.floor(ix)
else:
	print M

Submission status: Runtime Error

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.floor(ix)
else:
	print M

Submission status: Runtime Error

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

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

counta=0;
countb=0;

for i in a:
    if (n<a and a<x) or (x<a and a<n):
        counta+=1

for i in a:
    if (0<a and a<x):
        countb+=1

if (counta<countb):
    ans = counta
else:
    ans = countb

print(ans)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
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.floor(ix)
else:
	print M

Submission status: Runtime Error

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

cost_left = 0
for i in range(x-1,0,-1):
    if i in a:
        cost_left+= 1
cost_right = 0
for i in range(x+1, N):
    if i in a:
        cost_right+= 1
    
print(min(cost_left, cost_right))

Submission status: Runtime Error

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

#leftto0
cost_left = 0
b = range(x-1,0,-1)
for i in b:
    if i in a:
        cost_left+= 1
    
#right_to_N
cost_right = 0
for i in range(x+1, N):
    if i in a:
        cost_right+= 1
    
print(min(cost_left, cost_right))

Submission status: Runtime Error

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

#leftto0
cost_left = 0
b = range(x-1,0,-1)
for i in b:
    if i in a:
        cost_left+= 1
    
#right_to_N
cost_right = 0
for i in range(x+1, N):
    if i in a:
        cost_right+= 1
    
print(min(cost_left, cost_right))

Submission status: Runtime Error

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

#leftto0
cost_left = 0
b = range(0,x)
B = b.reverse()
for i in B:
    if i in a:
        cost_left+= 1
    
#right_to_N
cost_right = 0
for i in range(x+1, N):
    if i in a:
        cost_right+= 1
    
print(min(cost_left, cost_right))

Submission status: Runtime Error

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

#leftto0
cost_left = 0
for i in range(0,x).reverse:
    if i in a:
        cost_left+= 1
    
#right_to_N
cost_right = 0
for i in range(x+1, N):
    if i in a:
        cost_right+= 1
    
print(min(cost_left, cost_right))

Submission status: Runtime Error

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

a=Nlist[X:]
b=Nlist[:X]
print(min([a,b])