Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
N=int(input())
T=list(map(int,input().split()))
M=int(input())
total=0
for i in range(N):
    total+=T[i]
for i in range(M):
    K=total
    P,X=map(int,input().split())
    K=K-T[i]
    K+=X
    print(K)

Fixed submission:
N=int(input())
T=list(map(int,input().split()))
M=int(input())
total=0
for i in range(N):
    total+=T[i]
for i in range(M):
    K=total
    P,X=map(int,input().split())
    K=K-T[P-1]
    K+=X
    print(K)
Buggy python submission (verdict: Time Limit Exceeded):
a,b=map(int,input().split())
K=1
for i in range(a,b+1):
    K*=i
if K>0:
    print('Positive')
elif K<0:
    print('Negative')
else:
    print('Zero')

Fixed submission:
a,b=map(int,input().split())
K=1
if a>0:
    print('Positive')
elif a<=0 and b>=0:
    print('Zero')
elif (b-a)%2==0:
    print('Negative')
else:
    print('Positive')
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
 
count = 0
 
for i in range(s):
  if s[i] != t[i]:
    count += 1
    
 print(count)

Fixed submission:
s = list(input())
t = list(input())
count = 0

for i in range(len(s)):
  if s[i] != t[i]:
    count += 1

print(count)

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

count = 0
 
for i in range(s):
  if s[i] != t[0]:
    count += 1
    
 print(count)

Fixed submission:
s = list(input())
t = list(input())
count = 0

for i in range(len(s)):
  if s[i] != t[i]:
    count += 1

print(count)

Buggy python submission (verdict: Runtime Error):
s, t = input().split()
count = 0

for i in range(s):
  if s[i] != t[0]:
    count += 1
    
 print(count)

Fixed submission:
s = list(input())
t = list(input())
count = 0

for i in range(len(s)):
  if s[i] != t[i]:
    count += 1

print(count)
Buggy python submission (verdict: Runtime Error):
k = int(inut())
a, b = map(int, input().split())

for i in range(b-a):
  if (a + i) % k == 0:
    print("OK")
  else:
    print("NG")

Fixed submission:
k = int(input())
a, b = map(int, input().split())
count = 0
 
for i in range(b-a+1):
  if (a + i) % k == 0:
    count += 1
  
print("OK" if count > 0 else "NG")
Buggy python submission (verdict: Runtime Error):
s = input()

print("Yes" if s[3]==s[4] and s[5]==s[6] else "No")

Fixed submission:
s = input()

print("Yes" if s[2] == s[3] and s[4] == s[5] else "No")
Buggy python submission (verdict: Runtime Error):
li = input().split()

if li[1] == "+":
  print(int(li[0]+li[2]))
else:
  print(int(li[0]-li[2]))
  


Fixed submission:
li = input().split()
 
if li[1] == "+":
  print(int(li[0])+int(li[2]))
else:
  print(int(li[0])-int(li[2]))
Buggy python submission (verdict: Runtime Error):
N, D  = [int(i) for i in input().split()]
X = int(0)
Y = int(0)
B = int(0)
Z = int(0)
for i in range(N):
  A = []
  A = [int(N) for N in input().split()]
  X = A[0]
  Y = A[1]
  print(Z = ((X**2+Y**2)**0.5))
  if Z<= D:
    B+=1
print(B)


Fixed submission:
N, D  = [int(i) for i in input().split()]
X = int(0)
Y = int(0)
B = int(0)
Z = int(0)
for i in range(N):
  A = []
  A = [int(N) for N in input().split()]
  X = A[0]
  Y = A[1]
  Z = ((X**2+Y**2)**0.5)
  if Z<= D:
    B+=1
print(B)
Buggy python submission (verdict: Runtime Error):
N=input()
N=int(input())
N=str(N)
N = (N[-1])
if (N==2 or N==4 or N==5 or N==7 or N==9):
  print("hon")
elif (N==0 or N==1 or N==6 or N==8):
  print("pon") 
elif (N==3):
  print("bon")

Fixed submission:
N=int(input())
N=str(N)
N = int(N[-1])
if (N==2 or N==4 or N==5 or N==7 or N==9):
  print("hon")
elif (N==0 or N==1 or N==6 or N==8):
  print("pon") 
else:
  print("bon")
