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

length = K//2
for i in range(N-1):
    length = max(A[i+1] - A[i] , length)
    if lenghth == A[i+1] - A[i]:
        ans = A[i] + K - A[i+1]
      
if length == K//2:
    ans = A[-1] - A[0]
print(ans)

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

length = K//2
for i in range(N-1):
    length = max(A[i+1] - A[i], length)
    if lenghth == A[i+1] - A[i]:
        ans = A[i] + K - A[i+1]
      
if length <= K//2:
    ans = A[-1] - A[0]
print(ans)

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

length = A[0] + K - A[-1]
for i in range(N-1):
    length = max(A[i+1] - A[i] , length)
    if length == A[i+1] - A[i]:
        ans = A[i] + K - A[i+1]
      
if length == A[0] + K - A[-1]:
    ans = A[-1] - A[0]
print(ans)

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):
import numpy as np
import sys
readline = sys.stdin.buffer.readline
K, N = map(int, readline().split())
A = list(map(int,input().split()))
N1= A[0]+K-A[N-1]

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

print(N,N1)
c = min(K-N1,K-N)
print(c)

import numpy as np
import sys
readline = sys.stdin.buffer.readline
K, N = map(int, readline().split())
A = list(map(int,input().split()))
N1= A[0]+K-A[N-1]

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

print(K-N1)

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 = [int(x) for x in input().split()]
b = [0] *(n)
for i in range(n-1):
    b[i] =a[i+1]-a[i]
b[n] = a[0] + k - a[n-1]

print(k - max(b))


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

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(0,N-1):
  d = A[i + 1] - A[i]
  D.append(abs(d))
  
d2 = A[N-1] - K
D.append(abs(d2))

kankaku = max(D)
saitan = K - kankaku

print(saitan)

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

A = list(map(int, input().split()))
D = []

for i in range(0,N-1):
  d = A[i + 1] - A[i]
  D.append(abs(d))
  
d2 = A[N-1] - A[0]
D.append(abs(d2))

kankaku = max(D)
saitan = K - kankaku


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

A = list(map(int, input().split()))
D = []

for i in range(0,N-1):
  d = A[i + 1] - A[i]
  D.append(abs(d))
  
d2 = A[N-1] - (A[0] + K)
D.append(abs(d2))

kankaku = max(D)
saitan = K - kankaku

print(saitan)

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()))]
del A[index(min(A))]
for a in A:
  a-=min(A)
print(max(A)-min(A))

K,N=map(int,input().split())
A=[list(map(int,input().split()))]
print(max(A)-min(A))

K,N=map(int,input().split())
A=list(map(int,input().split()))
B=sorted(A)
C=[]
for i in range(N-1):
    C.append(B[i+1]-B[i])
C.append(B[0]+K-B[N-1])
print(K-max(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()))

max_distance = k - a[-1] - a[0]
str_index = 0
gl_index = -1
for i in range(n):
    if i == 0:
        continue
    elif max_distance < abs(a[i-1] - a[i]):
        max_distance = abs(a[i-1] - a[i])
        str_index = i-1
        gl_index = i
print(a[str_index] + (k - a[gl_index]))

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

if a[-1] <= k / 2:
    print(a[-1] - a[0])

else:
    max_distance = k - a[-1] - a[0]
    str_index = 0
    gl_index = -1
    for i in range(n):
       	if i == 0:
            continue
        elif max_distance < abs(a[i-1] - a[i]):
            max_distance = abs(a[i-1] - a[i])
            str_index = i-1
            gl_index = i
    print(a[str_index] + (k - a[gl_index]))

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

max_distance = k - a[-1] - a[0]
str_index = 0
gl_index = -1
for i in range(n):
   	if i == 0:
        continue
    elif max_distance < abs(a[i-1] - a[i]):
        max_distance = abs(a[i-1] - a[i])
        str_index = i-1
        gl_index = i
print(a[str_index] + (k - a[gl_index]))

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

