ZhenlongDai/ACPR huggingface dataset:
Problem: p00001
Buggy submission (Python3, verdict: Wrong Answer):
from sys import stdin

ns = []
for n in stdin:
  ns.append(n)
ns.sort(reverse = True)
for i in range(3):
  print(ns[i])

Failing test case input:
1819
645
0011
374
414
62
3676
3594
375
177

Expected output:
3676
3594
1819


Actual output:
645

62

414



Fixed submission (verdict: Accepted):
from sys import stdin
ns = [int(n) for n in stdin]
ns.sort(reverse = True)
for i in range(3):
  print(ns[i])

Problem: p00001
Buggy submission (Python3, verdict: Wrong Answer):


def main():
    List=[]

    for i in range(10):
        a=input()
        List.append(a)

    List.sort(reverse=True)
    print(List[0])
    print(List[1])
    print(List[2])
        
 
if __name__ == '__main__':
    main()

Failing test case input:
100
94
342
568
500
600
1422
2053
476
205

Expected output:
2053
1422
600


Actual output:
94
600
568


Fixed submission (verdict: Accepted):


def main():
    List=[]

    for i in range(10):
        a=int(input())
        List.append(a)

    List.sort(reverse=True)
    print(List[0])
    print(List[1])
    print(List[2])
        
 
if __name__ == '__main__':
    main()

Problem: p00001
Buggy submission (Python3, verdict: Wrong Answer):
mt=[]
for i in range(10):
    mt.append(int(input()))

high=[0,0,0]
for i in range(10):
    if  mt[i] > high[0]:
        high=[mt[i]]+high[:2]
    elif mt[i] > high[1]:
        high=[high[0]]+[mt[1]]+[high[1]]
    elif mt[i] > high[2]:
        high=high[:2]+[mt[i]]
print(high,sep='\n')

Failing test case input:
1819
2003
1094
2489
1723
492
4419
2848
2834
1724

Expected output:
4419
2848
2834


Actual output:
[4419, 2003, 2003]


Fixed submission (verdict: Accepted):

mt=[]
high=[0,0,0]
for i in range(10):
    mt.append(int(input()))
    if  mt[i] > high[0]:
        high=[mt[i]]+high[:2]
    elif mt[i] > high[1]:
        high=[high[0]]+[mt[i]]+[high[1]]
    elif mt[i] > high[2]:
        high=high[:2]+[mt[i]]
print ('\n'.join(map(str,high)))

Problem: p00001
Buggy submission (Python3, verdict: Wrong Answer):


first = 0
second = 0
third = 0
i = 0

for i in range(0,9):
    line = int(input())
    
    if first < int(line):
        third = second
        second = first
        first = int(line)
    elif second < int(line):
        third = second
        second = int(line)
    elif third < int(line):
        third = int(line)

print(first)
print(second)
print(third)

Failing test case input:
100
-2
-2
2950
000
145
1
4
2
297

Expected output:
2950
297
145


Actual output:
2950
145
100


Fixed submission (verdict: Accepted):


first = 0
second = 0
third = 0
i = 0

for i in range(0,10):
    line = int(input())
    
    if first < int(line):
        third = second
        second = first
        first = int(line)
    elif second < int(line):
        third = second
        second = int(line)
    elif third < int(line):
        third = int(line)
print(first)
print(second)
print(third)
Problem: p00001
Buggy submission (Python3, verdict: Wrong Answer):


import sys

def top_k_sort(data, k=3, reverse=True):
    data.sort(reverse=True)
    return data[:k]

def main():
    argv = sys.argv
    argc = len(argv)

    data = [int(v) for v in argv[1:]]
    for h in top_k_sort(data):
        print(h)

if __name__ == '__main__':
    main()

Failing test case input:
1819
385
1094
699
453
71
2542
12727
351
94

Expected output:
12727
2542
1819


Actual output:

Fixed submission (verdict: Accepted):


import sys

def top_k_sort(data, k=3, reverse=True):
    data.sort(reverse=True)
    return data[:k]

def main():
    data = []
    for line in sys.stdin:
        data.append(int(line))

    for h in top_k_sort(data):
        print(h)

if __name__ == '__main__':
    main()

Problem: p00001
Buggy submission (Python3, verdict: Wrong Answer):
High = []
for i in range(10):
    High.append(input())
