ZhenlongDai/ACPR huggingface dataset:
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,_,*a=map(int,open(0).read().split())
c=m=0
for x,y in zip(a,a[1:]):
  m=max(m,y-x)
  c+=y-x
print(c+k-y-max(m,k-y))

Failing test case input:
12 3
2 8 44

Expected output:
-24


Actual output:
-26


Fixed submission (verdict: Accepted):
k,_,*a=map(int,open(0).read().split());a.append(k+a[0]);b=[y-x for x,y in zip(a,a[1:])];print(sum(b)-max(b))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,n =map(int,input().split())
a=list(map(int,input().split()))
a.sort()
a.append(k+a[0])
ans = 0
for i in range(n):
    ans = max(ans,a[i+1]-a[i])
print(ans)

Failing test case input:
27 3
2 6 29

Expected output:
4


Actual output:
23


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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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(K-max(dist))


Failing test case input:
19 3
0 5 15

Expected output:
9


Actual output:
4


Fixed submission (verdict: Accepted):
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))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int, input().split())
A = list(map(int, input().split()))

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

Failing test case input:
10 3
0 1 110

Expected output:
-99


Actual output:
-101


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())
A = list(map(int, input().split()))

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

Problem: p02725
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
k, n = map(int, input().split())
a = list(map(int, input().split()))
max = 0
len = [0] * n
for i in range(n):
    if i == 0:
        len[i] = a[i]
    else:
        len[i] = a[i] - a[i - 1]
        if len[i] > len[max]:
            max = i
if len[max] > int(k / n) and len[max] > (k - a[n - 1]) and (a[n - 1] - a[0]) > len[max]:
    ans = (k - a[max]) + a[max - 1]
else:
    ans = a[n - 1] - a[0]
print(ans)

Failing test case input:
6 3
1 1 65

Expected output:
-58


Actual output:
64


Fixed submission (verdict: Accepted):
k, n = map(int, input().split())
a = list(map(int, input().split()))
max = 0
len = [0] * n
for i in range(n):
    if i == 0:
        len[i] = a[i]
    else:
        len[i] = a[i] - a[i - 1]
        if len[i] >= len[max]:
            max = i
print(min((k - a[max]) + a[max - 1], a[n - 1] - a[0]))
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int, input().split())
An = list(map(int, input().split()))

An = [0] + An + [K]

Bn = [0] * (N + 2)
for i in range(N+1):
    Bn[i] = abs(An[i+1] - An[i])


Bn = Bn[1:-2] + [Bn[0] + Bn[-1]]

print(sum(Bn) - max(Bn))

Failing test case input:
-1 3
0 3 29

Expected output:
-27


Actual output:
3


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())
An = list(map(int, input().split()))

Bn = [0] * N
for i in range(N-1):
    Bn[i] = An[i+1] - An[i]

Bn[-1] = K - An[-1] + An[0]
print(sum(Bn) - max(Bn))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

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

distance.remove(max(distance))
print(sum(distance))

Failing test case input:
50 3
2 3 128

Expected output:
-75


Actual output:
-77


Fixed submission (verdict: Accepted):
K, N = map(int, input().split(' '))
A = list(map(int, input().split(' ')))

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

distance.remove(max(distance))
print(sum(distance))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K,N=map(int,input().split())
Alist=list(map(int,input().split()))
kyori=[]
ans=0
for i in range(N-1):
    kyori.append(Alist[i+1]-Alist[i])
kyori.append(K-Alist[N-1])
kyori.remove(max(kyori))
for i in range(len(kyori)):
    ans+=kyori[i]
print(ans)

Failing test case input:
1 3
-1 5 17

Expected output:
-11


Actual output:
-10


Fixed submission (verdict: Accepted):
K,N=map(int,input().split())
Alist=list(map(int,input().split()))
kyori=[]
ans=0
for i in range(N-1):
    kyori.append(Alist[i+1]-Alist[i])
kyori.append(K-Alist[N-1]+Alist[0])
kyori.remove(max(kyori))
for i in range(len(kyori)):
    ans+=kyori[i]
print(ans)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,n = map(int,input().split())
li = list(map(int,input().split()))
li.sort()
if li[n-1] - li[0] <= li[n-2] + k - li[n-1]:
    print(li[n-1] - li[0])
else:
    print(li[n-2] + k - li[n-1])

Failing test case input:
11 3
0 6 7

Expected output:
5


Actual output:
7


Fixed submission (verdict: Accepted):
k,n = map(int,input().split())
li = list(map(int,input().split()))
ali = []
for i in range(n-1):
    ali.append(li[i+1] - li[i])
a = ali.index(max(ali))
if li[a] + k - li[a+1] <= li[n-1] - li[0]:
    print(li[a] + k - li[a+1])
else:
    print(li[n-1] - li[0])

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

res= a[n-1]

max=0
n_prev=0

for nn in a:
    if (nn-n_prev) < (k-a[n-1]):
        res=(nn-n_prev)
    n_prev=nn