max_distance = abs(k - a[-1] + a[0])
str_index = 0
gl_index = -1
for i in range(n):
    if i == 0:
        continue
    elif max_distance < abs(a[i-1] - a[i]):
        max_distance = abs(a[i-1] - a[i])
        str_index = i-1
        gl_index = i
if gl_index == -1:
    print(a[gl_index] - a[str_index])
else:
    print(a[str_index] + (k - a[gl_index]))

Verdicts: Wrong Answer

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(float, input().split())
m = list(map(float, input().split()))
min = float(0)
half_k = k / 2
for i in range(n):
    first = m[i]
    last = m[i-1]
    len = last - first
    if len < 0:
        len = len + k
    if min < len:
        min = len
print(int(min))


k, n = map(float, input().split())
m = list(map(float, input().split()))
half_k = k / 2
min = float(1000000)
for i in range(int(n)):
    first = m[i]
    last = m[i-1]
    len = last - first
    if len < 0:
        len = len + k
    if min > len:
        min = len
print(int(min))


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):
s = input().split(" ")
k = int(s[0])
n = int(s[1])

d = input().split(" ")
dist = []

for i in range(0,n):
    dist.append(int(d[i]))

ex = dist[0] + k - dist[n-1]
res = k - ex

for i in range(1, n):
 	diff = dist[i] - dist[i-1]
    aux = res + ex - diff
    
    if aux < res:
        res = aux
        
	ex = diff

print(str(res))

s = input().split(" ")
k = int(s[0])
n = int(s[1])

d = input().split(" ")
dist = []

for i in d:
    dist.append(int(i))

res = dist[n-1] - dist[0]

for i in range(1, n):
    diff = dist[i] - dist[i-1]
    aux = k - diff
    if aux < res:
        res = aux

print(str(res))


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=[int(i) for i in input().split()]
array=[a[n-1]-a[0]]
array.append(result)
for i in range(1,n):
  array.append(k+a[i-1]-a[i])
print(min(array))


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

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

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()))
gap = []

for i in range(N):
    if i < N - 1:
        sa = A[i+1] - A[i]
    else:
        sa = A[0] + (K - A[N-1])
    print(sa)
    gap.append(sa)
    i += 1
    
dist = max(gap)
ans = K - dist
print(ans)


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

for i in range(N):
    if i + 1 < N - 1:
        sa = A[i+1] - A[i]
    else:
        sa = A[0] + (K - A[N-1])
    print(sa)
    gap.append(sa)
    i += 1
    
dist = max(gap)
ans = K - dist
print(ans)


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

for i in range(N):
    if i < N - 1:
        sa = A[i+1] - A[i]
    else:
        sa = A[0] + (K - A[N-1])
    gap.append(sa)
    i += 1
    
dist = max(gap)
ans = K - dist
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):
k, n = map(int, input().split())
a = list(map(int, input().split()))

for i, d in enumerate(a):
    if i != 0:
        a[i] = d - a[i - 1]
    else:
        a[i] = d + 20 - a[n - 1]

a.sort(reverse=True)
print(k - a[0])

k, n = map(int, input().split())
a = list(map(int, input().split()))
a2 = []
for i, d in enumerate(a):
    if i != 0:
        a2.append(d - a[i - 1])
    else:
        a2.append(d + k - a[n - 1])
print(a, a2)
a2.sort(reverse=True)
print(a, a2)
print(k - a2[0])

k, n = map(int, input().split())
a = list(map(int, input().split()))
a2 = []
for i, d in enumerate(a):
    if i != 0:
        a2.append(d - a[i - 1])
    else:
        a2.append(d + k - a[n - 1])
# print(a, a2)
a2.sort(reverse=True)
# print(a, a2)
print(k - a2[0])

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

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

a_list = list(A)

dist = 0
max = 0
sum = 0

for i in range(len(a_list)):
  if i == len(int(a_list)) - 1:
    dist = abs(int(a_list[i]) - int(a_list[0]))
  else:
    dist = abs(int(a_list[i]) - int(a_list[i + 1]))
  
  if max < dist:
    sum += max
    max = dist
  else:
    sum += dist
    
