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, n = map(int, input().split())
clist = list(map(int, input().split()))
 
max1 = 0
ind = 0
for i in range(n-1):
    tmp = clist[i+1] - clist[i]
    if tmp > max1:
        max1 = tmp
        ind = i
 
print(clist[ind]+(k-clist[ind+1]))

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

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

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

print(k -max(tmp))

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

ans = 1e9
for i in range(N):
    ans = min(ans, min(A[(i+N-1)%N] + K - A[i], A[i] + K - A[(i+1)%N]))

print(ans)

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

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

print(K - max(dist))

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 = map(int, input().split())
A = input().split()
diff = np.append(np.array(A[1:]) - np.array(A[:-1]), K - A[-1])
diff = np.delete(diff, np.argmax(diff))
print(diff.sum())

import numpy as np
K, N = map(int, input().split())
A = np.array(list(map(int, input().split())))
diff = np.append(A[1:] - A[:-1], K + A[0] - A[-1])
print(np.delete(diff, np.argmax(diff)).sum())

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()))
C = A.sort()
B=C[1:]-C[:-1]
B.append(K+C[0]-C[N-1])
print(K-max(B))

import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
B.append(K+A[0]-A[N-1])
print(K-int(max(B))

import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
B.append(K+A[0]-A[N-1])
print(K-max(B))

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
B=A[1:]-A[:-1]
B.append(K+A[0]-A[N-1])
print(K-max(B))

import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=list(map(x-y))
B.append(K+A[0]-A[N-1])
print(K-max(B))

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

def distance(x):
    q=x[1:]-x[:-1]
    return q

B=distance(A)
B.append(K+A[0]-A[N-1])
print(K-max(B))

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
B=A[1:]-x[:-1]
B.append(K+A[0]-A[N-1])
print(K-max(B))

import numpy as np

K,N=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
x=np.array(A[1:])
y=np.array(A[:-1])
B=x-y
C=B.tolist()
C.append(K+A[0]-A[N-1])
print(K-int(max(C)))

Verdicts: Runtime Error

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):
K, N = list(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[-1] = K - A[-1]

print(K - max(distance))

K, N = list(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[-1] = K + A[0] - A[-1]

print(K - max(distance))


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):
n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for x in range(n-1):
  b=a[x+1]-a[x]
  ans=max(ans,b)
  
c=k-a[n-1]+a[0]

print(max(ans,c))


n,k=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for x in range(n-1):
  b=a[x+1]-a[x]
  ans=max(ans,b)
  
c=k-a[n]+a[0]

print(max(ans,c))

k,n=map(int,input().split())
a=list(map(int,input().split()))
ans=0
for x in range(n-1):
  b=a[x+1]-a[x]
  ans=max(ans,b)
  
c=k-a[n-1]+a[0]

print(k-max(ans,c))



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().split())
a = list(map(int, input().split()))

d = [k-a[-1]+a[0]]

for i in range(n-1):
    d.append(a[i+1]-a[i])

print(a-max(dist))


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

d = [k-a[-1]+a[0]]

for i in range(n-1):
    d.append(a[i+1]-a[i])

