Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]

for i in range(N):
    A_ = [A[j] for j in range(0, N) if i != j]
    print(max(A_))

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]

FIRST = max(A)
if A.count(FIRST) > 1:
    for i in range(N):
        print(FIRST)
else:
    SECOND = max([a for a in A if a != FIRST])
    for a in A:
        if a == FIRST:
            print(SECOND)
        else:
            print(FIRST)

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = [int(input()) for i in range(N)]

for i in range(N):
    left = [A[j] for j in range(0, i)]
    right = [A[j] for j in range(1+i, N)]
    print(max(right + left))

Fixed submission:
N = int(input())
A = [int(input()) for i in range(N)]

FIRST = max(A)
if A.count(FIRST) > 1:
    for i in range(N):
        print(FIRST)
else:
    SECOND = max([a for a in A if a != FIRST])
    for a in A:
        if a == FIRST:
            print(SECOND)
        else:
            print(FIRST)
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = []
for i in range(N):
    A = int(input())
    for j in range(len(X)):
        if A > X[j]:
            X[j] = A
            break
    else:
        X.append(A)
print(len(X))


Fixed submission:
import bisect

N = int(input())
A = [-int(input()) for i in range(N)]
X = []
for i in range(N):
    a = A[i]
    idx = bisect.bisect_left(X, a+0.1)
    if idx == len(X):
        X.append(a)
    else:
        X[idx] = a
print(len(X))

Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
X = []
for i in range(N):
    A = int(input())
    target = [x for x in X if x < A]
    if len(target) > 0:
        X[X.index(max(target))] = A
    else:
        X.append(A)
print(len(X))


Fixed submission:
import bisect

N = int(input())
A = [-int(input()) for i in range(N)]
X = []
for i in range(N):
    a = A[i]
    idx = bisect.bisect_left(X, a+0.1)
    if idx == len(X):
        X.append(a)
    else:
        X[idx] = a
print(len(X))
Buggy python submission (verdict: Runtime Error):
import math
A, B, C, D = list(map(int, input().split()))
A_ = A - 1
B_res = B - (B//C + B//D - B//int(C*D/math.gcd(C, D)))
A_res = A_ - (A_//C + A_//D - A_//int(C*D/math.gcd(C, D)))
print(B_res - A_res)

Fixed submission:
def gcd(a, b):
    if a < b:
        tmp = a
        a = b
        b = tmp

    r = a % b
    while r!=0:
        a = b
        b = r
        r = a % b
    return b

def lcm(a, b):
    return int(a * b / gcd(a, b))

A, B, C, D = list(map(int, input().split()))
A_ = A - 1
lcm_CD = lcm(C, D)
B_res = B - (B//C + B//D - B//lcm_CD)
A_res = A_ - (A_//C + A_//D - A_//lcm_CD)
print(B_res - A_res)
Buggy python submission (verdict: Time Limit Exceeded):
N, Q = list(map(int, input().split()))
X = [1 for i in range(N)]
s = [x for x in input()]

for i in range(Q):
    t, d = input().split()
    if d == 'L':
        for j in range(N):
            if s[j] == t:
                if j != 0:
                    X[j-1] += X[j]
                X[j] = 0
    elif d == 'R':
        for j in range(N, 0, -1):
            if s[j-1] == t:
                if j != N:
                    X[j] += X[j-1]
                X[j-1] = 0
print(sum(X))

Fixed submission:
def check_alive(n):
    p = n
    for spell in spells:
        if spell[0] == s[p]:
            p += 1 if spell[1] == 'R' else -1
        if p == -1:
            return 'L'
        elif p == N:
            return 'R'
    return 'OK'

N, Q = list(map(int, input().split()))
s = [x for x in input()]
spells = [input().split() for i in range(Q)]

def __main__():
    if check_alive(0) == 'R':
        print(0)
        return
    elif check_alive(0) == 'OK':
        left_alive = 0
    else:
        a, b = 0, N-1
        while b - a > 1:
            m = round((b+a)/2)
            if check_alive(m) == 'L':
                a = m
            else:
                b = m
        left_alive = b
    if check_alive(N-1) == 'L':
        print(0)
        return
    elif check_alive(N-1) == 'OK':
        right_alive = N-1
    else:
        a, b = 0, N-1
        while b - a > 1:
            m = round((b+a)/2)
            if check_alive(m) == 'R':
                b = m
            else:
                a = m
        right_alive = a
    
    print(right_alive - left_alive + 1)

if __name__ == "__main__":
    __main__()
Buggy python submission (verdict: Runtime Error):
s = input()
t = input()
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
        else:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j], dp[i][j+1])

ans = ''
i, j = 0, 0
while i <= len(s) and j <= len(s):
    if dp[-1-i][-1-j] == dp[-1-i-1][-1-j]:
        i += 1
    elif dp[-1-i][-1-j] == dp[-1-i][-1-j-1]:
        j += 1
    else:
        ans += s[-1-i]
        i += 1
        j += 1
print(ans[::-1])

Fixed submission:
s = input()
t = input()
dp = [[0]*(len(t)+1) for _ in range(len(s)+1)]
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1)
        else:
            dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j])
        dp[i+1][j+1] = max(dp[i+1][j+1], dp[i+1][j], dp[i][j+1])

