Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
A,B,C,D,E,F = map(int,input().split())
W=set()
for a in range(0,F+1,100*A):
    for b in range(0,F+1-a,100*B):
        W.add(a+b)
S=set()
for c in range(0,F+1,C):
    for d in range(0,F+1,D):
        S.add(c+d)
rate = -1
for w in W:
    for s in S:
        if 0 < w+s <= F and s <= w*E//100:
            if s/(w+s) > rate:
                rate = s/(w+s)
                ans = w+s, s
print(ans[0],ans[1])

Fixed submission:
n = int(input())
a = int(input())
print(n**2-a)
Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
A = [0]*10000000
for i in a:
  if A[i] == 0:
    A[i] = 1
  else:
    A[i] = 0
print(A.count(1))

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
wordcount = {}
for i in a:
  if i in wordcount:
    del wordcount[i]
  else:
    wordcount[i] = 1
print(len(wordcount))

Buggy python submission (verdict: Runtime Error):
n = int(input())
a = [int(input()) for i in range(n)]
A = [0]*100000
for i in a:
  if A[i] == 0:
    A[i] = 1
  else:
    A[i] = 0
print(A.count(1))

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
wordcount = {}
for i in a:
  if i in wordcount:
    del wordcount[i]
  else:
    wordcount[i] = 1
print(len(wordcount))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
a.sort()
mx = 0
for i in a:
  count = a.count(i) + a.count(i+1) +a.count(i+2)
  if count > mx:
    mx = count
print(mx)

Fixed submission:
n = int(input())
x = [0]*100001
a = list(map(int,input().split()))
m = 0
ma = 0
for i in range(n):
    x[a[i]]+=1
for i in range(100001-2):
    m=x[i]+x[i+1]+x[i+2]
    if m>ma:
        ma=m
print(ma)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
a.sort()
st = min(a)
ed = max(a)
count = a.count(st) + a.count(st+1) + a.count(st+2)
mx = count
for i in range(3,ed-st+1):
  count = count + a.count(st+i) -a.count(st+i-3)
  if count > mx:
    mx = count
print(mx)

Fixed submission:
n = int(input())
x = [0]*100001
a = list(map(int,input().split()))
m = 0
ma = 0
for i in range(n):
    x[a[i]]+=1
for i in range(100001-2):
    m=x[i]+x[i+1]+x[i+2]
    if m>ma:
        ma=m
print(ma)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
i = 1
count = 0
btn = [1]
if 2 not in a:
  print(-1)
  exit()
while(1):
  i = a[i-1]
  count += 1
  if i in btn:
    print(-1)
    break
  if i == 2:
    print(count)
    break
  btn.append(i)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
i = 1
count = 0
btn = [1]
while(1):
  i = a[i-1]
  count += 1
  if count>n:
    print(-1)
    break
  if i == 2:
    print(count)
    break
  btn.append(i)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = [int(input()) for i in range(n)]
i = 1
count = 0
btn = [1]
while(1):
  i = a[i-1]
  count += 1
  if i in btn:
    print(-1)
    break
  if i == 2:
    print(count)
    break
  btn.append(i)

Fixed submission:
n = int(input())
a = [int(input()) for i in range(n)]
i = 1
count = 0
btn = [1]
while(1):
  i = a[i-1]
  count += 1
  if count>n:
    print(-1)
    break
  if i == 2:
    print(count)
    break
  btn.append(i)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int,input().split()))
def judge(count):
  idx = 0
  for i in range(2,n+1):
    if count == -1:
      if sum(a[0:i]) < 0:
        pass
      else:
        check = sum(a[0:i]) + 1
        j = a[i-1]
        a[i-1] = j - check
        idx += check
    elif count == 1:
      if sum(a[0:i]) > 0:
        pass
      else:
        check = 1 - sum(a[0:i])
        j = a[i-1]
        a[i-1] = check+ j
        idx += check
    count *= -1
  return idx