print(k-max(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):
k,n = map(int, input().split())
A = list(map(int, input().split()))

path = 0

for i in range(n):
    if i == 0:
        path += min(abs(A[i]-A[n-1]),abs(A[i]-A[i+1]))
    elif i == n-1:
        path += min(abs(A[i]-A[i-1]),abs(A[i]-A[0]))
    else:
        path += min(abs(A[i]-A[i+1]),abs(A[i]-A[i-1]))

print(path)


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

longest = k - (A[-1] - A[0])

for i in range(n-1):
    if A[i+1] - A[i] > longest:
        longest = A[i+1] -A[i]
print(k-longest)

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=[]
for i in range(N-1):
    B.append(A[i+1]-A[i])
B.append(A[N-1]-A[0])
print(N-max(B))

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(K-(A[N-1]-A[0]))
print(K-max(B))

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(input().split())

l = list(map(int, input().split()))
m = [0]*n
count = 0

for i in range(n-1):
    m[count] = l[i+1] - l[i]
    count+=1
m[n-1] = k - l(n-1) + l[0]

print(k - max(m))

k,n = input().split()
k = int(k)
n = int(n)

l = list(map(int, input().split()))
m = [0]*n
count = 0

for i in range(n-1):
    m[count] = l[i+1] - l[i]
    count+=1
m[n-1] = k - l[n-1]+ l[0]

print(k - max(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()))

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


B.append(abs(K - A[-1] - A[0]))

B = sorted(B)

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


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

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


B.append(abs(K - A[-1] - A[0]))

B = sorted(B)

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


import numpy as np
K, N = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
half = K / 2
for i in A:
    if i >= half:
        ans += K - i
    else:
        ans += i

print(ans)


import numpy as np
K, N = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
if K % 2 == 0:
    half = K // 2
else:
    half = K // 2 + 1

for i in A:
    if i >= half:
        ans += K - i
    else:
        ans += i

print(ans)


import numpy as np
K, N = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
A = sorted(A)
new = []
for i in range(N-1):
    new.append(A[i+1]-A[i])
new.append(K + A[0] - A[-1])
new = sorted(new)
print(sum(new[:-1]))


Verdicts: Wrong Answer

Wrong Answer

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()))
sub = [abs(A[i] - A[i+1]) for i in range(N-1)]
sub.append(K-A[N-1])
print(K-max(sub))

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


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 = []
for i in range(N):
  A.append(int(input()))
A_m=[]

for i in range(1,N):
    A_m.append(int(A[i] - A[i-1]))
  

if abs(A[N-1]-A[0]) > 10:
  A_m.append(A[0]-A[N-1] +20)
else:
  A_m.append(A[N-1]-A[0])
  
X = sum(A_m) - max(A_m)

print(X)

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

A = []

for i in range(N):
  A.append(int(input()))
  
A_m = []

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


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

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

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().split())
A = list(map(int, input().split()))
A.sort()
m = 0
for i in range(1, len(A)):
    if A[i]-A[i-1]>m:
        m=A[i]-A[i-1]
if K-A[-1]+A[1]>m:
    print(A[-1]-A[1])
else:
    print(K-m)


K, N = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
m = 0
for i in range(1, len(A)):
    if A[i]-A[i-1]>m:
        m=A[i]-A[i-1]
if K-A[-1]>m:
    print(A[-1])
else:
    print(K-m)

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


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()))
longest = 0
for i in range(N):
  longest = max(longest, A[i + 1] - A[i])
longest = max(longest, A[0] + K - A[-1])
print(K - longest)

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

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 = input().split()
a = list(map(int, input().split()))

max = 0

for i in range(n - 1):
  if a[i + 1] - a[i] > max:
    max = a[i + 1] - a[i]

if (k - a[n]) + a[0] >= max:
  max = (k - a[n]) + a[0]

print(k - max)

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

max = 0

for i in range(n - 1):
  if a[i + 1] - a[i] > max:
    max = a[i + 1] - a[i]

if (k - a[n]) + a[0] >= max:
  max = (k - a[n]) + a[0]

print(k - max)


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

max = 0

for i in range(n - 1):
  if a[i + 1] - a[i] > max:
    max = a[i + 1] - a[i]

if (k - a[n - 1]) + a[0] >= max:
  max = (k - a[n - 1]) + a[0]

print(k - max)


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):
I = input().split()
K = int(I[0])
N = int(I[1])

I = input().split()

A = [ int(I[0]) ]
L = [ A[0] ]
for i in range(1,N):
  A.append( int(I[i]) )
  L.append( A[i] - A[i-1] )

L[0] = A[0]+(K-A[N-1])

A.sort()
print(L[N-1])

  


I = input().split()
K = int(I[0])
N = int(I[1])

I = input().split()

A = [ int(I[0]) ]
L = [ A[0] ]
for i in range(1,N):
  A.append( int(I[i]) )
  L.append( A[i] - A[i-1] )

L[0] = A[0]+(K-A[N-1])

L.sort()
print(K - L[N-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())
dis = list(map(int,input().split()))
print(sum(dis)-max(dis))



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



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.append(k+a[0])
dist = [abs(a[i+1]-a[i]) for i in range(n)]

print(a)
print(k-max(dist))

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

print(k-max(dist))

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())
b=list(map(int, input().split()))
b.sort()
a=[b[0]+k-b[n-1]]
for i in range(n-1):
    a.append(b[i+1]-b[i])
    print(b[i])