Buggy python submission (verdict: Runtime Error):
n = int(input())
m = [int(i) for i in input().split()]
mi = 2*10**5+1
h = 0
if n!=1:
  for i in range (n):
    if mi>m[i]:
      mi=m[i]
      h+=1
    g+=1
  print(h)
else:
  print(n)

Fixed submission:
n = int(input())
m = [int(i) for i in input().split()]
mi = 2*10**5+1
h = 0

for i in range (n):
  if mi>m[i]:
    mi=m[i]
    h+=1

    
print(h)

Buggy python submission (verdict: Runtime Error):
n = int(input())
m = [int(i) for i in input().split()]
mi = 2*10**5+1
h = 0
if n!=1:
  for i in range (n):
    if mi>m[i]:
      mi=m[i]
      h+=1
    g+=1
  print(h)
else:
  print(n)

Fixed submission:
n = int(input())
m = [int(i) for i in input().split()]
mi = 2*10**5+1
h = 0

for i in range (n):
  if mi>m[i]:
    mi=m[i]
    h+=1

    
print(h)

Buggy python submission (verdict: Runtime Error):
n = int(input())
m = [int(i) for i in input().split()]
mi = 2*10**5+1
h = 0
if n!=1:
  for i in range (n):
    if mi>m[i]:
      mi=m[i]
      h+=1
    g+=1
  print(h)
else:
  print(n)

Fixed submission:
n = int(input())
m = [int(i) for i in input().split()]
mi = 2*10**5+1
h = 0

for i in range (n):
  if mi>m[i]:
    mi=m[i]
    h+=1

    
print(h)

Buggy python submission (verdict: Runtime Error):
n = int(input())
m = [int(i) for i in input().split()]
mi = 2*10**5+1
h = 0
if n!=1:
  for i in range (n):
    if mi>m[i]:
      mi=m[i]
      h+=1
    g+=1
  print(h)
else:
  print(n)

Fixed submission:
n = int(input())
m = [int(i) for i in input().split()]
mi = 2*10**5+1
h = 0

for i in range (n):
  if mi>m[i]:
    mi=m[i]
    h+=1

    
print(h)
Buggy python submission (verdict: Runtime Error):
n=int(input())
A,B = input().split()
i=0
i=int(i)
list01=[]
for d in range(n): 
  lisa=A[i]+B[i]
  list01.append(lisa)
  i+=1
for s in list01:
print(s)

Fixed submission:
S=int(input())
W=int(input())
if S+W==3:
  print(3)
elif S+W==4:
  print(2)
elif S+W==5:
  print(1)
Buggy python submission (verdict: Runtime Error):
A,B = (int(x) for x in input().split())
a=A//2
d=1
s=0
d=int(d)
for i in range(a): 
  if A%d==0 and B%d==0:
    s=d
  d+=1
if s==1:
  print(int(A*B))
else:
  print(int(A*(B/s)))

Fixed submission:
A,B = (int(x) for x in input().split())
if A%2==0:
  a=A//2
else:
  a=(A+1)//2  

d=1
s=0
d=int(d)
for i in range(a): 
  if A%d==0 and B%d==0:
    s=d
  d+=1
if s==1 :
  print(int(A*B))
elif B%A==0:
  print(B)
elif A%B==0:
  print(A)

else:
  print(int(A*(B/s)))

Buggy python submission (verdict: Runtime Error):
A,B = (int(x) for x in input().split())
a=A//2
d=1
s=0
d=int(d)
for i in range(a): 
  if A%d==0 and B%d==0:
    s=d
  d+=1
print(int(A*(B/s)))


Fixed submission:
A,B = (int(x) for x in input().split())
if A%2==0:
  a=A//2
else:
  a=(A+1)//2  

d=1
s=0
d=int(d)
for i in range(a): 
  if A%d==0 and B%d==0:
    s=d
  d+=1
if s==1 :
  print(int(A*B))
elif B%A==0:
  print(B)
elif A%B==0:
  print(A)

else:
  print(int(A*(B/s)))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
ans = 1
for a in A:
    ans *= a
print(ans if ans <= pow(10,18) else -1)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
ans = 1
thld = pow(10,18)
if 0 in A:
    print(0)
else:
    for a in A:
        ans *= a
        if ans > thld:
            print(-1)
            exit()
    print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import math
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0

    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

n = int(input())
if n==1:
    print(0)
elif is_prime(n):
    print(1)
