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

m = 10 ** 12
for i in range(1,len(a)-1):
    r = k - abs(a[i] - a[i-1])
    l = k - abs(a[i] - a[i+1])
    print(r,l)
    if min(r,l) <= m:
        m = min(r,l)

r = abs(a[-1] - a[0])
l = k - abs(a[1] - a[0])
if min(r,l) <= m:
    m = min(r,l)

r = k - abs(a[-1] - a[-2])
l = abs(a[-1] - a[0])
if min(r,l) <= m:
    m = min(r,l)
    
print(m)


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

m = 10 ** 12
for i in range(1,len(a)-1):
    r = k - abs(a[i] - a[i-1])
    l = k - abs(a[i] - a[i+1])
    if min(r,l) <= m:
        m = min(r,l)

r = abs(a[-1] - a[0])
l = k - abs(a[1] - a[0])
if min(r,l) <= m:
    m = min(r,l)

r = k - abs(a[-1] - a[-2])
l = abs(a[-1] - a[0])
if min(r,l) <= m:
    m = min(r,l)
    
print(m)


Verdicts: Wrong Answer

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

Submission attempts (in order):
k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=len(a)
diff=max(a)-min(a)
temp1=a[0]
for i in range(1,b):
    temp2=a[i]
    a[i]=a[i]-temp1
    temp1=temp2


la=k-diff
a[0]=la

print(min(a))

k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=len(a)
diff=max(a)-min(a)
temp1=a[0]
for i in range(1,b):
    temp2=a[i]
    a[i]=a[i]-temp1
    temp1=temp2


la=k-diff
a[0]=la

print(k-min(a))

k,n=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
b=len(a)
diff=max(a)-min(a)
temp1=a[0]
for i in range(1,b):
    temp2=a[i]
    a[i]=a[i]-temp1
    temp1=temp2


la=k-diff
a[0]=la

print(sum(a)-max(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):
import numpy as np
a,b=map(int,input().split())

n_l=list(map(int,input().split()))
n_l=list(sorted(n_l))

arr = np.array(n_l)

diff = np.diff(arr)

print(a-max(diff))


import numpy as np
a,b=map(int,input().split())
#print(a)
n_l=list(map(int,input().split()))
n_l=list(sorted(n_l))

arr = np.array(n_l)


diff = np.diff(arr)
#print(diff)
#print(max(diff))
print(a-max(diff))

import numpy as np
a,b=map(int,input().split())
#print(a)
n_l=list(map(int,input().split()))
n_l.append(n_l[0]+a)
n_l=list(sorted(n_l))

arr = np.array(n_l)


diff = np.diff(arr)
#print(diff)
#print(max(diff))
print(a-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())
List = list(map(int, input().split()))
res = 0
mid = 0
for i in range(N):
  if i == N-1:
    res+= K-List[i]+List[0]
    mid = max(mid,K-List[i]+List[0])
  else:
    res+= List[i+1]+List[i]
    mid = max(mid,List[i+1]-List[i])
res = res - mid
print(res)
    

K,N=map(int,input().split())
List = list(map(int, input().split()))
res = 0
mid = 0
for i in range(N):
  if i == N-1:
    res+= K-List[i]+List[0]
    mid = max(mid,K-List[i]+List[0])
  else:
    res+= List[i+1]-List[i]
    mid = max(mid,List[i+1]-List[i])
res = res - mid
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 = [0]
for i in input().split():
    if i !="0":
        A.append( int(i) )


x =[A[i+1] - A[i] for i,v in enumerate(A[:-1]) ]
if N < len(x):
    x.append(K - A[-1] +A[1])
else:
    x.append(K -A[-1])

kyori_min = K - max(x)
print(kyori_min)


K,N = (int(x) for x in input().split(" "))
A = list(map(int, input().split()))
A.append(0) 


kyori = [ A[i+1] -A[i] for i,v in enumerate(A[:-1]) ]
kyori[-1] = kyori[-1] + K 
kyori.append(A[0] -A[-1] ) 
x_saisyo_saigo = kyori[-2] +kyori[-1]
kyori.append(x_saisyo_saigo) 


kyori_min = K - max(kyori)
print(kyori_min)

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())
al = [int(x) for x in input().split()]
d = [al[x+1]-al[x] for x in range(0, N-1)]
d.append(K-al[-1]-al[0])
print(sum(d)-max(d))

