TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,m = map(int,input().split())
a = input().split()
a =[int(s) for s in a]

a.insert(0,k)

dis = []

for i in range(m):
  part = int(a[i]) - int(a[i+1])
  dis.append(part)
  del part

dis.append(int(a[m-1]))
distance = dis*2

c =[]
for j in range(m):
  c = sum(distance[j:j+5])

print(min(c))

k,m = map(int,input().split())
a = input().split()
a =[int(s) for s in a]
a.sort(reverse=True)
a.insert(0,k)

dis = []

for i in range(m):
  part = int(a[i]) - int(a[i+1])
  dis.append(part)
  del part

dis.append(int(a[m-1]))
dis.sort()
print(dis)

print(sum(dis[:m-1]))


k,m = map(int,input().split())
a = input().split()
a =[int(s) for s in a]

a.insert(0,k)

dis = []

for i in range(m):
  part = int(a[i]) - int(a[i+1])
  dis.append(part)
  del part

dis.append(int(a[m-1]))
distance = dis*2

c =[]
for j in range(m):
  c = int(sum(distance[j:j+5]))

print(min(c))

#12
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []
for i in range(n-1):
    b.append(a[i+1]-a[i])

b.append(int(k-a[n-1]+a[0]))

c = max(b)
b.remove(c)

print(sum(b))


Verdicts: Runtime Error

Wrong Answer

Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k, n = map(int(input().split()))
al = list(map(int(input().split())))

dtlst = [al[0]]
for i in range(1,n):
  dtlst.append(al[i]-al[i-1])
dtlst.append(k - al[-1]+al[0])

print(k - max(dtlst))

k, n = map(int(input().split()))
al = list(map(int,input().split()))

dtlst = [al[0]]
for i in range(1,n):
  dtlst.append(al[i]-al[i-1])
dtlst.append(k - al[-1]+al[0])

print(k - max(dtlst))


k, n = map(int,input().split())
al = list(map(int,input().split()))

dtlst = [al[0]]
for i in range(1,n):
  dtlst.append(al[i]-al[i-1])
dtlst.append(k - al[-1]+al[0])