if a[0] > 0:
  b = judge(-1)
  print(b)
elif a[0] < 0:
  c = judge(1)
  print(c)
else:
  a[0] = 1
  b = judge(-1)
  a[0] = -1
  c = judge(1)
  print(min(b,c))


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans1,ans2 = 0,0
sum1,sum2 = 0,0
for i in range(n):
    sum1 += a[i]
    if i%2 == 1 and sum1 >= 0:
        ans1 += sum1 + 1
        sum1 = -1
    elif i%2 == 0 and sum1 <= 0:
        ans1 += -sum1 + 1
        sum1 = 1
for i in range(n):
    sum2 += a[i]
    if i%2 == 0 and sum2 >= 0:
        ans2 += sum2 + 1
        sum2 = -1
    elif i%2 == 1 and sum2 <= 0:
        ans2 += -sum2 + 1
        sum2 = 1
print(min(ans1,ans2))

Buggy python submission (verdict: Runtime Error):
a = list(map(int,input().split()))
def judge(count):
  idx = 0
  for i in range(2,n+1):
    if count == -1:
      if sum(a[0:i]) < 0:
        pass
      else:
        check = sum(a[0:i]) + 1
        j = a[i-1]
        a[i-1] = j - check
        idx += check
    elif count == 1:
      if sum(a[0:i]) > 0:
        pass
      else:
        check = 1 - sum(a[0:i])
        j = a[i-1]
        a[i-1] = check+ j
        idx += check
    count *= -1
  return idx
if a[0] > 0:
  b = judge(-1)
  print(b)
elif a[0] < 0:
  c = judge(1)
  print(c)
else:
  a[0] = 1
  b = judge(-1)
  a[0] = -1
  c = judge(1)
  print(min(b,c))


Fixed submission:
n = int(input())
a = list(map(int,input().split()))
ans1,ans2 = 0,0
sum1,sum2 = 0,0
for i in range(n):
    sum1 += a[i]
    if i%2 == 1 and sum1 >= 0:
        ans1 += sum1 + 1
        sum1 = -1
    elif i%2 == 0 and sum1 <= 0:
        ans1 += -sum1 + 1
        sum1 = 1
for i in range(n):
    sum2 += a[i]
    if i%2 == 0 and sum2 >= 0:
        ans2 += sum2 + 1
        sum2 = -1
    elif i%2 == 1 and sum2 <= 0:
        ans2 += -sum2 + 1
        sum2 = 1
print(min(ans1,ans2))
Buggy python submission (verdict: Runtime Error):
a,b,k=map(int, input().split())
a,b,k=map(int, input().split())

if a+b<k:
  print(0,0)
elif a<k:
  print(0,b+a-k)
else:
  print(a-k,b)

print("{} {}".format(a, b))

Fixed submission:
a,b,k = map(int, input().split())
 
if a > k:
  print(a-k,b)
  
elif a+b>k:
  print(0,b-k+a)
else:
  print(0,0)
Buggy python submission (verdict: Runtime Error):
num = int(input())
index = list(map(int, input().split()))
point = list(map(int, input().split()))
add = list(map(int, input().split()))

total = 0
for i in range(num):
  total += point[index[i]-1]

for j in range(num-1):
  if index[j+1] == index[j]+ 1:
    total += add[index[i]-1]


print(total)

Fixed submission:
num = int(input())

print(num ** 3)

Buggy python submission (verdict: Runtime Error):
num = input()

print(num **3)

Fixed submission:
num = int(input())

print(num ** 3)
Buggy python submission (verdict: Runtime Error):
from heapq import heappush, heappop, heapify

n = int(input())
values = list(map(int, input().split()))

heapify(values)

while len(values) > 1:
  a = heappop(values)
  b = heappop(values)
  heappush(values, (a+b) / 2)
  
print(values[0])


Fixed submission:
a = int(input())
s = str(input())

