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 = list(map(int, input().split())
distances = {}
for i in range(1, len(A) + 1):
	distances += (A[i] - A[i - 1]
most = max(distances.keys())
output = K - most
print(output)

K, N = map(int, input().split())
A = list(map(int, input().split())
distances = {}
for i in range(1, N):
	distances += (A[i] - A[i - 1]
most = max(distances.keys())
distances += (A[0] + K) - A[-1]                   
output = K - most
print(output)

K, N = map(int, input().split())
A = list(map(int, input().split())
distances = {}
for i in range(1, len(A) + 1):
	distances += (A[i] - A[i - 1]
most = max(distances.keys())
output = K - most
                  print(output)

K, N = map(int, input().split())
A = list(map(int, input().split())
distances = {}
for i in range(1, len(A)):
	distances += (A[i] - A[i - 1]
most = max(distances.keys())
distance += (A[0] + K) - A[-1]                   
output = K - most
print(output)

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

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

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

Verdicts: 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=map(int,input().split())
A=list(map(int,input().split()))
ans=0
ans+=min(min(A[0],abs(A[0]-K)),abs(A[0]-A[1]))
for i in range(1,N-1):
    ans+=min(abs(A[i-1]-A[i]),abs(A[i]-A[i+1]))
ans+=min(min(A[-1],abs(A[-1]-K)),abs(A[-1]-A[-2]))
print(ans)

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

ret = L
for i in range( len(a) ):
  ret = min( ret, L - abs(a[i] - a[i-1]))
print( ret )

L, k = map( int, input().split() )
a = list( map( int, input().split() ))
 
ret = L
for i in range( len(a) ):
  if i == 0:
    ret = min( ret, L - abs(a[0] - ( a[-1] - L )))
  else:
    ret = min( ret, L - abs(a[i] - a[i-1]))
print( ret )

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(i) for i in input().split()]

k = int(k/2)

#print(list(map(lambda x:k -x,A)))

print(sum(list(map(lambda x:k -x,A))))

k,n = map(int,input().split())
A = [int(i) for i in 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):
hoge = input().split()
K = int(hoge[0])
N = int(hoge[1])
A_list = list(map(int,input().split()))

kankaku = []
for i in range(len(A_list) - 1):
  kankaku.append(A_list[i+1] - A_list[i])
kankaku.append(A_list[0] - A_list[-1] + K)

print(kankaku)
_kankaku_max = max(kankaku)
print(K - _kankaku_max)

hoge = input().split()
K = int(hoge[0])
N = int(hoge[1])
A_list = list(map(int,input().split()))

kankaku = []
for i in range(len(A_list) - 1):
  kankaku.append(A_list[i+1] - A_list[i])
kankaku.append(A_list[0] - A_list[-1] + K)

_kankaku_max = max(kankaku)
print(K - _kankaku_max)

Verdicts: Wrong Answer

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

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


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

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

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

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

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

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

print(K - tmp)

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

tmp = [0 for _ in range(N)]
for i in range(N-1):
    tmp[i] = A[i+1] - A[i]

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

print(K - max(tmp))

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())
distances = list(map(int,input().split()))
distances.append(K-distances[-1])

for i in range(N-1, 0,-1):
    distances[i] -= distances[i-1]
print(sum(sorted(distances)[:-1]))


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

var = distances[0]
for i in range(N):
    distances[i] -= var
distances.append(K-distances[-1])

for i in range(N-1, 0,-1):
    distances[i] -= distances[i-1]

print(sum(sorted(distances)[:-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):
p, n = map(int, input().split())
l = list(map(int, input().split()))
m = max(p - l[-1], l[0])
for i in range(1, n):
    m = max(m, l[i] - l[i - 1])
print(m)


p, n = map(int, input().split())
l = list(map(int, input().split()))
m = p - l[-1]
for i in range(1, n):
    m = max(m, l[i] - l[i - 1])
print(m)


p, n = map(int, input().split())
l = list(map(int, input().split()))
m = p - l[-1] + l[0]
for i in range(1, n):
    m = max(m, l[i] - l[i - 1])
print(p-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()))
ans=10**9
for i in range(n):
  s=a[i]
  t=0
  for j in range(1,n):
    m=min(abs(s-a[i-j]),abs(s+20-a[i-j]),abs(s-a[i+j]),abs(20-s+a[i+j]))
    t=t+m
    s=a[i-j]
  ans=min(ans,t)
print(ans)

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


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


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


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


Verdicts: Runtime Error

Wrong Answer

Runtime Error

Wrong Answer

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

Submission attempts (in order):
K, N = map(int, input().split(' '))
A_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(N):
    l = A_ls[(i + 1) % N] - A_ls[i]
    if i < 0:
        l = K - A_ls[i] + A_ls[(i + 1) % N]
    if rst == -1:
        rst = l
    else:
        rst = max(rst, l)
print(K - rst)

K, N = map(int, input().split(' '))
A_ls = list(map(int, input().split(' ')))
rst = -1
for i in range(N):
    l = A_ls[(i + 1) % N] - A_ls[i]
    if l < 0:
        l = K - A_ls[i] + A_ls[(i + 1) % N]
    if rst == -1:
        rst = l
    else:
        rst = max(rst, l)
print(K - rst)

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

B = sorted([(A[i+1]- A[i]) for i in range(N)])
ans = K - B[-1]
print(ans)



K,N = map(int,input().split())
A = list(map(int,input().split()))
A.append(A[0]+K)

B = sorted([(A[i+1]- A[i]) for i in range(N)])
ans = K - B[-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):
K = int(input())
N = int(input())
A = []

for i in range(N):
    A.append(int(input()))

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

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

B.sort()

Big = B[N-1]

print(K-Big)



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

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

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

B.sort()

Big = B[N-1]

print(K-Big)

Verdicts: Runtime Error

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

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

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

l=[]

l.append(kn[0]-a[-1])

for i in range(kn[1]-1):
    l.append(a[i+1]-a[i])

print(kn[0]-max(l))


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

a= list(map(int, input().split()))
l=[]

l.append(kn[0]-a[-1])

for i in range(kn[1]-1):
    l.append(a[i+1]-a[i])

print(kn[0]-max(l))

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

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

l=[]

l.append(kn[0]-a[-1]+a[0])

for i in range(kn[1]-1):
    l.append(a[i+1]-a[i])

print(kn[0]-max(l))



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

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

print(k-length)

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

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

print(k-length)

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()))
ans = [0]*n 
for i in range(n):
    if a[i]>k/2:
        a[i] = abs(k-a[i])

a.sort(reverse=True)
kai = a[0]+a[1]
print(kai)


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

k,n = map(int,input().split())
lst_a = list(map(int,input().split()))
dis_max = 0
lo_last = lst_a[0]
for i in range(1,n):
    ilo = lst_a[i]
    dis_max = max(dis_max, ilo-lo_last)
    lo_last = ilo
ilo = lst_a[0]
dis_max = max(dis_max, ilo+k-lo_last)
print(k-dis_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())
dis=list(map(int,input().split()))
ans=[]
for i in range(n):
    if i>=1:
        ans.append(dis[i]-dis[i-1])
print(k-max(ans))


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


Verdicts: Wrong Answer

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

Submission attempts (in order):
import numpy as np
k,n=map(int,input().split())
a=list(map(int,input().split()))
a=np.array(a)
a1=abs(a[1:]-a[:-1])
a2=list(a1)
a2.append(abs(a[0]-a[-1]))
print(k-max(a1))

import numpy as np
k,n=map(int,input().split())
a=list(int,input().split())
a=np.array(a)
if max(abs(a[1:]-a[:-1])) < k-abs(a[0]-a[-1]):b=k-abs(a[0]-a[-1])
else:b= max(abs(a[1:]-a[:-1]))
print(k-b)

import numpy as np
k,n=map(int,input().split())
a=list(map(int,input().split()))
a=np.array(a)
a1=abs(a[1:]-a[:-1])
a1.append(abs(a[0]-a[-1]))
print(k-max(a1))


import numpy as np
k,n=map(int,input().split())
a=list(map(int,input().split()))
a=np.array(a)
a1=abs(a[1:]-a[:-1])
a2=list(a1)
a2.append(abs(a[0]-a[-1])%k)
print(k-max(a1))

import numpy as np
k,n=map(int,input().split())
a=list(map(int,input().split()))
a=np.array(a)
a1=abs(a[1:]-a[:-1])
a2=list(a1)
a2.append(abs(a[0]+k-a[-1]))
print(sum(a2)-max(a2))

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Wrong Answer

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

Submission attempts (in order):
K,N=map(int,input().split())
A=list(map(int,input().split()))
A+=[A[0]+K]
max_gap=max(y-x for x,y in zip(A,A[1:]))
print(max_gap)
print(K-max_gap)

K,N=map(int,input().split())
A=list(map(int,input().split()))
A+=[A[0]+K]
max_gap=max(y-x for x,y in zip(A,A[1:]))
print(K-max_gap)

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

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

int(K)
int(N)


B = []
for i in range(0, len(A)-1):
    B.insert(i,A[i+1]-A[i])
B.insert(int(N)-1,int(K)-A[int(N)-1]+A[0])

ans = 0

print(B)

for j in range(int(N)):
    ans += B[j]

ans -= max(B)

print(ans)

K,N = input().split()

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

int(K)
int(N)


B = []
for i in range(0, len(A)-1):
    B.insert(i,A[i+1]-A[i])
B.insert(int(N)-1,int(K)-A[int(N)-1]+A[0])

ans = 0

for j in range(int(N)):
    ans += B[j]

ans -= max(B)

print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
import statistics
K,N = map(int,input().split())
A = [int(n) for n in input().split()]

a1 = max(A)-min(A)

max_v = 0
for i in range(len(A)-1):
    A_i = None
    if (A[i+1]-A[i])>max_v:
        max_v = A[i+1]-A[i]
        A_i = i+1

a2 = A[A_i-1]+abs(K-A[A_i])
print(a2) if a1>a2 else print(a1)

import statistics
K,N = map(int,input().split())
A = [int(n) for n in input().split()]

a1 = max(A)-min(A)

for i in range(len(A)-1):
    max_v = 0
    index = None
    if (A[i+1]-A[i])>max_v:
        max_v = A[i+1]-A[i]
        index = i+1

a2 = A[index-1]+abs(K-A[index])
print(a1) if a1>a2 else print(a2)

import statistics
K,N = map(int,input().split())
A = [int(n) for n in input().split()]

a1 = max(A)-min(A)

max_v = 0
A_i = None
for i in range(len(A)-1):
    if (A[i+1]-A[i])>max_v:
        max_v = A[i+1]-A[i]
        A_i = i+1

a2 = A[A_i-1]+abs(K-A[A_i])
print(a2) if a1>a2 else print(a1)

Verdicts: Runtime Error

Wrong Answer

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

Submission attempts (in order):
k, n = map(int, input().split())
a = list(map(int, input().split())
b = []
for i in range(N):
    d = int(a[i+1]-a[i])
    b.append(int(d))

b.append(K - a[N-1] + a[0])

ans = K - max(b)

print(ans)

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

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

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

dist = 0

for i in range(len(arr)):
    if i is 0:
        if k - arr[i-1] > dist:
            dist = k - arr[i-1]
    
    if arr[i] - arr[i-1] > dist:
        dist = arr[i] - arr[i-1]

print(k - dist)

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

dist = 0

for i in range(len(arr)):
    if i is 0:
        if k - arr[i-1] + arr[i] > dist:
            dist = k - arr[i-1] + arr[i]
    
    if arr[i] - arr[i-1] > dist:
        dist = arr[i] - arr[i-1]

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

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

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

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

ans = 0
for i in range(len(An)-1):
    ans = max(ans, An[i+1]-An[i])


ans = max(ans, K - An[-1])

print(K-ans)


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


ans = 0
for i in range(len(An)-1):
    ans = max(ans, An[i+1]-An[i])


ans = max(ans, An[0] - (An[-1]-K))

print(K-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):
from sys import stdin
from collections import deque
q=deque()
K,N= list(map(int, (stdin.readline().strip().split())))
A=list(map(int, (stdin.readline().strip().split())))
B=A
max=A[1]-A[0]
home=0
home_B=0
place=0
kyori=0
for i in range(N-1):
    if max< A[i+1]-A[i]:
        max=A[i+1]-A[i]
        place=i
    home+=A[i+1]-A[i]
for i in range(place+1,N):
    B.insert(0,abs(B[i]-K))
    del B[i+1]
print(B)
for i in range(N-1):
    home_B+=abs(B[i+1]-B[i])
if home>home_B:
    print(home_B)
else:print(home)


from sys import stdin
from collections import deque
q=deque()
K,N= list(map(int, (stdin.readline().strip().split())))
A=list(map(int, (stdin.readline().strip().split())))
max=A[1]-A[0]
home=0
home_B=0
place=0
kyori=0
for i in range(N-1):
    if max< A[i+1]-A[i]:
        max=A[i+1]-A[i]
        place=i
B=A[place]
C=A[place+1]-K
D=B-C
if A[-1]-A[0]>D:print(D)
else:print(A[-1]-A[0])

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):
# ABC160_c

K, N = map(int, input().split())
A = list(map(int, input().split()))
ans = 0
for a in A:
    ans += min(a, K-a)
print(ans)


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

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

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

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

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

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

ans = A[N-1] - A[0]
for i in range(N-1):
  ans = min(ans, K - (A[i+1] - A[i]))
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):
def main():
    K, N = map(int, input().split(' '))
    half_k = K // 2
    A = list(map(int, input().split()))
    A.sort()
    A.append(A[0] + K)
    max_diff = A[-1] - half_k + A[0]
    for n in range(0, N - 1, 2):
        if max_diff < A[n + 1] - A[n]:
            max_diff = A[n + 1] - A[n]
    print(K - max_diff)


if __name__ == '__main__':
    main()


def main():
    K, N = map(int, input().split(' '))
    A = list(map(int, input().split()))
    A.sort()
    A.append(A[0] + K)
    max_diff = A[0] + K - A[-1]
    for a, b in zip(A, A[1:]):
        if (b - a) > max_diff:
            max_diff = b - a
    print(K - max_diff)


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()))
ans = k
for i in range(-1,n-1):
  ans = min(ans, k-(n[i+1]-n[i]))
print(ans)


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

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


Verdicts: Runtime Error

Wrong Answer

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

Submission attempts (in order):
s=input().split()
k,n=int(s[0]),int(s[1])
s=[]
a=input().split()

for i in range(0,n):
  
  if(i == n-1):
    s.append(abs(int(a[i])+k-int(a[0])))
  else:
  	s.append(abs(int(a[i])-int(a[i+1])))
print(k-max(s))
  
 
  



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

for i in range(0,n):
  
  if(i == n-1):
    s.append(abs(k-int(a[i])+int(a[0])))
  else:
  	s.append(abs(int(a[i])-int(a[i+1])))
print(k-max(s))
  
 
  



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

diffs = list()
max_diff = 0
for i in range(n):
    diff = 0
    if i == n-1:
        diff = k + a[0] - a[i]
    else:
        diff = a[i+1] - a[i]

    if max_diff < diff:
        max_diff = diff
    diffs.append(diff)

sum(diffs) - max_diff

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

diffs = list()
max_diff = 0
for i in range(n):
    diff = 0
    if i == n-1:
        diff = k + a[0] - a[i]
    else:
        diff = a[i+1] - a[i]

    if max_diff < diff:
        max_diff = diff
    diffs.append(diff)

print(sum(diffs) - max_diff)

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(" "))
houses = list(map(int, input().split(" ")))
print(houses)
dif_houses = [houses[x+1]-houses[x] for x in range(k-1)]
dif_houses.append(houses[0]-houses[k-1]+n)

max_dif = max(dif_houses)
print(n-max_dif)

n, k = map(int, input().split(" "))
houses = list(map(int, input().split(" ")))
dif_houses = [houses[x+1]-houses[x] for x in range(k-1)]
dif_houses.append(houses[0]-houses[k-1]+n)

max_dif = max(dif_houses)
print(n-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())
n_inf = list(map(int,input().split()))
n_inf.append(k)
n_inf.insert(0,0)
#print(n_inf)
kyori_list = [j for j in range(n+1)]
for i in range(n+1):
  kyori_list[i] = n_inf[i+1]-n_inf[i]

kyori_list.sort(reverse=1)

print(sum(kyori_list[1:n+1]))

k,n = map(int,input().split())
n_inf = list(map(int,input().split()))
#n_inf.append(k)
#n_inf.insert(0,0)
kyori_list = [j for j in range(n-1)]
for i in range(n-1):
  kyori_list[i] = n_inf[i+1]-n_inf[i]

kyori_list.append((n_inf[0])+(k-n_inf[n-1]))

kyori_list.sort(reverse=1)
print(sum(kyori_list[1: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):
# 160
K,N=map(int,input().split())
A=[int(i) for i in input().split()]

ans =[]

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

# 160
K,N=map(int,input().split())
A=[int(i) for i in input().split()]

ans =[]
for a in A:
    ans.append(min(a,K-a))
print(sum(ans))

# 160
K,N=map(int,input().split())
A=[int(i) for i in input().split()]

ans =[]

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

_in = list(map(int, input().split()))
k = _in[0]
n = _in[1]
p = 0
_i = list(map(int, input().split()))
dis = 0
mdis = k - _i[n-1] + _i[0]
print(mdis)
for i in range(1,n-1):
    dis = _i[i] - _i[i-1]
    print(dis)
    if dis>mdis:
        mdis = dis
print(k-mdis)

_in = list(map(int, input().split()))
k = _in[0]
n = _in[1]
p = 0
_i = list(map(int, input().split()))
dis = 0
mdis = k - _i[n-1] + _i[0]
for i in range(1,n):
    dis = _i[i] - _i[i-1]
    if dis>mdis:
        mdis = dis
print(k-mdis)

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):
import math

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

print(k-ans)

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

ans = 0
for i in range(0, n):
    ans = max(ans, A[i+1] - A[i])
print(k-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):
def solve():
  K = int(input())
  N = int(input())
  vals = [None] * N
  ans = 99999999
  for i in range(N):
    vals[i] = int(input())
  for i in range(N):
    cc = -1
    if i == 0:
      cc = vals[N-1] - vals[0]
    else:
      cc = vals[i-1] + K - vals[i]
    ans = min(ans, cc)
  print(ans)
solve()
  


def solve():
  raw = input().split()
  K = int(raw[0])
  N = int(raw[1])
  vals = [None] * N
  ans = 99999999
  raw = input().split()
  for i in range(N):
    vals[i] = int(raw[i])
  for i in range(N):
    cc = -1
    if i == 0:
      cc = vals[N-1] - vals[0]
    else:
      cc = vals[i-1] + K - vals[i]
    ans = min(ans, cc)
  print(ans)
solve()
  


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

a = [int(i) for i in a]

diff = list()
diff.insert(0,K-a[N-1]+a[0]) 
for i in range(2,N+1):       # seq 2 to N-1
  diff.insert(i-1,abs(a[i-1]-a[i-2]))

print (diff)

print (sum(diff)-max(diff))

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

a = [int(i) for i in a]

diff = list()
diff.insert(0,K-a[N-1]+a[0]) 
for i in range(2,N+1):       # seq 2 to N-1
  diff.insert(i-1,abs(a[i-1]-a[i-2]))

# print (diff)

print (sum(diff)-max(diff))

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

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

Verdicts: Wrong Answer

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

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

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

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

mx = K - A[N-1] +A[0]
for i in range(N-1):
  if A[i+1] - A[i] > mx:
    mx = A[i+1] - A[i]
    
ans = K - mx
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()))

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

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

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

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



A = sorted(A)
L = []
ANS = 0

A_max = max(A)

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

L = sorted(L)


L.pop(-1)

for i in range(len(L)):
    ANS = ANS + L[i]
    
print(ANS)
    

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



A = sorted(A)
L = []
ANS = 0

A_max = max(A)

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

L = sorted(L)
print(L)

L.pop(-1)

for i in range(len(L)):
    ANS = ANS + L[i]
    
print(ANS)

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



A = sorted(A)
L = []
ANS = 0

A_max = max(A)

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

L = sorted(L)


L.pop(-1)

for i in range(len(L)):
    ANS = ANS + L[i]
    
print(ANS)
    

Verdicts: Runtime Error

Wrong Answer

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

Submission attempts (in order):
N, K = map(int, input().split())
a = list(map(int, input().split()))
a.append(N+a[0]-a[-1])
max = 0
for i in range(len(a)-1):
  p = abs(a[i]-a[i+1])
  max = p if max < p else max
print(N-max)


N, K = map(int, input().split())
a = list(map(int, input().split()))
a.append(N+a[0])
#print(a)
max = 0
for i in range(len(a)-1):
  p = abs(a[i]-a[i+1])
  max = p if max < p else max
print(N-max)


Verdicts: Wrong Answer

Accepted