print(res)



Failing test case input:
20 3
1 5 15

Expected output:
10


Actual output:
4


Fixed submission (verdict: Accepted):

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

n_prev= a[n-1]-k

m=0

for nn in a:
    if (nn-n_prev) > m:
        m=nn-n_prev
        res=(k-m)
    n_prev=nn

print(res)
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
def input(): return sys.stdin.readline().rstrip()

def main():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    A += [K]
    print(min(A[N-1] - A[0], A[N] - A[1]))

if __name__ == '__main__':
    main()


Failing test case input:
2 3
-2 5 17

Expected output:
-10


Actual output:
-3


Fixed submission (verdict: Accepted):
import sys
def input(): return sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Problem: p02725
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
k, n= map(int,input().split())
a = list(map(int,input().split()))
for i in range(1,n):
  a[i] -= a[i-1]
a += [k-sum(a)]
print(k-max(a))

Failing test case input:
7 3
1 8 31

Expected output:
-16


Actual output:
-17


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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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

A = input()

A_list = A.split(' ')
for i in range(len(A_list)):
    A_list[i] = int(A_list[i])

amari = K-int(A_list[N-1])

aida_list = [0]*len(A_list)
for i in range(len(A_list)-1):
  aida_list[i] = A_list[i+1] - A_list[i]
aida_list[len(A_list)-1] = amari

max_ = max(aida_list)


aida_list.remove(max_)

ans = sum(aida_list)



print(ans)

Failing test case input:
20 3
5 11 15

Expected output:
10


Actual output:
9


Fixed submission (verdict: Accepted):

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

A = input()

A_list = A.split(' ')
for i in range(len(A_list)):
    A_list[i] = int(A_list[i])

amari = K-int(A_list[N-1])

aida_list = [0]*len(A_list)
for i in range(len(A_list)-1):
  aida_list[i] = A_list[i+1] - A_list[i]

aida_list[len(A_list)-1] = K - sum(aida_list)


max_ = max(aida_list)


aida_list.remove(max_)

ans = sum(aida_list)



print(ans)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int, input().split())
a = list(input().split())

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

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

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

Failing test case input:
7 3
1 8 28

Expected output:
-13


Actual output:
-14


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())
a = list(input().split())

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

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



print (sum(diff)-max(diff))
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N=map(int,input().split())
List=list(map(int,input().split()))
Newlist=list(List[i+1]-List[i]for i in range(N-1))
Newlist.append(List[0]+K-List[N-1])
print(max(Newlist))

Failing test case input:
19 3
1 5 15

Expected output:
9


Actual output:
10


Fixed submission (verdict: Accepted):
K, N=map(int,input().split())
List=list(map(int,input().split()))
Newlist=list(List[i+1]-List[i]for i in range(N-1))
Newlist.append(List[0]+K-List[N-1])
print(K-max(Newlist))

Problem: p02725
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
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])
  print(ans)
  
ans = max(ans,K-A[-1]+A[0])
print(K-ans)

Failing test case input:
37 3
0 0 66

Expected output:
-29


Actual output:
0
66
-29


Fixed submission (verdict: Accepted):
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)

Problem: p02725
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
k,n = map(int,input().split())
A = list(map(int,input().split()))

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

print(B, k-max(B) )

Failing test case input:
11 3
3 11 15

Expected output:
3


Actual output:
[-1, 8, 4] 3


Fixed submission (verdict: Accepted):
k,n = map(int,input().split())
A = list(map(int,input().split()))

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

print(k-max(B) )

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,n = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
a.reverse()
for i in range(n-1):
    a[i]-=a[i+1]-a[n-1]
a.append(k-sum(a))
ans = max(a)
print(ans)

Failing test case input:
63 3
-2 9 45

Expected output:
27


Actual output:
34


Fixed submission (verdict: Accepted):
k,n = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
a.reverse()
for i in range(n-1):
    a[i]-=a[i+1]
a[n-1] = 0
a.append(k-sum(a))
ans = k-max(a)
print(ans)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int, input().split())
A = list(map(int, input().split()))

diff = [None] * N

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

max_diff = max(diff)
answer = sum(diff) - max(diff)
print(answer)

Failing test case input:
26 3
2 12 22

Expected output:
16


Actual output:
14


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())
A = list(map(int, input().split()))

diff = [None] * N

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

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

max_diff = max(diff)
answer = sum(diff) - max(diff)
print(answer)
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
a.append(k)

m = 0
ans = 0
for i in range(1, n + 1):
    x = a[i] - a[i - 1]
    ans += x
    m = max(m, x)
print(ans - m)


Failing test case input:
67 3
-1 6 43

Expected output:
30


Actual output:
31


Fixed submission (verdict: Accepted):
k, n = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]

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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
a.sort()
a.insert(0,a[-1])
max_d = 0
for i in range(0,N-1):
  if abs(a[i+1] - a[i]) >= max_d:
    max_d = abs(a[i+1] - a[i])

print(K-max_d)


