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 sys
lines = sys.stsin.readlines()
K, N = map(int, lines[0].srtip().split())
As = map(int, lines[1].strip().split())

diffs =[]
for base, switch in zip(arr[:-1], arr[1:]):
  diffs append(switch-base)

diffs append(arr[0]+K-arr[-1])

print(K-max(diffs))

K, N = list(map(int, input().srtip().split()))
As = list(map(int, input().strip().split()))
 
diffs =[]
for base, switch in zip(arr[:-1], arr[1:]):
  diffs.append(switch-base)

diffs.append(arr[0]+K-arr[-1])
 
print(K-max(diffs))

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

import sys
lines = sys.stsin.readlines()
K, N = list(map(int, lines[0].srtip().split()))
As = list(map(int, lines[1].strip().split()))
 
diffs =[]
for base, switch in zip(arr[:-1], arr[1:]):
  diffs.append(switch-base)

diffs.append(arr[0]+K-arr[-1])
 
print(K-max(diffs))

import sys
lines = sys.stsin.readlines()
K, N = map(int, lines[0].srtip().split())
As = map(int, lines[1].strip().split())

diffs =[]
for base, switch in zip(arr[:-1], arr[1:]+[0]):
  diffs append(switch-base)

diffs append(arr[0]+K-arr[-1])

print(K-max(diffs))

import sys
lines = sys.stsin.readlines()
K, N = map(int, lines[0].srtip().split())
As = map(int, lines[1].strip().split())

range = max(As)-min(As)

if range*2<K:
  print(range)
else:
  print(K-range)

import sys
lines = sys.stsin.readlines()
K, N = list(map(int, lines[0].srtip().split()))
As = list(map(int, lines[1].strip().split()))

diffs =[]
for base, switch in zip(arr[:-1], arr[1:]):
  diffs.append(switch-base)

diffs.append(arr[0]+K-arr[-1])

print(K-max(diffs))

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

Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

Runtime Error

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

Submission attempts (in order):
import numpy as np

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

a_list.append(k)

ans_list = np.diff(a_list)

if max(ans_list) == ans_list[-1]:
    print(sum(ans_list) - max(ans_list) - a_list[0])
elif max(ans_list) == ans_list[0]:
    print(sum(ans_list) - max(ans_list) - ans_list[-1])
else:
    print(sum(ans_list) - max(ans_list))

import numpy as np

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

a_list.append(k+a_list[0])

ans_list = np.diff(a_list)

print(sum(ans_list) - max(ans_list))


Verdicts: Wrong Answer

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

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

min_list = []
for i in range(N):
    if i == 0:
        left = an[i] + K - an[-1]
        right = an[i+1] - an[i]
    elif i == N-1:
        left = an[i] - an[i-1]
        right = an[0] + K - an[N-1]
    else:
        left = an[i] - an[i-1]
        right = an[i+1] - an[i]
    min_list.append(min(K-left, K-right))
print(min(n_list))

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

min_list = []
for i in range(N):
    if i == 0:
        left = an[i] + K - an[-1]
        right = an[i+1] - an[i]
    elif i == N-1:
        left = an[i] - an[i-1]
        right = an[0] + K - an[N-1]
    else:
        left = an[i] - an[i-1]
        right = an[i+1] - an[i]
    min_list.append(min(K-left, K-right))
print(min(min_list))


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

ans=0
if max(a)<=k/2.0 or min(a)>=k/2.0:
  for i in range(n):
    ans+=abs(a[i+1]-a[i])
else:
  for i in range(n):
    if a[i]>k/2.0:
      a[i]-=k
    else:
      j=i
  for i in range(j):
     ans+=abs(a[i+1]-a[i])
  ans+=abs(a[n]-a[0])
  for i in range(j+1,n):
    ans+=abs(a[i+1]-a[i])
print(ans)

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

ans=0
if max(a)<=(k/2.0) or min(a)>=(k/2.0):
  for i in range(n-1):
    ans+=abs(a[i+1]-a[i])
else:
  for i in range(n):
    if a[i]>k/2.0:
      a[i]-=k
    else:
      j=i
  for i in range(j):
     ans+=abs(a[i+1]-a[i])
  ans+=abs(a[n]-a[0])
  for i in range(j+1,n-1):
    ans+=abs(a[i+1]-a[i])
print(ans)

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

ans=0
if max(a)<=(k/2.0) or min(a)>=(k/2.0):
  for i in range(n-1):
    ans+=abs(a[i+1]-a[i])