else:
    cnt = 0
    for i in range(2, n):
        if is_prime(i):
            c = 1
            while n%pow(i,c)==0:
                n /= pow(i,c)
                cnt += 1
                c += 1
        if n < i:
            break
    print(cnt)

Fixed submission:
import math
def fac(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

n = int(input())
if n==1:
    print(0)
elif is_prime(n):
    print(1)
else:
    cnt = 0
    P = fac(n)
    for p,_ in P:
        c = 1
        while n%pow(p,c)==0:
            n /= pow(p,c)
            cnt += 1
            c += 1
    print(cnt)
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
A = list(map(lambda x: x-1, map(int, input().split())))
isVisit = [False]*n
visits = []
visit = 0
for i in range(n):
    if isVisit[visit]:
        break
    else:
        isVisit[visit] = True
        visits.append(visit)
        visit = A[visit]

if len(visits)>=k:
    print(visits[k]+1)
else:
    k -= visits.index(visit)
    visits = visits[visits.index(visit):]
    print(visits[k%len(visits)]+1)

Fixed submission:
n, k = map(int, input().split())
A = list(map(lambda x: x-1, map(int, input().split())))
isVisit = [False]*n
visits = []
visit = 0
for i in range(n):
    if isVisit[visit]:
        break
    else:
        isVisit[visit] = True
        visits.append(visit)
        visit = A[visit]

if len(visits)>k:
    print(visits[k]+1)
else:
    k -= visits.index(visit)
    visits = visits[visits.index(visit):]
    print(visits[k%len(visits)]+1)
Buggy python submission (verdict: Runtime Error):
import sys
readline = sys.stdin.readline

def score(A):
    t = 0
    for ai,bi,ci,di in zip(a,b,c,d):
        if A[bi]-A[ai]==ci:
            t += di
    return t

def dfs(A):
    if len(A)==n:
        return score(A)
    ans = 0
    prev_last = A[-1] if len(A)>0 else 0
    for v in range(prev_last, m):
        A.append(v)
        ans = max(ans, dfs(A))
        A.pop()
    return ans

n, m, q = map(int, readline().split())
A,B,C,D = [0]*q, [0]*q, [0]*q, [0]*q
for i in range(q):
    a,b,C[i],D[i] = map(int, readline().split())
    A[i] = a-1
    B[i] = b-1

print(dfs([]))

Fixed submission:
import sys
readline = sys.stdin.readline
sys.setrecursionlimit(10**6)

def score(Ans):
    t = 0
    for ai,bi,ci,di in zip(A,B,C,D):
        if Ans[bi]-Ans[ai]==ci:
            t += di
    return t

def dfs(Ans):
    if len(Ans)==n:
        return score(Ans)
    ans = 0
    prev_last = Ans[-1] if len(Ans)>0 else 0
    for v in range(prev_last, m):
        Ans.append(v)
        ans = max(ans, dfs(Ans))
        Ans.pop()
    return ans

n, m, q = map(int, readline().split())
A,B,C,D = [0]*q, [0]*q, [0]*q, [0]*q
for i in range(q):
    a,b,C[i],D[i] = map(int, readline().split())
    A[i] = a-1
    B[i] = b-1

print(dfs([]))
Buggy python submission (verdict: Time Limit Exceeded):
a, b, n = map(int, input().split())
ans = 0
for i in range(1, min(n, b)+1):
    ans = max(ans, int(a*i/b)-a*int(i/b))
print(ans)

Fixed submission:
a, b, n = map(int, input().split())
x = min(b-1, n)
print(int(a*x/b)-a*int(x/b))
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
if int(s)<2019:
    print(0)
elif len(s)<5:
    print(1 if int(s)%2019==0 else 0)
else:
    n = len(s)
    ans = 0
    for i in range(n-1):
        for j in range(4+i,n):
            _s = s[i:j+1]
            if int(_s)%2019==0:
                ans += 1
    print(ans)

Fixed submission:
from collections import Counter
S = input()[::-1]
MOD = 2019
X = [0]
for i,s in enumerate(S):
    X.append((X[-1]+int(s)*pow(10,i,MOD))%MOD)
C = Counter(X)
print(sum([v*(v-1)//2 for v in C.values()]))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))
for i in range(1, n+1):
    print(A.count(i))

Fixed submission:
from collections import Counter
n = int(input())
A = Counter(list(map(int, input().split())))
for i in range(1, n+1):
    print(A[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i, n-1):
        if s[i] != s[j]:
            if 2*j-i <= n-1 and s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                ans -= 1
print(ans)

Fixed submission:
n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i, n-1):
        if s[i] != s[j]:
            if 2*j-i <= n-1 and s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i, n-1):
        if s[i] != s[j]:
            if 2*j-i <= n-1:
                if s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                    ans -= 1
print(ans)

Fixed submission:
n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i, n-1):
        if s[i] != s[j]:
            if 2*j-i <= n-1 and s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                ans -= 1
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i, n-1):
        for k in range(j, n):
            if j-i==k-j:
                if set([s[j], s[i], s[k]]) == set(['R', 'G', 'B']):
                    ans -= 1
print(ans)

Fixed submission:
n = int(input())
s = input()
ans = s.count('R')*s.count('G')*s.count('B')
for i in range(n-2):
    for j in range(i, n-1):
        if s[i] != s[j]:
            if 2*j-i <= n-1 and s[i]!=s[j] and s[i]!=s[2*j-i] and s[j]!=s[2*j-i]:
                ans -= 1
print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]