ans = ''
i, j = len(s), len(t)
while 0 < i and 0 < j:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        i -= 1
        j -= 1
        ans += s[i]
print(ans[::-1])
Buggy python submission (verdict: Time Limit Exceeded):
import sys
sys.setrecursionlimit(10**9)

N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]

for _ in range(M):
    x, y = list(map(lambda x: int(x) - 1, input().split()))
    G[x].append(y)

dp = [-1]*(N)

def f(v):
    if dp[v] != -1:
        return dp[v]
    ans = 0
    for nv in G[v]:
        ans = max(ans, f(nv) + 1)
    return ans

for i in range(N):
    dp[i] = f(i)

print(max(dp))

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]

for _ in range(M):
    x, y = list(map(lambda x: int(x) - 1, input().split()))
    G[x].append(y)

dp = [-1]*(N)

def f(v):
    if dp[v] != -1:
        return dp[v]
    ans = 0
    for nv in G[v]:
        ans = max(ans, f(nv) + 1)
    dp[v] = ans
    return ans

ans = 0
for i in range(N):
    ans = max(ans, f(i))

print(max(dp))

Buggy python submission (verdict: Runtime Error):
N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]

for _ in range(M):
    x, y = list(map(lambda x: int(x) - 1, input().split()))
    G[x].append(y)

dp = [-1]*(N)

def f(v):
    if dp[v] != -1:
        return dp[v]
    ans = 0
    for nv in G[v]:
        ans = max(ans, f(nv) + 1)
    return ans

for i in range(N):
    dp[i] = f(i)

print(max(dp))

Fixed submission:
import sys
sys.setrecursionlimit(10**9)

N, M = list(map(int, input().split()))
G = [[] for _ in range(N)]

for _ in range(M):
    x, y = list(map(lambda x: int(x) - 1, input().split()))
    G[x].append(y)

dp = [-1]*(N)

def f(v):
    if dp[v] != -1:
        return dp[v]
    ans = 0
    for nv in G[v]:
        ans = max(ans, f(nv) + 1)
    dp[v] = ans
    return ans

ans = 0
for i in range(N):
    ans = max(ans, f(i))

print(max(dp))
Buggy python submission (verdict: Time Limit Exceeded):
import math
n = int(input())

den = int(1e9 + 7)
c = lambda a, b: (math.factorial(a) // (math.factorial(a - b) * math.factorial(b)))
ans = 0
if n == 1:
    ans = 0
elif n == 2:
    ans = 2
else:
    for i in range(2, n + 1):   # number of 0|9
        ans = (ans + (8 ** (n - i) * (2 ** i - 2) * c(n, i))) % den
print(ans)

Fixed submission:
n = int(input())

den = int(1e9 + 7)
print((10**n - 2 * 9**n + 8**n) % den)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(" ")))

ans = 0
den = int(1e9 + 7)
for i in range(len(a) - 1):
    ans = (ans + a[i] * sum(a[i + 1:])) % den

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split(" ")))

ans = 0
den = int(1e9 + 7)
sum_a = [0 for i in range(len(a))]
sum_a[-1] = a[-1]
for i in range(len(a) - 1, 1, -1):
    sum_a[i - 1] = sum_a[i] + a[i - 1]
