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

A_list = list(itertools.permutations(l, N))

print(A_list)

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

A_list = list(itertools.permutations(l, N))
ans = 10**8
for i in A_list:
    tmp = 0
    
    if i[0] == min(A) and i[2] == max(A):
        pass
    else:
        for j in range(N-1):
            if abs((i[j+1]) - (i[j])) <= abs(K-i[j+1]):
                tmp = tmp +  abs((i[j+1]) - (i[j]))
            else:
                tmp = tmp + abs(K-i[j+1])
        
        if tmp <= ans:
            ans = tmp
print(ans)

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

ans = A[-1]-A[0]
for i in range(N-1):
    ans = min(ans, K-A[i+1]+A[i])
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):
from fractions import gcd
A, B, C, D = map(int, input().split())

if A % C ==0:ca = A//C-1
else: ca = A//C
cb = B//C


if A % D ==0: ad = A//D-1
else:da = A//D 
db = B//D

lcm = C * D //gcd(C,D)
if A % lcm==0: cda = A//lcm-1
else:cda = A//lcm
cdb = B//lcm

print(B-A+1-((cb-ca)+(db-da)-(cdb-cda)))

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

mini = K
right = left = K
for i in range(N):
	l_begin = i-1
	r_begin = i+1
	if i == 0:
		l_begin = N-1
		right = A[l_begin] - A[i]
		left = K - (A[r_begin]-A[i])
	elif i == N-1:
		r_begin = 0
		right = K - (A[i]-A[l_begin])
		left = A[i] - A[r_begin]
	else:
		right = K - (A[i]-A[l_begin])
		left = K - (A[r_begin]-A[i])
	local = min(right, left)
	if local < mini:
		mini = local
		

print(mini)

Verdicts: Runtime Error

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

Submission attempts (in order):
import numpy as np

K, N = map(int, input().split(" "))
loc = list(map(int, input().split(" ")))
loc = np.array(loc)

dist = np.diff(loc)
np.append(dist,K - loc[N-1] + loc[0])

most_far = np.max(dist)
print(K-most_far)

import numpy as np

K, N = map(int, input().split(" "))
loc = list(map(int, input().split(" ")))
loc = np.array(loc)

dist = np.diff(loc)
dist = np.append(dist, K - loc[N - 1] + loc[0])

most_far = np.max(dist)
print(K - most_far)


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 = 10**6 + 1
for i in range(n):
    ans = min(a[-1] - a[i])
    a.append(a[i]+k)
print(ans)

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

ans = 10**6 + 1
for i in range(n):
    ans = min(ans, a[-1] - a[i])
    a.append(a[i]+k)
print(ans)


Verdicts: Runtime Error

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

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

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

print(B)
print(K - max(B))

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

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


print(K - max(B))

Verdicts: Wrong Answer

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

Submission attempts (in order):
KN=list(map(int,input().strip().split()))
K=KN[0]
N=KN[1]
A_list=list(map(int,input().strip().split()))

Dis_list=[A_list[n]-A_list[n-1] for n in range(1,N)]
Dis_list.append(K-(A_list[N-1]-A_list[0]))

min_distance=K-max(Dis_list)

print(Dis_list)
print(min_distance)


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

Dis_list=[A_list[n]-A_list[n-1] for n in range(1,N)]
Dis_list.append(K-(A_list[N-1]-A_list[0]))

min_distance=K-max(Dis_list)

print(min_distance)


Verdicts: Wrong Answer

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

Submission attempts (in order):
n,k = map(int,input().split())
l = list(map(int,input().split()))
dif = []
for i in range(k):
    if(i==k-1):
        dif.append(abs(n-l[i]) + l[0])
    else:
        dif.append(abs(l[i]-l[i-1]))

ans = sum(dif)-max(dif)
print(ans)


n,k = map(int,input().split())
l = list(map(int,input().split()))
l = sorted(l)
dif = []
for i in range(k):
    if(i==k-1):
        dif.append(abs(l[i]-(n+l[0])))
    else:
        dif.append(abs(l[i]-l[i+1]))
        