K,N = (int(x) for x in input().split())
al = [int(x) for x in input().split()]
d = [al[x+1]-al[x] for x in range(0, N-1)]
d.append(K-al[-1]+al[0])
print(sum(d)-max(d))

Verdicts: Wrong Answer

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

Submission attempts (in order):
import numpy as np

input1=list(map(int,input().split()))
input2=list(map(int, input().split()))

distance=[]
for order,value in enumerate(input2):
    if order==0:
        pass
    else:
        distance.append(value-input2[order-1])


distance.append(input1[0]-np.array(distance).sum())

input1=list(map(int,input().split()))
input2=list(map(int, input().split()))

distance=[]
for order,value in enumerate(input2):
    if order==0:
        pass
    else:
        distance.append(value-input2[order-1])
distance.append(input1[0]-sum(distance))

print(input1[0]-max(distance))

Verdicts: Wrong Answer

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

Submission attempts (in order):
# coding:utf-8
k, n = map(int, input().split())
a = list(map(int, input().split()))
a += k
for i in range(n+1):
  l = max(l, a[i+1]-a[i])

print(k-l)

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

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

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

Verdicts: Runtime Error

Wrong Answer

Runtime Error

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

Submission attempts (in order):
a,b=map(int,input().split())
s=list(map(int,input().split()))
ans=[]
for i in range(b-1):
    ans.append(s[i]-s[i-1])
ans.append(a-s[b]+s[0])
print(a-max(ans))







a,b=map(int,input().split())
s=list(map(int,input().split()))
ans=[]
for i in range(b-1):
    ans.append(s[i]-s[i-1])
ans.append(a-s[b]+s[0])
print(sum(ans)-max(ans))







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







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







Verdicts: Runtime Error

Runtime Error

Runtime Error

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
lines = input().split()
dists = []
for base, switch in zip(As[:-1], As[1:]):
    dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))

import sys
lines = sys.stdin.readlines()
K, N = map(int, lines[0].strip().split())
As = map(int, lines[1].strip().split())
for idx, A in enumerate(As[:-1]):
  dists.append(A - As[idx+1])
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))


import sys
lines = sys.stdin.readlines()
K, N = map(int, lines[0].strip().split())
As = map(int, lines[1].strip().split())
dists = []
for idx, A in enumerate(As[:-1]):
  dists.append(A - As[idx+1])
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))

import sys
lines = sys.stdin.readlines()
K, N = map(int, lines[0].strip().split())
As = map(int, lines[1].strip().split())
dists = []
for base, switch in zip(As[:-1], As[1:]):
  dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))

lines = input().split()
K, N = map(int, lines[0].strip().split())
As = map(int, lines[1].strip().split())
dists = []
for base, switch in zip(As[:-1], As[1:]):
    dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))


lines = map(int, input().split())
K, N = map(int, lines[0].strip().split())
As = map(int, lines[1].strip().split())
dists = []
for base, switch in zip(As[:-1], As[1:]):
    dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))


lines = input().split()
K, N = map(int, lines[0].split())
As = map(int, lines[1].split())
dists = []
for base, switch in zip(As[:-1], As[1:]):
    dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))

K, N = map(int, input().split())
As = map(int, input().split())
dists = []
for base, switch in zip(As[:-1], As[1:]):
    dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))

K, N = list(map(int, input().split()))
As = list(map(int, input().split()))
dists = []
for base, switch in zip(As[:-1], As[1:]):
    dists.append(switch - base)
dists.append(As[0]+(K-As[-1]))
print(K - max(dists))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
K,N=map(int,input().split())
A=list(map(int,input().split()))
B=sorted(A)
s=K-B[N-1]
t=B[N-1]-B[N-2]
if s>t:
  m=B[N-1]-B[0]
else:
  m=B[N-2]+K-B[N-1]
print(m)

K,N=map(int,input().split())
A=list(map(int,input().split()))
ma=0
for i in range(N-1):
  ma=max(ma,A[i+1]-A[i])