Failing test case input:
10 3
0 1 100

Expected output:
-89


Actual output:
-90


Fixed submission (verdict: Accepted):
K, N = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
a.sort()
a.insert(0,a[-1])
max_d = 0
for i in range(0,N):
    if a[i+1] - a[i] >= 0 and a[i+1] - a[i] >= max_d:
      max_d = a[i+1] - a[i]
    elif a[i+1] - a[i] < 0 and a[i+1] - a[i] +K >= max_d:
      max_d = a[i+1] - a[i] + K
      
print(K-max_d)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, n = map(int, input().split(' '))
a = list(map(int, input().split(' ')))

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

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

sum(diffs) - max_diff

Failing test case input:
10 3
1 8 52

Expected output:
-34


Actual output:

Fixed submission (verdict: Accepted):
k, n = map(int, input().split(' '))
a = list(map(int, input().split(' ')))

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

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

print(sum(diffs) - max_diff)

Problem: p02725
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
A = sorted(A)
B = [0 for i in range(N)]
for i in range(N-1):
  B[i] = A[i + 1] - A[i]
B[N - 1] = N - A[N - 1] + A[0]
ans = N - max(B)
print(ans)


Failing test case input:
5 3
0 0 48

Expected output:
-43


Actual output:
-45


Fixed submission (verdict: Accepted):
K, N = list(map(int, input().split()))
A = list(map(int, input().split()))
A = sorted(A)
B = [0 for i in range(N)]
for i in range(N-1):
  B[i] = A[i + 1] - A[i]
B[N - 1] = K - A[N - 1] + A[0]
ans = K - max(B)
print(ans)
Problem: p02725
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
K,N = map(int,input().split())
A = list(map(int,input().split()))

m = 0
for i in range(N-1):
    l = A[i+1] - A[i]
    if m <= l:
        m = l
        
if m <= K-A[N-1]+A[0]:
    m = K-A[N-1]+A[0]
    
print(m)

Failing test case input:
3 3
1 8 18

Expected output:
-7


Actual output:
10


Fixed submission (verdict: Accepted):
K,N = map(int,input().split())
A = list(map(int,input().split()))

m = 0
for i in range(N-1):
    l = A[i+1] - A[i]
    if m <= l:
        m = l
        
if m <= K-A[N-1]+A[0]:
    m = K-A[N-1]+A[0]
    
print(K-m)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int, input().split())
a = list(input().split())

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

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

print (diff)

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

Failing test case input:
10 3
-2 5 50

Expected output:
-35


Actual output:
[-42, 7, 45]
-35


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())
a = list(input().split())

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

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



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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))

tmp = 0

for i in range(1, len(a)):
    if a[i]-a[i-1] >=0:
        tmp = a[i] - a[i-1]

if a[0]+k-a[len(a)-1] > tmp:
    tmp = a[0]+k-a[len(a)-1]

print(k-tmp)

Failing test case input:
7 3
0 16 17

Expected output:
-9


Actual output:
6


Fixed submission (verdict: Accepted):
k, n = list(map(int, input().split()))
a = list(map(int, input().split()))

tmp = 0

for i in range(1, len(a)):
    if a[i]-a[i-1] >=tmp:
        tmp = a[i] - a[i-1]

if a[0]+k-a[len(a)-1] > tmp:
    tmp = a[0]+k-a[len(a)-1]

print(k-tmp)

Problem: p02725
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
def main():
  K, N = map(int, input().split())
  As = list(map(int, input().split()))
  r = 0
  for x in range(N-1, -1, -1):
    if As[x] == 0:
      As[x] = K
    elif As[x-1] == 0:
      As[x-1] = K
    solve = int(As[x] - As[x-1])
    if 0 <= solve:
      r += solve
  print(r)

if __name__ == "__main__":
  main()

Failing test case input:
20 3
3 11 29

Expected output:
2


Actual output:
26


Fixed submission (verdict: Accepted):
def check(a):
  if a < 0:
    return a * -1
  else:
    return a

def main():
  K, N = map(int, input().split())
  As = list(map(int, input().split()))
  r = []
  r.append(K-As[-1]+As[0])
  for x in range(N-1, -1, -1):
    solve = As[x] - As[x-1]
    r.append(check(solve))
  ans = sorted(r)
  ans.remove(ans[-1])
  print(K-ans[-1])

if __name__ == "__main__":
  main()
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,n=map(int,input().split())
A=list(map(int,input().split()))
ans=A[0]-A[-1]+n
for i in range(n-1):
  a=A[i+1]-A[i]
  if a>ans:
    ans=a
print(k-a)

Failing test case input:
9 3
2 11 15

Expected output:
0


Actual output:
5


Fixed submission (verdict: Accepted):
k,n=map(int,input().split())
A=list(map(int,input().split()))
ans=A[0]-A[-1]+k
for i in range(n-1):
  a=A[i+1]-A[i]
  if a>ans:
    ans=a
print(k-ans)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
round,house_num = map(int,input().split())

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