print(sum(dif) - 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())
L = list(map(int,input().split()))
if K not in L:
  L.reverse()
  K = L[0]
  for i in range(1,len(L)):
    K-=L[i]
  print(K)
else:
  K = 0
  for i in range(len(L)-1):
    K += abs(L[i+1]-L[i])
  print(K)
    
    


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

Verdicts: Wrong Answer

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

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

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

x_list = A_list[:-1]

y_list = A_list[1:]

diff_list = list(map(lambda x,y: y - x, x_list, y_list))
diff_list.append(int(K-A_list[-1]))

print(K - max(diff_list))

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

x_list = A_list[:-1]

y_list = A_list[1:]

diff_list = list(map(lambda x,y: y - x, x_list, y_list))
diff_list.append(int(K-A_list[-1]))

print(K - max(diff_list))

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

x_list = A_list[:-1]

y_list = A_list[1:]

diff_list = list(map(lambda x,y: y - x, x_list, y_list))
diff_list.append(int(K-A_list[-1]))

print(K - max(diff_list))

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

x_list = A_list[:-1]

y_list = A_list[1:]

diff_list = list(map(lambda x,y: y - x, x_list, y_list))
diff_list.append(int(K-A_list[-1] + A_list[0]))

print(K - max(diff_list))


Verdicts: Wrong Answer

Wrong Answer

Wrong Answer

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

Submission attempts (in order):
import sys
sys.setrecursionlimit(4100000)

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

b.append(k-a[n-1]+a[0])
print(b)
anss = max(b)
ans = k - anss
print(str(ans))

import sys
sys.setrecursionlimit(4100000)

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

b.append(k-a[n-1]+a[0])
anss = max(b)
ans = k - anss
print(str(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 = [int(input()) for i in range(N)]

D = []
for i in range(N):
	D.append((K + A[i] - A[i - 1]) % K)
    
print(K - max(D))

# K = int(input())
# N = int(input())

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

print(
  n - \
    max(
      [a_2 - a_1 \
          for a_1, a_2 in \
          zip(
            a_list[:-1], 
            a_list[1:]
          )
      ] + \
      [n - a_list[-1] + a_list[0]]
    )
)

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

print(
  n - \
    max(
      [a_2 - a_1 \
          for a_1, a_2 in \
          zip(
            a_list[:-1], 
            a_list[1:]
          )
      ] + \
      [n - a_list[-1] + a_list[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):
    k,n = map(int,input().split())
     
    s = list(map(int,input().split()))
    longest = 0
    for i in range(n-1):
        long = s[i+1] - s[i]
        if long > longest:
            longest = long
    if longest >= k - s[n-1] + s[0]:
        print(k - longest)
    else:
        print(s[n-1] - s[0])

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

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

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()))
for i in range(n):
  if a[i] >= k/2:
    a[i] = a[i] -k
print(max(a)-min(a))


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

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

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

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

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

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

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

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

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

Verdicts: Wrong Answer

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())
mtrx=list(map(int,input().split()))
mtrx.append(K)
length = []
for i in range(len(mtrx)-1):
    length.append(mtrx[i+1]-mtrx[i])
print(K-max(length))

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

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

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):
l = input().split(" ")
j = input().split(" ")
k = int(m[0])
n = int(m[1])
A = []
for i in range(j):
  d1 = j[i+1] - j[i]
  d2 = j[i+2] - j[i+1]
  min = min(d1,d2)
  A.append(int(min))
print(A)

KN = input().split(' ')
K = int(KN[0])
N = int(KN[1])
M = K/2
Al = input().split(' ')
A = []


def distance(d1,d2,M,K):
  if d1<=M and d2>=M:
    return d1+(K-d2)
  else:
    return abs(d2-d1)

for home in Al:
  A.append(int(home))

m = distance(A[0],A[-1],M,K)

for i in range(N-1):
  m = max(m,distance(A[i],A[i+1],M,K))

print (10-m)


l = input().split(" ")
j = input().split(" ")
k = int(l[0])
n = int(l[1])
for i in range(n-1):
  d1 = int(j[i+1]) - int(j[i])
  d2 = int(j[i+2]) - int(j[i+1])
  max = max(d1,d2)
dt = k - int(max)
print(dt)


KN = input().split(' ')
K = int(KN[0])
N = int(KN[1])
M = K/2
Al = input().split(' ')
A = []
for home in Al:
  A.append(int(home))
m = 0

m = distance(A[0],A[-1],M,K)

for i in range(N-1):
  m = max(m,distance(A[i],A[i+1],M,L))
print (10-m)

def distance(d1,d2,M,K):
  if d1<=M and d2<=M:
    return abs(d2-d1)
  if d1<=M and d2>=M:
    return d1+(K-d2)
  if d1>=M and d2>=M:
    return abs(d2-d1)

l = input().split(" ")
j = input().split(" ")
k = int(m[0])
n = int(m[1])
for i in range(j):
  d1 = j[i+1] - j[i]
  d2 = j[i+2] - j[i+1]
  max = max(d1,d2)
  dt = k - int(max)
print(dt)


l = input().split(" ")
j = input().split(" ")
k = int(l[0])
n = int(l[1])
x = 0
for i in range(n):
  d = int(j[i+1]) - int(j[i])
  x = max(x,d)
dt = k - int(x)
print(dt)


l = input().split(" ")
j = input().split(" ")
k = int(l[0])
n = int(l[1])
for i in range(j):
  d1 = j[i+1] - j[i]
  d2 = j[i+2] - j[i+1]
  max = max(d1,d2)
  dt = k - int(max)
print(dt)


l = input().split(" ")
j = input().split(" ")
k = int(l[0])
n = int(l[1])
x = 0
for i in range(n-1):
  d = int(j[i+1]) - int(j[i])
  x = max(x,d)
dt = k - int(x)
print(dt)


l = input().split(" ")
j = input().split(" ")
k = int(l[0])
n = int(l[1])
for i in range(n-1):
  d1 = int(j[i+1]) - int(j[i])
  d2 = int(j[i+2]) - int(j[i+1])
  max = max(d1,d2)
  dt = k - int(max)
print(dt)


l = input().split(" ")
j = input().split(" ")
k = int(l[0])
n = int(l[1])
x = 0
m = k-int(j[-1])+int(j[0])
for i in range(n-1):
  d = int(j[i+1]) - int(j[i])
  x = max(x,d)
x = max(x,m)
dt = k - int(x)
print(dt)


Verdicts: Runtime Error

Wrong Answer

Runtime Error

Runtime Error

Runtime Error

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

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

x = 0
longest = 0
for a in list_a:
  if a - x > longest:
    longest = a - x
    x = a - x
if longest < a[0] + (k - a[n-1]):
  longest = a[0] + (k - a[n-1]):
print(k-longest)

k, n = map(int, input().split())
list_a = list(map(int, input().split()))
 
x = 0
longest = 0
for a in list_a:
  if a - x > longest:
    longest = a - x
    x = a - x
if longest < a[0] + (k - a[n-1]):
  longest = a[0] + (k - a[n-1])
print(k-longest)

k, n = map(int, input().split())
list_a = list(map(int, input().split()))
 
x = 0
longest = 0
for a in list_a:
  if a - x > longest:
    longest = a - x
  x = a
if longest < list_a[0] + (k - list_a[n-1]):
  longest = list_a[0] + (k - list_a[n-1])
print(k-longest)

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


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

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


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




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


Verdicts: Wrong Answer

Wrong Answer

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()))
sub = [A[0]+K-A[N-1]]
print(A)
for _ in range(N-1):
    p = A.pop()
    sub.append(K-p)
    K = p
print(sub)
sub.remove(max(sub))
print(sum(sub))

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

for _ in range(N):
    p = A.pop()
    sub.append(K-p)
    K = p

print(sub)
sub.remove(max(sub))
print(sum(sub))