else:
  for i in range(n):
    if a[i]>k/2.0:
      a[i]-=k
    else:
      j=i
  for i in range(j):
     ans+=abs(a[i+1]-a[i])
  ans+=abs(a[n-1]-a[0])
  for i in range(j+1,n-1):
    ans+=abs(a[i+1]-a[i])
print(ans)

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

ans=0
if max(a)<=(k/2.0) or min(a)>=(k/2.0):
  for i in range(n-1):
    ans+=abs(a[i+1]-a[i])
else:
  max_=0
  for i in range(n-1):
    max_=max(max_,abs(a[i+1]-a[i]))
  max_=max(max_,abs(a[0]-(a[n-1]-k)))
  ans=k-max_
print(ans)

Verdicts: Runtime Error

Runtime Error

Wrong Answer

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

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

a=[]
for i in range(N-1):
  a.append(abs(A[i]-A[i+1]))
  #print(a)
a.append(abs(K-A[N-1]))
print(a)

a.remove(max(a)) 
ans=sum(a)
print(ans)


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

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


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

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


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(' ')))
t = 0
id = 0
l = 0
for i in range(n):
    if i < n - 1:
        d = abs(a[i] - a[i + 1])
    else:
        d = k - a[n - 1] + a[0]
    if t < d:
        t = d
        id = i + 1 if i < n - 1 else 0
for i in range(n - 1):
    l += abs(a[(i + id) % n] - a [(i + id + 1) % n]) if i + id + 1 < n - 1 else k - a[n - 1] + a[0]
print(l)

k, n = map(int, input().split(' '))
a = list(map(int, input().split(' ')))
t = 0
id = 0
l = 0
for i in range(n):
    if i < n - 1:
        d = abs(a[i] - a[i + 1])
    else:
        d = k - a[n - 1] + a[0]
    if t < d:
        t = d
        id = i + 1 if i < n - 1 else 0
for i in range(n - 1):
    l += abs(a[(i + id) % n] - a [(i + id + 1) % n]) if i + id != n - 1 else k - a[n - 1] + a[0]
print(l)

Verdicts: Wrong Answer

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

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

print(k-max_dis)

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

print(k-max_dis)

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

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


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

print(min(B))








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


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

print(min(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):
# -*- coding: utf-8 -*-
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.append(A[0])

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

print(K-distance_max)
        


# -*- coding: utf-8 -*-
K, N = map(int, input().split())
A = list(map(int, input().split()))
A.append(A[0]+K)

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

print(K-distance_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=(int(x) for x in input().split())
A =[int(x) for x in input().split()]

A.append(K + A[0])
print(A)
A_sub = []

for i in range(len(A)-1):
    A_sub.append(abs(A[i] - A[i + 1]))
# print(A_sub)
print(sum(A_sub) - max(A_sub))

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

A.append(K + A[0])
# print(A)
A_sub = []

for i in range(len(A)-1):
    A_sub.append(abs(A[i] - A[i + 1]))
# print(A_sub)
print(sum(A_sub) - max(A_sub))

Verdicts: Wrong Answer

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

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

ll = l[:]

ll.append(k)
ll.pop(0)
s = []

for i,j in zip(l,ll):
    s.append(j - i)

print(k - max(s))

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

s = []

for i,j in zip(l[1:],l):
    s.append(i-j)

s.append(k + l[0] - l[-1])

print(k - max(s))


Verdicts: Wrong Answer

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

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

x = 0
index = 0

for i in range(n-1):
    if x < a[i+1] - a[i]:
        x = a[i+1] - a[i]
        index = i

if x < k-a[-1]+a[0]:
    x = k-a[-1]+a[0]

print(k - x,k,  x,k-a[-1]+a[0])


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

x = 0
index = 0

for i in range(n-1):
    if x < a[i+1] - a[i]:
        x = a[i+1] - a[i]
        index = i

if x < k-a[-1]+a[0]:
    x = k-a[-1]+a[0]

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

c = abs(A[1] - A[N-1])

for i in range(N-1):
  d = abs(A[i] - A[i+1])
  if c < d:
    c = d
  else:
    c = c
    
print(K-c)

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

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

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

for i in range(N-1):
  d = abs(A[i] - A[i+1])
  if c < d:
    c = d
  else:
    c = c
    
print(K-c)

Verdicts: Wrong Answer

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

Submission attempts (in order):
K,N=input().split()
A=input().split()
n=0
m=1
S=list()
for i in range(int(N)-1):
  S.append(int(A[n+1])-int(A[n]))
  n=n+1
S.append(int(A[0])+(int(K)-int(A[-1])))

ans=int(K)-int(max(S))
print(ans)
print(S)


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

ans=int(K)-int(max(S))
print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
N,M=(int(x) for x in input().split())
A=list(map(int, input().split()))
A=np.array(A)
B=A[1:]-A[:-1]
b=max(B)
c=A[-1]-A[0]
if c > N/2:
    c=int(c-N/2)
else:
    c=c
d=max(b,c)
print(N-d)

import numpy as np

N,M=(int(x) for x in input().split())
A=list(map(int, input().split()))
A=np.array(A)
B=A[1:]-A[:-1]
b=max(B)
c=A[-1]-A[0]
if c > N/2:
    d=int(N-c)
else:
    d=c
e=max(b,d)
f=N-e

print(f)


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
from functools import *
import sys
sys.setrecursionlimit(100000)



def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())

K,N=acinput()

A=acinput()
A.append(A[0]+K)
B=np.array(A)+K

a=np.array(A)

print(K-np.max(a[1:]-a[:-1]))



print(2*np.pi*K-np.max(a[1:]-a[:-1]))

print(a)
print(a[1:]-a[:-1])




import numpy as np
from functools import *
import sys
sys.setrecursionlimit(100000)



def acinput():
    return list(map(int, input().split(" ")))


def II():
    return int(input())

K,N=acinput()

A=acinput()
A.append(A[0]+K)
B=np.array(A)+K

a=np.array(A)

print(K-np.max(a[1:]-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):
import sys


def input():
    return sys.stdin.readline().strip()


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

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


import sys


def input():
    return sys.stdin.readline().strip()


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

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


main()


import sys


def input():
    return sys.stdin.readline().strip()


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

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


if __name__ == "__main__":
    main()


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

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

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

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

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

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

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

Verdicts: Wrong Answer

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

Submission attempts (in order):
k, n = input().split()
a = input().split()
max = 0
for i in range(len(a)):
    d = a[i]-a[i-1]
    if d>max:
        max=d
print(k-max)

k, n = input().split()
a = input().split()
max = 0
for i in range(len(a)):
    if i==0:
        continue
    d = a[i]-a[i-1]
    if d>max:
        max=d
print(k-max)

k, n = input().split()
a = input().split()
max = 0
for i in range(len(a)):
    if i==0:
        continue
    d = int(a[i])-int(a[i-1])
    if d>max:
        max=d
print(k-max)

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

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

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]+a[0])
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):
kp = list(map(int, input().rsplit()))
A = list(map(int, input().rsplit()))
max_range = kp[0]-A[-1]+A[0]
for idx in range(len(A)):
  dif = A[idx+1]-A[idx] 
  if dif >max_range:
    max_range = dif