High.sort(reverse = True)

for i in range(3):
    print(High[i])

Failing test case input:
100
94
342
667
500
600
1422
2053
476
205

Expected output:
2053
1422
667


Actual output:
94
667
600


Fixed submission (verdict: Accepted):
High = []
for i in range(10):
    High.append(int(input()))
for i in range(3):
    print(max(High))
    High.remove(max(High))

Problem: p00001
Buggy submission (Python3, verdict: Wrong Answer):
m = []
for i in range(0, 10):
    m.append(input())
m.sort(reverse=True)
for i in range(0, 3):
    print(m[i])

Failing test case input:
100
-2
-2
2950
000
145
1
4
2
297

Expected output:
2950
297
145


Actual output:
4
297
2950


Fixed submission (verdict: Accepted):
m = []
for i in range(0, 10):
    m.append(int(input()))
m.sort(reverse=True)
for i in range(0, 3):
    print(m[i])

Problem: p00001
Buggy submission (Python3, verdict: Wrong Answer):





li = []
for x in range(3):
    s = input()
    s = int(s)
    li.append(s)

li.sort()
li.reverse()

for y in range(3):
    print(li[y])

Failing test case input:
1819
236
0011
269
43
93
3782
6789
-1
43

Expected output:
6789
3782
1819


Actual output:
1819
236
11


Fixed submission (verdict: Accepted):





li = []
for x in range(10):
    s = input()
    s = int(s)
    li.append(s)

li.sort()
li.reverse()

for y in range(3):
    print(li[y])

Problem: p00001
Buggy submission (Python3, verdict: Wrong Answer):
def main():
    a = []
    for i in range(10):
        a.append(input())

    a.sort()
    a.reverse()

    for i in range(3):
        print(i)

if __name__ == '__main__':
    main()

Failing test case input:
1819
645
0011
374
414
62
3676
6789
0
177

Expected output:
6789
3676
1819


Actual output:
0
1
2


Fixed submission (verdict: Accepted):
def main():
    a = []
    for i in range(10):
        a.append(int(input()))

    a.sort()
    a.reverse()

    for i in range(3):
        print(a[i])

if __name__ == '__main__':
    main()
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
(n,m)=map(int,input().split())
a=input().split()
a=list(map(int,a))
l=[]
k=0
a=sorted(a)
for i in range(m-1):
    d=abs(a[i]-a[i+1])
    k=k+d
    l.append(d)

c=abs(a[-1]-a[0]-d)
l.append(c)
l=sorted(l)
l1=sum(l)
print(l1-l[-1])

Failing test case input:
19 3
0 5 25

Expected output:
-1


Actual output:
10


Fixed submission (verdict: Accepted):
(n,m)=map(int,input().split())
a=input().split()
a=list(map(int,a))
l=[]
k=0
a=sorted(a)
for i in range(m-1):
    d=abs(a[i]-a[i+1])
    k=k+d
    l.append(d)

c=n-k
l.append(c)
l=sorted(l)
l1=sum(l)
print(l1-l[-1])

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(len(A)-1):
    A[i]=A[i+1]-A[i]
A[len(A)-1]=K-A[len(A)-1]
print(sum(A)-max(A))

Failing test case input:
37 3
-1 0 91

Expected output:
-54


Actual output:
-53


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

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

Failing test case input:
11 3
0 6 7

Expected output:
5


Actual output:
-2


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

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


Failing test case input:
11 3
2 8 80

Expected output:
-61


Actual output:
78


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

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

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

m = max(m, a[0] + k - a[n-1])

print(m)

Failing test case input:
51 3
2 10 41

Expected output:
20


Actual output:
31


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

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

m = max(m, a[0] + k - a[n-1])

print(k - m)
Problem: p02725
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
k,n = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
right = a[n-1] - a[0]
left = a[0] + 20-a[n-1]
m = min(right,left)
for i in range(1,n):
  ans = 0
  ans = 20-a[i]+a[i-1] 
  m = min(ans,m)
print(m)

Failing test case input:
11 3
3 11 15

Expected output:
3


Actual output:
8


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

Problem: p02725
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
K,N = map(int,input().split())
A = list(map(int,input().split()))
A.append(K)
A.sort()
B = []
for i in range(len(A) - 1):
	B.append(A[i + 1] - A[i])