print(k-max(a))


k,n=map(int,input().split())
b=list(map(int, input().split()))
b.sort()
a=[b[0]+k-b[n-1]]
for i in range(n-1):
    a.append(b[i+1]-b[i])
print(k-max(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(int, input().split())
A = list(map(int, input().split()))
A = [0] + A + [K] 

diff = []
for i in range(len(A)):
    if i < N+1:
        diff.append(A[i+1] - A[i])

longest_interval = diff.index(max(diff))
diff.pop(longest_interval)
ans = sum(diff)

print(ans)


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

diff = []
for i in range(len(A)):
    if i < N-1:
        diff.append(A[i+1] - A[i])

diff = diff + [K-A[-1]+A[0]]
longest_interval = diff.index(max(diff))
diff.pop(longest_interval)
ans = sum(diff)

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

all_length = k*2
point = []
for i in range(n):
    a_left  = k-a[i]
    a_right = k+a[i]
    point.append(a_left)
    point.append(a_right)
point = list(set(point))
point.sort()

num = len(point)
num = round(num)
distance = []
for i in range(num):
    dis = 0
    for j in range(n-1):
        dis += point[i+j+1] - point[i+j]
    distance.append(dis)
mindis = min(distance)
print(mindis)

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])
print(k-l)

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):
a=input().split(' ')
b=input().split(' ')
c=0
for i in int(a[1]):
    if i != a[1]-1:
        if int(b[i+1]) - int(b[i]) > c:
            c = int(b[i+1]) - int(b[i])
    else:
        if int(a[0]) - int(b[-1])+ int(b[0]) > c:
            c = int(a[0]) - int(b[-1])+ int(b[0])
print(int(a[0])-c)

a=input().split(' ')
b=input().split(' ')
c=0
for i in int(a[1]):
    if i != int(a[1])-1:
        if int(b[i+1]) - int(b[i]) > c:
            c = int(b[i+1]) - int(b[i])
    else:
        if int(a[0]) - int(b[-1])+ int(b[0]) > c:
            c = int(a[0]) - int(b[-1])+ int(b[0])
print(int(a[0])-c)


a=input().split(' ')
b=input().split(' ')
c=0
for i in range(int(a[1])):
    if i != int(a[1])-1:
        if int(b[i+1]) - int(b[i]) > c:
            c = int(b[i+1]) - int(b[i])
    else:
        if int(a[0]) - int(b[-1])+ int(b[0]) > c:
            c = int(a[0]) - int(b[-1])+ int(b[0])
print(int(a[0])-c)


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().split())
now = -10**9
for i in range(N):
  if i == N-1:
    if K-A[N-1]+A[i]>now:
      now = K-A[N-1]+A[i]
  else:
    if A[i+1]-A[i] > now:
      now = A[i+1]-A[i]
print(K-now)

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


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



AN = A[0]+(K-sum(A))
A2 = A[1:N]
A2.append(AN)

print(sum(A2)-max(A2))


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


A2 = [A[i+1] - A[i] for i in range(N-1)]
AN = A[0]+(A[0]+(K-A[N-1]))
A2.append(AN)

print(K-max(A2))


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



AN = A[0]+A[N-1]
A2 = A[1:N]
A2.append(AN)

print(sum(A2)-max(A2))

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


A2 = [A[i+1] - A[i] for i in range(N-1)]
AN = A[0]+(K-A[N-1])
A2.append(AN)

print(K-max(A2))


Verdicts: Wrong Answer

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_str = input().split()
A = [int(h) for h in A_str]
print(A)
D = []
for i in range(1,N):
  D.append(A[i]-A[i-1])
D.append(A[0]+(K-A[N-1]))
print(D)
maximum = max(D)
print(K-maximum)

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

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):
N = int(input())
x = 0
a = []
for i in range(2,N,2):
    while i % 2 == 0:
        i //= 2
        x += 1
    a.append(x)
    x = 0
a = sorted(a)
a = a[::-1]
print(a[0])

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

for i in range(N - 1):
    x.append(A[i + 1] - A[i])