print(kp[0] - max_range)
  

kp = list(map(int, input().rsplit()))
A = list(map(int, input().rsplit()))
max_range = kp[0]-A[-1]+A[0]
for idx in range(len(A)-1):
  dif = A[idx+1]-A[idx] 
  if dif >max_range:
    max_range = dif
 
print(kp[0] - max_range)

Verdicts: Runtime Error

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

Submission attempts (in order):
K, N = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * N
for i in A:
  B[i]=A[i+1]-A[i]
  
B[N-1]=A[0]+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(0, N-1):
  if i < N-1:
    B[i]=A[i+1]-A[i]
  else:
    B[N-1] = A[0] + K - A[N-1]

print(K-max(B))


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

print(K-max(B))


K, N = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * N
count = 0
for i in A:
  count += 1
  if count < N:
    B[i]=A[i+1]-A[i]
  else:
    B[N-1] = A[0] + 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 A if i < N-1:
  B[i]=A[i+1]-A[i]

B[N-1] = A[0] + K - A[N-1]

print(K-max(B))

K, N = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * N
count = 0
for i in A:
  count += 1
  if count != N:
    B[i]=A[i+1]-A[i]
  else:
    B[N-1] = A[0] + K - A[N-1]

print(K-max(B))


K, N = map(int, input().split())
A = list(map(int, input().split()))
B = []
while all(a< N-1 for a in A):
  B.append(A[a+1]-A[a])

B.append(A[1]+K-A[a])

print(K-max(B))

K, N = map(int, input().split())
A = list(map(int, input().split()))
B = []
for a in A:
  if a < N:
    B.append(A[a+1]-A[a])
  else:
    B.append(A[1]+K-A[a])

print(K-max(B))

K, N = map(int, input().split())
A = list(map(int, input().split()))
B = [0] * N
k = 0
for i in A:
  k += 1
  if k != N:
    B[k-1]=A[k]-A[k-1]
  else:
    B[N-1] = A[0] + K - A[N-1]

print(K-max(B))


Verdicts: Runtime Error

Wrong Answer

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()))
a.append(k)

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

print(ans)

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