#BFS
## 距離の初期化
D = [[10000]*w for _ in range(h)]
D[0][0] = 0 if S[0][0]=='.' else 1
## キューの初期化.
que = deque([[0,0]])
## 探索方向の初期化.
directs = [[0,1],[1,0]]
## キューが尽きるまで探索を行う.
while que:
    ### 現在地の取得.
    hi, wi = que.pop()
    ### 以下の移動方向を探索する.
    for dh,dw in directs:
        #### 迷路の範囲外の場合は探索しない.
        if not (0<=hi+dh<h and 0<=wi+dw<w): continue
        #### 白から黒に移る場合、コストが増える.
        if S[hi][wi]!=S[hi+dh][wi+dw] and S[hi+dh][wi+dw]=='#':
            D[hi+dh][wi+dw] = min(D[hi+dh][wi+dw], D[hi][wi]+1)
        else:
            D[hi+dh][wi+dw] = min(D[hi+dh][wi+dw], D[hi][wi])
        que.appendleft([hi+dh, wi+dw])
print(D[-1][-1])

Fixed submission:
from collections import deque
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
DP = [[10000]*w for _ in range(h)]
DP[0][0] = 0 if S[0][0]=='.' else 1

directs = [[0,1], [1,0]]
for hi in range(h):
    for wi in range(w):
        for dh,dw in directs:
            if not (0<=hi+dh<h and 0<=wi+dw<w): continue
            if S[hi][wi]=='.' and S[hi+dh][wi+dw]=='#':
                DP[hi+dh][wi+dw] = min(DP[hi+dh][wi+dw], DP[hi][wi]+1)
            else:
                DP[hi+dh][wi+dw] = min(DP[hi+dh][wi+dw], DP[hi][wi])
print(DP[-1][-1])

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]

#BFS
## 距離の初期化
D = [[10000]*w for _ in range(h)]
D[0][0] = 0 if S[0][0]=='.' else 1
## キューの初期化.
que = deque([[0,0]])
## 探索方向の初期化.
directs = [[0,1],[1,0]]
## キューが尽きるまで探索を行う.
while que:
    ### 現在地の取得.
    hi, wi = que.pop()
    ### 以下の移動方向を探索する.
    for dh,dw in directs:
        #### 迷路の範囲外の場合は探索しない.
        if not (0<=hi+dh<h and 0<=wi+dw<w): continue
        #### 白から黒に移る場合、コストが増える.
        if S[hi][wi]!=S[hi+dh][wi+dw] and S[hi+dh][wi+dw]=='#':
            D[hi+dh][wi+dw] = min(D[hi+dh][wi+dw], D[hi][wi]+1)
        else:
            D[hi+dh][wi+dw] = min(D[hi+dh][wi+dw], D[hi][wi])
        que.appendleft([hi+dh, wi+dw])
print(D[-1][-1])

Fixed submission:
from collections import deque
h, w = map(int, input().split())
S = [list(input()) for _ in range(h)]
DP = [[10000]*w for _ in range(h)]
DP[0][0] = 0 if S[0][0]=='.' else 1