print(min(K-ma,A[N-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):
N , M = (map(int , input().split()))
A = list(map(int , input().split()))
A.insert(0,0)
a_lis = []
for i in range(0,len(A)-1):
    a_lis.append(A[i+1]-A[i])
print(N - max(a_lis))

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

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

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

print(min(k-max(b), sum(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])

print(k-max(b))

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

if a[0] == 0:
    print(a[n-1]-n[1])
else:
    print(a[n-1]-n[0])

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

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

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

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

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Wrong Answer

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

Submission attempts (in order):
# A = [list(map(int, input().split())) for _ in range(3)]
# X = int(input())
# B = [int(input()) for _ in range(n)]
# A = list(map(int, input().split()))
k, n = map(int, input().split())
A = list(map(int, input().split()))
A.append(A[0]+k)
diff = 0
for i in range(n):
    diff = A[i+1]-A[i]
print(k-max(diff))


# A = [list(map(int, input().split())) for _ in range(3)]
# X = int(input())
# B = [int(input()) for _ in range(n)]
# A = list(map(int, input().split()))
k, n = map(int, input().split())
A = list(map(int, input().split()))
A.append(A[0]+k)
diff = 0
for i in range(n):
    diff = max(A[i+1]-A[i], diff)
print(k-diff)


Verdicts: Runtime Error

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

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

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

Verdicts: Wrong Answer

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

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

d = [a[i+1] - a[i] for i in range(n - 1)]
d.append(a[0] - a[n-1] + k)
print(k - max(d))

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

d = [a[i+1] - a[i] for i in range(n - 1)]
d.append(a[0] - a[n-1] + k)
print(k - max(d))

Verdicts: Wrong Answer

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

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

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

Verdicts: Runtime Error

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

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

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

i = 0
dis = []

for i in range(n):
  if way[i] < k // 2:
    dis.append((k // 2 - way[i]))
  elif way[i] == k//2:
    dis.append(way[i])
  else:
    dis.append(k - way[i])

route = []
route.append(way[n-1] - way[0])

x = 1

for x in range(n):
  route.append(dis[x] + way[x - 1])

print(route)
print(min(route))

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



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

i = 0
dis = [] 

for i in range(n):
  if way[i] < (k // 2):
    dis.append(k // 2 - way[i])
  elif way[i] == k // 2:
    dis.append(way[i])
  else:
    dis.append(k - way[i])

print(dis)

route = []
route.append(way[n-1] - way[0])

x = 1

for x in range(n):
  route.append(dis[x] + way[x - 1])


print(min(route))

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

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

i = 0
dis = [] 

for i in range(n):
  if way[i] < k // 2:
    dis.append((k // 2 - way[i]))
  elif way[i] == k//2:
    dis.append(way[i])
  else:
    dis.append(k - way[i])

print(dis)

route = []
route.append(way[n-1] - way[0])

x = 1

for x in range(n):
  route.append(dis[x] + way[x - 1])

print(min(route))

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

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())
arr=list(map(int,input().split()))
arr.append(arr[0])
ans=10**18
for i in range(n):
  dist1=(k-arr[i])%k+arr[i-1]
  dist2=arr[i]+(k-arr[i+1])%k
  ans=min(ans,dist1,dist2)
print(ans)

k,n=map(int,input().split())
arr=list(map(int,input().split()))
ans=10**18
for i in range(n):
  dist1=(k-arr[i])%k+arr[i-1]
  dist2=arr[i]+(k-arr[(i+1)%n])%k
  ans=min(ans,dist1,dist2)
print(ans)

k,n=map(int,input().split())
arr=list(map(int,input().split()))
ans=10**18
for i in range(n):
  dist1=(arr[i-1]-arr[i])%k
  dist2=(arr[i]-arr[(i+1)%n])%k
  ans=min(ans,dist1,dist2)
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):
# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy

# import numpy as np
# from scipy.special import comb



# INF = 1001001001001
# MOD = 1000000007


def main():

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

    if N == 2:
        d = abs(A[0]-A[1])
        print(min(d, K-d))
    else:
        max_d = N - A[N-1] + A[0]
        for i in range(N - 1):
            max_d = max(max_d, abs(A[i] - A[i+1]))
        print(K - max_d)


if __name__ == '__main__':
    main()


# import sys
# import math
# import itertools
# from collections import deque
# from collections import defaultdict
# import heapq
# import copy

# import numpy as np
# from scipy.special import comb



# INF = 1001001001001
# MOD = 1000000007


def main():

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

    if N == 2:
        d = abs(A[0]-A[1])
        print(min(d, K-d))
    else:
        max_d = K - A[N-1] + A[0]
        for i in range(N - 1):
            max_d = max(max_d, abs(A[i] - A[i+1]))
        print(K - max_d)


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

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

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

print(length)
max_length = max(length)
ans = k- max_length

print(ans)

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

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

max_length = max(length)
ans = k- max_length
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):
a.append(a[0] + k)
m = []
for i in range(n):
    m.append(m, a[i+1] - a[i])
print(k - max(m))

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

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

Verdicts: Runtime Error

Runtime Error

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

Submission attempts (in order):
import numpy as np
k,n = map(int,input().split())
a = np.array(input().split(),dtype=int)
max = 0
for i in range(n):
    if max < a[i]-a[i-1]:
        max = a[i]-a[i-1]

print(k-max)


import numpy as np
k,n = map(int,input().split())
a = np.array(input().split(),dtype=int)
max = 0
for i in range(n):
    if max < (a[i]-a[i-1])%k:
        max = (a[i]-a[i-1])%k

print(k-max)


Verdicts: Wrong Answer

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
k,n = map(int,input().spliut())
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):
N , N_point = map(int,input().split())
list_point = input().split()

for i in range(len(list_point)):
  list_point[i] = int(list_point[i])


distance = []
for i in range(len(list_point)):
  
  if i == 0:
    distance.append(list_point[i])
  
  if i == len(list_point)-1:
    distance.append(N - list_point[i])
    break
  distance.append(list_point[i+1]-list_point[i])
  
distance.sort()
print(distance)
answer = []
for i in range(N_point):
  answer.append(distance[i])

print(sum(answer))

N , N_point = map(int,input().split())
list_point = input().split()

for i in range(len(list_point)):
  list_point[i] = int(list_point[i])


distance = []
for i in range(len(list_point)):
  if i == 0:
    distance.append(list_point[i] + N-list_point[len(list_point)-1])
    distance.append(list_point[i+1]-list_point[i])
    continue
  if i == len(list_point)-1:
    break
  distance.append(list_point[i+1]-list_point[i])


distance.sort()

distance.remove(max(distance))


print(sum(distance))

Verdicts: Wrong Answer

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
k,n = map(int,input().split())
A = list(map(int,input().split()))
A.append(k)
A.sort()
m = max(y-x for x,y in zip(A,A[1:]))
ans = k-m
print(ans)

import numpy as np
k,n = map(int,input().split())
A = list(map(int,input().split()))
A.append(k)
A.sort()
dist = np.diff(A)
ans = k-max(dist)
print(ans)

k,n = map(int,input().split())
A = list(map(int,input().split()))
A.sort()
A.append(k+A[0])
m = max(y-x for x,y in zip(A,A[1:]))
ans = k-m
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):
import numpy as np

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

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

print(A_dist)
A_dist_max = max(A_dist)
print(K-A_dist_max)
    

import numpy as np

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

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


A_dist_max = max(A_dist)
print(K-A_dist_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):
#import pysnooper
#import numpy

#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit

#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline

k,n=map(int,input().split())
a=[int(i) for i in input().split()]
absdis=[min(abs(a[0]-a[-1]),abs(20-a[0]-a[-1]))]
for i in range(1,n):
    absdis.append(abs(a[i]-a[i-1]))
#print(absdis)
print(sum(absdis)-max(absdis))

#import pysnooper
#import numpy

#from collections import Counter,deque
#from operator import itemgetter,mul
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit

#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache,reduce
#from math import factorial,hypot
#import sys
#from fractions import gcd
setrecursionlimit(10**6+1)
input=stdin.readline

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

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):
if a[0] == 0:
    print(a[len(a) - 1] - a[1])
else:
    print(a[len(a) - 1] - a[0])

import numpy as np

k, n = map(int,input().split())
a = np.array(list(map(int, input().split())))
diff = a[1:] - a[:-1]
diff = np.append(diff, k - a[-1] + a[0])
if np.argmax(diff) == len(a) - 1:
    print(a[-1] - a[0])
else:
    print(k - a[np.argmax(diff) + 1] + a[np.argmax(diff)])

Verdicts: Runtime Error

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

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

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

li.append(abs(A[0] + (K - A[-1])))
print(sum(li) - max(li))

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

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

    li.append(abs(A[0] + (K - A[-1])))
    print(sum(li) - max(li))
except:
    pass

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):
N,M = map(int,input().split())
L = [list(map(int,input().split())) for i in range(M)]
dict = {}
 
if M == 0 :
    if N == 1 :
        print(0)
    else :
        print(10**(N-1))
    exit()
 
for x in L :
    dict.setdefault(x[0],[])
    dict[x[0]].append(x[1])
dict.setdefault(1,[1])
 
for k,v in dict.items():
    dict[k] = set(v)
 
ansList = ["0"]*N
for i in range(N) :
    if i+1 in dict :
        ansList[i] = str(list(dict[i+1])[0])
 
isZeroHead = 2 <= N and ansList[0] == "0"
isOverlapping = any([ 2 <= len(v) for v in dict.values()])  
ans = -1 if isZeroHead or isOverlapping else int("".join(ansList))
 
# print(dict)


print(ans)

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

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

l.remove(max(l))
print(sum(l))

Verdicts: Runtime Error

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

Submission attempts (in order):
n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
 
sol=[]
for i in range(n-1):
  sol.append(a[i+1]-a[i])
sol.append(a[0]-a[n-1]+k)
 
sorted(sol)
#unwanted segment of max length removed while printing
print(sum(sol[0:n-1]))

l,n=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
 
sol=[]
for i in range(n-1):
  sol.append(a[i+1]-a[i])
sol.append(a[0]-a[n-1]+k)
sol.sort()
#unwanted segment of max length removed while printing
print(sum(sol[0:n-1]))

=[int(x) for x in input.split()]
a=[int(x) for x in input.split()]
 
sol=[]
for i in range(n-1):
  sol.append(a[i+1]-a[i])
sol.append(a[0]-a[n-1]+k)
 
sol.sort()
#unwanted segment of max length removed while printing
print(sum(sol)[0:n-1])


n,k=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
 
sol=[]
for i in range(n-1):
  sol.append(a[i+1]-a[i])
sol.append(a[0]-a[n-1]+k)
 
sol.sort()
#unwanted segment of max length removed while printing
print(sum(sol[0:n-1]))

n,k=[int(x) for x in input.split()]
a=[int(x) for x in input.split()]
 
sol=[]
for i in range(n-1):
  sol.append(a[i+1]-a[i])
sol.append(a[0]-a[n-1]+k)
 
sorted(sol)
#unwanted segment of max length removed while printing
print(sum(sol[0:n-1]))


n,k=[int(x) for x in input.split()]
a=[int(x) for x in input.split()]

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

sol.sorted()
#unwanted segment of max length removed while printing
print(sum(sol)[0:n-1])

k,n=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
 
sol=[]
for i in range(n-1):
  sol.append(a[i+1]-a[i])
sol.append(a[0]-a[n-1]+k)
 
sol.sort()
print(sum(sol[:n-1]))

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

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

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

for i in range(N):
  if A[i] > K/2:
    A[i] = K/2 - A[i]
 
A.sort()
print(A)

print(int(A[N-1] - A[0]))

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

D = [0]*N

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

print(D)
print(K - D[N-1])

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

Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):

K,N = map(int, input("K,N:").split())
An_list = np.array(input("An:").split(), dtype=int)


An_delta_list = np.array([], dtype=int)


for i in range(len(An_list)-1):
    An_delta_list = np.append(An_delta_list, An_list[i+1] -An_list[i])
An_delta_list = np.append(An_delta_list, K - An_list[-1])


An_delta_max = np.max(An_delta_list)
result = np.sum(An_delta_list) - An_delta_max


print(result)


K,N = map(int, input("K,N:").split())
An_list = np.array(input("An:").split(), dtype=int)






An_delta_list = np.array([], dtype=int)


for i in range(len(An_list)-1):
    An_delta_list = np.append(An_delta_list, An_list[i+1] -An_list[i])
An_delta_list = np.append(An_delta_list, K - An_list[-1])


An_delta_max = np.max(An_delta_list)
result = np.sum(An_delta_list) - An_delta_max
print(result)



import numpy as np

K,N = map(int, input().split())
An_list = np.array(input().split(), dtype=int)

An_delta_list = np.diff(An_list)
An_delta_list = np.append(An_delta_list, K - An_list[N-1])
An_delta_max = np.max(An_delta_list)
result = np.sum(An_delta_list) - An_delta_max
print(result)

import numpy as np

K,N = map(int, input().split())
An_list = np.array(input().split(), dtype=int)

An_delta_list = np.diff(An_list)
An_delta_list = np.append(An_delta_list, (K - An_list[-1])+An_list[0])
An_delta_max = np.max(An_delta_list)
result = np.sum(An_delta_list) - An_delta_max
print(result)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

Runtime Error

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

Submission attempts (in order):
A=input()
LA=A.split()
K=int(LA[0])
N=int(LA[1])

B=input()
LB=B.split()

C=0
samax=0
start=0

for n in LB:
  sa=int(int(n)-int(C))
  C=n
  if samax < sa:
    samax=sa
    start=int(n)-int(samax)

ans1=int(LB[N-1])-int(LB[0])
ans2=int((K-int(LB[N-1]))+int(start))

if ans2 > ans1:
  ans=ans1
else :
  ans=ans2
print(ans)


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

B=input()
LB=B.split()

C=0
samax=0
start=0

for n in LB:
  sa=int(int(n)-int(C))
  C=n
  if samax < sa:
    samax=sa
    start=int(n)-int(samax)
    goal=int(n)
ans1=int(LB[N-1])-int(LB[0])
ans2=int((K-goal)+int(start))

if ans2 > ans1:
  ans=ans1
else :
  ans=ans2
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):
"""Boot-camp-for-Beginners_Easy012_C_Next-Prime_30-August-2020.py"""
import numpy as np

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