print(sum)
  

K,N = input().split()
A = input().split()
 
a_list = list(A)

dist = 0
dist_list = []
max = 0
sum = 0
 
for i in range(len(a_list)):
  if i == len(a_list) - 1:
    dist = int(K) - abs(int(a_list[i]) - int(a_list[0]))
  else:
    dist = abs(int(a_list[i]) - int(a_list[i + 1]))
  if i != 0: 
    if max < dist:
        sum += max
        max = dist
    else:
        sum += dist
  else:
      max = dist
  print(sum,dist)
    
print(sum)

K,N = input().split()
A = input().split()
 
a_list = list(A)

dist = 0
dist_list = []
max = 0
sum = 0
 
for i in range(len(a_list)):
  if i == len(a_list) - 1:
    dist = int(K) - abs(int(a_list[i]) - int(a_list[0]))
  else:
    dist = abs(int(a_list[i]) - int(a_list[i + 1]))
  if i != 0: 
    if max < dist:
        sum += max
        max = dist
    else:
        sum += dist
  else:
      max = dist
  
    
print(sum)

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

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

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 calc(K, N, A):
    A.sort()
    B = [A[i + 1] - A[i] for i in range(N - 1)]
    return K - max(B)


(K, N) = tuple([int(s) for s in input().split()])
A = [int(s) for s in input().split()]
print(calc(K, N, A))

def calc(K, N, A):
    B = [A[i + 1] - A[i] for i in range(N - 1)] + [A[0] + K - A[N - 1]]
    print(B)
    return K - max(B)


(K, N) = tuple([int(s) for s in input().split()])
A = [int(s) for s in input().split()]
print(calc(K, N, A))

def calc(K, N, A):
    B = [A[i + 1] - A[i] for i in range(N - 1)] + [A[0] + K - A[N - 1]]
    return K - max(B)


(K, N) = tuple([int(s) for s in input().split()])
A = [int(s) for s in input().split()]
print(calc(K, N, A))

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

B=[]
t=0
for a in A:
    B.append(a-t)
    t=a
B[0] +=k-t

print(B, k-max(B) )

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

B=[]
t=0
for a in A:
    B.append(a-t)
    t=a
B[0] +=k-t

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 = map(int, input().split())
A = list(map(int, input().split()))
diff_list = []
sum_val = 0

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

print(sum(diff_list)-max(diff_list))

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

diff_list.append(K-A[-1] + A[0])

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


print(sum(diff_list)-max(diff_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):
K,N=map(int,input().split())
A=[int(_) for _ in input().split()]
a=0
for i in range(N-1):
  tmp=A[i+1]-A[i]
  if a<tmp:
    a=tmp

print(min(K-a,A[0]))


K,N=map(int,input().split())
A=[int(_) for _ input().split()]
a=0
for i in range(N-1):
  tmp=A[i+1]-A[i]
  if a<tmp:
    a=tmp
print(K-a)

K,N=map(int,input().split())
A=[int(_) for _ in input().split()]
a=A[0]
for i in range(N-1):
  tmp=A[i+1]-A[i]
  if a<tmp:
    a=tmp

print(K-a)


K,N=map(int,input().split())
A=[int(_) for _ in input().split()]
a=0
for i in range(N-1):
  tmp=A[i+1]-A[i]
  if a<tmp:
    a=tmp
print(K-a)


K,N=map(int,input().split())
A=[int(_) for _ in input().split()]
a=K-A[N-1]+A[0]
for i in range(N-1):
  tmp=A[i+1]-A[i]
  if a<tmp:
    a=tmp

print(K-a)


Verdicts: Wrong Answer

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

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

k,n=map(int,input().split())
a=list(map(int,input().split()))
max_d=0
for i in range(n):
    x=0
    if i==n-1:
        if a[0]==0:
            x=k-a[i]
        else:
            x=k-a[i]+a[0]
    else:
        x=a[i+1]-a[i]
    if x>max_d:
        max_d=x
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 = [int(x) for x in input().split()]
a.append(K)
dist = [0]*(N+1)

dist[0] = a[N-1] - K - a[0]
for i in range(len(a)-1):
    dist[i+1] = a[i+1] - a[i]

dist.pop()
dist.remove(max(dist))
ans = abs(min(dist)) + abs(max(dist))
print(ans)

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

dist = [0] * (N + 1)

for i in range(N-1):
    dist[i] = a[i+1] - a[i]

dist[N] = K - a[N - 1] + a[0]

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):
def main():
    k,n = tuple([int(t)for t in input().split()])
    a = [int(t)for t in input().split()]

    l = 0
    dist = []
    for a_i in a[1:]:
        dist.append(a_i-l)
        l = a_i
    dist.append(k-a[-1]+a[0])
    print(dist)
    print(k-max(dist))