print(sum(B) - max(B))

Failing test case input:
11 3
3 11 15

Expected output:
3


Actual output:
4


Fixed submission (verdict: Accepted):
K,N = map(int,input().split())
A = list(map(int,input().split()))
B = []
B.append(K - A[-1] + A[0])
for i in range(len(A) - 1):
	B.append(A[i + 1] - A[i])
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()))



AN = A[0]+(K-sum(A))
A2 = A[1:N]
A2.append(AN)

print(sum(A2)-max(A2))


Failing test case input:
-1 3
0 3 29

Expected output:
-27


Actual output:
-30


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


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

print(K-max(A2))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
inputNumber = input()
K = int(inputNumber.split(" ")[0])
N = int(inputNumber.split(" ")[1])

inputNumber = input()
A=inputNumber.split(" ")

A_Length=len(A)

for i in range(A_Length):
    A[i] = int(A[i])

result=0

for i in range(A_Length):
    if i == A_Length - 1:
        if result < (K - A[i]) + A[0]:
            result = (K - A[i]) + A[0]
    else:
        if result < A[i] - A[i-1]:
            result = A[i+1] - A[i]

result = K - result
print(result)





Failing test case input:
12 3
1 1 54

Expected output:
-41


Actual output:
12


Fixed submission (verdict: Accepted):
inputNumber = input()
K = int(inputNumber.split(" ")[0])
N = int(inputNumber.split(" ")[1])

inputNumber = input()
A=inputNumber.split(" ")

A_Length=len(A)

for i in range(A_Length):
    A[i] = int(A[i])

result=0

for i in range(A_Length):
    if i == A_Length - 1:
        if result < (K - A[i]) + A[0]:
            result = (K - A[i]) + A[0]
    else:
        if result < A[i+1] - A[i]:
            result = A[i+1] - A[i]





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

ans=[]
for i in range(n-1):
  ans.append(A[-1]-A[i]+A[max(0,i-1)])
print(min(ans))
  

Failing test case input:
8 3
-2 5 50

Expected output:
-37


Actual output:
43


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

ans=[]
for i in range(n):
  ans.append(A[-1]-A[i])
  A.append(k+A[i])
print(min(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 = []
for i in range(len(A) - 1):
    B.append(A[i + 1] - A[i])
B.append(K - A[-1])

print(sum(sorted(B)[:-1]))

Failing test case input:
8 3
2 8 64

Expected output:
-48


Actual output:
-50


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

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

print(sum(sorted(B)[:-1]))

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 x in range(n-1):
  b=a[x+1]-a[x]
  ans=max(ans,b)
  
c=k-a[n-1]+a[0]

print(max(ans,c))



Failing test case input:
27 3
1 6 41

Expected output:
-8


Actual output:
35


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

print(k-max(ans,c))

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

Failing test case input:
27 3
1 10 41

Expected output:
-4


Actual output:
31


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


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

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

Failing test case input:
27 3
1 6 29

Expected output:
4


Actual output:
-1


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())
A = list(map(int, input().split()))
res = A[0] - A[N-1] + K
for i in range(N-1):
    res = max(abs(A[i]-A[i+1]), res)
print(K-res)
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, n = map(int, input().split())
a = list(map(int, input().split()))

d = [None]*n

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

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

print(k - max(d))

Failing test case input:
20 3
1 5 14

Expected output:
11


Actual output:
10


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

d = [None]*n

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

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

print(k - max(d))

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

Failing test case input:
5 3
2 8 52

Expected output:
-39


Actual output:
[-3, -47, 5]
-50


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

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

print(max)

Failing test case input:
10 3
-1 0 91

Expected output:
-81


Actual output:
91


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

print(k - max)

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

print(min(sum(d[:-1]),sum(d[1:])))

Failing test case input:
8 3
-2 10 50

Expected output:
-32


Actual output:
-4


Fixed submission (verdict: Accepted):
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[-1]+a[0])
d=sorted(d,reverse=True)
print(sum(d[1:]))

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

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


Failing test case input:
7 3
0 5 30

Expected output:
-18


Actual output:
2


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

max1 = 0
for i in range(1,n):
    max1 = max((a[i]-a[i-1]),max1)