for i in range(len(a) - 1):
    ans = (ans + a[i] * sum_a[i + 1]) % den

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(" ")))
 
ans = 0
den = int(1e9 + 7)
for i in range(len(a)):
    for j in range(i + 1, len(a)):
        ans = (ans + a[i] * a[j]) % den

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split(" ")))

ans = 0
den = int(1e9 + 7)
sum_a = [0 for i in range(len(a))]
sum_a[-1] = a[-1]
for i in range(len(a) - 1, 1, -1):
    sum_a[i - 1] = sum_a[i] + a[i - 1]
for i in range(len(a) - 1):
    ans = (ans + a[i] * sum_a[i + 1]) % den

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(" ")))
 
ans = 0
den = int(1e9 + 7)
for i in range(len(a)):
    for j in range(i + 1, len(a)):
        ans = (ans + (a[i] * a[j]) % den) % den

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split(" ")))

ans = 0
den = int(1e9 + 7)
sum_a = [0 for i in range(len(a))]
sum_a[-1] = a[-1]
for i in range(len(a) - 1, 1, -1):
    sum_a[i - 1] = sum_a[i] + a[i - 1]
for i in range(len(a) - 1):
    ans = (ans + a[i] * sum_a[i + 1]) % den

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split(" ")))

ans = 0
den = int(1e9 + 7)
for i in range(len(a)):
    for j in range(i + 1, len(a)):
        ans = (ans + ((a[i] % den) * (a[j] % den) % den)) % den

print(ans)

Fixed submission:
n = int(input())
a = list(map(int, input().split(" ")))

ans = 0
den = int(1e9 + 7)
sum_a = [0 for i in range(len(a))]
sum_a[-1] = a[-1]
for i in range(len(a) - 1, 1, -1):
    sum_a[i - 1] = sum_a[i] + a[i - 1]
for i in range(len(a) - 1):
    ans = (ans + a[i] * sum_a[i + 1]) % den

print(ans)
Buggy python submission (verdict: Runtime Error):
k = int(input())

if k == 7:
    ans = 1
elif k % 2 == 0:
    ans = -1
else:
    for i in range(1, (len(str(k)) * 3) + 1):
        tgt = int("7" * i)
        if tgt % k == 0:
            ans = i
            break

print(ans)

Fixed submission:
print("Yes") if int(input()) >= 30 else print("No")
Buggy python submission (verdict: Runtime Error):
a, b, c = list(map(int, input().split()))
k = int(input())

ans = False

for i in range(k):
	if c <= b:
      	c *= 2
    elif b <= a:
      	b *= 2
    else:
      	ans = True
        break

if ans:
  	print("Yes")
else:
  	print("No")

Fixed submission:
a, b, c = list(map(int, input().split()))
k = int(input())
 
ans = False
 
for i in range(k):
    if c <= b:
        c *= 2
    elif b <= a:
        b *= 2
    else:
        ans = True
        break
if c > b and b > a:
    ans = True

if ans:
  	print("Yes")
else:
  	print("No")
Buggy python submission (verdict: Runtime Error):
N = int(input())
rest = N//1000
return 1000-rest

Fixed submission:
N = int(input())
rest = N%1000
if rest==0:
  print(0)
else:
  print(1000-rest)
Buggy python submission (verdict: Runtime Error):
from collectinos import defaultdict
d = defaultdict(int)
N = int(input())
for i in range(N):
  d[input()] += 1
print(f"AC x {d['AC']}")
print(f"WA x {d['WA']}")
print(f"TLE x {d['TLE']}")
print(f"RE x {d['RE']}")

Fixed submission:
from collections import defaultdict
d = defaultdict(int)
N = int(input())
for i in range(N):
  d[input()] += 1
print(f"AC x {d['AC']}")
print(f"WA x {d['WA']}")
print(f"TLE x {d['TLE']}")
print(f"RE x {d['RE']}")
Buggy python submission (verdict: Time Limit Exceeded):
from collections import defaultdict as dd
d = dd(int)
N = int(input())
for i in [int(n) for n in input().split()]:
  d[i] = d[i]+1