print(k - max(dtlst))


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N=map(int,input())
A=list(map(int,input().split())
L_max=0
for i in range(A):
    if i<len(A)-1:
        l=A[i+1]-A[i]
    else:
        l=K-A[-1]+A[0]
    if L_max<l:
        L_max=l
ans=sum(A)-L_max
print(ans)

K,N=map(int,input().split())
A=list(map(int,input().split()))
max_ans=0
for i in range(N):
    if i==N-1:
        ans=K-A[N-1]+A[0]
    else:
        ans=A[i+1]-A[i]
    if max_ans<ans:
        max_ans=ans
ans=K-max_ans
print(ans)

Verdicts: Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
import numpy as np



first_input = list(map(lambda x:int(x), input().split(" ")))
second_input = list(map(lambda x:int(x), input().split(" ")))


#first_input = list(map(lambda x:float(x), input().split(" ")))
#second_input = list(map(lambda x:float(x), input().split(" ")))

##get string
#first_input = input().split(" ")

K = first_input[0]
N= first_input[1]

A_list = second_input

A_list.append(K+A_list[0])

dist_list = np.array(A_list)[1:]-np.array(A_list)[:-1]
print(A_list)
print(dist_list)

print(sum(dist_list)-max(dist_list))


import numpy as np



first_input = list(map(lambda x:int(x), input().split(" ")))
second_input = list(map(lambda x:int(x), input().split(" ")))


#first_input = list(map(lambda x:float(x), input().split(" ")))
#second_input = list(map(lambda x:float(x), input().split(" ")))

##get string
#first_input = input().split(" ")

K = first_input[0]
N= first_input[1]

A_list = second_input

A_list.append(K+A_list[0])

dist_list = np.array(A_list)[1:]-np.array(A_list)[:-1]

print(sum(dist_list)-max(dist_list))


Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
import sys
a,b=map(int,input().split())
c=list(map(int,input().split()))
c.sort()
d=[0]*1000000
for i in range(b-1):
  d[i]+=abs(c[i]-c[i+1])

d.append(a-c[-1])

print(a-max(d))





import sys
a,b=map(int,input().split())
c=list(map(int,input().split()))
c.sort()
d=[0]*a
for i in range(b-1):
  d[i]+=abs(c[i]-c[i+1])

d.append(a-c[-1])

print(a-max(d))





import sys
a,b=map(int,input().split())
c=list(map(int,input().split()))
c.sort()
d=[0]*1000000
for i in range(b-1):
  d[i]+=abs(c[i]-c[i+1])
  

d.append(a-(c[-1]-c[0]))

print(a-max(d))





Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n=map(int,input().split())
l=list(map(int,input().split()))
l.append(l[0]+k)
a=10**10
for i in range(n):
    a=min(a,l[i+1]-l[i])
print(k-a)

k,n=map(int,input().split())
l=list(map(int,input().split()))
l.append(l[0]+k)
a=0
for i in range(n):
    a=max(a,l[i+1]-l[i])
print(k-a)


Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n=map(input(),int.split())
a=list(input(),int.split())

m=0
for i in range(n-1):
    d=a[i+1]-a[i]
    m=max(d,m)
d_last=a[0]+k-a[n-1]
m=max(d_last,m)

ans=k-m
print(ans)

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

m=0
for i in range(n-1):
    d=a[i+1]-a[i]
    m=max(d,m)
d_last=a[0]+k-a[n-1]
m=max(d_last,m)

ans=k-m
print(ans)

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

m=0
for i in range(n-1):
    d=a[i+1]-a[i]
    m=max(d,m)
d_last=a[0]+k-a[n-1]
m=max(d_last,m)

ans=k-m
print(ans)

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

m=0
for i in range(n-1):
    d=a[i+1]-a[i]
    m=max(d,m)
d_last=a[0]+k-a[n-1]
m=max(d_last,m)

ans=k-m
print(ans)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
n, k = map(int, input().split())
array = list(map(int, input().split())) + [n]
a = [array[i] - array[i-1] for i in range(1, n+1)]
print(sum(a) - max(a))

n, k = map(int, input().split())
array = list(map(int, input().split()))
array = array + [array[0] + n]
a = [array[i] - array[i-1] for i in range(1, k+1)]
print(n - max(a))

Verdicts: Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N=map(int,input().split())
A=list(map(int,input().split()))
x=[]
y=[]
for i in A:
  if i>10:
    a=20-i
    y.append(a)
  else:
    x.append(i)
if len(A)==1:
  if A[0]>=10:
    print(20-A[0])
  else:
    print(A[0])
else:
  ans=max(x)+max(y)
  print(ans)

K,N=map(int,input().split())
A=list(map(int,input().split()))
x=[]

for i in A:
  if i>10:
    a=i-20
    x.append(a)
  else:
    x.append(i)
if len(x)==1:
  print(abs(x[0]))
else:
  xmax=max(x)
  xmin=min(x)
  ans=xmax-xmin
  print(ans)

K,N=map(int,input().split())
A=list(map(int,input().split()))
sa=[]
sa.append(int(K-A[-1]+A[0]))
for i in range(1,N):
  tmp=A[i]-A[i-1]
  sa.append(tmp)
ans=K-max(sa)
print(ans)

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []

for i in range(1,n+1):
  b.append(a[i] - a[i-1])
b.append(k - a[n] + a[0])
b = sorted(b)

print(sum(b:[:n])

k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []

for i in range(1,n):
  b.append(a[i]-a[i-1])
b.append(k-a[n-1]+a[0])

b.sorted(b)

print(sum(b[:-1]))


k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []

for i in range(1,n+1):
  b.append(a[i] - a[i-1])
b.append(k - a[n] + a[0])
b = sorted(b)

print(sum(b[:n])

k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []

for i in (1,n):
  b.append(a[i] - a[i-1])
b.append(k - a[n-1] + a[0])
b = sorted(b)

print(sum(b[:-1]))

k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []

for i in range(1,n):
  b.append(a[i]-a[i-1])
b.append(k-a[n-1]-a[0])

b.sorted(b)

print(sum(b[:-1]))

k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []

for i in range(1,n+1):
  b.append(a[i] - a[i-1])
b.append(k - a[n] + a[0])
b = sorted(b)

print(sum(b[:n-1])


k,n = map(int,input().split())
a = list(map(int,input().split()))
b = []

for i in range(1,n):
  b.append(a[i] - a[i-1])
b.append(k - a[n-1] + a[0])
b = sorted(b)

print(sum(b[:-1]))


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
x = input()
num = int(x.split()[1])
perimeter = int(x.split()[0])
houses = [int(i) for i in input().split()]

maxDis = perimeter - houses[-1] + houses[0]
total = maxDis
for i in range(1, len(houses)):
    maxDis = max(maxDis, houses[i]-houses[i-1])
    total += houses[i]-houses[i-1]
print(total)

x = input()
num = int(x.split()[1])
perimeter = int(x.split()[0])
houses = [int(i) for i in input().split()]

maxDis = perimeter - houses[-1] + houses[0]
total = maxDis
for i in range(1, len(houses)):
    maxDis = max(maxDis, houses[i]-houses[i-1])
    total += houses[i]-houses[i-1]
print(total-maxDis)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):

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

A.remove(0)
A.append(A[0])

max_distance = 0
pre = 0

for i in A:

    if abs(i - pre) > max_distance:
        max_distance = abs(i - pre)
    pre = i



print (K - max_distance)


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

diff = K + A[0] - A[-1]

for i in range(N-1):
    diff = max(diff , A[i+1]-A[i])

print(K-diff)


Verdicts: Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k, n = map(int, input().split())
a = list(map(int, input().split()))

distance = [0]*n

for i in range(n-1):
  print(a[i+1],a[i])
  distance[i] = a[i+1] - a[i]
distance[n-1] = k-a[n-1] + a[0]

distance.sort(reverse=True)
print(distance)
print(sum(distance[1:]))

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

distance = [0]*n

for i in range(n-1):
  distance[i] = a[i+1] - a[i]
distance[n-1] = k-a[n-1] + a[0]

distance.sort(reverse=True)
print(sum(distance[1:]))

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N=map(int, input().split())
A=list(map(int, input().split()))
 
B=[0]*N

for i in range(N-1):
    B[i]=A[i+1]-A[i]

B[-1]=K-A[-1]


ans = K-max(B)
print(ans)

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

B=[0]*N

for i in range(N-1):
    B[i]=A[i+1]-A[i]

B[-1]=A[0]+K-A[-1]

B=sorted(B)

ans = sum(B[0:-1])
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
import numpy as np

K,N=list(map(int, input().split()))

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


A=np.array(A)

lin=np.array(A[:-1])
le=np.array(A[1:])

length=abs(lin-le)

rem=abs(K-A[-1]+A[0])
print(length)
A=np.append(length,rem)

M=np.max(A)

print(K-M)

import numpy as np

K,N=list(map(int, input().split()))

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


A=np.array(A)

lin=np.array(A[:-1])
le=np.array(A[1:])

length=abs(lin-le)

rem=abs(K-A[-1]+A[0])

A=np.append(length,rem)

M=np.max(A)

print(K-M)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
def main():
  k, N = (int(x) for x in input().split())
  min_LIST = []
  LIST = []
  LIST = list(map(int,input().split()))

  for i in range(len(LIST) - 1):
    min_LIST.append(LIST[i + 1] - LIST[i])
    if(min_LIST[i] <= (LIST[i + 1] - LIST[i])):
      x = (LIST[i + 1] - LIST[i])
      print(x)

  print(min_LIST)

  min_LIST.append(LIST[0] + (k - LIST[-1]))
  if(x <= (LIST[0] + (k - LIST[-1]))):
    x = (LIST[0] + (k - LIST[-1]))

  sum_list = sum(min_LIST) - x

  print(sum_list)
if __name__ == "__main__":
  main()






def main():
  k, N = (int(x) for in input().split())
  LIST = []
  min_LIST = []
  for i in range(N):
    l.append(int(input()))

  for i in range(len(LIST) - 1):
    min_LIST.append(LIST[i + 1] - LIST[i])
    if(min_LIST <= (LIST[i + 1] - LIST[i])):
      x = (LIST[i + 1] - LIST[i])

  if(min_LIST <= (LIST[0] + (k - LIST[-1])):
    x = (LIST[0] + (k - LIST-1]))

  sum_list = sum(min_LIST) - x

  print(sum_list)
if __name__ == "__main__":
  main()






def main():
  k, N = (int(x) for x in input().split())
  min_LIST = []
  LIST = []
  LIST = list(map(int,input().split()))

  for i in range(len(LIST) - 1):
    min_LIST.append(LIST[i + 1] - LIST[i])
    if(min_LIST[i] <= (LIST[i + 1] - LIST[i])):
      x = (LIST[i + 1] - LIST[i])
      print(x)

  print(min_LIST)

  min_LIST.append(LIST[0] + (k - LIST[-1]))
  if(x <= (LIST[0] + (k - LIST[-1]))):
    x = (LIST[0] + (k - LIST[-1]))

  sum_list = sum(min_LIST) - x

  print(sum_list)
if __name__ == "__main__":
  main()






def main():
  k, N = (int(x) for x in input().split())
  min_LIST = []
  LIST = []
  LIST = list(map(int,input().split()))
  x = 0

  for i in range(len(LIST) - 1):
    min_LIST.append(LIST[i + 1] - LIST[i])
    if(x <= min_LIST[i]):
      x = min_LIST[i]

  if(N != 2):
    min_LIST.append(LIST[0] + (k - LIST[-1]))
    if(x <= (LIST[0] + (k - LIST[-1]))):
      x = (LIST[0] + (k - LIST[-1]))

  sum_list = sum(min_LIST) - x

  print(sum_list)
if __name__ == "__main__":
  main()


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N=map(int,input().split())
L=list(map(int,input().split()))
A=[]
for i in range(N-1):
  A.append(L[i+1]-L[i])
L.append(K-L[L-1]+L[0])
print(K-max(L))



K,N=map(int,input().split())
L=list(map(int,input.split()))
A=[]
for i in range(N-1):
  A.append(L[i+1]-L[i])
L.append(K-L[L-1]+L[0])
print(K-max(L))

K,N=map(int,input().split())
L=list(map(int,input().split()))
A=[]
for i in range(N-1):
  A.append(L[i+1]-L[i])
L.append(K-L[N-1]+L[0])
print(K-max(L))

K,N=map(int,input().split())
L=list(map(int,input().split()))
A=[]
for i in range(N-1):
  A.append(L[i+1]-L[i])
A.append(K-L[N-1]+L[0])
print(K-max(A))

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k, n = map(int, input().split())
a = list(map(int, input().split()))
d = 0

for i in range(n-1):
    d = (d, a[i+1] - a[i])
d = (d, k - a[-1] + a[0])

print(K - d)

k, n = map(int, input().split())
a = list(map(int, input().split()))
d = 0

for i in range(n-1):
    d = max(d, a[i+1] - a[i])
d = max(d, k - a[-1] + a[0])

print(k - d)

Verdicts: Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
kn = list(map(int,input().split()))
a = list(map(int,input().split()))

k = kn[0]
n = kn[1]


dis = []

for i in range(n):
    if i == 0:
        dis.append(min((a[n-1] - a[0]), (k - a[n-1] + a[0])))
    else:
        dis.append(min((a[i] - a[i-1]), (k - a[i] + a[i-1])))

print(dis)
del dis[dis.index(max(dis))]

print(sum(dis))

'''
dis = [[0]*n]

for i in range(n):
    for j in range(n):
        if i+j+1 >= n-1:
            dis[i][j] = k - a[i+j+1-(n-1)] + a[i+j+1-(n-1)-1]
        else:
            dis[i][j] = a[i+j+1] - a[i+j]

    dis.append([0]*n)
    print(dis)

print(dis)
'''

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

k = kn[0]
n = kn[1]


dis = []

for i in range(n):
    if i == 0:
        dis.append(min((a[n-1] - a[0]), (k - a[n-1] + a[0])))
    else:
        dis.append(min((a[i] - a[i-1]), (k - a[i] + a[i-1])))

del dis[dis.index(max(dis))]

print(sum(dis))

'''
dis = [[0]*n]

for i in range(n):
    for j in range(n):
        if i+j+1 >= n-1:
            dis[i][j] = k - a[i+j+1-(n-1)] + a[i+j+1-(n-1)-1]
        else:
            dis[i][j] = a[i+j+1] - a[i+j]

    dis.append([0]*n)
    print(dis)

print(dis)
'''

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k=int(input())
n=int(input())
n_list=[int(input()) for i in range(n)]
for i in range(len(n_list)):
  if n_list[i] > k-n_list[i]:
    n_list[i]=-(k-n_list[i])
n_list.sort()
print(n_list[-1]-n_list[0])


k,n = map(int,input().split())
n_list = list(map(int,input().split()))
for i in range(len(n_list)):
  if n_list[i] > k-n_list[i]:
    n_list[i]=-(k-n_list[i])
n_list.sort()
print(n_list[-1]-n_list[0])

(n,m)=map(int,input().split())
a=input().split()
a=list(map(int,a))
l=[]
k=0
a=sorted(a)
for i in range(m-1):
    d=abs(a[i]-a[i+1])
    k=k+d
    l.append(d)
# k=k-d
c=n-k
l.append(c)
l=sorted(l)

print(n-l[-1])

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = map(int,input().split())
A = list(map(int, input().split()))

l = [0] * N
hoge = 0

for n in range(N):
  l[n] = A[n]-hoge
  hoge = hoge + l[n]
  
l = l + [K-A[N-1]]

print(sum(l)-max(l))

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

l = [0] * N
hoge = 0

for n in range(N):
  l[n] = A[n]-hoge
  hoge = hoge + l[n]
  
l = l + [K-A[N-1]]

if A[0]!=0 :
  l[N] = l[N]+l[0]
  l[0] = 0

print(sum(l)-max(l))

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k, n = map(int, input().split())
a_list = list(map(int, input().split()))
d_list = [a_list[0] + k - a_list[n - 1]]
for i in range(0, n - 1):
  d_list.append(a_list[i + 1] - a_list[i])
  print(d_list)
ans = sum(d_list) - max(d_list)
print(ans)

k, n = map(int, input().split())
a_list = list(map(int, input().split()))
d_list = [a_list[0] + k - a_list[n - 1]]
for i in range(0, n - 1):
  d_list.append(a_list[i + 1] - a_list[i])
ans = sum(d_list) - max(d_list)
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
import numpy as np

N, K = map(int, input().split())


locations = input().split()
dists = []
prev_location = None

for location in locations:
  if prev_location is None:
    prev_location = int(location)
  else:
	  dists.append(int(location) - prev_location)  
	  prev_location = int(location)
dists.append(N - int(locations[-1]))

# print(dists)
print(N - np.array(dists).max())

import numpy as np

N, K = map(int, input().split())


locations = input().split()
dists = []
prev_location = None

for location in locations:
  if prev_location is None:
    prev_location = int(location)
  else:
	  dists.append(int(location) - prev_location)  
	  prev_location = int(location)
dists.append(N - int(locations[-1]) + int(locations[0]))

# print(dists)
print(N - np.array(dists).max())

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = map(int,input().split())
A = input().split()
for i in range(N):
    A[i] = int(A[i])
max = 0
for i in range(N-1):
    diff = abs(A[i] - A[i+1])
    if diff >= max:
        max = diff

if abs(K - A[N-1]) >= max:
    max = abs(K - A[N-1])

print(K - max)

K, N = map(int,input().split())
A = input().split()
for i in range(N):
    A[i] = int(A[i])
max = 0
for i in range(N-1):
    diff = abs(A[i] - A[i+1])
    if diff >= max:
        max = diff

if abs(K - A[N-1] + A[0]) >= max:
    max = abs(K - A[N-1] + A[0])

print(K - max)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N = map(int,input().split())
listA = list(map(int,input().split()))
listB = []

for i in listA:
  if i > K/2:
    temp = i - K
    listB.append(temp)
  else:
    listB.append(i)
print(listB)
out1 = max(listA) - min(listA)
out2 = max(listB) - min(listB)
if out1 >= out2:
  print(out2)
else:
  print(out1)

K,N = map(int,input().split())
listA = list(map(int,input().split()))

listB = []

sum = max(listA) - min(listA)
listB.append(sum)

## n - (n-1) ##
for i in range(1,N):
  out = listA[i] - listA[i-1]
  out = K - out
  listB.append(out)


print(min(listB))

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N = map(int,input().split())
A_list = list(map(int,input().split()))
sa = []
for i in range(1,N):
    sa.append(abs(A_list[i]-A_list[i-1]))
sa.append(K-A_list[-1])
print(sa)
print(sum(sa)-max(sa))


K,N = map(int,input().split())
A_list = list(map(int,input().split()))
sa = []
for i in range(1,N):
    sa.append(abs(A_list[i]-A_list[i-1]))
sa.append(K-A_list[-1] + A_list[0])
print(sum(sa)-max(sa))


Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = input().split()
distance = list(map(int, input().split()))

relative = []
relative[0] = distance[0]
for i in range(1, len(distance)):
    relative[i] = distance[i+1] - distance[i]
relative.append(K -  distance[-1])
print(sum(relative) - max(relative))

K, N = input().split()
distance = list(map(int, input().split()))

relative = []
relative.append(distance[0])
for i in range(int(N)-1):
    relative.append(distance[i+1] - distance[i])
relative[0] += (int(K) -  distance[-1])
print(sum(relative) - max(relative))

Verdicts: Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
def C():
    kn=list(map(int,input().split()))
    A=list(map(int,input().split()))
    sum=0
    d=[]
    sum_ans=[]
  
    
    for i in range(kn[1]):
        
        if i==kn[1]-1:
            d.append(kn[0]-A[i])
        else:
            d.append(A[i+1]-A[i])
        
    
    for i in range(1,kn[1]):
        sum_ans.append(min(kn[0]-d[i],kn[0]-d[i-1]))
    
    print(min(sum_ans))    
        
    
if __name__=='__main__':
    C()

def C():
    kn=list(map(int,input().split()))
    A=list(map(int,input().split()))
    d=[]
    sum_ans=[]
   
    for i in range(kn[1]):
        
        if i==kn[1]-1:
            d.append(kn[0]-A[i])
        else:
            d.append(A[i+1]-A[i])
        
        
    sum_ans.append(A[kn[1]-1]-A[0])
    for i in range(1,kn[1]):
        sum_ans.append(min(kn[0]-d[i],kn[0]-d[i-1]))
    
    print(min(sum_ans))    
        
    
if __name__=='__main__':
    C()

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
KN = list(map(int, input().split()))
dis = list(map(int, input().split()))
lists = []
for i in range(KN[1]-1):
    lists.append(dis[i+1]-dis[i])

lists.append(KN[0]+dis[0]-dis[KN[1]-1])
print(lists)
print(KN[0]-max(lists))

KN = list(map(int, input().split()))
dis = list(map(int, input().split()))
lists = []
for i in range(KN[1]-1):
    lists.append(dis[i+1]-dis[i])

lists.append(KN[0]+dis[0]-dis[KN[1]-1])
print(KN[0]-max(lists))

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
from collections import deque
A = deque()
K, N = map(int, input().split())
A = list(map(int, input().split()))
max = 0
for i in range(N-1):
    if abs(A[i]-A[i+1]) > max:
        max = abs(A[i]-A[i+1])
if abs(A[0]-(K-A[N-1])) > max:
    max = abs(A[0]-A[N-1])
print(K - max)

K, N = map(int, input().split())
A = list(map(int, input().split()))
max = 0
for i in range(N-1):
    if abs(A[i]-A[i+1]) > max:
        max = abs(A[i]-A[i+1])
if abs(A[0]+(K-A[N-1])) > max:
    max = abs(A[0]+(K-A[N-1]))
print(K - max)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k, n = map(int, input().split())
a = list(map(int, input().split()))
d = (abs(a[n - 1] - 20) if a[0 == 0] else abs(a[n - 1] - a[0]))
for i in range(1, n):
    d = max(d, abs(a[i - 1] - a[i]))
print(k - d)


k, n = map(int, input().split())
a = list(map(int, input().split()))
d = k + a[0] - a[n - 1]
for i in range(1, n):
    d = max(d, a[i] - a[i - 1])
print(k - d)


Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
a=a.split(' ')
for b in range(n):
    a[b]=int(a[b])

m=0
for b in range(n-1):
    if m<=a[b+1]-a[b]:
        m=a[b+1]-a[b]

if m<=k-a[n-1]+a[0]:
    m=k-a[n-1]+a[0]

print(k-m)

k,n=map(int,input('').split())
a=input('')
a=a.split(' ')
for b in range(n):
    a[b]=int(a[b])
a.sort()

m=0
for b in range(n-1):
    if m<=a[b+1]-a[b]:
        m=a[b+1]-a[b]

if m<=k-a[n-1]+a[0]:
    m=k-a[n-1]+a[0]

print(k-m)

Verdicts: Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = map(int, input().split())
A = list(map(int, input().split()))
d = []

for i in range(N-1):
  d.append(A[i+1] - A[i])
d.append((K - A[N-1]) + A[0])

print(d)
d.remove(max(d))
print(sum(d))

K, N = map(int, input().split())
A = list(map(int, input().split()))
d = []

for i in range(N-1):
  d.append(A[i+1] - A[i])
d.append((K - A[N-1]) + A[0])

print(d)
d.remove(max(d))
print(sum(d))

K, N = map(int, input().split())
A = list(map(int, input().split()))
d = []

for i in range(N-1):
  d.append(A[i+1] - A[i])
d.append((K - A[N-1]) + A[0])

d.remove(max(d))
print(sum(d))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = map(int, input().split())
A = list(map(int, input().split()))

M = 0
for i in range(N):
    if M <= A[i] - A[i-1] :
        M = A[i] - A[i-1]
ans = K - M
print(ans)


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

M = 0
for i in range(N):
    if M <= A[i] - A[i-1] :
        M = A[i] - A[i-1]
    elif M <= K - A[N-1] + A[0]:
        M = K - A[N-1] + A[0]
ans = K - M
print(ans)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k, n = map(int, input().split())
a = list(map(int, input().split()))
dmin = k - (a[n - 1] - a[0])
for i in range(n - 1):
    if (a[i + 1] - a[i]) < dmin:
        dmin = a[i + 1] - a[i]
print(k - dmin)

k, n = map(int, input().split())
a = list(map(int, input().split()))
dmax = k - (a[n - 1] - a[0])
for i in range(n - 1):
    if (a[i + 1] - a[i]) > dmax:
        dmax = a[i + 1] - a[i]
print(k - dmax)

Verdicts: Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = [int(x) for x in input().split()]
A_list = [int(x) for x in input().split()]

max_distance = 0
max_distance_idx = 0
for i in range(0, N-1):
  dist = A_list[i+1]-A_list[i]
  if max_distance < dist:
    max_distance = dist
    max_distance_idx = i

if max_distance <= (K-A_list[N-1]) + (A_list[0]):
  print(max_distance)
else:
  print((A_list[max_distance_idx]) + (K-A_list[max_distance_idx+1]))

K, N = [int(x) for x in input().split()]
A_list = [int(x) for x in input().split()]

if N <= 1:
  print(0)
 
max_distance = 0
max_distance_idx = 0
for i in range(0, N-1):
  dist = A_list[i+1]-A_list[i]
  if max_distance < dist:
    max_distance = dist
    max_distance_idx = i
 
if max_distance <= (K-A_list[N-1]) + (A_list[0]):
  print(max_distance)
else:
  print((A_list[max_distance_idx]) + (K-A_list[max_distance_idx+1]))

K, N = [int(x) for x in input().split()]
A_list = [int(x) for x in input().split()]

max_distance = 0
max_distance_idx = 0
for i in range(0, N-1):
  dist = A_list[i+1]-A_list[i]
  if max_distance < dist:
    max_distance = dist
    max_distance_idx = i

if max_distance <= (K-A_list[N-1]) + (A_list[0]):
  print(A_list[N-1] - A_list[0])
else:
  print((A_list[max_distance_idx]) + (K-A_list[max_distance_idx+1]))

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n = map(int,input(),split())
a = list(map(int,input().split()))
tm = a[0]
a.append(tm)
m = 11414114514
 
for i in range(n):
  m = min(m,a[i+1]-a[i])
  
print(k-m)

k,n = map(int,input().split())
a = list(map(int,input().split()))
tm = a[0]
a.append(tm)
m = 11414114514
 
for i in range(n):
  m = min(m,a[i+1]-a[i])
  
print(k-m)

k,n = map(int,input().split())
a = list(map(int,input().split()))
a.append(a[0])
m = -9878789894545656
 
for i in range(n):
  m = max(m,a[i+1]-a[i])
  
print(k-m)

k,n = map(int,input(),split())
a = list(map(int,input().split()))
a += [a[0]]
m = 11414114514

for i in range(n):
  m = min(m,a[i]-a[i+1])
  
print(k-m)

k,n = map(int,input(),split())
a = list(map(int,input().split()))
a.append(a[0])
m = 11414114514
 
for i in range(n):
  m = min(m,a[i+1]-a[i])
  
print(k-m)

k,n = map(int,input(),split())
a = list(map(int,input().split()))
tm = a[0]
a.append(tm)
m = -9878789894545656
 
for i in range(n):
  m = max(m,a[i+1]-a[i])
  
print(k-m)

k,n = map(int,input().split())
a = list(map(int,input().split()))
tm = a[0]
a.append(tm)
m = -9878789894545656
 
for i in range(n):
  m = max(m,a[i+1]-a[i])
  
print(k-m)

k,n = map(int,input().split())
a = list(map(int,input().split()))
tm = a[0]
a.append(tm)
m = -9878789894545656
 
for i in range(n-1):
  m = max(m,a[i+1]-a[i])
  
m = max(m,a[0]+k-a[n-1])
  
print(k-m)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N=map(int,input().split())
A=list(map(int,input().split()))
d=0
for i in range(N-1):
  if d == 0 and A[i+1]-A[0] >= K/2:
    d=d+A[i]-A[0]+K-A[i+1]-A[0]
if d == 0:
  d=d+A[N-1]-A[0]
print(d)

K,N=map(int,input().split())
A=list(map(int,input().split()))
List=[]
for i in range(N-1):
  b=A[i+1]-A[i]
  List.append(b)
SL=sorted(List)
print(K-SL[-1])

K,N=map(int,input().split())
A=list(map(int,input().split()))
List=[]
for i in range(N):
  b=A[i]-A[i-1]
  if b < 0:
    b=K+b
  List.append(b)
SL=sorted(List)
print(K-SL[-1])

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):


K,N = list(map(int,input().split()))
A = list(map(int,input().split()))
A.append(K)
B = []
ans = K
for i in range(N):
    B.append(abs(A[i]-A[i+1]))

print(K-max(B))




K,N = list(map(int,input().split()))
A = list(map(int,input().split()))
A.append(K)
B = []
ans = K
for i in range(N):
    B.append(abs(A[i]-A[i+1]))
print(B)
print(K-max(B))




K,N = list(map(int,input().split()))
A = list(map(int,input().split()))
B = []
for i in range(N-1):
    B.append(abs(A[i+1]-A[i]))
B.append(K+A[0]-A[-1])

print(K-max(B))


Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
k,n=map(int,input().split())
A=list(map(int,input().split()))
A.append(K+A[0])

for i in range(n):
  l=max(A[i]-A[i-1])

print(K-l)

k,n=map(int,input().split())
a=list(map(int,input().split()))
a.append(k+a[0])
 
for i in range(1,n):
  l=max(a[i]-a[i-1])
 
print(k-l)

k,n=map(int,input().split())
a=list(map(int,input().split()))
a.append(k+a[0])

for i in range(1,n):
  l=max(a[i]-a[i-1])

print(K-l)

k,n=map(int,input().split())
a=list(map(int,input().split()))
a.append(k+a[0])

l=0
for i in range(1,n+1):
  l=max(l,a[i]-a[i-1])
 
print(k-l)

Verdicts: Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K, N = map(int, input().split())
A = list(map(int(input().split())))

K.append(A[0]+K)
l = K+1
for i in range(N):
  l = min(l, A[i+1]-A[i])

print(K-l)

K, N = map(int, input().split())
A = list(map(int, input().split()))
         
for i in range(N):
  if A[i] >= K/2: A[i] -= K

print(max(A) - min(A))

K, N = map(int, input().split())
A = list(map(int, input().split()))
         
for i in range(N):
  if A[i] >= K/2: A[i] -= K
    
print(max(A) - min(A))

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






A.append(A[0]+K)
l = 0
for i in range(N):
  l = max(l, A[i+1]-A[i])

ans = K -l
print(ans)

Verdicts: Runtime Error

Wrong Answer

Wrong Answer

Accepted
Problem: There is a circular pond with a perimeter of K meters, and N houses around them.  The i-th house is built at a distance of A_i meters from the northmost point of the pond, measured clockwise around the pond.  When traveling between these houses, you can only go around the pond.  Find the minimum distance that needs to be traveled when you start at one of the houses and visit all the N houses.

Submission attempts (in order):
K,N=list(map(int,input().split(' ')))
A=list(map(int,input().split(' ')))
k=0
Anew=[]
for i in range(1,N):
    Anew.append(A[i]-A[i-1])
print(K-max(Anew))

K,N=list(map(int,input().split(' ')))
A=list(map(int,input().split(' ')))
k=0
Anew=[]
for i in range(1,N):
    Anew.append(abs(A[i]-A[i-1]))
print(K-max(Anew))

K,N=list(map(int,input().split(' ')))
A=list(map(int,input().split(' ')))
k=0
Anew=[]
for i in range(1,N):
    Anew.append(abs(A[i]-A[i-1]))
Anew.append(abs(K-A[-1]+A[0]))
print(Anew)
print(K-max(Anew))

K,N=list(map(int,input().split(' ')))
A=list(map(int,input().split(' ')))
k=0
Anew=[]
for i in range(1,N):
    Anew.append(abs(A[i]-A[i-1]))
Anew.append(abs(K-A[-1]+A[0]))
print(K-max(Anew))

Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

Accepted