if __name__ == "__main__":
    main()

def main():
    k,n = tuple([int(t)for t in input().split()])
    a = [int(t)for t in input().split()]

    l = a[0]
    dist = []
    for a_i in a[1:]:
        dist.append(a_i-l)
        l = a_i
    dist.append(k-a[-1]+a[0])

    print(k-max(dist))

if __name__ == "__main__":
    main()

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 for i in range(N)]
print(A)
print(B)


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

B[N-1] = K - (A[N-1] - A[0])
B_max = max(B)
print(B)
print(K - B_max)


K, N = map(int, input().split())
A = list(map(int, input().split()))
B = [0 for i in range(N)]

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

B[N-1] = K - (A[N-1] - A[0])
B_max = max(B)
print(K - B_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 = [int(x.strip()) for x in input().split()]
for i in range(n):
  if i != 0 and i != n-1:
    dist_r = a[i-1] + (k - a[i])
    dist_l = a[i] + (k - a[i+1])
    min_dist = min(dist_r,dist_l)
  elif i == 0:
    dist_r = a[n-1] + (k - a[i])
    dist_l = a[i] + (k - a[i+1])
    min_dist0 = min(dist_r,dist_l)
  else:
    dist_r = a[i-1] + (k - a[i])
    dist_l = a[i] + (k - a[0])
    min_distn = min(dist_r,dist_l)
ans = min(min_dist,min_dist0,min_distn)
print(ans)

k,n = map(int, input().split())
a = [int(x.strip()) for x in input().split()]
min_dist = k
for i in range(n):
  if i != 0 and i != n-1:
    dist_r = a[i-1] + (k - a[i])
    dist_l = a[i] + (k - a[i+1])
    if min_dist > min(dist_r,dist_l):
      min_dist = min(dist_r,dist_l)
  elif i == 0:
    dist_r = a[n-1] - a[i]
    dist_l = a[i] + (k - a[i+1])
    min_dist0 = min(dist_r,dist_l)
  else:
    dist_r = a[i-1] + (k - a[i])
    dist_l = a[i] - a[0]
    min_distn = min(dist_r,dist_l)
ans = min(min_dist,min_dist0,min_distn)
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()))
a.append(a[0]+k-a[-1])
l = max(a)
print(k-l)

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: 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-1):
    d = a[i+1] - a[i]
    m = max(m, d)
d_last = k - a[n-1]
m = max(m, d_last)

res = k - m
print(res)

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(m, d)
d_last = k - a[n-1] + a[0]
m = max(m, d_last)

res = k - m
print(res)

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(filter(lambda x: x != 0, (int(x) for x in input().split())))
print(sum(A) / len(A))


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

m = A[min(((i, abs(max(A) / 2 - n)) for i, n in enumerate(A)), key=lambda x: x[1])[0]]
print(m)
print(max((max(A) - m), (m - min(A))))


import sys
import random