directs = [[0,1], [1,0]]
for hi in range(h):
    for wi in range(w):
        for dh,dw in directs:
            if not (0<=hi+dh<h and 0<=wi+dw<w): continue
            if S[hi][wi]=='.' and S[hi+dh][wi+dw]=='#':
                DP[hi+dh][wi+dw] = min(DP[hi+dh][wi+dw], DP[hi][wi]+1)
            else:
                DP[hi+dh][wi+dw] = min(DP[hi+dh][wi+dw], DP[hi][wi])
print(DP[-1][-1])
Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
flip = 1
for i in range(q):
    T = input().split()
    if T[0] == '1':
        flip *= -1
    else:
        _flip = 1 if T[1]=='1' else -1
        if (flip * _flip)==1:
            s = T[2] + s
        else:
            s = s + T[2]
print(s if flip==1 else s[::-1])

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
flip = 1
for i in range(q):
    T = input().split()
    if T[0] == '1':
        flip *= -1
    else:
        _flip = 1 if T[1]=='1' else -1
        if (flip * _flip)==1:
            s.appendleft(T[2])
        else:
            s.append(T[2])
print("".join(s) if flip==1 else "".join(reversed(s)))

Buggy python submission (verdict: Time Limit Exceeded):
s = input()
q = int(input())
for i in range(q):
    T = input().split()
    if T[0] == '1':
        s = s[::-1]
    else:
        if T[1] == '1':
            s = T[2] + s
        else:
            s = s + T[2]
print(s)

Fixed submission:
from collections import deque

s = deque(input())
q = int(input())
flip = 1
for i in range(q):
    T = input().split()
    if T[0] == '1':
        flip *= -1
    else:
        _flip = 1 if T[1]=='1' else -1
        if (flip * _flip)==1:
            s.appendleft(T[2])
        else:
            s.append(T[2])