ans = k
for i in range(n):
    ans = min(ans, k - a[i + 1] + a[i])

print(ans)

Verdicts: Wrong Answer

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

Submission attempts (in order):
# coding: utf-8
import itertools

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

for i in range(1,n):
    l = a[i] - a[i-1]
    if l < 0:
        l += 20
    if l > max:
        max = l
print(k - max)

# coding: utf-8
k, n = map(int, input().split())
a = list(map(int, input().split()))
max = 0

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

for j in range(n,2*n):
    aa[j] = aa[j] + k

dis = k

for i in range((2*n)-1):
    tonari = aa[i+1]-aa[i]
    dis = min(dis,k-tonari)

print(dis)
print(aa)

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

for j in range(n):
    aa[j] = aa[j] + k

aaa = a + aa
dis = k

for i in range((2*n)-1):
    short = aaa[i+1]-aaa[i]
    dis = min(dis,k-short)

print(dis)

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

for j in range(n,2*n):
    aa[j] = aa[j] + k

dis = k

for i in range((2*n)-1):
    tonari = aa[i+1]-aa[i]
    dis = min(dis,k-tonari)

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


tmp_sum = 0
j = 0

dist = []
for i in range(1,len(B)):
  d = abs(B[i]-B[i-1])
  tmp_sum += d
  dist.append(d)
  if(i == N-1):
    ans = tmp_sum 
    print('ans :',ans)
  elif(i >= N):
    tmp_sum -= dist[j]
    j += 1
    ans = min(ans,tmp_sum)
    print('ans :',ans)
print(ans)    
    

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


tmp_sum = 0
j = 0

dist = []
for i in range(1,len(B)):
  d = abs(B[i]-B[i-1])
  tmp_sum += d
  dist.append(d)
  if(i == N-1):
    ans = tmp_sum 
    
  elif(i >= N):
    tmp_sum -= dist[j]
    j += 1
    ans = min(ans,tmp_sum)
    
print(ans)    
    

Verdicts: Wrong Answer

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

Submission attempts (in order):
def samax_index(A):
    samax = 0
    max_i = 0
    prev_v = 0
    for i, v in enumerate(A):
        if samax <= (v - prev_v):
            max_i = i
            samax = v - prev_v
        prev_v = v
    return max_i


def distance(A, start_i, N):
    print(start_i)
    if (start_i == 0) or ((start_i + 1) == N):
        total = A[start_i] - A[1]
    else:
        total = A[start_i]
        total += A[-1] - A[start_i + 1]

    print(total)


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

A = list(map(int, input().split()))
A.append(K)
A.insert(0, 0)
start_i = samax_index(A) - 1


distance(A, start_i, N)


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

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

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

print(K - max(S))


Verdicts: Wrong Answer

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

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


def max_distance_homes(homes):
    max_distance = 0
    for i in range(len(homes) - 1):
        distance = homes[i + 1] - homes[i]
        if max_distance < distance:
            max_distance = distance
    distance = max(homes[-1] - homes[0], k + homes[0] - homes[-1])
    if max_distance < distance:
        max_distance = distance
    return max_distance

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


def max_distance_homes(homes):
    max_distance = 0
    for i in range(len(homes) - 1):
        distance = homes[i + 1] - homes[i]
        if max_distance < distance:
            max_distance = distance
    distance = k + homes[0] - homes[-1]
    if max_distance < distance:
        max_distance = distance
    return max_distance


print(k - max_distance_homes(home_positions))

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 collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)


k,n = map(int,input().split())
a = list(map(int,input().split()))
d = k//2
aright = []
aleft = []
for i in range(len(a)):
    if a[i]>d:
        a[i] -= d
diff = []
for i in range(len(a)-1):
    d2 = a[i+1]-a[i]
    diff.append(abs(d2))
print(sum(a))




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

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

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

Verdicts: Wrong Answer

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

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

max_d = 0
for i in range(0, N-1):
    if A[i] == 0:
        pass
    else:
        d = abs(A[i] - A[len(A)-1])
        max_d = max(d, max_d)

print(k - max_d)

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

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

print(d)
print(sum(d) - max(d))

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

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

#print(A)
#print(d)
print(sum(d) - max(d))

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 = input().split()
for i in range(0, len(A)):
    A[i] = int(A[i])

dist = []
for i in range(0, len(A)-1):
    dist.append(A[i+1]-A[i])
dist.append(A[len(A)-1]-A[0])
print(dist)

print(K-max(dist))


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

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

print(K - max(dist))


Verdicts: Wrong Answer

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

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

sub = A[1] - A[0]
max = N * sub
sub_2 = K - max