max1 = max(max1,(a[0]+(k-a[n-1])))
print(k - max1)
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()]
b = a
a.sort()

ans = 0

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

ans2 = ans
ans2=ans2-2*a[n-1]+a[n-2]+a[0]+k
print(min(ans,ans2))

Failing test case input:
11 3
3 11 15

Expected output:
3


Actual output:
7


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

a.sort()
b=[a[0]+k-a[n-1]]
ans = a[0]+k-a[n-1]

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

ans-=max(b)

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

A.append(A[0]+K)
maxD = 0

for n in range(0, N):
  maxD = max(maxD, A[n+1] - A[n])
  
print(maxD)

Failing test case input:
8 3
-2 10 50

Expected output:
-32


Actual output:
40


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

Problem: p02725
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
k, n = map(int, input().split())
A = list(map(int, input().split()))
if n == 2:
    a1, a2 = A
    print(min(a2 - a1, k + a1 - a2))
else:
    A[-1] -= k
    maximum = 0
    for i in range(n):
        x = A[i] - A[i-1]
        if x > maximum:
            maximum = x
    print(k - maximum)


Failing test case input:
10 3
-2 5 50

Expected output:
-35


Actual output:
-25


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

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

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

Ank = [0] + An[:] + [k]

node = [Ank[i+1] - Ank[i]  for i in range(len(Ank) - 1)]

print(sum(node) - max(node))

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

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

x = k - A[-1]
for i in range(1,n):
    y = A[i]-A[i-1]
    if y > x:
        x = y

print(k-x)

Failing test case input:
20 3
5 10 15

Expected output:
10

Actual output:
15


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

x = k + A[0] - A[n-1]

for i in range(1,n):
    y = A[i]-A[i-1]
    if y > x:
        x = y

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

sorted_A = sorted(A)


dis = []
for i in range(len(sorted_A)-1):
    dis.append(abs(sorted_A[i] - sorted_A[i+1]))

last_dis = abs(sorted_A[-1] - sorted_A[0])

if(last_dis > K/2):
    last_dis -= K

dis.append(last_dis)

print(K - max(dis))

Failing test case input:
27 3
0 5 15

Expected output:
15


Actual output:
17


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

sorted_A = sorted(A)
sorted_A = [i - sorted_A[0] for i in sorted_A]

dis = []
for i in range(len(sorted_A)-1):
    dis.append(abs(sorted_A[i] - sorted_A[i+1]))

last_dis = abs(sorted_A[-1] - sorted_A[0])

if(last_dis >= K/2):
    last_dis = K - last_dis

dis.append(last_dis)

print(K - max(dis))

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

Failing test case input:
5 3
0 8 28

Expected output:
-15


Actual output:
28


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

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

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()))
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 (PyPy3 (2.4.0), verdict: Wrong Answer):
k, n = map(int, input().split())
A = input().split()
a = [int(i) for i in A]

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

for i in range(n):
    if kyori < a[i] - a[i-1]:
        kyori = a[i] - a[i-1]
print(kyori)

Failing test case input:
51 3
2 10 41

Expected output:
20


Actual output:
31


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

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

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

maxx=-float('INF')
for i in range(n-1):
    if houses[i+1]-houses[i]>maxx:
        maxx=houses[i+1]-houses[i]

maxx=max([maxx,k-(houses[-1]-houses[0])])
print(maxx)


Failing test case input:
20 3
1 5 14

Expected output:
11


Actual output:
9


Fixed submission (verdict: Accepted):
k,n=map(int,input().split())
houses=list(map(int,input().split()))
houses.sort()
maxx=-float('INF')
for i in range(n-1):
    if houses[i+1]-houses[i]>maxx:
        maxx=houses[i+1]-houses[i]

maxx=max([maxx,k-(houses[-1]-houses[0])])
print(k-maxx)

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

Failing test case input:
20 3
0 4 64

Expected output:
-40


Actual output:
60


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

Problem: p02725
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
k, n = map(int, input().split())
A = list(map(int, input().split()))
s = A[0]
for i in range(n):
  A[i] -= s
ans = 0
idx = n

for i in range(n):
  if A[i] > k-A[i]:
    ans += k-A[i]
    print(k-A[i], A[i])
    idx = i
    break