def test(K, N, A):
    ans = []
    maxp = N-1
    minp = 0
    for i in range(len(A)):
        ans.append(A[maxp] - A[minp])
        A[i] += K
        maxp = (maxp + 1) % (N)
        minp = (minp + 1) % (N)
    print(min(ans))

if __name__ == "__main__":
    if "random" in sys.argv:
        K = int(random.random() * 20000)
        N = int(random.random() * 65536)
        A = sorted([int(random.random() * K) for _ in range(N)])
    else:
        K, N = [int(x) for x in input().split()]
        A = [int(x) for x in input().split()]
    test(K,N,A)
    pass


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

a.sort()
print(a)
print(sum(a[:-1]))


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

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

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

a.sort()
print(sum(a[:-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()))

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

print(K - MIN_LIST)

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

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

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

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

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: 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):
m,n=map(int,input().split())
li=list(map(int,input().split()))
M=0
for i in range(n-1):
    if li[i+1]-li[i]>M:
        M=li[i+1]-li[i]
if m-li[-1]>M:
    M=m-li[-1]
print(M)

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

m,n=map(int,input().split())
li=list(map(int,input().split()))
M=0
li.append(li[0]+m)
for i in range(n):
    if abs(li[i+1]-li[i])>M:
        M=abs(li[i+1]-li[i])
print(m-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(" "))
alist = list(map(int, input().split(" ")))
glist = []
for i in range(n-1):
  glist.append(alist[i+1]-alist[i])
glist.append(k+a[0]-a[n-1])

print(k-max(glist))


k ,n  = map(int, input().split(" "))
alist = list(map(int, input().split(" "))
glist =  []
for i in range(n-1):
    glist.append(alist[i+1]-alist[i])
glist.append(k+alist[0]-alist[n-1])

print(int(k-max(glist)))
    
   

k,n = map(int,input().split(" "))
alist = list(map(int, input().split(" ")))
glist = []
for i in range(n-1):
  glist.append(alist[i+1]-alist[i])
glist.append(k+alist[0]-alist[n-1])

print(k-max(glist))

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

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

print(N-max(K))

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

print(K-max(C))

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=0
for i in range(n-1):
 p=a[i+1]-a[i]
 if p >= x:
  x=p

X=max(x,k-a[n-1]-a[0])
print(k-X)

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

x=0
for i in range(n-1):
 p=a[i+1]-a[i]
 if p >= x:
  x=p
  
print(k-x)

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

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

X=max(x,k-a[n-1]-a[0])
print(k-X)

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

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

X=max(x,k-a[n-1]+a[0])
print(k-X)

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 = list(map(int,input().split()))+[K]
D = [abs(A[n+1]-A[n]) for n in range(N)]
print(K-max(D))

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

K,N = map(int,input().split())
A = list(map(int,input().split()))
A+= [A[0]+K]
D = [abs(A[n+1]-A[n]) for n in range(N)]
print(K-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())
A = list(map(int, input().split()))
Ap = []
l = 0

for n in A:
  if n != 0 and n > K/2:
    Ap.append(n-K)
  else:
    Ap.append(n)


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


Ap.sort()
lp = 0
for j in range(N-1):
  lp += abs(Ap[i]-Ap[i+1])


if l >= lp:
  result = lp
elif l < lp:
  result = l 

print(Ap)
print(result) 

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

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


length.append(K-sum(length))

max_l = length[0]
for j in range(N):
  if max_l <= length[j]:
    max_l = length[j]
  else:
    pass


length.remove(max_l)
result = sum(length)
print(result)

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


r_ans = 10**9
if a[0] + a[n-1] >= k:
    r_ans = a[n-1] - a[0]
    # print(a[n-1] - a[0])


else:
    max_n = 0
    for i in range(n-1):
        diff = abs(a[i] - a[i+1])
        max_n = max(diff, max_n)
    # print(k - max_n)
    l_ans = k - max_n

print(min(r_ans, l_ans))

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


if a[0] + a[n-1] <= k - a[0] - a[n-1]:
    print(a[n-1] - a[0])


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

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

bef = a[0]
max_diff = 0
for i in range(1,n):
    diff = abs(bef - a[i])
    max_diff = max(diff, max_diff)
    bef = a[i]

print(k - max(max_diff, k - abs(a[n-1] - a[0])))

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

answer = []

for i,home in enumerate(A):
    kouho = home - A[i - 1]
    if kouho < 0:
        answer.append(20 + kouho)
    else:
        aanswer.append(kouho)

print(20 - max(answer))


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

answer = []

for i,home in enumerate(A):
    if home < A[i - 1]:
        answer.append(home - A[i - 1] + KN[0])
    else:
        answer.append(home - A[i - 1])

print(KN[0] - max(answer))


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

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

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

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

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

Verdicts: Wrong Answer

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()))
A.sort()
P=[A[0]]
for i in range(len(A)-1):
    a = abs(A[i+1] -A[i])
    P.append(a)