times = int(input())
for i in range(times):
  a, b = [int(n) for n in input().split()]
  d[b], d[a] = d[b] + d[a], 0
  print(sum([ key*value for key, value in d.items() if value > 0]))
  

Fixed submission:
from collections import defaultdict as dd
d = dd(int)
N = int(input())
for i in [int(n) for n in input().split()]:
  d[i] = d[i]+1
times = int(input())
summation = sum([ key*value for key, value in d.items() if value > 0])
for i in range(times):
  a, b = [int(n) for n in input().split()]
  summation = summation + (b-a)*d[a]
  d[b], d[a] = d[b] + d[a], 0
  print(summation)
Buggy python submission (verdict: Runtime Error):
N = int(input())
N = N%10
if N in [2,4,5,7,9]:
  return'hon'
elif N in[0,1,6,8]:
  return 'pon'
elif N == 3:
  return 'bon'

Fixed submission:
N = int(input())
N = N%10
if N in [2,4,5,7,9]:
  print('hon')
elif N in[0,1,6,8]:
  print('pon')
elif N == 3:
  print('bon')
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

A_sum = sum(A)
ans = 0

for i in range(N-1):
    B = A.pop(0)
    A_sum -= B
    ans += A_sum*B
print(ans % (10**9+7))


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

A_sum = sum(A)
ans = 0


for i in range(N-1):
    A_sum -= A[i]
    ans += A_sum*(A[i])

print(ans%(10**9+7))
Buggy python submission (verdict: Runtime Error):
N, D = map(int, input().split())
ans = 0
for in range(N):
  X, Y = map(int, input().split())
  if x**2 + y**2 <= D**2:
    ans += 1

print(ans)

Fixed submission:
N, D = map(int, input().split())
ans = 0
for i in range(N):
  X, Y = map(int, input().split())
  if X**2 + Y**2 <= D**2:
    ans += 1
 
print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
if N < K*3:
    for i in range(N):
        print(N, end=' ')
    print('')
else:
    for k in range(K):
        B = [0]*N
        for i in range(N):
            for j in range(max(i-A[i], 0), min(A[i]+i+1, N)):
                B[j] += 1
        A = B
    print(A)

Fixed submission:
S = list(input())
print(''.join(S[0:3]))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
A = list(map(int, input().split()))

ans = 1
for i in range(N):
    ans *= A[i]

if ans <= 10**18:
    print(ans)
else:
    print(-1)


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

ans = 1

if 0 in A:
    print(0)
    exit()

for i in range(N):
    ans *= A[i]
    if ans > 10**18:
        print(-1)
        exit()

print(ans)
Buggy python submission (verdict: Runtime Error):
import sys
N = int(input())
A = list(map(int, input().split()))

l = []

if A[0] != 0:
    print(-1)
    sys.exit()

for i in range(N+1):
    if A[i] > 2*A[i+1]:
        print(-1)
        sys.exit()

temp = 1
for i in range(N+1):
    l.append(temp-A[i])
    temp = (temp-A[i])*2

for i in range(N+1):
    if l[i] < 0:
        print(-1)
        sys.exit()

ans = 1
node = 0
for i in range(N, 0, -1):
    if l[i-1] >= node + A[i]:
        node += A[i]
        ans += node
    else:
        ans += node + A[i]
        node = l[i-1]

print(ans)

Fixed submission:
import sys
N = int(input())
A = list(map(int, input().split()))

l = []

if N == 0:
    if A[0] != 1:
        print(-1)
        exit()

temp = 1
for i in range(N+1):
    l.append(temp-A[i])
    temp = (temp-A[i])*2

for i in range(N+1):
    if l[i] < 0:
        print(-1)
        sys.exit()



ans = 1
node = 0
for i in range(N, 0, -1):
    if l[i-1] >= node + A[i]:
        node += A[i]
        ans += node
    else:
        ans += node + A[i]
        node = l[i-1]

print(ans)

Buggy python submission (verdict: Runtime Error):
import sys
N = int(input())
A = list(map(int, input().split()))

l = []

if A[0] != 0:
    print(-1)
    sys.exit()

if N == ０:
    print(-1)
    sys.exit()

temp = 1
for i in range(N+1):
    l.append(temp-A[i])
    temp = (temp-A[i])*2