x.append(A[0] + K - A[N - 1])
x = sorted(x)
del x[N - 1]
print(sum(x))

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 main():
    K, N = [int(_) for _ in input().split()]
    A = map(int, input().split())
    mx = 0

    for i in range(N-1):
        dis = A[i+1]-A[i]
        if dis > mx:
            mx = dis
    se = A[N-1] - A[0]
    if (k-(se)) > mx:
        mx = k - se
    print(mx)
main()

def main():
    K, N = [int(_) for _ in input().split()]
    A = list(map(int, input().split()))
    mx = 0

    for i in range(N-1):
        dis = A[i+1] - A[i]
        if dis > mx:
            mx = dis
    se = A[N-1] - A[0]
    
    if K-se > mx:
        mx = K - se
    print(K - mx)
main()

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()))
sa=[0]*n
for i in range(n-1):
    sa[i]=a[i+1]-a[i]
    sa[n-1]=a[0]+(k-a[n-1])
print(sa)
ans=max(sa)
ans=k-ans
print(ans)

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

a= list(map(int,input().split()))
sa=[0]*n
for i in range(n-1):
    sa[i]=a[i+1]-a[i]
    sa[n-1]=a[0]+(k-a[n-1])
#print(sa)
ans=max(sa)
ans=k-ans
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 = list(map(int,input().split()))
a =  list(map(int,input().split()))

res= a[n-1]

max=0
n_prev=0

for nn in a:
    if (nn-n_prev) < (k-a[n-1]):
        res=(nn-n_prev)
    n_prev=nn

print(res)




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

res= a[n-1]

max=0
n_prev=0

for nn in a:
    if (nn-n_prev) > (k-a[n-1]):
        res=(nn-n_prev)
    n_prev=nn

print(res)




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

n_prev= a[n-1]-k

m=0

for nn in a:
    if (nn-n_prev) > m:
        m=nn-n_prev
        res=(k-m)
    n_prev=nn

print(res)



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()))
result = 0
mx = -float("inf")
for i in range(N-1):
    mx = max(mx, A[i+1] - A[i])
mx = max(mx, K - A[-1])

result = K - mx
print(result)

K, N = map(int, input().split())
A = list(map(int, input().split()))
result = 0
mx = -float("inf")
for i in range(N-1):
    mx = max(mx, A[i+1] - A[i])
mx = max(mx, K - A[-1])

result = K - mx + A[0]
print(result)

K, N = map(int, input().split())
A = list(map(int, input().split()))
result = 0
mx = -float("inf")
for i in range(N-1):
    mx = max(mx, A[i+1] - A[i])
mx = max(mx, K - A[-1] + A[0])

result = K - mx
print(result)

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

space = []
for i in range(n - 1):
    s = a[i + 1] - a[i]
    space.append(s)
space.append(k - a[n - 1])

print(k - max(space))

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

space = []
for i in range(n - 1):
    s = a[i + 1] - a[i]
    space.append(s)
space.append(k +a[1] - a[n - 1])

print(k - max(space))


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

space = []
for i in range(n - 1):
    s = a[i + 1] - a[i]
    space.append(s)
space.append(k - a[n - 1])

print(k + a[1] - max(space))

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

space = []
for i in range(n - 1):
    s = a[i + 1] - a[i]
    space.append(s)
space.append(k +a[0] - a[n - 1])

print(k - max(space))


Verdicts: Wrong Answer

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):
import numpy as np
k,n = map(int, input().split())
a = list(map(int, input().split()))
b = np.zeros(n)
for i in range(0,n-1):
  b[i] = a[i+1] -a[i]

b[n-1] = k - a[n-1] + a[0]
print(a,b)
ans = k - max(b)
print(int(ans))

import numpy as np
k,n = map(int, input().split())
a = list(map(int, input().split()))
b = np.zeros(n)
for i in range(0,n-1):
  b[i] = a[i+1] -a[i]
  
b[n-1] = k - a[n-1] + a[0]
print(a,b)
ans = k - max(b)
print(ans)

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

b[n-1] = k - a[n-1] + a[0]
ans = k - max(b)
print(int(ans))

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):
p, n = map(int,input().split())
l = list(map(int,input().split()))
ans = min(max(l)-min(l), p-max(l)+ min(l))