ans += A[idx-1]
print(ans)


Failing test case input:
20 3
0 4 64

Expected output:
-40


Actual output:
-44 64
-40


Fixed submission (verdict: Accepted):
k, n = map(int, input().split())
A = list(map(int, input().split()))
s = A[0]
c = [0]*n 
for i in range(n):
  c[i] = k + A[i]
b = A + c 
ans = float('inf')
for i in range(n):
  ans = min(ans, b[i+n-1]-b[i])
print(ans)

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:
27 3
0 5 15

Expected output:
15


Actual output:
12


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 (Python (3.4.3), verdict: Wrong Answer):
def main():
    K, N = map(int,input().split())
    A = list(map(int,input().split()))
    A.append(K)
    B = []
    for i in range(N):
        B.append(A[i+1] - A[i]) 
    
    tmp = max(B)
    print(sum(B) - tmp)

main()

Failing test case input:
27 3
1 5 29

Expected output:
3


Actual output:
2


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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
inputNumber = input()
K = int(inputNumber.split(" ")[0])
N = int(inputNumber.split(" ")[1])

inputNumber = input()
A=inputNumber.split(" ")
for i in range(len(A)):
    A[i] = int(A[i])

result=0

for i in range(len(A)):
    if i == len(A) - 1:
        if result < (K - A[i]) + A[0]:
            result = (K - A[i]) + A[0]
    else:
        if result < A[i] - A[i-1]:
            result = A[i+1] - A[i]

print(result)





Failing test case input:
20 3
0 3 17

Expected output:
6


Actual output:
14


Fixed submission (verdict: Accepted):
inputNumber = input()
K = int(inputNumber.split(" ")[0])
N = int(inputNumber.split(" ")[1])

inputNumber = input()
A=inputNumber.split(" ")

A_Length=len(A)

for i in range(A_Length):
    A[i] = int(A[i])

result=0

for i in range(A_Length):
    if i == A_Length - 1:
        if result < (K - A[i]) + A[0]:
            result = (K - A[i]) + A[0]
    else:
        if result < A[i+1] - A[i]:
            result = A[i+1] - A[i]





result = K - result
print(result)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
inputs = [int(i) for i in input().split()]
K,N = inputs[0],inputs[1]

input_lines = [int(i) for i in input().split()]

max_range = input_lines[0]+(K-input_lines[-1])
for i in range(N):
    if i!=N-1:
        torange = input_lines[i+1]-input_lines[i]
        if torange>max_range:
            max_range = torange
print(max_range)


Failing test case input:
7 3
0 5 17

Expected output:
-5


Actual output:
12


Fixed submission (verdict: Accepted):
inputs = [int(i) for i in input().split()]
K,N = inputs[0],inputs[1]

input_lines = [int(i) for i in input().split()]

max_range = input_lines[0]+(K-input_lines[-1])
for i in range(N):
    if i!=N-1:
        torange = input_lines[i+1]-input_lines[i]
        if torange>max_range:
            max_range = torange
print(K-max_range)

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()
x = a[-1] - a[0]
y = k - a[-1] + a[-2]

print(min(x,y))

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

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

print(k - max(d))
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k,n = map(int, input().split())
an = list(map(int, input().split()))

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

Failing test case input:
1 3
3 6 29

Expected output:
-22


Actual output:
-3


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

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

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

max_distance = K + (A[0] + A[-1])

for i in range(1,N):
  max_distance = max(max_distance, A[i] - A[i-1])
  
print(K - max_distance)

Failing test case input:
27 3
0 5 15

Expected output:
15


Actual output:
-15


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

max_distance = K + (A[0] - A[-1])

for i in range(1,N):
  max_distance = max(max_distance, A[i] - A[i-1])
  
print(K - max_distance)

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

max = 0

for i in range(n-1):
    if(a[i+1]-a[i])>max:
        max= a[i+1]-a[i]

if (k-a[n-1]) + a[0]:
    max = (k-a[n-1]) + a[0]

print(k-max)


Failing test case input:
67 3
-1 6 43

Expected output:
30


Actual output:
44


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

max = 0

for i in range(n-1):
    if(a[i+1]-a[i])>max:
        max= a[i+1]-a[i]

if  (k-a[n-1]) + a[0] >= max:
    max = (k-a[n-1]) + a[0]