theta = []
for i in range(len(A)):
    if i == len(A)-1:
        theta.append(2*np.pi*(K-A[i]+A[0])/K)
    else:
        theta.append(2*np.pi*(A[i+1]-A[i])/K)



theta.remove(max(theta))

s=0
for j in range(len(theta)):
    s+=theta[j]
#print(s)
l_min=(s*K)/(2*np.pi)
print(int(l_min)+1)

"""Boot-camp-for-Beginners_Easy012_C_Next-Prime_30-August-2020.py"""
import numpy as np

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

theta = []
for i in range(len(A)):
    if i == len(A)-1:
        theta.append(2*np.pi*(K-A[i]+A[0])/K)
    else:
        theta.append(2*np.pi*(A[i+1]-A[i])/K)



theta.remove(max(theta))

s=0
for j in range(len(theta)):
    s+=theta[j]
#print(s)
l_min=(s*K)/(2*np.pi)
print(int(l_min)+1)

"""Boot-camp-for-Beginners_Easy012_C_Next-Prime_30-August-2020.py"""
import numpy as np

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

theta = []
for i in range(len(A)):
    if i == len(A)-1:
        theta.append(2*np.pi*(K-A[i]+A[0])/K)
    else:
        theta.append(2*np.pi*(A[i+1]-A[i])/K)