K, N = map(int,input().split())
A = list(map(int, input().split()))
a = A[0]
sub = []
for _ in range(N):
    p = A.pop()
    sub.append(K-p)
    K = p
sub[0] += a
print(sub)
sub.remove(max(sub))
print(sum(sub))

K, N = map(int,input().split())
A = list(map(int, input().split()))
a = A[0]
sub = []
for _ in range(N):
    p = A.pop()
    sub.append(K-p)
    K = p
sub[0] += a
sub.remove(max(sub))
print(sum(sub))

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


K, N, *A = map(int, open(0).read().split())
B = []
for i in range(N - 1):
    B.append(A[i + 1] - A[i])
B.append(K - A[-1] + A[0])
print(K - max(B))


Verdicts: Wrong Answer

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

Submission attempts (in order):
import sys
lines = sys.stdin.readlines()    

KN = lines[0].strip(" ")
A = lines[1].strip(" ")

K=int(KN[0])

X = K - int(A[-1])
temp = 0
for Ai in A:
  Y = int(Ai) - temp
  if Y > X:
    X = Y
  temp = int(Ai)

print(K-X)
  


import sys
lines = sys.stdin.readlines()    

KN = input().strip(" ")
A = input().strip(" ")

K=int(KN[0])

X = K - int(A[-1])
temp = 0
for Ai in A:
  Y = int(Ai) - temp
  if Y > X:
    X = Y
  temp = int(Ai)

print(K-X)
  


import sys
lines = sys.stdin.readlines()    

KN = lines[0].strip(" ")
A = lines[1].strip(" ")

K=KN[0]

X = K - A[-1]
temp = 0
for Ai in A:
  Y = Ai - temp
  if Y > X:
    X = Y
  temp = Ai

print(K-X)
  

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

ans = K - A[-1] + A[0]
for n in range(N-1):
  dis = A[n+1] - A[n]
  ans = max(ans, dis)
  
print(K-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):
import sys
input = sys.stdin.buffer.readline

def main():
    L,N = map(int,input().split())
    a = list(map(int,input().split()))
    
    ans = 0
    for i in range(N-1):
        ans = max(ans,a[i+1]-a[i])
        
    ans = max(ans,N+a[0]-a[-1])
    
    print(L-ans)
    
if __name__ == "__main__":
    main()


import sys
input = sys.stdin.buffer.readline

def main():
    K,N = map(int,input().split())
    a = list(map(int,input().split()))
    
    a = [a[-1]-K] + a + [a[0]+K]
    
    ans = K
    
    for i in range(N):
        use = max(a[i+1]-a[i],a[i+2]-a[i+1])
        ans = min(ans,K-use)
    
    print(ans)
    
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):
date0=input().rstrip().split(" ")
date1=input().rstrip().split(" ")
list0=[]
list1=[]
for i in range(int(date0[1])):
  list0.append(int(date1[i]))
#print(list0)
list0=sorted(list0)
#print(list0)
for j in range(int(date0[1])-1):
  list1.append(list0[j+1]-list0[j])
list1.append(int(date0[0])-list0[int(date0[1])-1])
list1=sorted(list1,reverse=True)
print(int(date0[0])-list1[0])

date0=input().rstrip().split(" ")
date1=input().rstrip().split(" ")
list0=[]
list1=[]
for i in range(int(date0[1])):
  list0.append(int(date1[i]))
list0=sorted(list0)
for j in range(int(date0[1])-1):
  list1.append(list0[j+1]-list0[j])