if a >= 3200:
  print(s)
else:
  print('red')
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import combinations
N, S = int(input()), input()
result = set()
for indexes in combinations(range(N, 0, -1), N - 3):
    tmp = S
    for i in indexes:
        tmp = tmp[:i - 1] + tmp[i:]
    result.add(tmp)
print(len(result))


Fixed submission:
N = input()
S = input()
count = 0
for i in range(1000):
    n = "{:03d}".format(i)
    n1, n2, n3 = n[0], n[1], n[2]
    i1 = S.find(n1)
    if -1 < i1 < len(S) - 2:
        S1 = S[i1 + 1:]
        i2 = S1.find(n2)
        if -1 < i2 < len(S1) - 1:
            S2 = S1[i2 + 1:]
            i3 = S2.find(n3)
            if -1 < i3:
                count += 1
                continue
print(count)
Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
A = int(math.sqrt(N))
for i in range(A, N + 1):
    if N % i == 0 or len(str(i)) == len(str(N)):
        print(len(str(i)))
        break


Fixed submission:
import math
N = int(input())
for i in range(int(math.sqrt(N)) + 1, 0, -1):
    q, m = divmod(N, i)
    if m == 0:
        print(len(str(q)))
        break

Buggy python submission (verdict: Time Limit Exceeded):
import math
N = int(input())
A = int(math.sqrt(N))
for i in range(A, N + 1):
    if N % i == 0:
        print(len(str(i)))
        break


Fixed submission:
import math
N = int(input())
for i in range(int(math.sqrt(N)) + 1, 0, -1):
    q, m = divmod(N, i)
    if m == 0:
        print(len(str(q)))
        break
Buggy python submission (verdict: Runtime Error):
target = int(input())
rest = 0
for i in range(1, int(target/2)):
  if target % i == 0:
	rest = target / i
    if rest < 10:
      break

if rest > 0:
  print("Yes")
else:
  print("No")

Fixed submission:
target = int(input())
rest = 0
for i in range(1, int(target/2)+2):
    if target % i == 0:
        rest = target / i
    if i < 10 and rest < 10:
        print("Yes")
        exit(0)
 
print("No")
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
nums = [int(input()) for _ in range(n)]

for i in range(n):
  print(max(nums[0: i] + nums[i + 1:]))


Fixed submission:
n = int(input())
nums = [int(input()) for _ in range(n)]
max_num = max(nums)
max_cnt = len([i for i in nums if i == max_num])

for i in range(n):
  if nums[i] < max_num or max_cnt > 1:
    print(max_num)
  else:
    print(max(set(nums) - set([nums[i]])))
Buggy python submission (verdict: Runtime Error):
n, x = map(int, input().split())
li = list(map(int, input().split()))
res = 0
index = 0

while res <= x:
  res += li[index]
  index += 1

print(index)

Fixed submission:
n, x = map(int, input().split())
li = list(map(int, input().split()))
res = 0
cnt = 1

for i in li:
  res += i
  if res > x:
    break

  cnt += 1

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
s = list(input())
l_index = 0
cnt = 0

if len(s) == 1:
  print(cnt)
else:
  while True:
    for k, v in enumerate(s):
      l_index = k
      if k == 0:
        next
      elif v == s[k - 1]:
        cnt += 1
        s[k] = str((int(v) + 1) % 2)
        break

    if l_index == len(s) - 1:
      break

  print(cnt)


Fixed submission:
s = list(input())
r = ''
if s[0] == '0':
  r = ['0' if i % 2 == 0 else '1' for i in range(len(s))]
elif s[0] == '1':
  r = ['1' if i % 2 == 0 else '0' for i in range(len(s))]

mul = [str(int(s[i]) + int(r[i])) for i in range(len(s))]

print(mul.count('1'))
Buggy python submission (verdict: Runtime Error):
s = input()
count = 0
lens = []