print('sub  : ' + str(sub))
print('sub2 : ' + str(sub_2))

if sub_2 >= sub:
    print(sub * (N - 1))
else:
    print(sub * (N - 2) + sub_2)

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

sub_a = []

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

max_sub = max(sub_a)

print(K - max_sub)

Verdicts: Wrong Answer

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

Submission attempts (in order):
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
for i in range(a[1]):
    if i==a[1]-1:
        if b[0]==0:
            b[0]=a[0]
            c.append(abs(b[i]-b[0]))
        else:
            c.append(abs(b[i]-a[0]))
    elif i!=a[1]-1:
        c.append(abs(b[i]-b[i+1]))
print(a[0]-max(c))

a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
for i in range(a[1]):
    if i==a[1]-1:
        if b[0]==0:
            b[0]=a[0]
            c.append(abs(b[i]-b[0]))
        else:
            c.append(abs(b[i]-(b[0]+a[0])))
    elif i!=a[1]-1:
        c.append(abs(b[i]-b[i+1]))
print(a[0]-max(c))

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

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

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

B = []

for i in range(1, n):
    B.append(aa[i]-aa[i-1])
    
B.append(k-sum(B))
print(k-max(B))

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

B = []

for i in range(1, n):
    B.append(aa[i] - aa[i - 1])

B.append(k - sum(B))
print(k - max(B))

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):
#!/usr/bin/env python3
# coding: utf-8
# import sys
# import pprint
# import numpy as np
# import code
import functools

if __debug__:
    debug = lambda *x: None
else:
    import logging
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    debug = logger.debug

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

debug(k)
debug(n)
debug(a)

aa = a.copy()
aa.pop(0)
aa.append(k + a[0])
debug(aa)
# r = functools.reduce(lambda )

d = [y - x for x, y in zip(a,aa)]
debug(d)
d.sort()
debug(d)
d.pop()
debug(d)
debug(sum(d))


#!/usr/bin/env python3
# coding: utf-8
# import sys
# import pprint
# import numpy as np
# import code
import functools

if __debug__:
    debug = lambda *x: None
else:
    import logging
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    debug = logger.debug

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

debug(k)
debug(n)
debug(a)

aa = a.copy()
aa.pop(0)
aa.append(k + a[0])
debug(aa)
# r = functools.reduce(lambda )

d = [y - x for x, y in zip(a,aa)]
debug(d)
d.sort()
debug(d)
d.pop()
debug(d)
print(sum(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()))

hanbun = k /2
a.sort
print(a)
i = 0
while True:
    if a[i] != 0:
        end = a[i]
        break
    else:
        i += 1
start = a[n-1]


result = start - end
if result < 0:
    result = result * -1
print(result)

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

B=[]
i=0
while i<=N-2:
    B.append(A[i+1]-A[i])
    i=i+1
B=sorted(B)
print(K-max(B1,B[-1]))

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

B1=K-A[N-1]+A[0]

B=[]
i=0
while i<=N-2:
    B.append(A[i+1]-A[i])
    i=i+1
B=sorted(B)
print(K-max(B1,B[-1]))

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):
while True:
  a = 1


print(0)

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

print(sum(B) - max(B))


Verdicts: Time Limit Exceeded

Wrong Answer

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

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

for _ in range(len(a)-1):
    if diff < abs(a[_]-a[_+1]):
        diff = abs(a[_]-(a[_+1]))

print(k-diff)

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

for i in range(len(a)-1):
    if diff < a[i] - a[i+1]:
        diff = a[i] - a[i+1]

if diff < k-a[0] + a[-1]:
    diff = k-a[0] + a[-1]

ans = k-diff

print(ans)


Verdicts: Wrong Answer

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

Submission attempts (in order):
k,n=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
maxi=0
for i in range(n-1):
    cal=abs(a[i]-a[(i+1)])
    if(cal>maxi):
        maxi=cal
if(k-a[n-1]>maxi):
    maxi=k-a[n-1]
print(maxi)

k,n=[int(x) for x in input().split()]
a=[int(x) for x in input().split()]
maxi=0
for i in range(n-1):
    cal=abs(a[i]-a[(i+1)])
    if(cal>maxi):
        maxi=cal
if(abs(k-a[n-1])+a[0]>maxi):
    maxi=abs(k-a[n-1])+a[0]
print(k-maxi)

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()))
d = []
for i in range(n):
  if i+1<n:
    d.append(abs(l[i+1]-l[i]))
  else:
    if 0 in l:
      d.append(abs(k - l[i]))
    else:
      d.append(abs(k - l[i] + l[0])
print(sum(d)-max(d))

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

Verdicts: Runtime Error

Accepted