list1.append(int(date0[0])-list0[int(date0[1])-1]+list0[0])
list1=sorted(list1,reverse=True)
print(int(date0[0])-list1[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):
K,N = map(int,input().split())
A = list(map(int,input().split()))

per_dist = list(A[i+1]-A[i] for i in range(0,N-1))
last_dist = A[0] + K - A[N]
per_dist = per_dist.append(last_dist)
max_dist = max(per_dist)
print(K - max_dist)

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

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

print(A)

kyori = 0
for i in A:
    kyori += i - kyori

print(kyori)

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

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

print(A)

kyori = 0
for i in A:
    kyori += i - kyori

print(kyori)


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

per_dist = list(A[i+1]-A[i] for i in range(0,N-1))
last_dist = A[0] + K - A[N - 1]
per_dist = per_dist.append(last_dist)
max_dist = max(per_dist)
print(K - max_dist)

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

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

print(A)

kyori = 0
for i in A:
    kyori += i - kyori

print(kyori)


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

per_dist = list(A[i+1]-A[i] for i in range(0,N-1))
last_dist = A[0] + K - A[N - 1]
type(last_dist)
per_dist.append(last_dist)
max_dist = max(per_dist)
print(K - max_dist)

Verdicts: Runtime Error

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

  

K,N = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(N-1):
    m=a[i+1]-a[i]
    ans = max(ans,m)
h = K - a[N-1]+a[0]
ans = max(ans,h)
ans = K-ans

  


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

  


Verdicts: Wrong Answer

Wrong Answer

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

Submission attempts (in order):
k,n=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
a.append(k)
l=[]
for i in range(len(a)-1):
    s = a[i+1]-a[i]
    if s<0:
        s=-s
    l.append(s)
max_value=max(l)
print(k-max_value)

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

if a[0]==0:
    a.append(k)
else:
    a.append(k+a[0])
l=[]
for i in range(len(a)-1):
    s = a[i+1]-a[i]
    if s<0:
        s=-s
    l.append(s)
max_value=max(l)
#max_index=l.index(max_value)
print(k-max_value)

Verdicts: Wrong Answer

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

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


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

K, N = map(int, input().split())
A = list(map(int, input().split()))
m = K + A[0] - A[N-1]
for i in range(N-1):
  d = A[i+1] - A[i]
  m = max([d, m])
print(K-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):
if __name__ == "__main__":
    k, n = map(int, input().split())
    a = list(map(int, input().split()))
    import numpy as np
    a = np.array(a)

    kouho = a[0] + (k - a[-1])

    sa = a[1:] - a[0: -1]

    kouho1 = k - max(sa)

    print(max(kouho,kouho1))


if __name__ == "__main__":
    k, n = map(int, input().split())
    a = list(map(int, input().split()))
    import numpy as np
    a = np.array(a)

    sa_kouho = a[0] + (k - a[-1])

    sa = a[1:] - a[0: -1]

    sa_kouho1 = max(sa)

    print(k - max(sa_kouho, sa_kouho1))



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
import sys
sys.setrecursionlimit(10**8)

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs

def main(inputs):
	k,n=getIntList(inputs[0])
	aList=getIntList(inputs[1])
	
	d=k-aList[n-1]+aList[0]
	di=n-1
# 	print(d,di)
	for ai in range(n-1):
		dd=aList[ai+1]-aList[ai]
# 		print(dd)
		if dd>d:
			di=ai
			d=dd
	
	print(k-d)


if __name__=="__main__":
	inputs=getInputs()

	main(inputs)


def getIntList(inp):
	return [int(_) for _ in inp]


from sys import stdin
import sys
sys.setrecursionlimit(10**8)

def getInputs():
	inputs=[]
	for line in stdin:
		line=line.split()
		inputs.append(line)
	return inputs

def main(inputs):
	k,n=getIntList(inputs[0])
	aList=getIntList(inputs[1])
	
	d=k-aList[n-1]+aList[0]
	di=n-1
# 	print(d,di)
	for ai in range(n-1):
		dd=aList[ai+1]-aList[ai]
# 		print(dd)
		if dd>d:
			di=ai
			d=dd
	
	print(k-d)


if __name__=="__main__":
	inputs=getInputs()

	main(inputs)


Verdicts: Runtime Error

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

Submission attempts (in order):
K, N = input().split()
K = int(K)
N = int(N)
houses = list(map(int, input().split()))
maxDistance = 0
distance = 0
for i in range(N):
  firstHouse = houses[i]
  lastHouse = houses[i - 1]
  if lastHouse > firstHouse:
    distance = lastHouse - firstHouse
  else:
    distance = (K - firstHouse) + lastHouse
  if distance > maxDistance:
    maxDistance = distance
print(distance)

K, N = input().split()
K = int(K)
N = int(N)
houses = list(map(int, input().split()))
first = True
distance = 0
for i in range(N):
  firstHouse = houses[i]
  lastHouse = houses[i - 1]
  if lastHouse > firstHouse:
    distance = lastHouse - firstHouse
  else:
    distance = (K - firstHouse) + lastHouse
  if first or distance < minDistance:
    minDistance = distance
    first = False
print(minDistance)

Verdicts: Wrong Answer

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

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

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

Verdicts: Wrong Answer

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

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


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


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


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

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

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

ans = A[-1] - A[0]
for i in range(N-1):
  ans = min(ans, A[i] - A[i+1] + K)
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,*a=map(int,open(0).read().split())
a+=[k+a[0]]
print(min(y-x for x,y in zip(a,a[1:])))

k,n,*a=map(int,open(0).read().split())
a+=[k+a[0]]
print(k-max(y-x for x,y in zip(a,a[1:])))

Verdicts: Wrong Answer

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

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

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

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

Verdicts: Wrong Answer

Wrong Answer

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

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

a.append(k+a[0])

print("k+a[0]:",k+a[0])
d = 0

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

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

a.append(k+a[0])

d = 0

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 28 21:11:28 2020

@author: Kanaru Sato
"""

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

for i in range(n-1):
    d = a[i+1]-a[i]
    if d > k/2:
        d = k-d
    dl.append(d)

d = a[n-1]-a[0]
if d > k/2:
    d = k-d
dl.append(d)

print(dl)
ans = k-max(dl)

print(ans)

# -*- coding: utf-8 -*-
"""
Created on Sat Mar 28 21:11:28 2020

@author: Kanaru Sato
"""

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

for i in range(n-1):
    d = a[i+1]-a[i]
    if d > k/2:
        d = k-d
    dl.append(d)

d = a[n-1]-a[0]
if d > k/2:
    d = k-d
dl.append(d)

ans = k-max(dl)

print(ans)

Verdicts: Wrong Answer

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

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

D=[]
for i in range(len(A)-1):
    d=A[i+1]-A[i]
    D.append(D)

print(K-max(D))

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

D=[]
for i in range(len(A)-1):
    d=A[i+1]-A[i]
    D.append(d)

print(K-max(D))

Verdicts: Runtime Error

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

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

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

max = K-A[-1]+A[0]
for i in range(N-1):
    if last < A[i+1]-A[i]:
        max = A[i+1]-A[i]

print(K-max)

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

print(K-l)

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

Verdicts: Wrong Answer

Runtime Error

Wrong Answer

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

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

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

a.append(k)

big = 0
big_count = a[0]

for i in range(n):
    b = a[i + 1] - a[i]
    print(b)
    if b > big_count:
        print('ここ')
        big_count = b
        big = i

if big == 0:
    ans = a[n - 1] - a[0]
else:
    ans = a[i - 1] + (k - a[i])

print(ans)

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

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

a.append(k + a[0])

section = []

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

b_max = max(section)
ans = k - b_max

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

S = [0]*(N+1)

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

Smax = S.index(max(S))

ans = sum(S)-S[Smax]
print(ans)

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

S =[A[0]]+ [0]*(N)

for i in range(N):
    if i==N-1:
        S[i+1] = K- A[i]
    else:
        S[i+1] = A[i+1] - A[i]

Smax = S.index(max(S))

ans = sum(S)-S[Smax]
print(ans)

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

S = [0]*(N+1)

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

Smax = S.index(max(S))

ans = sum(S)-S[Smax]
print(ans)

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

S = [0]*(N)

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

Smax = S.index(max(S))

ans = sum(S)-S[Smax]
print(ans)

Verdicts: Wrong Answer

Wrong Answer

Runtime Error

Accepted