print(k-max)

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

Failing test case input:
7 3
0 4 28

Expected output:
-17


Actual output:
-14


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

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(a[0]+k-a[n-1])
c=max(b)
print(c)

Failing test case input:
7 3
0 4 17

Expected output:
-6


Actual output:
13


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(a[0]+k-a[n-1])
c=max(b)
print(k-c)
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int,input().split())
A = list(map(int,input().split()))

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

max = max(length)
sum1 = sum(length) 

if A[0] == 0:
    length.append(K-A[N-1])
else:
    length.append(A[N-1]-A[0])

sum2 = sum(length)-max 

if sum1 >= sum2:
    print(sum2)
else:
    print(sum1)


Failing test case input:
10 3
-2 9 50

Expected output:
-31


Actual output:
52


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

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

max = max(length)
sum1 = sum(length) 

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

sum2 = sum(length)-max 

if sum1 >= sum2:
    print(sum2)
else:
    print(sum1)

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int,input().split())
A = list(map(int, input().split()))
sub = [A[0]+K-A[N-1]]
print(A)
for _ in range(N-1):
    p = A.pop()
    sub.append(K-p)
    K = p
print(sub)
sub.remove(max(sub))
print(sum(sub))

Failing test case input:
27 3
1 6 41

Expected output:
-8


Actual output:
[1, 6, 41]
[-13, -14, 35]
-27


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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def around(K,A):
    N2 = A.pop(0)
    A.append(N2+K)
    return A

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

X = 0
X_min = 1000000000
for j in range(0,len(A)):
    X=0
    X = A[len(A)-1] - A[0]
    X_min = X
    A=around(K,A)
    
print(X_min)

Failing test case input:
20 3
0 9 17

Expected output:
11


Actual output:
12


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

X = 0
space = 0
idx = 0
A.append(A[0]+K)
for j in range(0,len(A)-1):
    X=0
    X = A[j+1] - A[j]
    if space < X:
        space = X
        idx = j
    
print(A[idx] + K - A[idx+1] )

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
 
k, n = map(int, sys.stdin.readline().split())
a = [int(i) for i in sys.stdin.readline().split()]
a.sort()
max_dist = 0
for i in range(1, n):
  if i == n-1:
    max_dist = max(k - a[i - 1] + a[i], max_dist)
  else:
  	max_dist = max(a[i] - a[i - 1], max_dist)
  
sys.stdout.write(str(k - max_dist))

Failing test case input:
7 3
0 8 17

Expected output:
-2


Actual output:
-9

Fixed submission (verdict: Accepted):
import sys
 
k, n = map(int, sys.stdin.readline().split())
a = [int(i) for i in sys.stdin.readline().split()]
a.sort()
max_dist = 0
for i in range(1, n):
	max_dist = max(a[i] - a[i - 1], max_dist)
    
if len(a) != 0:
	max_dist = max(a[0] + k - a[-1], max_dist)
sys.stdout.write(str(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()))

S = [0]*(N+1)

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

Smax = S.index(max(S))

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

Failing test case input:
10 3
0 1 58

Expected output:
-47


Actual output:
-48


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

S = [0]*(N)

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

Smax = S.index(max(S))

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

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


Failing test case input:
20 3
5 10 15

Expected output:
10

Actual output:
15


Fixed submission (verdict: Accepted):

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)

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

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

B += K - A[-1]
print(B - D)


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()))
D = 0

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

D = max(D, K + A[0] - A[-1])
print(K - D)

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):
    d = a[i+1] - a[i]
    m = max(m, d)
d_last = k - a[n-1]
m = max(m, d_last)

res = k - m
print(res)

Failing test case input:
20 3
5 10 15

Expected output:
10

Actual output:
15


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

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

res = k - m
print(res)
Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


K, N = list(map(int, input().strip().split()))
A = list(map(int, input().strip().split()))
m = 0
ind = 0
ans = 0

for i in range(N-1):
  _m = A[i+1] - A[i]
  if _m > m:
    m = _m
    ind = i+1
    last = i

_m = K - A[N-1]
if _m > m:
  m = _m
  ind = 0
  last = N-1




i = ind
while i != last:
  
  if i < N-1:
    ans += A[i+1] - A[i]
    i += 1
  else:
    ans += K - A[i]
    i = 0