min = distance[-1] - distance[0]

for i in range(house_num - 1):
  if round-(distance[i+1]-distance[i]) < min:
    min = round-(distance[i+1]-distance[i])
  print(min)

Failing test case input:
1 3
0 0 43

Expected output:
-42


Actual output:
1
-42


Fixed submission (verdict: Accepted):
round,house_num = map(int,input().split())

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

min = distance[-1] - distance[0]

for i in range(house_num - 1):
  if round-(distance[i+1]-distance[i]) < min:
    min = round-(distance[i+1]-distance[i])
print(min)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, n = map(int,input().split())
a_l = list(map(int,input().split()))

a_l.sort()
print(a_l[-1]-a_l[0])

Failing test case input:
9 3
0 5 17

Expected output:
-3


Actual output:
17


Fixed submission (verdict: Accepted):
k, n = map(int,input().split())
a_l = list(map(int,input().split()))

b_l = [a_l[i]-a_l[i-1] for i in range(n)]
b_l[0] += k
b_l.sort()
print(k-b_l[-1])

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


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

a=list(map(int,input().split()))
l=0
r=0
t=a[n-1]

for i in a[:n-1]:
    x=t-i
    y=k-x
    if x<=y :
        if x>r:
            r=x
    else:
        if y>l:
            l=y
    

print(l+r)

Failing test case input:
19 3
0 5 25

Expected output:
-1


Actual output:
0


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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

k, n = map(int, input().split())
a = list(map(int, input().split()))
distance = []
for i in range(n):
  if i == n-1:
    distance.append(abs(k - a[i]))
  else:
  	distance.append(abs(a[i+1] - a[i]))
distance.sort()
print(sum(distance[:-1]))

Failing test case input:
20 3
1 5 17

Expected output:
8


Actual output:
7


Fixed submission (verdict: Accepted):

k, n = map(int, input().split())
a = list(map(int, input().split()))
distance = []
for i in range(len(a)):
  if i == len(a) - 1:
    distance.append(k+a[0] - a[i])
  else:
  	distance.append(a[i+1] - a[i])
distance.sort()
print(sum(distance[:-1]))
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):






from sys import stdin,setrecursionlimit










setrecursionlimit(10**6+1)
input=stdin.readline

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

print(sum(absdis)-max(absdis))

Failing test case input:
7 3
0 8 28

Expected output:
-13


Actual output:
16


Fixed submission (verdict: Accepted):






from sys import stdin,setrecursionlimit










setrecursionlimit(10**6+1)
input=stdin.readline

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

print(sum(absdis)-max(absdis))

Problem: p02725
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
K, N = map(int, input().split())

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

dist_list = []
dist_list.append(20 - A[N-1] + A[0])
for i in range(1, N):
  dist_list.append(A[i]-A[i-1])
dist_list.remove(max(dist_list))
print(sum(dist_list))


Failing test case input:
17 3
0 6 29

Expected output:
-6


Actual output:
-3


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())

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

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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
i = list(map(int,input().split()))
house = list(map(int,input().split()))
house.append(i[0])
ans = []
for h in range(len(house)-1):
  num = house[h+1]-house[h]
  ans.append(num)
ans.append(ans[-1]+house[0])
ans.remove(max(ans))
ans.remove(max(ans))
print(sum(ans))

Failing test case input:
12 3
2 8 73

Expected output:
-53


Actual output:
-120


Fixed submission (verdict: Accepted):
i = list(map(int,input().split()))
house = list(map(int,input().split()))

ans = []
for h in range(len(house)-1):
  num = house[h+1]-house[h]
  ans.append(num)
l = i[0] - house[-1] + house[0]
ans.append(l)

ans.remove(max(ans))

print(sum(ans))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int, input().split())
A = list(map(int, input().split()))

B = []

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

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

Failing test case input:
19 3
1 5 15

Expected output:
9


Actual output:
8


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())
A = list(map(int, input().split()))

B = []

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

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

Problem: p02725
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import math
k,n= map(int,input().split())
a = list(map(int,input().split()))
ans = 0
for i in range(1,len(a)):
  s = a[i]-a[i-1]
  ans =max(ans,s)
print(k-ans)


Failing test case input:
37 3
-1 1 18

Expected output:
19


Actual output:
20


Fixed submission (verdict: Accepted):
import math
k,n= map(int,input().split())
a = list(map(int,input().split()))
ans = a[0]+k-a[n-1]
for i in range(1,len(a)):
  s = a[i]-a[i-1]
  ans =max(ans,s)
print(k-ans)
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,n = map(int,input().split())
al = input().split()
al2 = [int(i) for i in al]
distance = []
for i in range(len(al)-1):
    distance.append(al2[i+1]-al2[i])
distance.append(k-al2[-1])
distance.remove(max(distance))
print(sum(distance))

Failing test case input:
9 3
2 6 29

Expected output:
-14


Actual output:
-16


Fixed submission (verdict: Accepted):