for i, _ in enumerate(s):
  for c in s[i:]:
    if c in ['A', 'G', 'C', 'T']:
      count += 1
  	else:
      break
  lens.append(count)
  count = 0
  
print(max(lens))
  

Fixed submission:
s = input()
acgt = ["A","C","G","T"]
res = []
parts = ""

for i in range(len(s)):
    parts = ""
    for c in s[i:]:
        if c in acgt:
            parts += c
        else:
            break
    res.append(len(parts))

print(max(res))

Buggy python submission (verdict: Runtime Error):
s = input()
acgt = ["A","C","G","T"]
res = []
parts = ""

for i in range(len(s)):
    parts = ""
    for c in s[i:]:
        if c in acgt:
            parts += c
        else:
            res.append(len(parts))
            break

print(max(res))

Fixed submission:
s = input()
acgt = ["A","C","G","T"]
res = []
parts = ""

for i in range(len(s)):
    parts = ""
    for c in s[i:]:
        if c in acgt:
            parts += c
        else:
            break
    res.append(len(parts))

print(max(res))
Buggy python submission (verdict: Runtime Error):
t = ['01','10']
s = input()

def count_removal(c):
  is_01 = c.count(t[0])
  is_10 = c.count(t[1])
  if is_01 >= is_10 and is_01 > 0:
    return count_removal(c.replace(t[0], '')) + c.count(t[0]) * 2
  elif is_01 < is_10 and is_10 > 0:
    return count_removal(c.replace(t[1], '')) + c.count(t[1]) * 2
  else:
    return 0

print(count_removal(s))

Fixed submission:
s = input()

if s.count('1') > 0 and s.count('0') > 0:
  print(min(s.count('1'), s.count('0')) * 2)
else:
  print(0)

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

def count_removal(c):
  if '01' in c:
    return count_removal(c.replace('01', '')) + c.count('01')*2
  else:
    return 0

print(count_removal(s))

Fixed submission:
s = input()

if s.count('1') > 0 and s.count('0') > 0:
  print(min(s.count('1'), s.count('0')) * 2)
else:
  print(0)
Buggy python submission (verdict: Time Limit Exceeded):
m = int(input())
cnt = 0  ; d0 = 0 
for _ in range(m):
    d, c = map(int, input().split())
    for i in range(c):
        w = d0 + d
        if w > 9:
            d0 = w - 9
            cnt += 2
        else:
            d0 = w
            cnt += 1
print(cnt-1)


Fixed submission:
mat = [[[0, 0]]*10 for _ in range(10)]
def dsr(i):
    x, cnt = 0, 0
    for j in range(10):
        w = x + i
        if w > 9:
            x = w - 9
            cnt += 2
        else:
            x = w
            cnt += 1
        mat[i][j] = [x, cnt-1]
    #mat[i][0][0] = mat[i][9][0]
    x0 = mat[i][9][1] - mat[i][8][1]   #; print('x0', x0)
    for j in range(10):
        mat[i][j][1] += x0 

for i in range(10):
    dsr(i)
#print2(mat)

m = int(input())
cnt = 0; x0 = 0   
for _ in range(m):
    d, c = map(int, input().split())
    q, r = divmod(c-1, 9)
    cnt += mat[d][8][1]*q + mat[d][r][1] - mat[d][0][1] 
    x = mat[d][r][0]
    #print('x, cnt', x, cnt)
    w = x0 + x
    if w > 9:
        x0 = w - 9
        cnt += 2
    else:
        x0 = w
        cnt += 1
    #print('x0, x, cnt', x0, x,  cnt)    
print(cnt-1)

Buggy python submission (verdict: Runtime Error):
m = int(input())
a = []
for _ in range(m):
    d, c = map(int, input().split())
    a.extend([d]*c)
#print(a)

cnt = 0
for i in range(len(a)-1):
    w = a[i]+a[i+1] 
    if w > 9:
        a[i+1] = w - 9
        cnt += 2
    else:
        a[i+1] = w
        cnt += 1