print(ans)

Failing test case input:
11 3
3 11 15

Expected output:
3


Actual output:
0


Fixed submission (verdict: Accepted):


K, N = list(map(int, input().strip().split()))
A = list(map(int, input().strip().split()))
m = 0
ind = 0
ans = 0

for i in range(N-1):
  _m = A[i+1] - A[i]
  if _m > m:
    m = _m
    ind = i+1
    last = i

_m = K + A[0] - A[N-1]
if _m > m:
  m = _m
  ind = 0
  last = N-1




i = ind
while i != last:
  
  if i < N-1:
    ans += A[i+1] - A[i]
    i += 1
  else:
    ans += K + A[0] - A[i]
    i = 0

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()))
d=[0]*(N+1)
for n in range(N+1):
    if n==0:
        d[n]=A[0]
    elif n==N:
        d[n]=K-A[n-1]
    else:
        d[n]=A[n]-A[n-1]
if d[0]!=0:
    d=d[1:]
print(sum(d)-max(d))

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()))
d=[0]*(N+1)
if A[0]!=0:
    tmp=A[0]
    A=list(map(lambda x: x-tmp, A))
for n in range(N+1):
    if n==0:
        d[n]=A[0]
    elif n==N:
        d[n]=K-A[n-1]
    else:
        d[n]=A[n]-A[n-1]
print(sum(d)-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()))
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))


Failing test case input:
20 3
5 10 15

Expected output:
10

Actual output:
15


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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
k, n = map(int,input(). split())
lstr_a = input().split(" ")
lint_a = [int(n) for n in lstr_a]
alist = sorted(lint_a)
t = alist.count(0)

for i in range(n-1):
  if alist[i]-alist[i-1]>=k/2:
    answer = k-alist[i]+alist[i-1]
    print(answer)
    break

answer = alist[n-1]-alist[0]
print(answer)

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())
lstr_a = input().split(" ")
lint_a = [int(n) for n in lstr_a]
alist = sorted(lint_a)
t = alist.count(0)
x = 0
for i in range(n-1):
  x = max(alist[i+1]-alist[i], x)
b = k-alist[n-1]+alist[0]
c = max(x,b)
answer = k-c
print(answer)
Problem: p02725
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
K, N = map(int, input().split())
A = list(map(int, input().split()))

max_ = [0, 20+A[0]-A[-1]]

for i in range(1, N):
    tmp = A[i] - A[i-1]
    if tmp > max_[1]:
        max_[0] = i
        max_[1] = tmp
print(K-max_[1])

Failing test case input:
11 3
0 6 7

Expected output:
5


Actual output:
-2


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


max_ = [0, K+A[0]-A[-1]]


for i in range(1, N):
    tmp = A[i] - A[i-1]
    if tmp > max_[1]:
        max_[0] = i
        max_[1] = tmp
print(K-max_[1])

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
n= [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
lake = n[0]
num_ie = n[1]
kyori = []
for i in range(num_ie-1):
    kyori.append(l[i+1]-l[i])
kyori.append(lake - l[num_ie-1] + l[0])
output = 0
output += sum(kyori) 
output -= max(kyori)

print(kyori)
print(output)

Failing test case input:
11 3
2 8 44

Expected output:
-25


Actual output:
[6, 36, -31]
-25


Fixed submission (verdict: Accepted):
n= [int(x) for x in input().split()]
l = [int(x) for x in input().split()]
lake = n[0]
num_ie = n[1]
kyori = []
for i in range(num_ie-1):
    kyori.append(l[i+1]-l[i])
kyori.append(lake - l[num_ie-1] + l[0])
output = 0
output += sum(kyori) 
output -= max(kyori)

print(output)

Problem: p02725
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):


import sys


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    k, n = map(int, sys.stdin.readline().split())
    a = list(map(int, sys.stdin.readline().split()))
    print(a[-1]-a[0])


if __name__ == "__main__":
    
    main()


Failing test case input:
10 3
-2 5 50

Expected output:
-35


Actual output:
52


Fixed submission (verdict: Accepted):


import sys


def IOE():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("output.txt", "w")