P.append(abs(K - A[-1] + A[0]))
P.sort()
del P[-1]
ans = sum(P)
print(ans)


K,N = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
D = K - A[-1] 
if D > A[0]:
    print(K-D)
else:
    print(K-A[0])

K,N = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
P=[A[0]]
for i in range(len(A)-1):
    a = abs(A[i+1] -A[i])
    P.append(a)
P.append(K - A[-1] + A[0])
P.sort()
del P[-1]
ans = sum(P)
print(ans)


K,N = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
P=[A[0]]
for i in range(len(A)-1):
    a = abs(A[i+1] -A[i])
    P.append(a)
P.append(K - A[-1] + A[0])
P.sort()
del P[-1]
sum(P)
print(P)

K,N = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
P=[]
for i in range(len(A)-1):
    a = abs(A[i+1] -A[i])
    P.append(a)
P.append(abs(K - A[-1] + A[0]))
P.sort()
del P[-1]
ans = sum(P)
print(ans)

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()))
sum = 0

if A[0] == 0:
  for i in range(2, N):
    sum += abs(A[i-i] - A[i])
  print(sum)
else:
  for i in range(1, N):
    sum += abs(A[i-1] - A[i])
    print(i, sum)
  print(sum)

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

for i in range(N - 1):
  if i == N - 1:
    dist = A[0] + K - A[i]
  else:
    dist = A[i+1] - A[i]
  
  if dist > max_dist:
    max_dist = dist
    
print(K - max_dist)

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

print(K - max(diff))

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()) 
c=list(map(int, input().split())) 
a = 0
b = 0
for i in range(N):
  print(a)
  if i == 0:
    a = min((c[N-1]-c[0]),K-(c[i+1]-c[0]))
  elif i == N-1:
    a = min(a,K-(c[i-1]-c[i]))
    a = min(a,K-(c[0]-c[i]))
    
  else:
    a = min(a,K-(c[i-1]-c[i]))
    a = min(a,K-(c[i+1]-c[i]))
    
print(a)

K,N=map(int, input().split()) 
c=list(map(int, input().split())) 
a = 0
b = 0
for i in range(N):
  if i == 0:
    a = min((c[N-1]-c[0]),K-(c[i+1]-c[0]))
  elif i == N-1:
    a = min(a,K-(c[i-1]-c[i]))
    a = min(a,K-(c[0]-c[i]))
    
  else:
    a = min(a,K-(c[i-1]-c[i]))
    a = min(a,K-(c[i+1]-c[i]))
    
print(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 = input().split()
K = int(K)
N= int(N)
A = [int(x) for x in input().split()]

dis=[]
now = 0

for i in range(N):
    dis.append(A[i] - now)
    now = A[i]

dis.append(K - A[N -1])

distance = K - max(dis)

print(distance)

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

dis=[]
now = 0

for i in range(N):
    dis.append(A[i] - now)
    now = A[i]

dis.append(K-A[N-1]+dis[0])

distance = K - max(dis)

print(distance)

Verdicts: Wrong Answer

Accepted