p, n = map(int,input().split())
l = list(map(int,input().split()))
l.sort()
val = l[-1]-l[0]
for i in range(1,n):
    val = min(val, l[-1] - l[i] + p-l[-1]+l[i-1])
print(val)


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):
M,N = list(map(int,input().split()))
A = input().split()
A.append(M)
dis = 0
for i in range(N):
    if A[i+1]-A[i] >= dis:
        dis = A[i+1]-A[i]
        
print(A[-2]-A[0]-(dis-A[1]-A[0]))

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

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):
#include <stdio.h>
int main(void){
    long k,n,i,max=-1,a[200000];
    scanf("%ld%ld",&k,&n);
    for(i=0;i<n;i++) scanf("%ld",&a[i]);
    for(i=0;i<n-1;i++){
        int tmp=a[i+1]-a[i];
        if(tmp>max) max=tmp;
    }
    printf("%ld",k-max);
    return 0;
}

k,n = map(int,input().split())
a = list(map(int,input().split()))
m = a[0]+k-a[n-1]
for i in range(n-1):
    m = max(m,a[i+1]-a[i])
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()))
mi = float("inf")
ma = 0
tokei = 1
ans = 0

for index, tmp in enumerate(A):
    if index==0:
        left = tmp
    elif index == 1:
        right = tmp
        b1 = right - left
        b2 = left+K-right
#         print(b1)
#         print(b2)
        if b1>b2:
            ans = b2
            tokei = 0
            break
        else:
            ans = b1
    else:
        b1 = tmp-right
        b2 = left+K-tmp
#         print(b1)
#         print(b2)
        print(left)
        print(right)
        if b1<b2:
            ans += b1
            right = tmp
        else:
            ans += b2
            break
print(ans)

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

interval=[]
for i in range(N-1):
    interval+=[A[i+1]-A[i]]
    interval+=[A[0]+K-A[N-1]]
#     print(interval)
 
print(K-max(interval))

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()))
for i in range(n):
    a.append(k+a[i])
right = [0]

for i in range(1, 2*n):
    right.append(right[-1] + a[i] - a[0])

ans = abs(a[0] - a[-2])
for i in range(1, n):
    ans = min(ans, abs(a[i] - a[n+i-1]))
print(ans)




k, n = map(int, input().split())
a = list(map(int, input().split()))
for i in range(n):
    a.append(k+a[i])
right = [0]

for i in range(1, 2*n):
    right.append(right[-1] + a[i] - a[0])

ans = abs(a[0] - a[-2])
for i in range(1, n+1):
    ans = min(ans, abs(a[i] - a[n+i-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):
n,k = map(int,input().split())
a = sorted([i for i in map(int,input().split())])
maxi = -1
ans = (n + (n - a[-1]%n))%n + a[0]
#print(ans)
for i in range(1,len(a)):
    maxi = max(maxi,a[i] - a[i - 1])
    ans += a[i] - a[i - 1]
maxi = max(maxi,(a[-1] + (a[-1] - a[0]))%n)
ans -= maxi
print(ans)



n,k = map(int,input().split())
a = sorted([i for i in map(int,input().split())])
maxi = -1
ans = (n + (n - a[-1]%n))%n + a[0]
#print(ans)
for i in range(1,len(a)):
    maxi = max(maxi,a[i] - a[i - 1])
    ans += a[i] - a[i - 1]
maxi = max(maxi,(n + (n - a[-1]%n))%n)
ans -= maxi
print(ans)



n,k = map(int,input().split())
a = sorted([i for i in map(int,input().split())])
maxi = -1
ans = (n + (n - a[-1]%n))%n + a[0]
#print(ans)
for i in range(1,len(a)):
    maxi = max(maxi,a[i] - a[i - 1])
    ans += a[i] - a[i - 1]
maxi = max(maxi,(n + (n - a[-1]%n))%n + a[0])
ans -= maxi
print(ans)



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):
n,k = list(map(int,input().split()))
arr = list(map(int,input().split()))
max_d = k-arr[-1] + arr[0]
for i in range(n):
  max_d = max(max_d,arr[i+1]-arr[i])
print(k-max_d)

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


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



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().split())
a=list(map(int,input().split()))
a.append(a[0])
dis=[]
for i in range(n):
    d=abs(a[i]-a[i+1])
    if d>k/2:
        d=k-d
    dis.append(d)