print("".join(s) if flip==1 else "".join(reversed(s)))
Buggy python submission (verdict: Time Limit Exceeded):
def comb(n,k,p):
    from math import factorial
    if n<0 or k<0 or n<k: return 0
    if n==0 or k==0: return 1
    a=factorial(n) %p
    b=factorial(k) %p
    c=factorial(n-k) %p
    return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
    if b==0: return 1
    if b%2==0:
        d=power_func(a,b//2,p)
        return d*d %p
    if b%2==1:
        return (a*power_func(a,b-1,p ))%p
def main():
    n, a, b = map(int, input().split())
    mod = 10**9+7
    print((pow(2,n,mod)-1-comb(n,a,mod)-comb(n,b,mod))%(10**9+7))

main()

Fixed submission:
def main():
    n, a, b = map(int, input().split())
    mod = 10**9+7
    s = pow(2, n, mod)-1
    x = 1
    y = 1
    for i in range(1, b+1):
        x = x*(n-i+1)%mod
        y = y*i%mod
        if i==a or i==b:
            s -= x*pow(y, mod-2, mod)

    print(s%mod)

main()
Buggy python submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
S = ['_']*n
for i in range(n):
    S[i] = input()
cS = Counter(S).most_common()
mx = cS[0][1]
ans = []
for i in range(n):
    if cS[i][1]==mx:
        ans.append(cS[i][0])
    else:
        break
ans = sorted(ans)
for i in range(len(ans)):
    print(ans[i])

Fixed submission:
from collections import Counter
n = int(input())
S = ['_']*n
for i in range(n):
    S[i] = input()
cS = Counter(S).most_common()
mx = cS[0][1]
ans = []
for i in range(len(cS)):
    if cS[i][1]==mx:
        ans.append(cS[i][0])
    else:
        break
ans = sorted(ans)
for i in range(len(ans)):
    print(ans[i])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
A = list(map(int, input().split()))

r = 'YES'
for i in range(n-1):
    if A[i] in A[i+1:]:
        r = 'NO'
        break
print(r)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
print('YES' if len(A)==len(set(A)) else 'NO')
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n, k = map(int, input().split())
    P = list(map(int, input().split()))
    r = 0
    for i in range(n-k+1):
        t = sum(P[i:i+k])
        r = r if r>t else t
    print((r+k)/2)

main()

Fixed submission:
def func(x):
    return (x+1)/2

n, k = map(int, input().split())
P = list(map(func, map(int, input().split())))
t = sum(P[0:k])
r = t
for i in range(n-k):
    t = t-P[i]+P[i+k]
    r = r if r>t else t
print(r)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
P = list(map(int, input().split()))
r = 0
for i in range(n-k+1):
    r = max(r, sum(P[i:i+k]))
print((r+k)/2)

Fixed submission:
def func(x):
    return (x+1)/2

n, k = map(int, input().split())
P = list(map(func, map(int, input().split())))
t = sum(P[0:k])
r = t
for i in range(n-k):
    t = t-P[i]+P[i+k]
    r = r if r>t else t
print(r)
Buggy python submission (verdict: Time Limit Exceeded):
HP, n = map(int, input().split())
AB = [list(map(int,input().split())) for _ in range(n)]

# DP
## DP[i]は、モンスターにダメージ量iを与えるのに必要な魔力の最小コスト
## DPの初期化
DP = [float('inf')] * (HP+1); DP[0] = 0
## HP分だけDPを回す.
for now_hp in range(HP):
    ## 全ての魔法について以下を試す.
    for damage, cost in AB:
        ### 与えるダメージは、現在のダメージ量＋魔法のダメージか体力の小さい方
        next_hp = min(now_hp+damage, HP)
        ### 今の魔法で与えるダメージ量に必要な最小コストは、->
        ####->現在わかっている値か今のHPまでの最小コスト＋今の魔法コストの小さい方
        DP[next_hp] = min(DP[next_hp], DP[now_hp]+cost)
print(DP[-1])

Fixed submission:
HP, n = map(int, input().split())
AB = [list(map(int,input().split())) for _ in range(n)]

# DP
## DP[i]は、モンスターにダメージ量iを与えるのに必要な魔力の最小コスト
## DPの初期化
DP = [float('inf')] * (HP+1); DP[0] = 0
## HP分だけDPを回す.
for now_hp in range(HP):
    ## 全ての魔法について以下を試す.
    for damage, cost in AB:
        ### 与えるダメージは、現在のダメージ量＋魔法のダメージか体力の小さい方
        next_hp = min(now_hp+damage, HP)
        ### 今の魔法で与えるダメージ量に必要な最小コストは、->
        ####->現在わかっている値か今のHPまでの最小コスト＋今の魔法コストの小さい方
        DP[next_hp] = min(DP[next_hp], DP[now_hp]+cost)
print(DP[-1])
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
P = [int(i) for i in input().split()]
r = 1
for i in range(1, n):
    if P[i] < min(P[:i]):
        r += 1
print(r)

Fixed submission:
n = int(input())
P = [int(i) for i in input().split()]
r = 0
m = n+1
for i in range(n):
    if P[i] < m:
        r += 1
        m = P[i]
print(r)
Buggy python submission (verdict: Runtime Error):
from functools import reduce
def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

n = int(input())
A = [int(i) for i in input().split()]
k = lcm_list(A)
r = 0
for i in range(n):
    r += k//A[i]
    if r > 10**9+7:
        r %= 10**9+7
print(r)

Fixed submission:
n = int(input())
C = [[0]*10 for _ in range(10)]
for i in range(1,n+1):
    C[int(str(i)[0])][int(str(i)[-1])] += 1
ans = 0
for i in range(10):
    for j in range(10):
        ans += C[i][j]*C[j][i]
print(ans)
Buggy python submission (verdict: Runtime Error):
import math
A, B = map(int, input().split())
print((A*B)//math.gcd(A, B))

Fixed submission:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
A, B = map(int, input().split())
print(A*B//gcd(A, B))
Buggy python submission (verdict: Runtime Error):
import math
n = int(input())
if n%2==1:
    print(0)
else:
    print(sum([n//(2*pow(5,i)) for i in range(1,math.ceil(math.log(n,5)))]))

Fixed submission:
import math
n = int(input())
if n%2==1:
    print(0)
else:
    print(sum([n//(2*pow(5,i)) for i in range(1,math.ceil(math.log(n+1,5)))]))
Buggy python submission (verdict: Runtime Error):
n = int(input())
A = list(map(int, input().split()))
mod = 1000000007
ans = 1
cnt = [3 for i==0 else 0 for i in range(n+1)]

for a in A:
    ans = ans*cnt[a]%mod
    if ans==0: break
    cnt[a] -= 1
    cnt[a+1] += 1
print(ans)

Fixed submission:
n = int(input())
A = list(map(int, input().split()))
mod = 1000000007
ans = 1
cnt = [3 if i==0 else 0 for i in range(n+1)]

for a in A:
    ans = ans*cnt[a]%mod
    if ans==0: break
    cnt[a] -= 1
    cnt[a+1] += 1
print(ans)