k,n = map(int,input().split())
al = input().split()
al2 = [int(i) for i in al]
distance = []
for i in range(len(al)-1):
    distance.append(al2[i+1]-al2[i])
distance.append(((al2[0])+(k-al2[-1])))
distance.remove(max(distance))
print(sum(distance))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int,input().split())
A = list(map(int,input().split()))
gap = []

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


Failing test case input:
20 3
1 5 17

Expected output:
8


Actual output:
4
12
4
8


Fixed submission (verdict: Accepted):
K, N = map(int,input().split())
A = list(map(int,input().split()))
gap = []

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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))

    shiftA = A[1:] + [K]

    subA = [shiftA[i] - A[i] for i in range(N)]
    maxA = max(subA)
    subA.remove(maxA)

    print(sum(subA))

if __name__ == '__main__':
    main()

Failing test case input:
50 3
2 3 128

Expected output:
-75


Actual output:
-77


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

    shiftA = A[1:] + [K+A[0]]

    subA = [shiftA[i] - A[i] for i in range(N)]
    maxA = max(subA)
    subA.remove(maxA)

    print(sum(subA))

if __name__ == '__main__':
    main()
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int, input().strip().split())
As = list(map(int, input().strip().split()))

interval = 0
max_interval = 0
index = None
distance = 0
for i in range(N):
    if i == 0:
        interval = 20 - As[-1] + As[0]
    else:
        interval = abs(As[i] - As[i-1])
    if interval > max_interval:
        max_interval = interval
        index = i
if index == 0:
    distance = K - As[index-1] + As[index]
else:
    distance = K - As[index] + As[index -1]
print(distance)

Failing test case input:
27 3
1 5 15

Expected output:
14


Actual output:
17


Fixed submission (verdict: Accepted):
K, N = map(int, input().strip().split())
As = list(map(int, input().strip().split()))

max_interval = 0
index = None
distance = 0
for i in range(N):
    if i == N-1:
        interval = K - As[i] + As[0]
    else:
        interval = abs(As[i+1] - As[i])
    if interval > max_interval:
        max_interval = interval
        index = i
        
if index == N-1:
    distance = As[index] - As[0]
else:
    distance = As[index] + K - As[index+1]
print(distance)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int, input().split())
A = list(map(int, input().split()))

diff = [None] * N

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

diff[0] = A[0]
diff[N-1] = K - A[N-1]

max_diff = max(diff)
answer = sum(diff) - max(diff)
print(answer)

Failing test case input:
7 3
0 2 28

Expected output:
-19


Actual output:
-21


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())
A = list(map(int, input().split()))

diff = [None] * N

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

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

max_diff = max(diff)
answer = sum(diff) - max(diff)
print(answer)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    K,N = map(int,input().split())
    A_list = list(map(int,input().split()))
    dist_list = []
    A_list.append(K)
    for i in range(1,len(A_list)):
        dist_list.append(A_list[i]-A_list[i-1])
    d_sorted = sorted(dist_list)
    print(int(sum(d_sorted[0:N-1])))
main()


Failing test case input:
51 3
2 10 41

Expected output:
20


Actual output:
18


Fixed submission (verdict: Accepted):
import sys
sys.setrecursionlimit(10**7)
input = lambda: sys.stdin.readline().strip()

def main():
    K,N = map(int,input().split())
    A_list = list(map(int,input().split()))
    A_list = [i-A_list[0] for i in A_list]
    dist_list = []

    A_list.append(K)
    for i in range(1,len(A_list)):
        d = (A_list[i]-A_list[i-1])
        dist_list.append(d)
    d_sorted = sorted(dist_list)
    print(int(sum(d_sorted[0:N-1])))

main()
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,n=map(int,input().split())
a=list(map(int,input().split()))
t=0
for i in range(1,n):
  t=max(t,a[i]-a[i-1])
print(k-t)


Failing test case input:
27 3
1 5 15

Expected output:
14


Actual output:
17


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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K,N = map(int, input().split())
A = list(map(int,input().split()))


l_s = []
check = 0
for i in range(0,N):
    if(A[i] == 0):
        check =1
if(check == 1):
    A.append(K)
    for i in range(1,N+1):
          l_s.append(A[i]-A[i-1])
    num = 0
    ans = 99999999999999999
    for i in range(0,N):
        num = K - l_s[i]
        ans = min(ans,num)
    print(ans)
    
else: 
    A.append(K)
    for i in range(1,N+1):
          l_s.append(A[i]-A[i-1])
    m1 = max(l_s)
    ans = K-m1
    print(ans)

Failing test case input:
37 3
-1 1 18

Expected output:
19


Actual output:
18


Fixed submission (verdict: Accepted):
K,N = map(int, input().split())
A = list(map(int,input().split()))


l_s = []
check = 0
for i in range(0,N):
    if(A[i] == 0):
        check =1