for i in range(N+1):
    if l[i] < 0:
        print(-1)
        sys.exit()

ans = 1
node = 0
for i in range(N, 0, -1):
    if l[i-1] >= node + A[i]:
        node += A[i]
        ans += node
    else:
        ans += node + A[i]
        node = l[i-1]

print(ans)

Fixed submission:
import sys
N = int(input())
A = list(map(int, input().split()))

l = []

if N == 0:
    if A[0] != 1:
        print(-1)
        exit()

temp = 1
for i in range(N+1):
    l.append(temp-A[i])
    temp = (temp-A[i])*2

for i in range(N+1):
    if l[i] < 0:
        print(-1)
        sys.exit()



ans = 1
node = 0
for i in range(N, 0, -1):
    if l[i-1] >= node + A[i]:
        node += A[i]
        ans += node
    else:
        ans += node + A[i]
        node = l[i-1]

print(ans)
Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

now = 1
temp_l = [0]*N
temp_count = [-1]*N
temp_count[0] = 0
for i in range(N):
    pre = now
    now = A[pre-1]
    if temp_l[now-1] == 1:
        end = now
        temp = i+1
        break
    else:
        temp_l[now-1] = 1
        temp_count[now-1] = i+1

s_index = temp_count[end-1]
repeat = temp - s_index
K -= s_index
K = K % repeat

print(temp_count.index(K+s_index)+1)

Fixed submission:
S = list(input())
T = list(input())

ans = 'Yes'
for i in range(len(S)):
    if S[i] != T[i]:
        ans = 'No'

print(ans)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

temp = 0
temp_l = [1]
now = 1
while True:
    temp += 1
    pre = now
    now = A[pre-1]
    if now in temp_l:
        end = now
        break
    else:
        temp_l.append(now)

s_index = temp_l.index(end)
repeat = temp - s_index
K -= s_index
K = K % repeat

print(temp_l[s_index:][K])

Fixed submission:
S = list(input())
T = list(input())

ans = 'Yes'
for i in range(len(S)):
    if S[i] != T[i]:
        ans = 'No'

print(ans)
Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)

l = [0] * 2019
for i in range(N):
    l[int(S[i:N])%2019] += 1

ans = l[0]

for i in range(1, 2019):
    ans += l[i] * (l[i]-1) // 2

print(ans)

Fixed submission:
S, W = map(int, input().split())

if W >= S:
    print('unsafe')
else:
    print('safe')

Buggy python submission (verdict: Runtime Error):
import collections

S = input()
N = len(S)
l = []
for i in range(N):
    l.append(int(''.join(S[i:N]))%2019)

c = collections.Counter(l)

values, counts = zip(*c.most_common())
counts = list(counts)

try:
    ans = counts.pop(list(values).index(0))
except:
    ans = 0

for i in range(len(counts)):
    if counts[i] != 1:
        ans += counts[i] * (counts[i]-1) // 2

print(ans)




Fixed submission:
S, W = map(int, input().split())

if W >= S:
    print('unsafe')
else:
    print('safe')

Buggy python submission (verdict: Runtime Error):
S = input()
N = len(S)
l = []
temp = 0
index = 0
for i in range(N):
    l.append(int(''.join(S[i:N])))

ans = 0
for i in range(N-1):
    for j in range(i,N):
        if (l[i] - l[j])/(10**(N-j)) % 2019 == 0 and l[i]-l[j] != 0:
            ans += 1

if ans == 0:
    print(0)
else:
    print(ans+1)

Fixed submission:
S, W = map(int, input().split())

if W >= S:
    print('unsafe')
else:
    print('safe')
Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

K = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(i, j, k)
            
print(ans)

Fixed submission:
import math
from functools import reduce

K = int(input())

def gcd(*numbers):
    return reduce(math.gcd, numbers)

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(i, j, k)
            
print(ans)
Buggy python submission (verdict: Runtime Error):
K = int(input())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

print(l[k-1])

Fixed submission:
K = int(input())
l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
 
print(l[K-1])
Buggy python submission (verdict: Runtime Error):
N = int(input())
S = []
for i in range(N):
  S.append(str(input()))
  