def main():
    k, n = map(int, sys.stdin.readline().split())
    a = list(map(int, sys.stdin.readline().split()))
    minn = min(a[n - 1] - a[0], int(10e10))
    for i in range(n):
        ans = (a[n - 1] - a[i]) + (k + a[i - 1] - a[n - 1])
        minn = min(ans, minn)
    print(minn)


if __name__ == "__main__":
    
    main()
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:
      r = max(As) - sorted(As)[-2]
      break
    solve = int(As[x] - As[x-1])
    if 0 <= solve:
      r += solve
  print(r)

if __name__ == "__main__":
  main()

Failing test case input:
37 3
0 4 91

Expected output:
-50


Actual output:
87


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())
lst = [int(x) for x in input().split()]
a = 0
for i in range(N - 1):
    a = max(a, lst[i + 1] - lst[i])
print(K - a - lst[0])


Failing test case input:
20 3
1 5 14

Expected output:
11


Actual output:
10


Fixed submission (verdict: Accepted):
K, N = map(int, input().split())
lst = [int(x) for x in input().split()]
a = lst[0]
m = 0
for i in range(N - 1):
    m = max(m, (lst[i + 1] - a) - (lst[i] - a))

print(K - max(m, K - (lst[-1] - a)))

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
K, N = map(int,input().split())
A = list(map(int, input().split()))
a = A[0]
sub = []
for _ in range(N):
    p = A.pop()
    sub.append(K-p)
    K = p
sub[0] += a
print(sub)
sub.remove(max(sub))
print(sum(sub))

Failing test case input:
7 3
1 8 28

Expected output:
-13


Actual output:
[-20, 20, 7]
-13


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

Problem: p02725
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
X = input().split()
K = int(X[0])
N = int(X[1])
Y = input().split()
Z = []
for i in range(N):
    Z.append(int(Y[i]))
result = Z[0]+ K - Z[N-1]

for i in range(N):
    if result < Z[i] - Z[i-1]:
        result = Z[i] - Z[i -1]
    i = i + 1
print(result)


Failing test case input:
2 3
-2 5 17

Expected output:
-10


Actual output:
12


Fixed submission (verdict: Accepted):
X = input().split()
K = int(X[0])
N = int(X[1])
Y = input().split()
Z = []
for i in range(N):
    Z.append(int(Y[i]))
result = Z[0]+ K - Z[N-1]

for i in range(N):
    if result < Z[i] - Z[i-1]:
        result = Z[i] - Z[i -1]
    i = i + 1
print(K - result)
Problem: p02725
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

a = sorted(a)
if a[0] == 0:
    if n > 3:
        print(min(a[1] + (k - a[2]), a[n - 1]))
    else:
        print(abs(a[n - 1] - a[1]))
else:
    print(abs(a[n - 1] - a[0]))


Failing test case input:
10 3
-1 0 91

Expected output:
-81


Actual output:
92


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

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

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

ma = 0
for i in range(n):
    ma = max(ma, diff[i])

print(k - ma)

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



def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))

k,n = invr()
nums = inlt()
ans = min(nums[-1] - nums[0],k - (nums[1]))
for i in range(1,n - 1):
    
    result = min(k - (nums[i] - nums[i - 1]), \
             k - abs(nums[i + 1] - nums[i]))
    
    if result < ans:
        ans = result

ans = min(ans,k - (nums[-1] - nums[-2]))
print(ans)


Failing test case input:
20 3
5 11 15

Expected output:
10


Actual output:
9


Fixed submission (verdict: Accepted):



def inp():
    return(int(input().rstrip()))
def inlt():
    return(list(map(int,input().rstrip().split())))
def insr():
    s = input().rstrip()
    return(s[:len(s) - 1])
def invr():
    return(map(int,input().rstrip().split()))

k,n = invr()
nums = inlt()
ans = min(nums[-1] - nums[0],k - (nums[1] - nums[0]))
for i in range(1,n - 1):
    
    result = min(k - (nums[i] - nums[i - 1]), \
             k - abs(nums[i + 1] - nums[i]))
    
    if result < ans:
        ans = result

ans = min(ans,k - (nums[-1] - nums[-2]))
print(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):
  if a[i] >= int(K/2):
    a[i] = a[i]-int(K/2)
  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:
2 3
-2 5 17

Expected output:
-10


Actual output:
-16


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)