if(check == 1):
    for i in range(1,N):
          l_s.append(A[i]-A[i-1])
    l_s.append(K-A[N-1])
    num = 0
    ans = 99999999999999999
    for i in range(0,N):
        num = K - l_s[i]
        ans = min(ans,num)
    print(ans)
    
else: 
    for i in range(1,N):
        l_s.append(A[i]-A[i-1])
    l_s.append(K-A[N-1]+A[0])
    m1 = max(l_s)
    ans = K-m1
    print(ans)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,n=input().split();
a=input().split();
k=int(k);
n=int(n);
by=0;
for i in range(n):
	a[i]=int(a[i]);
for i in range(n-1):
	if a[i+1]-a[i]>by:
		by=a[i+1]-a[i];
if (k-a[n-1])+a[0]>by :
	by=(k-a[n-1])+a[0];
print(by);


Failing test case input:
20 3
1 2 15

Expected output:
7


Actual output:
13


Fixed submission (verdict: Accepted):
k,n=input().split();
a=input().split();
k=int(k);
n=int(n);
by=0;
for i in range(n):
	a[i]=int(a[i]);
for i in range(n-1):
	if a[i+1]-a[i]>by:
		by=a[i+1]-a[i];
if (k-a[n-1])+a[0]>by :
	by=(k-a[n-1])+a[0];
print(k-by);

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int, input().split())
A = list(map(int, input().split()))
A = [0] + A + [K] 

diff = []
for i in range(len(A)):
    if i < N+1:
        diff.append(A[i+1] - A[i])

longest_interval = diff.index(max(diff))
diff.pop(longest_interval)
ans = sum(diff)

print(ans)


Failing test case input:
37 3
-1 1 18

Expected output:
19


Actual output:
18


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())
A = list(map(int, input().split()))

diff = []
for i in range(len(A)):
    if i < N-1:
        diff.append(A[i+1] - A[i])

diff = diff + [K-A[-1]+A[0]]
longest_interval = diff.index(max(diff))
diff.pop(longest_interval)
ans = sum(diff)

print(ans)
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, n = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
kyoris = []
for i in range(len(a)-1):
    kyoris.append(abs(a[i]-a[i+1]))
lastkyori = (k - a[-1]) + a[0]
kyoris.append(lastkyori)
print(max(kyoris))


Failing test case input:
5 3
0 0 48

Expected output:
-43


Actual output:
48


Fixed submission (verdict: Accepted):
k, n = [int(s) for s in input().split()]
a = [int(s) for s in input().split()]
kyoris = []
for i in range(len(a)-1):
    kyoris.append(abs(a[i]-a[i+1]))
lastkyori = (k - a[-1]) + a[0]
kyoris.append(lastkyori)
print(k - max(kyoris))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,n=map(int,input().split())
lista=list(map(int,input().split())) 
ans=[]
for i in range(1,n):
  ans.append(lista[i]-lista[i-1])
print(k-max(ans))

Failing test case input:
20 3
5 11 15

Expected output:
10


Actual output:
14


Fixed submission (verdict: Accepted):
k,n=map(int,input().split())
lista=list(map(int,input().split())) 
lista.append(lista[0]+k)
ans=[]
for i in range(1,n+1):
  ans.append(lista[i]-lista[i-1])
print(k-max(ans))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,n = map(int,input().split())
a = list(map(int,input().split()))
if a[0] == 0:
	dis = [k - a[n-1]]
else:
	dis = [a[n-1] - a[0]]
for i in range(n-1):
	dis.append(a[i+1]-a[i])
print(k - max(dis))


Failing test case input:
7 3
1 8 31

Expected output:
-16


Actual output:
-23


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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

K, N = na()
A = na()
A.append(K)
t = [A[i+1] - A[i] for i in range(N)]
print(sum(t) - max(t))
    



Failing test case input:
6 3
1 1 105

Expected output:
-98


Actual output:
-99


Fixed submission (verdict: Accepted):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  

K, N = na()
A = na()
A.append(A[0]+K)
t = [A[i+1] - A[i] for i in range(N)]
print(sum(t) - max(t))
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
a.sort()
a.insert(0,a[-1])
max_d = 0
for i in range(0,N-1):
  if abs(a[i+1] - a[i]) >= max_d:
    max_d = abs(a[i+1] - a[i])

print(max_d,K-max_d)


Failing test case input:
24 3
0 6 20

Expected output:
10


Actual output:
20 4


Fixed submission (verdict: Accepted):
K, N = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
a.sort()
a.insert(0,a[-1])
max_d = 0
for i in range(0,N):
    if a[i+1] - a[i] >= 0 and a[i+1] - a[i] >= max_d:
      max_d = a[i+1] - a[i]
    elif a[i+1] - a[i] < 0 and a[i+1] - a[i] +K >= max_d:
      max_d = a[i+1] - a[i] + K
      
print(K-max_d)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    ans = A[-1] - A[0]
    for i in range(N-1):
        d = A[i + 1] - A[i]
        ans = max(ans, d)
    print(K - ans)

if __name__ == '__main__':
    main()


Failing test case input:
-1 3
0 3 29