#print(a)
print(cnt)

Fixed submission:
mat = [[[0, 0]]*10 for _ in range(10)]
def dsr(i):
    x, cnt = 0, 0
    for j in range(10):
        w = x + i
        if w > 9:
            x = w - 9
            cnt += 2
        else:
            x = w
            cnt += 1
        mat[i][j] = [x, cnt-1]
    #mat[i][0][0] = mat[i][9][0]
    x0 = mat[i][9][1] - mat[i][8][1]   #; print('x0', x0)
    for j in range(10):
        mat[i][j][1] += x0 

for i in range(10):
    dsr(i)
#print2(mat)

m = int(input())
cnt = 0; x0 = 0   
for _ in range(m):
    d, c = map(int, input().split())
    q, r = divmod(c-1, 9)
    cnt += mat[d][8][1]*q + mat[d][r][1] - mat[d][0][1] 
    x = mat[d][r][0]
    #print('x, cnt', x, cnt)
    w = x0 + x
    if w > 9:
        x0 = w - 9
        cnt += 2
    else:
        x0 = w
        cnt += 1
    #print('x0, x, cnt', x0, x,  cnt)    
print(cnt-1)
Buggy python submission (verdict: Runtime Error):
N = int(input())
M = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    u, v = u-1, v-1
    M[u].append((v, w))
    M[v].append((u, w))

visited = [False] * N
color = [0] * N

def dfs(u, c):
    visited[u] = True   #; print('u, c', u, c)
    for vw in M[u]:
        v, w = vw       #; print(vw)
        if visited[v] == False:
            if w%2 == 0:
                color[v] = c * 0b1
            else:
                color[v] = c ^ 0b1
            #print('v, c', v, c)
            dfs(v, color[v])

dfs(u, 0)
for i in range(N):
    print(color[i])

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N = int(input())
M = [[] for _ in range(N)]
for i in range(N-1):
    u, v, w = map(int, input().split())
    u, v = u-1, v-1
    M[u].append((v, w))
    M[v].append((u, w))

visited = [False] * N
color = [0] * N

def dfs(u, c):
    visited[u] = True   #; print('u, c', u, c)
    for vw in M[u]:
        v, w = vw       #; print(vw)
        if visited[v] == False:
            if w%2 == 0:
                color[v] = c * 0b1
            else:
                color[v] = c ^ 0b1
            #print('v, c', v, c)
            dfs(v, color[v])

dfs(u, 0)
for i in range(N):
    print(color[i])
Buggy python submission (verdict: Runtime Error):
N = int(input())
a = [[0]*3 for i in range(N)]

for i in range(N):
  a[i] = [int(i) for i in input().split()] 

def f(n, i):
  if n ==0:
    return a[0][i]
  i1 = (i+1) % 3
  i2 = (i+2) % 3
  if F[n][i]:
    return F[n][i]
  F[n][i] = max(f(n-1, i1), f(n-1, i2)) + a[n][i] 
  return F[n][i]  

F =[[None]*3 for _ in range(N)]

print(max(f(N-1, 0), f(N-1,1), f(N-1,2)))


Fixed submission:
import sys
sys.setrecursionlimit(1000000)

N = int(input())
a = [[0]*3 for i in range(N)]

for i in range(N):
  a[i] = [int(i) for i in input().split()] 

def f(n, i):
  if n ==0:
    return a[0][i]
  i1 = (i+1) % 3
  i2 = (i+2) % 3
  if F[n][i]:
    return F[n][i]
  F[n][i] = max(f(n-1, i1), f(n-1, i2)) + a[n][i] 
  return F[n][i]  

F =[[None]*3 for _ in range(N)]

print(max(f(N-1, 0), f(N-1,1), f(N-1,2)))
Buggy python submission (verdict: Runtime Error):
ef agree(s1, t1):
    for i in range(len(t1)):
        if not(s1[i] == t1[i] or s1[i] =='?'):
            return False
    return True