from collections import Counter
N = int(input())
S = []
for i in range(N):
  S.append(str(input()))
ans_list = []
  

c = Counter(S)
keys, values = zip(*c.most_common())

for i in range(len(values)):
  if max(values) == values[i]:
    ans_list.append(keys[i])
    
sorted(ans_list)
for i in range(len(ans_list)):
  print(ans_list[i])



Fixed submission:
from collections import Counter
N = int(input())
S = []
for i in range(N):
  S.append(str(input()))

c = Counter(S)
max_value = max(list(c.values()))
ans_list = sorted(list(c.items()))

for i in range(len(ans_list)):
  if ans_list[i][1] == max_value:
    print(ans_list[i][0])
Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = 0
place = 0
for i in range(N-K+1):
  temp = sum(list(p[i:i+K]))
  if temp > ans:
    ans = temp
    place = i
    
print((ans+K)/2)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))

rp = sum(list(p[0:K]))
rm = 0
ans = rp
for i in range(N-K):
  rp += p[i+K]
  rm += p[i]
  if rp - rm > ans:
    ans = rp - rm

print((ans+K)/2)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
p = list(map(int, input().split()))

ans = []
for i in range(N-K+1):
  if sum(list(p[i:i+K])) > sum(ans):
    ans = list(p[i:i+K])
    
print((sum(ans)+K)/2)

Fixed submission:
N, K = map(int, input().split())
p = list(map(int, input().split()))

rp = sum(list(p[0:K]))
rm = 0
ans = rp
for i in range(N-K):
  rp += p[i+K]
  rm += p[i]
  if rp - rm > ans:
    ans = rp - rm

print((ans+K)/2)
Buggy python submission (verdict: Time Limit Exceeded):
A, B, K = map(int, input().split())

for i in range(K):
    if A >= 1:
        A -= 1
    elif B >= 1:
        B -= 1

print(A, B)

Fixed submission:
A, B, K = map(int, input().split())

A -= K
if A < 0:
    K = abs(A)
    A = 0
else:
    K = 0

B -= K
if B < 0:
    B = 0

print(A, B)
Buggy python submission (verdict: Runtime Error):
import itertools
N = int(input())
A = list(map(int, input().split()))
ans = 0

for v in itertools.combinations(A, 2):
    ans += v[0] ^ v[1]
    
print(ans % (10**9 + 7))

Fixed submission:
A1, A2, A3 = map(int, input().split())

if A1 + A2 + A3 > 21:
  print('bust')
else:
  print('win')
Buggy python submission (verdict: Runtime Error):
l =  ['SUN','MON','TUE','WED','THU','FRI','SAT']
S = str(input())

print(int(7 - S.index()))l =  ['SUN','MON','TUE','WED','THU','FRI','SAT']
S = str(input())

print(int(7 - l.index(S)))

Fixed submission:
l =  ['SUN','MON','TUE','WED','THU','FRI','SAT']
S = str(input())

print(int(7 - l.index(S)))
Buggy python submission (verdict: Time Limit Exceeded):
N = int(input())
ans = 1000000000001

for i in range(N):
  if N % (i+1) == 0:
    if (N/(i+1)) + (i+1) -2 < ans:
      ans = int((N/(i+1)) + (i+1) -2)

print(ans)

Fixed submission:
N = int(input())
ans = 1000000000001

for i in range(int(N**0.5)):
  if N % (i+1) == 0:
    A = N / (i+1)
    B = (i+1)
    if A + B - 2 < ans:
      ans = int(A + B - 2)
print(ans)
Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

for i in range(N):
  ans += B[A[i]]
  if i > 0:
    if A[i-1]+1 == A[i]:
      ans += C[i-1]
      
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = sum(B)

for i in range(N-1):
  if A[i] + 1 == A[i+1]:
    ans += C[A[i]-1]
    
print(ans)

Buggy python submission (verdict: Runtime Error):
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = 0

for i in range(N):
  ans += B[A[i]]
  if i > 0:
    if int(A[i-1]+1) == int(A[i]):
      ans += C[i-1]
      
print(ans)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

ans = sum(B)

for i in range(N-1):
  if A[i] + 1 == A[i+1]:
    ans += C[A[i]-1]
    
print(ans)