Expected output:
-27


Actual output:
-30


Fixed submission (verdict: Accepted):
def main():
    K, N = map(int, input().split())
    A = list(map(int, input().split()))
    ans = K - A[-1] + A[0]
    for i in range(N-1):
        d = A[i + 1] - A[i]
        ans = max(ans, d)
    print(K - ans)

if __name__ == '__main__':
    main()

Problem: p02725
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import math
a , b = map(int,input().split())
res = list(map(int,input().split()))
if len(res) == 1:
    print(0)
else:
    if res[0] == 0:
        aa = a - res[1]
        bb = res[-1] - 0
    else:
        aa = res[1] + (a - res[-1])
        bb = res[-1] - res[1]
    minn = min(aa,bb)
    print(minn)

Failing test case input:
24 3
0 6 29

Expected output:
1


Actual output:
18


Fixed submission (verdict: Accepted):
import math
a , b = map(int,input().split())
res = list(map(int,input().split()))
res2 = []
if len(res) == 1:
    print(0)
else:
    for i in range(len(res)-1):
        aa = res[i+1] - res[i]
        res2.append(aa)
    if res[0] == 0:
        res2.append(a-res[-1])
    else:
        res2.append(res[0] + (a - res[-1]))
print(sum(res2) - max(res2))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, n = map(int, input().split())
A = list(map(int, input().split()))

kyori = 0
if A[0] == 0:
    kyori = k-A[-1]
else:
    kyori = A[-1]-A[0]

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


Failing test case input:
20 3
1 5 17

Expected output:
8


Actual output:
4


Fixed submission (verdict: Accepted):
k, n = map(int, input().split())
A = list(map(int, input().split()))

kyori = 0
if A[0] == 0:
    kyori = k-A[-1]
else:
    kyori = k-(A[-1]-A[0])

for i in range(n-1):
    kyori = max(kyori, A[i+1]-A[i])
print(k-kyori)
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


def main():
    *N, = map(int, open(0).read().split())
    A = N[2:]
    K = N[0]
    N = N[1]

    S = []
    for i in range(0, N):
        if i == 0:
            S.append(A[0] + 20 - A[N - 1])
        else:
            S.append(A[i] - A[i - 1])
    print(sum(S) - max(S))

main()

Failing test case input:
8 3
2 3 102

Expected output:
-91


Actual output:
-79


Fixed submission (verdict: Accepted):


def main():
    *N, = map(int, open(0).read().split())
    A = N[2:]
    K = N[0]
    N = N[1]

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

main()

Problem: p02725
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import itertools
import math
import fractions
import functools
k, n = map(int, input().split())
a = list(map(int, input().split()))

sub = [0] * n
for i in range(n-1):
    sub[i] = a[i+1]-a[i]

sub[n-1] = k - a[n-1] + a[0]
print(sub)
print(k-max(sub))

Failing test case input:
37 3
0 0 66

Expected output:
-29


Actual output:
[0, 66, -29]
-29


Fixed submission (verdict: Accepted):
import itertools
import math
import fractions
import functools
k, n = map(int, input().split())
a = list(map(int, input().split()))

sub = [0] * n
for i in range(n-1):
    sub[i] = a[i+1]-a[i]

sub[n-1] = k - a[n-1] + a[0]

print(k-max(sub))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K,N=map(int,input().split())
A=list(map(int,input().split()))
m=0
for i in range(N-1):
  if m<(A[i+1]-A[i]):
    m=(A[i+1]-A[i])
if m<(K-A[-1]+A[0]):
  print(K-A[-1]+A[0])
else:
  print(m)

Failing test case input:
7 3
0 5 17

Expected output:
-5


Actual output:
12


Fixed submission (verdict: Accepted):
K,N=map(int,input().split())
A=list(map(int,input().split()))
m=0
for i in range(N-1):
  if m<(A[i+1]-A[i]):
    m=(A[i+1]-A[i])
if m<(K-A[-1]+A[0]):
  print(A[-1]-A[0])
else:
  print(K-m)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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])
ans = min(ans, k - a[0])

print(ans)

Failing test case input:
7 3
1 8 31

Expected output:
-16


Actual output:
-17


Fixed submission (verdict: Accepted):
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)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

k, n, *a = map(int, open(0).read().split())
a.append(k)
e = []
for i in range(n):
    e.append(a[i+1]-a[i])
print(sum(e)-max(e))

Failing test case input:
7 3
1 8 28

Expected output:
-13


Actual output:
-14


Fixed submission (verdict: Accepted):

k, n, *a = map(int, open(0).read().split())
a.append(k+a[0])
e = []
for i in range(n):
    e.append(a[i+1]-a[i])
print(sum(e)-max(e))
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, n = map(int, input().split())
a = list(map(int, input().split()))

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

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

Failing test case input:
10 3
0 1 110

Expected output:
-99


Actual output:
-81