s = input()
t = input()  
ls, lt  = len(s), len(t)

ss =[]
for i in range(ls - lt +1):
    #print(s[i:i+lt], t)
    if agree(s[i:i+lt], t):
        ss.append( (s[:i]+t).replace('?', 'a') )
#print(ss)

if ss:
    print(min(ss))
else:
    print('UNRESTORABLE')

Fixed submission:
def agree(s1, t1):
    for i in range(len(t1)):
        if not(s1[i] == t1[i] or s1[i] =='?'):
            return False
    return True

s = input()
t = input()  
ls, lt  = len(s), len(t)

ss =[]
for i in range(ls - lt +1):
    #print(s[i:i+lt], t)
    if agree(s[i:i+lt], t):
        ss.append( (s[:i] + t + s[i+lt:]).replace('?', 'a') )
#print(ss)

if ss:
    print(min(ss))
else:
    print('UNRESTORABLE')
Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N = int(input())
a    = [ int(x) for x in input().split() ]
arev = [ -x for x in a[::-1] ]

Hl = a[:N]
heapq.heapify(Hl) #; print(Hl)

Hr = arev[:N]
heapq.heapify(Hr) #; print(Hr)

sumL = [sum(Hl)]
for i in range(N):
    x = heapq.heappushpop(Hl, a[N+i])
    #print(i, x, Hl, sum(Hl))
    sumL.append(sum(Hl))
    
sumR = [sum(Hr)]
for i in range(N):
    y = heapq.heappushpop(Hr, arev[N+i])
    #print(i, y, Hr, sum(Hr))
    sumR.append(sum(Hr))

#print(sumL, sumR)
dif = [ i+j for i, j in zip(sumL, sumR[::-1])]  #; print(dif)
print(max(dif))

Fixed submission:
import heapq

N = int(input())
a    = [ int(x) for x in input().split() ]
arev = [ -x for x in a[::-1] ]

Hl = a[:N]
heapq.heapify(Hl) #; print(Hl)
suml = sum(Hl)
sumL = [suml]

Hr = arev[:N]
heapq.heapify(Hr) #; print(Hr)
sumr = sum(Hr)
sumR = [sumr]

for i in range(N):
    x = heapq.heappushpop(Hl, a[N+i])
    #print(i, x, Hl, sum(Hl))
    suml += -x + a[N+i]
    sumL.append(suml)
    
for i in range(N):
    x = heapq.heappushpop(Hr, arev[N+i])
    #print(i, x, Hr, sum(Hr))
    sumr += -x + arev[N+i]
    sumR.append(sumr)

#print(sumL, sumR)
dif = [ i+j for i, j in zip(sumL, sumR[::-1])]  #; print(dif)
print(max(dif))

Buggy python submission (verdict: Time Limit Exceeded):
import heapq

N = int(input())
a    = [ int(x) for x in input().split() ]
aneg = [-x for x in a]
arev = a[::-1]

HL0 = aneg[:N-1]
heapq.heapify(HL0) #; print(HL0)

sumL = []
for i in range(N+1):
    heapq.heappush(HL0, aneg[N-1+i])
    H = HL0.copy() #; print(i, H)
    sum_ = 0
    for j in range(N):
        x = heapq.heappop(H) #; print(x) 
        sum_ += x     
    sumL.append(sum_)

    
HR0 = arev[:N-1]
heapq.heapify(HR0) #; print(HR0)

sumR = []
for i in range(N+1):
    heapq.heappush(HR0, arev[N-1+i])
    H = HR0.copy() #;     print(i, H)
    sum_ = 0
    for j in range(N):
        x = heapq.heappop(H) #; print(x) 
        sum_ += x      
    sumR.append(sum_)

# print(sumL, sumR)    
sumL = [-x for x in sumL ]    
sumR = sumR[::-1]