theta.remove(max(theta))

s=0
for j in range(len(theta)):
    s+=theta[j]
#print(s)
l_min=(s*K)/(2*np.pi)
print(l_min)


"""Boot-camp-for-Beginners_Easy012_C_Next-Prime_30-August-2020.py"""
import numpy as np

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

theta = []
for i in range(len(A)):
    if i == len(A)-1:
        theta.append(2*np.pi*(K-A[i]+A[0])/K)
    else:
        theta.append(2*np.pi*(A[i+1]-A[i])/K)



theta.remove(max(theta))

s=0
for j in range(len(theta)):
    s+=theta[j]
#print(s)
l_min=(s*K)/(2*np.pi)
print(l_min)

"""Boot-camp-for-Beginners_Easy012_C_Next-Prime_30-August-2020.py"""
import numpy as np

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

theta = []
for i in range(len(A)):
    if i == len(A)-1:
        theta.append((K-A[i]+A[0]))
    else:
        theta.append((A[i+1]-A[i]))

theta.remove(max(theta))

s=0
for j in range(len(theta)):
    s+=theta[j]
#print(s)
l_min=s
print(l_min)

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

A_sorted=sorted(A)

if sorted_A[N-1]-sorted_A[0] <K/2:
    print(sorted_A[N-1]-sorted_A[0])

else:
    for i in range (0, N-1):
        if A[i] > K/2:
            A[i]=A[i]-K
        else:
            A[i]=A[i]

    a=A_sorted[N-1]-A_sorted[0]
    b=K-a

    print(min(a, b))

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

for i in range (N-2):
    A_length=list(A[i+1]-A[i])
A_length.append = [K-(A[N-1]-A[0])]
print(K-(max(A_length)))


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

for i range (0, N-1):
    if A[i] > K/2:
        A[i]=K-A[i]
    else:
        A[i]=A[i]

A_sorted=sorted(A)

print(A_sorted[N-1]-A_sorted[0])

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

for i range (0, N-1):
    if A[i] > K/2:
        A[i]=A[i]-K
    else:
        A[i]=A[i]

A_sorted=sorted(A)

print(A_sorted[N-1]-A_sorted[0])

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

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted