Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
s = []
for i in range(5):
    s.apppend(int(input())
k = int(input())
for i in range(4):
    if s[i+1]-s[i] >k:
        print(":(")
        break
else:
    print("Yay!")

Fixed submission:
s = []
for i in range(5):
    s.append(int(input()))
k = int(input())
for i in range(4):
    if s[i+1]-s[0] >k:
        print(":(")
        break
else:
    print("Yay!")

Buggy python submission (verdict: Runtime Error):
s = []
for i in range(5):
    s.apppend(int(input()))
k = int(input())
for i in range(4):
    if s[i+1]-s[i] >k:
        print(":(")
        break
else:
    print("Yay!")

Fixed submission:
s = []
for i in range(5):
    s.append(int(input()))
k = int(input())
for i in range(4):
    if s[i+1]-s[0] >k:
        print(":(")
        break
else:
    print("Yay!")
Buggy python submission (verdict: Runtime Error):
s = input()
if s[5] == 1:
    print("TBD")
else:
    if s[6]>4:
        print("Heisei")
    else:
        print("TBD")

Fixed submission:
s = input()
if int(s[5]) == 1:
    print("TBD")
else:
    if int(s[6])<5:
        print("Heisei")
    else:
        print("TBD")
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0

for i in range(1,n):
    for s in range(1,min(k,i)+1):
        dp[i] = min(dp[i],dp[i-s]+abs(h[i]-h[i-s]))

print(dp[-1])

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0

for i in range(1,n):
    for s in range(1,min(k,i)+1):
        dp[i] = min(dp[i],dp[i-s]+abs(h[i]-h[i-s]))

print(dp[-1])

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0

for i in range(1,n):
    for s in range(min(k,i)+1):
        dp[i] = min(dp[i],dp[i-s]+abs(h[i]-h[i-s]))

print(dp[-1])

Fixed submission:
n,k = map(int,input().split())
h = list(map(int,input().split()))
dp = [float("inf")]*n
dp[0] = 0

for i in range(1,n):
    for s in range(1,min(k,i)+1):
        dp[i] = min(dp[i],dp[i-s]+abs(h[i]-h[i-s]))

print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

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

v1 = []

v2 = []

q = 0

for i in v:
    if q == 0:
        v1.append(i)
        q = 1
    else:
        v2.append(i)
        q = 0
        
maxv1 = 0

maxv2 = 0

for i in set(v1):
    a = tuple(v1).count(i)
    if a>maxv1:
        maxv1 = a
        
for i in set(v2):
    b = tuple(v2).count(i)
    if b>maxv2:
        maxv2 = b
        
if v1 == v2:
    print(n//2)
else:
    print(n-maxv1-maxv2)

Fixed submission:
import collections

n = int(input())

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

v1 = v[::2]

v2 = v[1::2]
        
if len(set(v))==1:
    print(n//2)
else:
    maxv1 = collections.Counter(v1).most_common()

    maxv2 = collections.Counter(v2).most_common()


    if maxv1[0][0] == maxv2[0][0]:    
        ans1 = (len(v1) - maxv1[0][1]) + (len(v2) - maxv2[1][1])
        ans2 = (len(v1) - maxv1[1][1]) + (len(v2) - maxv2[0][1])
        print(min(ans1, ans2))
    else:
        ans = (len(v1) - maxv1[0][1]) + (len(v2) - maxv2[0][1])
        print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

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

v1 = []

v2 = []

q = 0

for i in v:
    if q == 0:
        v1.append(i)
        q = 1
    else:
        v2.append(i)
        q = 0
        
maxv1 = 0

maxv2 = 0

for i in set(v1):
    a = v1.count(i)
    if a>maxv1:
        maxv1 = a
        
for i in set(v2):
    b = v2.count(i)
    if b>maxv2:
        maxv2 = b
        
if v1 == v2:
    print(n//2)
else:
    print(n-maxv1-maxv2)

Fixed submission:
import collections

n = int(input())

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

v1 = v[::2]

v2 = v[1::2]
        
if len(set(v))==1:
    print(n//2)
else:
    maxv1 = collections.Counter(v1).most_common()

    maxv2 = collections.Counter(v2).most_common()


    if maxv1[0][0] == maxv2[0][0]:    
        ans1 = (len(v1) - maxv1[0][1]) + (len(v2) - maxv2[1][1])
        ans2 = (len(v1) - maxv1[1][1]) + (len(v2) - maxv2[0][1])
        print(min(ans1, ans2))
    else:
        ans = (len(v1) - maxv1[0][1]) + (len(v2) - maxv2[0][1])
        print(ans)
Buggy python submission (verdict: Runtime Error):
h,w = map(int,input().split())

f = []

for i in range(h):
    f.append(list(input()))
    
a = []
    
for i in range(len(f)):
    if f[i] == ["."]*len(f[i]):
        a.append(i)
        
for i in a:
    del f[i]
    for s in range(len(a)):
        a[s] -= 1
        
f2 = []

for i in range(w):
    s = []
    
    for k in f:
        s.append(k[i])
        
    f2.append(s)
    
b = []
    
for i in range(len(f2)):
    if f2[i] == ["."]*len(f2[i]):
        b.append(i)
        
for i in b:
    del f2[i]
    for s in range(len(b)):
        b[s] -= 1
        
ff = []

for i in range(len(f2)):
    s = []
    
    for k in f2:
        s.append(k[i])
        
    ff.append(s)
        
for i in ff:
    for s in range(len(i)-1):
        print(i[s],end = "")
    
    print(i[-1])

Fixed submission:
h,w = map(int,input().split())

f = []

for i in range(h):
    f.append(list(input()))
    
a = []
    
for i in range(len(f)):
    if f[i] == ["."]*len(f[i]):
        a.append(i)
        
for i in a:
    del f[i]
    for s in range(len(a)):
        a[s] -= 1
        
f2 = []

for i in range(w):
    s = []
    
    for k in f:
        s.append(k[i])
        
    f2.append(s)
    
b = []
    
for i in range(len(f2)):
    if f2[i] == ["."]*len(f2[i]):
        b.append(i)
        
for i in b:
    del f2[i]
    for s in range(len(b)):
        b[s] -= 1
        
ff = []

for i in range(len(f2[0])):
    s = []
    
    for k in f2:
        s.append(k[i])
        
    ff.append(s)
        
for i in ff:
    for s in range(len(i)-1):
        print(i[s],end = "")
    
    print(i[-1])
Buggy python submission (verdict: Runtime Error):
s = list(input())

k = int(input())

cnt = 0

if len(s) == 1:
    print(s[0])
else:
    if s[0] == "1":
        while s[0] == "1":
            cnt += 1
            del s[0]
        if cnt>=k:
            print(1)
        else:
            print(s[0])
            
    else:
        print(s[0])

Fixed submission:

s = list(input())

k = int(input())

cnt = 0

if len(s) == 1:
    print(s[0])
else:
    if s[0] == "1":
        
        while s[0] == "1":
            cnt += 1
            del s[0]
            if cnt>=k:
                print(1)
                break
            
        if cnt<k:
            print(s[0])
            
    else:
        print(s[0])

Buggy python submission (verdict: Runtime Error):
s = list(input())

if s[0] != "1":
    print(int(s[0]))
else:
    print(int(s[1]))
    
    

Fixed submission:

s = list(input())

k = int(input())

cnt = 0

if len(s) == 1:
    print(s[0])
else:
    if s[0] == "1":
        
        while s[0] == "1":
            cnt += 1
            del s[0]
            if cnt>=k:
                print(1)
                break
            
        if cnt<k:
            print(s[0])
            
    else:
        print(s[0])
Buggy python submission (verdict: Runtime Error):
s = list(input())
al = list("abcdefghijklmnopqrstuvwxyz")
if s[0] == "A" and s[-1] in al and s[1] in al:
    del s[0]
    del s[0]
    del s[-1]
    f = 0
    for i in s:
        if i == "C":
            if f == 1:
                print("WA")
                break
            else:
                f = 1
                continue
        else:
            if i in al:
                continue
            else:
                print("WA")
                break
    else:
        if f = 1:
            print("AC")
        else:
            print("WA")
else:
    print("WA")

Fixed submission:
s = list(input())
al = list("abcdefghijklmnopqrstuvwxyz")
if s[0] == "A" and s[-1] in al and s[1] in al:
    del s[0]
    del s[0]
    del s[-1]
    f = 0
    for i in s:
        if i == "C":
            if f == 1:
                print("WA")
                break
            else:
                f = 1
                continue
        else:
            if i in al:
                continue
            else:
                print("WA")
                break
    else:
        if f == 1:
            print("AC")
        else:
            print("WA")
else:
    print("WA")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int,input().split()))
y = x.copy()
y.sort()
z = set(x)
t1 = y[n//2-1]
t2 = y[n//2]
idx = dict([])
for i in z:
    idx[i] = y.index(i)
for i in x:
    t = idx[i]
    if t<n//2:
        print(t2)
    else:
        print(t1)

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
y = x.copy()
y.sort()
z = set(x)
t1 = y[n//2-1]
t2 = y[n//2]
idx = dict([])
idx[y[0]] = 0
l = y[0]
cnt = 0
for i in y:
    if i == l:
        cnt += 1
        continue
    else:
        idx[i] = cnt
        l = i
        cnt += 1

for i in x:
    t = idx[i]
    if t<n//2:
        print(t2)
    else:
        print(t1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int,input().split()))
y = x.copy()
y.sort()
t1 = y[n//2-1]
t2 = y[n//2]
y = tuple(y)
for i in x:
    t = y.index(i)
    if t<n//2:
        print(t2)
    else:
        print(t1)

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
y = x.copy()
y.sort()
z = set(x)
t1 = y[n//2-1]
t2 = y[n//2]
idx = dict([])
idx[y[0]] = 0
l = y[0]
cnt = 0
for i in y:
    if i == l:
        cnt += 1
        continue
    else:
        idx[i] = cnt
        l = i
        cnt += 1

for i in x:
    t = idx[i]
    if t<n//2:
        print(t2)
    else:
        print(t1)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int,input().split()))
y = x.copy()
y.sort()
t1 = y[n//2-1]
t2 = y[n//2]
for i in x:
    t = y.index(i)
    if t<n//2:
        print(t2)
    else:
        print(t1)

Fixed submission:
n = int(input())
x = list(map(int,input().split()))
y = x.copy()
y.sort()
z = set(x)
t1 = y[n//2-1]
t2 = y[n//2]
idx = dict([])
idx[y[0]] = 0
l = y[0]
cnt = 0
for i in y:
    if i == l:
        cnt += 1
        continue
    else:
        idx[i] = cnt
        l = i
        cnt += 1

for i in x:
    t = idx[i]
    if t<n//2:
        print(t2)
    else:
        print(t1)
Buggy python submission (verdict: Runtime Error):
a,b = map(int,input().split())

x = int(str(a)+str(b))

for i in x:
    if i**2 == x:
        print("Yes")
        break
    elif i**2<x:
        continue
    else:
        print("No")
        break

Fixed submission:
a,b = map(int,input().split())

x = int(str(a)+str(b))

for i in range(x):
    if i**2 == x:
        print("Yes")
        break
    elif i**2<x:
        continue
    else:
        print("No")
        break
Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
ans = 0
for i in range(1,n+1):
    s = 0
    for t in str(i):
        s　 += int(t)
    if a-1< s < b+1:
        ans += str(i)
print(ans)

Fixed submission:
n,a,b = map(int,input().split())
ans = 0
for i in range(1,n+1):
    s = 0
    for t in str(i):
        s += int(t)
    if a-1< s < b+1:
        ans += i
print(ans)

Buggy python submission (verdict: Runtime Error):
n,a,b = map(int,input().split())
ans = 0
for i in range(1,n+1):
    if a-1 < sum(list(str(i))) < b+1:
        ans += i
print(ans)

Fixed submission:
n,a,b = map(int,input().split())
ans = 0
for i in range(1,n+1):
    s = 0
    for t in str(i):
        s += int(t)
    if a-1< s < b+1:
        ans += i
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
x = list(map(int,input().split()))
y = set(x)
s = []
for i in y:
    s.append(x.count(i))
s.sort()
ans = 0
for i in range(len(s)-k):
    ans += s[i]
print(ans)

Fixed submission:
import collections as c
n,k = map(int,input().split())
x = list(map(int,input().split()))
y = c.Counter(x)
s = []
for i in y.items():
    s.append([i[1],i[0]])
s.sort()
ans = 0
for i in range(len(s)-k):
    ans += s[i][0]
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
k = int(input())
x = list(map(int,input().split()))
ans = 0

for i in x:
  ans += min(abs(x-k),x)
  
print(ans)

Fixed submission:
n = int(input())
k = int(input())
x = list(map(int,input().split()))
ans = 0

for i in x:
  ans += min(abs(i-k),i)*2
  
print(ans)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = list(map(int,input(),split()))
s = [0]*max(a)+2
for i in a:
    i += 1
    s[i-1] += 1
    s[i] += 1
    s[i+1] += 1

Fixed submission:
n = int(input())
a = list(map(int,input().split()))
s = [0]*(max(a)+4)
for i in a:
    s[i] += 1
    s[i+1] += 1
    s[i+2] += 1

print(max(s))
Buggy python submission (verdict: Runtime Error):
al = list("abcdefghijklmnopqrstuvwxyz")

s = list(input())
for i in s:
    if i in al:
        del al[al.index(i)]
        
if len(s) == 0:
    print("None")
else:
    print(al[0])

Fixed submission:
al = list("abcdefghijklmnopqrstuvwxyz")

s = list(input())
for i in s:
    if i in al:
        del al[al.index(i)]
        
if len(al) == 0:
    print("None")
else:
    print(al[0])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

ans = 1

while ans<=n:
    if ans*2>n:
        print(ans)
    else:
        ans *= 2

Fixed submission:
n = int(input())

ans = 1

while ans<=n:
    if ans*2>n:
        print(ans)
        break
    else:
        ans *= 2
Buggy python submission (verdict: Runtime Error):
x,y = map(int,input().split())
for i in range(x+1):
    print("#",end = "")
print("#")
for i in range(y):
    print("#"+input()+"#")
for i in range(x+1):
    print("#",end = "")
print("#")

Fixed submission:
y,x = map(int,input().split())
for i in range(x+1):
    print("#",end = "")
print("#")
for i in range(y):
    print("#"+input()+"#")
for i in range(x+1):
    print("#",end = "")
print("#")
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
print(k*((k-1)**(n-1))

Fixed submission:
n,k = map(int,input().split())
print(k*((k-1)**(n-1)))
Buggy python submission (verdict: Time Limit Exceeded):
import bisect
N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(0,N-1):
    for j in range(i+1,N):
        D=L[i]+L[j]
        ans+=bisect.bisect_left(L[j+1:],D)
print(ans)

Fixed submission:
N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(0,N-1):
    for j in range(i+1,N):
        D=L[i]+L[j]
        l=j
        r=N
        while r-l>1:
            med=(l+r)//2
            if D>L[med]:
                l=med
            else:
                r=med
        ans+=l-j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
D,l,r=0,0,0
for i in range(0,N-1):
    for j in range(i+1,N):
        D=L[i]+L[j]
        l=j
        r=N
        while r-l>1:
            med=(l+r)//2
            if D>L[med]:
                l=med
            else:
                r=med
        ans+=l-j
print(ans)

Fixed submission:
N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(0,N-1):
    for j in range(i+1,N):
        D=L[i]+L[j]
        l=j
        r=N
        while r-l>1:
            med=(l+r)//2
            if D>L[med]:
                l=med
            else:
                r=med
        ans+=l-j
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(0,N-1):
    for j in range(i+1,N):
        D=L[i]+L[j]
        l=j
        r=N
        while r-l>1:
            med=(l+r)//2
            if D>L[med]:
                l=med
            else:
                r=med
        ans+=l-j
print(ans)

Fixed submission:
N=int(input())
L=sorted(list(map(int,input().split())))
ans=0
for i in range(0,N-1):
    for j in range(i+1,N):
        D=L[i]+L[j]
        l=j
        r=N
        while r-l>1:
            med=(l+r)//2
            if D>L[med]:
                l=med
            else:
                r=med
        ans+=l-j
print(ans)
Buggy python submission (verdict: Runtime Error):
N=long(input())
print(N**3)

Fixed submission:
N=int(input())
print(N**3)
Buggy python submission (verdict: Runtime Error):
N,A,B,C=[input() for i in range(4)]
ans=0
for i in range(N):
    if A[i]!=B[i] and A[i]!=C[i] and B[i]!=C[i]:
        ans+=2
    elif A[i]!=B[i] or A[i]!=C[i]:
        ans+=1
print(ans)

Fixed submission:
N=int(input())
A,B,C=[input() for i in range(3)]
ans=0
for i in range(N):
    if A[i]!=B[i] and A[i]!=C[i] and B[i]!=C[i]:
        ans+=2
    elif A[i]!=B[i] or A[i]!=C[i]:
        ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
N,H,W=[input() for i in range(3)]
print((N-H+1)*(N-W+1))

Fixed submission:
N,H,W=[int(input()) for i in range(3)]
print((N-H+1)*(N-W+1))
Buggy python submission (verdict: Runtime Error):
N=int(input())
h=list(map(int,input().split()))
memo=[-1 for i in range(N)]
memo[0]=0
def dp(i):
    if memo[i]!=-1:
        return memo[i]
    cos=dp(i-1)+abs(h[i]-h[i-1])
    if i-2>=0:
        cos=min(cos,dp(i-2)+abs(h[i]-h[i-2]))
    memo[i]=cos
    return cos
print(dp(N-1))

Fixed submission:
import sys
sys.setrecursionlimit(int(3e6))
N=int(input())
h=list(map(int,input().split()))

memo=[-1 for i in range(N)]
memo[0]=0
def dp(i):
    if memo[i]!=-1:
        return memo[i]
    cos=dp(i-1)+abs(h[i]-h[i-1])
    if i-2>=0:
        cos=min(cos,dp(i-2)+abs(h[i]-h[i-2]))
    memo[i]=cos
    return cos
print(dp(N-1))
Buggy python submission (verdict: Time Limit Exceeded):
# 2020/07/25
# M-SOLUTIONS プロコンオープン 2020 - C

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

# Calc
pt = a[0]

for i in range(1, k):
    pt = pt * a[i]

for i in range(k, n):
    bef_pt = pt
    pt = pt * a[i] // a[i-k] 

    # Output
    if bef_pt < pt:
        print('Yes')
    else:
        print('No')


Fixed submission:
# 2020/07/25
# M-SOLUTIONS プロコンオープン 2020 - C

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

# Calc
for i in range(k, n):
    # Output
    if a[i] > a[i-k]:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
# 2020/07/25
# M-SOLUTIONS プロコンオープン 2020 - C

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

# Calc
pt = a[0]
km1 = k - 1

for i in range(k):
    pt = pt * a[i]

for i in range(k, n):
    bef_pt = pt
    pt = pt / a[i-k] * a[i]

    # Output
    if bef_pt < pt:
        print('Yes')
    else:
        print('No')


Fixed submission:
# 2020/07/25
# M-SOLUTIONS プロコンオープン 2020 - C

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

# Calc
for i in range(k, n):
    # Output
    if a[i] > a[i-k]:
        print('Yes')
    else:
        print('No')

Buggy python submission (verdict: Time Limit Exceeded):
# 2020/07/25
# M-SOLUTIONS プロコンオープン 2020 - C

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

# Calc
pt = a[0]
for i in range(1, n):
    if i <= k - 1:
        pt = pt * a[i]
    else: # i > k - 1
        bef_pt = pt
        pt = pt / a[i-k] * a[i]
        # Output
        if bef_pt < pt:
            print('Yes')
        else:
            print('No')


Fixed submission:
# 2020/07/25
# M-SOLUTIONS プロコンオープン 2020 - C

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

# Calc
for i in range(k, n):
    # Output
    if a[i] > a[i-k]:
        print('Yes')
    else:
        print('No')
Buggy python submission (verdict: Runtime Error):
# 2020/04/04
# AtCoder Beginner Contest 161 - B

# Input
n, m = map(int,input().split())
a = list(map(int,input().split()))

# Init
sump = 0
sump_m = 0

# Calc
for i in range(n):
    sump = sump + a[i]

a.sort()
a.reverse()

ans = 'Yes'
for i in range(m):
    if a[m] < sump / (4 * m):
        ans = 'No'

# Output
print(ans)


Fixed submission:
# 2020/04/04
# AtCoder Beginner Contest 161 - B

# Input
n, m = map(int,input().split())
a = list(map(int,input().split()))

# Init
sump = 0
sump_m = 0

# Calc
for i in range(n):
    sump = sump + a[i]

a.sort()
a.reverse()

ans = 'Yes'
for i in range(m):
    if a[i] < sump / (4 * m):
        ans = 'No'

# Output
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
# 2020/02/09
# AtCoder Beginner Contest 154 - D

# Input
n, k = map(int,input().split())
p = list(map(int,input().split()))

acm = [0] * n

# Calc
for i in range(k-1, n):
    for j in range(i-k+1, i+1):
        acm[i] = acm[i] + p[j] + 1

ans = max(acm) / 2

# Output
print(ans)


Fixed submission:
# 2020/02/09
# AtCoder Beginner Contest 154 - D

# Input
n, k = map(int,input().split())
p = list(map(int,input().split()))

acm = [0] * n

# Calc
for i in range(n):
    if i-k < 0:
        minu = 0
    else:
        minu = p[i-k]
    acm[i] = acm[i-1] + p[i] - minu

ans = (max(acm) + k) / 2

# Output
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
# 2020/02/09
# AtCoder Beginner Contest 154 - D

# Input
n, k = map(int,input().split())
p = list(map(int,input().split()))

acm = [0] * n

# Calc
for i in range(k-1, n):
    for j in range(i-k+1, i+1):
        acm[i] = acm[i] + p[j] + 1

ans = max(acm) / 2

# Output
print(ans)


Fixed submission:
# 2020/02/09
# AtCoder Beginner Contest 154 - D

# Input
n, k = map(int,input().split())
p = list(map(int,input().split()))

acm = [0] * n

# Calc
for i in range(n):
    if i-k < 0:
        minu = 0
    else:
        minu = p[i-k]
    acm[i] = acm[i-1] + p[i] - minu

ans = (max(acm) + k) / 2

# Output
print(ans)
Buggy python submission (verdict: Runtime Error):
# 2019/11/23
# DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選 - B

# Binary Search
def binSearch (tlis, tval):
    lf = 0
    rg = len(tlis)
    while(lf <= rg):
        ct = int((lf + rg) / 2)
        if tlis[ct] < tval:
            lf = ct + 1
        elif tlis[ct] > tval:
            rg = ct - 1
        else:
            return ct
    return ct

# Input
n = int(input())
a = list(map(int,input().split()))
acm_a = list()
acm_a.append(0)

# Sum
for i in range(len(a)):
    acm_a.append(a[i] + acm_a[i])

# Calc Center
center = acm_a[len(a)] / 2
ctidx = binSearch(acm_a, center)

if (center - acm_a[ctidx]) < (acm_a[ctidx] - center):
    ans = (acm_a[len(a)] - acm_a[ctidx + 1]) - acm_a[ctidx+1]
elif (center - acm_a[ctidx]) > (acm_a[ctidx] - center):
    ans = acm_a[ctidx+1] - (acm_a[len(a)] - acm_a[ctidx + 1])
else:
    ans = 0

# Output
print(ans)


Fixed submission:
# 2019/11/23
# DISCO presents ディスカバリーチャンネル コードコンテスト2020 予選 - B

# Binary Search
def binSearch (tlis, tval):
    lf = 0
    rg = len(tlis)
    while(lf <= rg):
        ct = int((lf + rg) / 2)
        if tlis[ct] < tval:
            lf = ct + 1
        elif tlis[ct] > tval:
            rg = ct - 1
        else:
            return ct
    return ct

# Input
n = int(input())
a = list(map(int,input().split()))
acm_a = list()
acm_a.append(0)

# Sum
for i in range(len(a)):
    acm_a.append(a[i] + acm_a[i])

acm_a.append(acm_a[len(a)])
# Calc Center
center = acm_a[len(a)] / 2
ctidx = binSearch(acm_a, center)

ans = min(abs((acm_a[len(a)] - acm_a[ctidx-1]) - acm_a[ctidx-1]), abs((acm_a[len(a)] - acm_a[ctidx]) - acm_a[ctidx]), abs((acm_a[len(a)] - acm_a[ctidx+1]) - acm_a[ctidx+1]))

# Output
print(ans)