dif = [ i-j for i, j in zip(sumL, sumR) ]

# print(l_sumL, l_sumR) ; print(dif)
print(max(dif))

Fixed submission:
import heapq

N = int(input())
a    = [ int(x) for x in input().split() ]
arev = [ -x for x in a[::-1] ]

Hl = a[:N]
heapq.heapify(Hl) #; print(Hl)
suml = sum(Hl)
sumL = [suml]

Hr = arev[:N]
heapq.heapify(Hr) #; print(Hr)
sumr = sum(Hr)
sumR = [sumr]

for i in range(N):
    x = heapq.heappushpop(Hl, a[N+i])
    #print(i, x, Hl, sum(Hl))
    suml += -x + a[N+i]
    sumL.append(suml)
    
for i in range(N):
    x = heapq.heappushpop(Hr, arev[N+i])
    #print(i, x, Hr, sum(Hr))
    sumr += -x + arev[N+i]
    sumR.append(sumr)

#print(sumL, sumR)
dif = [ i+j for i, j in zip(sumL, sumR[::-1])]  #; print(dif)
print(max(dif))
Buggy python submission (verdict: Runtime Error):
S = input()
T = ['dream', 'dreamer', 'erase', 'eraser']
lenT = [len(i) for i in T]

def dayDream(Sres_in):
    global isDream     #;print('dayDream: ', Sres_in)
    for i, d in enumerate(T):
        #print('d:', d)
        if Sres_in[:lenT[i]] == d:            
            Sres_out = Sres_in[lenT[i]:]
            if Sres_out =='':                
                isDream = True   #; print('YES')
                return 
            else:
                dayDream(Sres_out)
    #print('return', Sres_in)
    return
    
isDream = False
dayDream(S)
if isDream:
    print('YES')
else:
    print('NO')

Fixed submission:
import sys
sys.setrecursionlimit(1000000)

S = input()

T = ['dream', 'dreamer', 'erase', 'eraser']
lenT = [len(i) for i in T]

def dayDream(pin):
    global isDream               #;print('dayDream: ', pin, S[pin:])
    for i, d in enumerate(T):
        #print('d:', d)
        if S[pin:pin+lenT[i]] == d:            
            pout = pin + lenT[i] #; print(d, pout)
            if pout == len(S):                
                isDream = True   #; print('YES')
                return 
            else:
                dayDream(pout)
    #print('dayDream return', pin)
    return
    
isDream = False
dayDream(0)
if isDream:
    print('YES')
else:
    print('NO')
Buggy python submission (verdict: Runtime Error):
n, k = map(int, input().split())
ans = max((n - k + 1) / n, 0)
for a in range(1, min(k, n + 1)):
    ans += 0.5 ** (k // a).bit_length() / n
print(f'{ans:.12f}')

Fixed submission:
n, k = map(int, input().split())
ans = max((n - k + 1) / n, 0)
for a in range(1, min(k, n + 1)):
    cnt = 0
    while k > a:
        a *= 2
        cnt += 1
    ans += 0.5 ** cnt / n
print('{:.12f}'.format(ans))
Buggy python submission (verdict: Runtime Error):
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int N, M; cin >> N >> M;
    vector<int> X(M);
    for (auto& xi : X) cin >> xi;
    sort(X.begin(), X.end());
    vector<int> diff(M - 1);
    for (int i = 0; i < M - 1; i++) {
        diff[i] = abs(X[i] - X[i + 1]);
    }
    sort(diff.begin(), diff.end());
    int res = 0;
    for (int i = 0; i < (M - 1) - (N - 1); i++) {
        res += diff[i];
    }
    cout << res << endl;
    return 0;
}

Fixed submission:
N, M = map(int, input().split())
X = sorted(map(int, input().split()))
D = sorted(abs(x - y) for x, y in zip(X, X[1:]))
if N > 1:
    print(sum(D[:-(N-1)]))
else:
    print(sum(D))