Fixed submission (verdict: Accepted):
k, n = map(int, input().split())
a = list(map(int, input().split()))
a2 = []
for i, d in enumerate(a):
    if i != 0:
        a2.append(d - a[i - 1])
    else:
        a2.append(d + k - a[n - 1])

a2.sort(reverse=True)

print(k - a2[0])

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
a,b = map(int,input().split())
aaa = [int(i) for i in input().split()]

aaa.append(aaa[0] + a)

result = [c1 - c0 for c0,c1 in zip(aaa,aaa[0:])]

print(a - max(result))

Failing test case input:
19 3
0 5 25

Expected output:
-1


Actual output:
19


Fixed submission (verdict: Accepted):
a,b = map(int,input().split())
aaa = [int(i) for i in input().split()]

aaa.append(aaa[0] + a)

result = [c1 - c0 for c0,c1 in zip(aaa,aaa[1:])]

print(a - max(result))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = list(map(int, input().split()))
lst_A = list(map(int, input().split())) 

def main(K, N, lst_A):

    lst_A.append(K)
    diff_dis = [lst_A[i+1] - lst_A[i] for i in range(N)]

    sum_dis = sum(diff_dis)
    return sum_dis - max(diff_dis)

if __name__ == "__main__":

    answer = main(K, N, lst_A)
    print(answer)

Failing test case input:
34 3
1 5 29

Expected output:
10


Actual output:
9


Fixed submission (verdict: Accepted):
K, N = list(map(int, input().split()))
lst_A = list(map(int, input().split())) 

def main(K, N, lst_A):

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

    sum_diff = sum(diff_dis)
    answer = sum(diff_dis)

    for diff in diff_dis:
        _answer = sum_diff - diff
        answer  = min(answer, _answer)

    return answer

if __name__ == "__main__":

    answer = main(K, N, lst_A)
    print(answer)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, n = map(int, input().split())
a = list(map(int, input().split()))
kyori = []

for i in range(len(a)):
    if i == len(a) - 1:
        kyori.append(k - a[i])
    else:
        kyori.append(a[i+1] - a[i])
    
print(sum(kyori)-max(kyori))


Failing test case input:
8 3
2 8 102

Expected output:
-86


Actual output:
-88


Fixed submission (verdict: Accepted):
k, n = map(int, input().split())
a = list(map(int, input().split()))
kyori = []

for i in range(n):
    if i == n - 1:
        kyori.append(a[0] + k - a[i])
    else:
        kyori.append(a[i+1] - a[i])
print(k - max(kyori))
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,n = map(int,input().split())

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


Failing test case input:
37 3
-1 1 18

Expected output:
19


Actual output:
18


Fixed submission (verdict: Accepted):
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])

Problem: p02725
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
K, N = map(int, input().split())
nums = list(map(int, input().split()))

before = 0
max_n = 0
for num in nums:
  dist = num - before
  max_n = max(max_n, dist)
max_n = max(max_n, K-nums[-1])
print(K-max_n)

Failing test case input:
34 3
0 6 23

Expected output:
17


Actual output:
11


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())
nums = list(map(int, input().split()))

before = 0
max_n = 0
for num in nums:
  dist = num - before
  max_n = max(max_n, dist)
  before = num
max_n = max(max_n, K-nums[-1]+nums[0])
print(K-max_n)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K,N=map(int,input().split())
A=[int(x) for x in input().split()]

m=[]
if N==2:
   if A[1]-A[0]<=K/2:
       ans=A[1]-A[0]
   else:
       ans=K+A[0]-A[1]
    
else:
    for i in range(N-2):
        m.append(A[i+1]-A[i])
    if A[N-1]-A[0]>=(K/2):
        m.append(K+A[0]-A[N-1])
    else:
        m.append(A[N-1]-A[0])
    ans=K-max(m)
print(ans)

Failing test case input:
10 3
-1 0 91

Expected output:
-81


Actual output:
9


Fixed submission (verdict: Accepted):
K,N=map(int,input().split())
A=[int(x) for x in input().split()]
 
m=[]
if N==2:
   if A[1]-A[0]<=K/2:
       ans=A[1]-A[0]
   else:
       ans=K+A[0]-A[1]
    
else:
    for i in range(N-1):
        m.append(A[i+1]-A[i])
    m.append(K+A[0]-A[N-1])
    ans=K-max(m)
print(ans)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

circ_length, n_house = map(int, input().split())
places = list(map(int, input().split()))

delta_places = []
for i in range(n_house):
  d = abs(places[i] - places[i-1])
  delta_places.append(d)

result = circ_length - max(delta_places)
print(result)


Failing test case input:
20 3
1 5 17

Expected output:
8


Actual output:
4


Fixed submission (verdict: Accepted):

circ_length, n_house = map(int, input().split())
places = sorted(list(map(int, input().split())))

delta_places = []
for i in range(n_house):
  if i == 0:
    d = circ_length - places[-1] + places[0]
  else:
    d = places[i] - places[i-1]
  delta_places.append(d)

result = circ_length - max(delta_places)

print(result)