print(dis,k-max(dis))

k,n=map(int,input().split())
a=list(map(int,input().split()))
a.append(a[0])
dis=[]
for i in range(n):
    d=abs(a[i]-a[i+1])
    if d>k/2:
        d=k-d
    dis.append(d)
print(k-max(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())
A = {}
for i in range(N):
    A[i] = int(input())
max = 0
for i in range(N):
    len = 0
    if i == 0:
        len = int(A[i] + (K - A[N - 1]))
    else:
        len = int(A[i] - A[i - 1])

    if len > max:
        max = len

print(K - max)

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

    if len > max:
        max = len

print(K - max)

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):
# -*- coding: utf-8 -*-

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

Bn=An[1:]+[K+An[0]]
print(An)
print(Bn)
dis = [x-y for x,y in zip(An,Bn)]
print(K-abs(min(dis)))


# -*- coding: utf-8 -*-

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

Bn=An[1:]+[K+An[0]]
dis = [x-y for x,y in zip(An,Bn)]
print(K-abs(min(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,N=map(int,input().split())
A=list(map(int,input().split()))
n=2*10^6
for i in range(N):
  m = abs(A[i-1] - A[i])
  if n > m:
    n = m
print(m)

K,N=map(int,input().split())
A=list(map(int,input().split()))
n=2*10^6
for i in range(N):
  m = abs(A[i-1] - A[i])
  if n > m:
    n = m
print(m)

K,N=map(int,input().split())
A=list(map(int,input().split()))
n=0
j=[-1, -1]

for i in range(N):
  if i + 1 < N:
    if A[i + 1] - A[i] > n:
      n = A[i + 1] - A[i]
      j = [i, i+1]
  else:
    if K - A[i] + A[0] > n:
      n = K - A[i] + A[0]
      j = [i, 0]
print(K - n)

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 = [int(i) for i in input().strip().split()]
arr = [int(i) for i in input().strip().split()] + [k + arr[0]]
max_d = 0
for i in range(1, n + 1):
    max_d = max(max_d, abs(arr[i] - arr[i - 1]))
print(k - max_d)

k, n = [int(i) for i in input().strip().split()]
arr = [int(i) for i in input().strip().split()]
arr += [k + arr[0]]
max_d = 0
for i in range(1, n + 1):
    max_d = max(max_d, abs(arr[i] - arr[i - 1]))
print(k - max_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):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    K, N = map(int, readline().split())
    A = list(map(int, readline().split()))
    d = [A[i]-A[i-1] for i in range(1,N)]
    ans = min(K-max(d), max(d))
    print(ans)
    return

if __name__ == '__main__':
    main()


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    K, N = map(int, readline().split())
    A = map(int, readline().split())
    ans = max(K - max(A) + min(A),max(A) -min(A))
    print(ans)
    return

if __name__ == '__main__':
    main()

import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    K, N = map(int, readline().split())
    A = list(map(int, readline().split()))
    d = [A[i]-A[i-1] for i in range(1,N)]
    d.append(K - max(A) + min(A))
    ans = min(K-max(d), max(d))
    print('d:',d)
    print(ans)
    return

if __name__ == '__main__':
    main()


import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main():
    K, N = map(int, readline().split())
    A = list(map(int, readline().split()))
    sorted(A)
    d = [A[i]-A[i-1] for i in range(1,N)]
    d.append(K - max(A) + min(A))
    ans = K-max(d)
    print(ans)
    return

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):
a,b = map(int,input().split())
List = [int(i) for i in input().split()]
s = [0]*b
s[b-1] = abs(a- List[b-1])
for i in range(b-1):
    s[i] = abs(List[i]-List[i+1])
print(a-max(s))

a,b = map(int,input().split())
List = [int(i) for i in input().split()]
s = [0]*b
s[b-1] = abs(List[0] + a- List[b-1])
for i in range(b-1):
    s[i] = abs(List[i]-List[i+1])
print(a-max(s))

Verdicts: Wrong Answer

Accepted