Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
S = [0]+list(accumulate(A))
AS = [0]*N
count = 0
for i in range(N):
  AS[i] = A[i]+S[i]
for i in range(N):
  num = AS[i]
  for j in range(i+1,N):
    if num*2 >= A[j]:
      num += A[j]
      if j == N-1:
        ans = len(A)-count
        print(ans)
        exit()
    else:
      count += 1
      break

Fixed submission:
from itertools import accumulate

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
S = list(accumulate(A))
AS = []
flg = False
count = 0

for i in range(N-1):
  AS.append(S[i]*2 - A[i+1])
for j in range(N-2,-1,-1):
  if AS[j] < 0:
    count = j+1
    break
print(len(A)-count)

Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
S = [0]+list(accumulate(A))
count = 0

for i in range(N):
  num = A[i] + S[i]
  for j in range(i+1,N):
    if num*2 >= A[j]:
      num += A[j]
    else:
      count -= 1
      break
  count += 1

print(count)

Fixed submission:
from itertools import accumulate

N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
S = list(accumulate(A))
AS = []
flg = False
count = 0

for i in range(N-1):
  AS.append(S[i]*2 - A[i+1])
for j in range(N-2,-1,-1):
  if AS[j] < 0:
    count = j+1
    break
print(len(A)-count)
Buggy python submission (verdict: Time Limit Exceeded):
K,S = map(int,input().split())
ans = 0
if 3*K < S:
  pass
else:
  for x in range(K+1):
    for y in range(K+1):
      for z in range(K+1):
        if x+y+z == S:
          ans += 1
print(ans)

Fixed submission:
K,S = map(int,input().split())
ans = 0
if 3*K < S:
  pass
else:
  for x in range(K+1):
    for y in range(K+1):
      z = S-x-y
      if 0 <= z <= K:
        ans += 1

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
from itertools import accumulate
from bisect import bisect_left

N = int(input())
l = [int(x) for x in range(1,N+1)]

al = list(accumulate(l))
b = bisect_left(al,N)

if al[b] == N:
  for i in range(b+1):
    print(i+1)
else:
  ng = al[b] - N
  for j in range(1,b+2):
    if j != ng:
      print(j)

Fixed submission:
N = int(input())
l = [int(x) for x in range(1,N+1)]

total_num,max_num = 0,0

if N <= 2:
  print(N)
  exit()

for i in range(1,N):
  total_num += i
  if total_num >= N:
    max_num = i
    break

if total_num == N:
  for i in range(max_num):
    print(i+1)
else:
  ng_num = total_num - N
  for j in range(max_num):
    if j+1 != ng_num:
      print(j+1)
Buggy python submission (verdict: Time Limit Exceeded):
X = str(input())
lx = len(X)
st = []

for i in range(lx):
  if X[i] == "S":
    st.append("S")
  else:
    if "S" in st:
      st.pop()
    else:
      st = ["T"] + st
   
print(len(st))

Fixed submission:
X = str(input())
X = X.replace("ST","")
lx = len(X)
s_count = 0
t_count = 0
for i in range(lx):
  if X[i] == "S":
    s_count += 1
  else:
    if s_count:
      s_count -= 1
    else:
      t_count += 1
   
print(s_count + t_count)

Buggy python submission (verdict: Time Limit Exceeded):
X = str(input())
X = X.replace("ST","")
lx = len(X)
st = []

for i in range(lx):
  if X[i] == "S":
    st.append("S")
  else:
    if "S" in st:
      st.pop()
    else:
      st = ["T"] + st
   
print(len(st))

Fixed submission:
X = str(input())
X = X.replace("ST","")
lx = len(X)
s_count = 0
t_count = 0
for i in range(lx):
  if X[i] == "S":
    s_count += 1
  else:
    if s_count:
      s_count -= 1
    else:
      t_count += 1
   
print(s_count + t_count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
X = str(input())
X = X.replace("ST","")
lx = len(X)
st = deque([])

for i in range(lx):
  if X[i] == "S":
    st.append("S")
  else:
    if "S" in st:
      st.pop()
    else:
      st.appendleft("T")
   
print(len(st))

Fixed submission:
X = str(input())
X = X.replace("ST","")
lx = len(X)
s_count = 0
t_count = 0
for i in range(lx):
  if X[i] == "S":
    s_count += 1
  else:
    if s_count:
      s_count -= 1
    else:
      t_count += 1
   
print(s_count + t_count)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
X = str(input())
lx = len(X)
st = deque([])

for i in range(lx):
  if X[i] == "S":
    st.append("S")
  else:
    if "S" in st:
      st.pop()
    else:
      st.appendleft("T")
      
print(len(st))

Fixed submission:
X = str(input())
X = X.replace("ST","")
lx = len(X)
s_count = 0
t_count = 0
for i in range(lx):
  if X[i] == "S":
    s_count += 1
  else:
    if s_count:
      s_count -= 1
    else:
      t_count += 1
   
print(s_count + t_count)

Buggy python submission (verdict: Time Limit Exceeded):
X = str(input())
while X.count("ST") > 0:
  X = X.replace("ST","")

print(len(X))

Fixed submission:
X = str(input())
X = X.replace("ST","")
lx = len(X)
s_count = 0
t_count = 0
for i in range(lx):
  if X[i] == "S":
    s_count += 1
  else:
    if s_count:
      s_count -= 1
    else:
      t_count += 1
   
print(s_count + t_count)

Buggy python submission (verdict: Time Limit Exceeded):
X = str(input())
while X.count("ST") > 0:
  X = X.replace("ST","")

print(len(X))

Fixed submission:
X = str(input())
X = X.replace("ST","")
lx = len(X)
s_count = 0
t_count = 0
for i in range(lx):
  if X[i] == "S":
    s_count += 1
  else:
    if s_count:
      s_count -= 1
    else:
      t_count += 1
   
print(s_count + t_count)
Buggy python submission (verdict: Runtime Error):
from bisect import *
S = list(str(input()))
K = int(input())

alp = list("abcdefghijklmnopqrstuvwxyz")

for i in range(len(S)):
  b = bisect_left(alp,S[i])
  print(b,K,S)
  if i == len(S)-1:
    S[i] = alp[(b+K)%26]
  elif 26 - b <= K:
    K -= (26 - b)
    S[i] = "a"
  if K == 0:
    break
  
print("".join(S))

Fixed submission:
from bisect import *
S = list(str(input()))
K = int(input())

alp = list("abcdefghijklmnopqrstuvwxyz")

for i in range(len(S)):
  b = bisect_left(alp,S[i])

  if i == len(S)-1:
    S[i] = alp[(b+K)%26]
  elif b == 0:
    continue
  elif 26 - b <= K:
    K -= (26 - b)
    S[i] = "a"
  if K == 0:
    break
  
print("".join(S))
Buggy python submission (verdict: Runtime Error):
a, b, k = inpm()
ta = a - k
ao = b
if(ta < 0):
    ao = b - ta
    ta = 0
if(ao < 0):
    ao = 0
print(str(ta) + ' ' + str(ao))


Fixed submission:
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

a, b, k = inpm()
ta = a - k
ao = b
if(ta < 0):
    ao = b + ta
    ta = 0
if(ao < 0):
    ao = 0
print(str(ta) + ' ' + str(ao))
Buggy python submission (verdict: Runtime Error):
N = line(input().rstrip())
sum = 0

for i in range(len(N)):
  sum += int(N[i])
 
if sum % 9 == 0:
  print("Yes")
else:
  print("No")

Fixed submission:
N = list(input().rstrip())
sum = 0
 
for i in range(len(N)):
  sum += int(N[i])
 
if sum % 9 == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Time Limit Exceeded):
from functools import reduce
n=input()
s=list(map(int,(input().split(" "))))
#s.sort()
ans=reduce(lambda x,y:x*y,s)
if ans > 1e18:
    print(-1)
else:
    print(ans)

Fixed submission:
n,*l=map(int,open(0).read().split())
a=1
for i in sorted(l):
  a*=i
  if a>10**18: a=-1; break
print(a)

Buggy python submission (verdict: Time Limit Exceeded):
n=input()
s=list(map(int,(input().split(" "))))
s.sort()
ans=1
for i in s:
    ans*=i
if ans > 1e18:
    print(-1)
else:
    print(ans)

Fixed submission:
n,*l=map(int,open(0).read().split())
a=1
for i in sorted(l):
  a*=i
  if a>10**18: a=-1; break
print(a)

Buggy python submission (verdict: Runtime Error):
n=input()
s=list(map(int,(input().split(" "))))
ans=1
for i in s:
    ans*=i
    if ans > 1e18:
        print(-1)
        sys.exit(0)
print(ans)

Fixed submission:
n,*l=map(int,open(0).read().split())
a=1
for i in sorted(l):
  a*=i
  if a>10**18: a=-1; break
print(a)
Buggy python submission (verdict: Runtime Error):
a,b,c = [int(i) for i in input().split()]
print("YES" if b-a==c-b "NO")

Fixed submission:
a,b,c = [int(i) for i in input().split()]
print("YES" if b-a==c-b else "NO")
Buggy python submission (verdict: Runtime Error):
s = raw_input().split()
print [s[0][0], s[1]][0], s[2][0]].join()

Fixed submission:
s=input().split()
print(s[0][0]+s[1][0]+s[2][0])
Buggy python submission (verdict: Time Limit Exceeded):
s=raw_input();i=a=0;exec"a+=s[i]!=s[-~i];i+=1;"*~-len(s);print a

Fixed submission:
s=raw_input()
print sum([s[i]!=s[i+1] for i in range(len(s)-1)])
Buggy python submission (verdict: Runtime Error):
N = int(input())
s = input()
l = input()
for i in range(1,N):
    if s[-i:]!=l[:i]:
        a=2*N-i+1
        break
print(a if s!=l else N)

Fixed submission:
i=input;N=int(i());s=i();l=i();n=N;j=0
exec("j=max(n*(s[-n:]==l[:n]),j);n-=1;"*N);print(2*N-j)
Buggy python submission (verdict: Runtime Error):
import scipy.misc as scm

H, W, A, B = [int(input()) for _ in range(4)]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)

Fixed submission:
import scipy.misc as scm

H, W, A, B = [int(i) for i in input().split()]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)

Buggy python submission (verdict: Runtime Error):
H, W, A, B = [int(input()) for _ in range(4)]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)

Fixed submission:
import scipy.misc as scm

H, W, A, B = [int(i) for i in input().split()]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)

Buggy python submission (verdict: Runtime Error):
#H, W, A, B = [int(input()) for _ in range(4)]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)

Fixed submission:
import scipy.misc as scm

H, W, A, B = [int(i) for i in input().split()]
MOD = 10**9 + 7
f = [1]
a = [1]
for i in range(1, H+W-1):
    f.append((f[i-1] * i) % MOD)
    a.append(pow(f[i], MOD-2, MOD))
ans = 0
for i in range(B, W, 1):
    ans += (((f[(H-A-1)+i] * a[H-A-1] * a[i]) % MOD) * ((f[(A-1)+(W-1-i)] * a[A-1] * a[W-1-i]) % MOD))
    ans %= MOD
print(ans)
Buggy python submission (verdict: Runtime Error):
x = int(input())
y = !x
print(y)

Fixed submission:
x = int(input())
print(1-x)

Buggy python submission (verdict: Runtime Error):
x = int(input())
print(!x)

Fixed submission:
x = int(input())
print(1-x)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))
ans = 1 ;
for i in range(0, n) :
    ans *= x[i]
if ans > 1000000000000000000 :
    print(-1)
else :
    print(ans)

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

if 0 in x :
    print(0)
else :
    ans = 1
    con = True
    for i in range(0, n):
        ans *= x[i]
        if ans > 1000000000000000000:
            print(-1)
            con = False
            break
    if con : print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
x = list(map(int, input().split()))
mx = 1E18
ans = 1 ;
for i in range(0, n) :
    ans *= x[i]
if ans > mx :
    print(-1)
else :
    print(ans)

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

if 0 in x :
    print(0)
else :
    ans = 1
    con = True
    for i in range(0, n):
        ans *= x[i]
        if ans > 1000000000000000000:
            print(-1)
            con = False
            break
    if con : print(ans)

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

for i in range(1,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 = a[0]

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

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

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
N, M = map(int, input().split())
H = list(map(int, input().split()))
A, B = [], []
for _ in range(M):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
ans = 0
for i in range(N):
    L = []
    if i+1 not in A and i+1 not in B:
        ans += 1
    else:
        for j in range(M):
            if A[j] == i+1:
                if H[A[j]-1] != H[B[j]-1]:
                    L.append(H[A[j]-1])
                    L.append(H[B[j]-1])
            elif B[j] == i+1:
                if H[A[j]-1] != H[B[j]-1]:
                    L.append(H[A[j]-1])
                    L.append(H[B[j]-1])
        if len(L) == 0:
            d = 1
        elif max(L) == H[i]:
            ans += 1
print(ans)

Fixed submission:
n,m=map(int,input().split())
way=[[] for i in range(n)]
H = list(map(int,input().split()))
for i in range(m):
    a,b=map(int,input().split())
    way[a-1].append(b-1)
    way[b-1].append(a-1)
ans=0
for i in range(n):
    high=True
    for j in way[i]:
        if H[i]<=H[j]:
            high=0
            break
    if high:
        ans+=1
print(ans)
Buggy python submission (verdict: Runtime Error):
import math

k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        a = gcd(i,j)
        for l in range(1,k+1):
            ans += gcd(a,l)

print(ans)

Fixed submission:
import math

k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        a = math.gcd(i,j)
        for l in range(1,k+1):
            ans += math.gcd(a,l)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

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

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

k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        a = gcd(i,j)
        for l in range(1,k+1):
            ans += gcd(a,l)

print(ans)

Fixed submission:
import math

k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        a = math.gcd(i,j)
        for l in range(1,k+1):
            ans += math.gcd(a,l)

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
import math
from functools import reduce

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

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

k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        for l in range(1,k+1):
            ans += gcd(i,j,l)

print(ans)

Fixed submission:
import math

k = int(input())
ans = 0

for i in range(1,k+1):
    for j in range(1,k+1):
        a = math.gcd(i,j)
        for l in range(1,k+1):
            ans += math.gcd(a,l)

print(ans)
Buggy python submission (verdict: Time Limit Exceeded):
import collections
n = int(input())
s = [input() for _ in range(n)]
D = []

c = collections.Counter(s)

for i in range(len(c.most_common())):
    if c.most_common()[i][1] == c.most_common()[0][1]:
        d = c.most_common()[i][0]
        D.append(d)
    else:
        break

e = sorted(D)

for i in e:
    print(i)

Fixed submission:
N = int(input())
A = {}
for i in range(N):
  s = input()
  if s in A:
    A[s] += 1
  else:
    A[s] = 1
s_max = max(A.values())
for j in sorted(k for k in A if A[k] == s_max):
  print(j)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))

for i in range(n):
    if a.count(a[i]) == 1:
        continue
    else:
        print('NO')
        exit()

print('YES')

Fixed submission:
import collections

n = int(input())
a = list(input().split())
c = collections.Counter(a)

if c.most_common()[0][1] != 1:
    print('NO')
    exit()

print('YES')
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
a = list(map(int, input().split()))
b = []

if n % 2 == 0:
    for i in range(n):
        if i % 2 == 0:
            b.append(a[i])
        else:
            b.insert(0,a[i])
else:
    for i in range(n):
        if i % 2 == 0:
            b.insert(0,a[i])
        else:
            b.append(a[i])

print(*b)

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

if n % 2 == 0:
    b = a[n-1::-2] + a[::2]
else:
    b = a[n-1::-2] + a[1::2]

print(*b)

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

if n % 2 == 0:
    for i in range(n):
        if i % 2 == 0:
            b.append(a[i])
        else:
            b.insert(0,a[i])
else:
    for i in range(n):
        if i % 2 == 0:
            b.insert(0,a[i])
        else:
            b.append(a[i])

for j in b:
    print(j,end=' ')

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

if n % 2 == 0:
    b = a[n-1::-2] + a[::2]
else:
    b = a[n-1::-2] + a[1::2]

print(*b)

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

for i in range(n):
    b.append(a[i])
    b = list(reversed(b))

for j in b:
    print(j,end=' ')

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

if n % 2 == 0:
    b = a[n-1::-2] + a[::2]
else:
    b = a[n-1::-2] + a[1::2]

print(*b)
Buggy python submission (verdict: Time Limit Exceeded):
x = int(input())
ans = 0
count = 0

while 1:
    count += 6
    ans += 1
    if count >= x:
        print(ans)
        exit()
    count += 5
    ans += 1
    if count >= x:
        print(ans)
        exit()

Fixed submission:
x = int(input())
a = x % 11
b = x // 11

if a == 0:
    c = 0
elif a <= 6:
    c = 1
else:
    c = 2

print(b * 2 + c)
Buggy python submission (verdict: Time Limit Exceeded):
N,*A=map(int,open(0).read().split())
m=1000000000+7
ans=0
for i in range(N):
    for j in range(i+1,N):
        ans+=(A[i]*A[j])
        ans%=m
print(ans)


Fixed submission:
N,*A=map(int,open(0).read().split())
l=[]
s=0
for a in reversed(A):
    s+=a
    l.append(s)
l.reverse()
m=1000000000+7
ans=0
for i in range(N-1):
    ans+=A[i]*l[i+1]
    ans%=m
print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
N,*A=map(int,open(0).read().split())
m=1000000000+7
ans=0
for i in range(N):
    for j in range(i+1,N):
        ans+=A[i]*A[j]
ans%=m
print(ans)


Fixed submission:
N,*A=map(int,open(0).read().split())
l=[]
s=0
for a in reversed(A):
    s+=a
    l.append(s)
l.reverse()
m=1000000000+7
ans=0
for i in range(N-1):
    ans+=A[i]*l[i+1]
    ans%=m
print(ans)
Buggy python submission (verdict: Runtime Error):
import heapq
l=lambda:[int(x) for x in input().split()]
H,W=l()
CH,CW=l()
DH,DW=l()
dh=DH-1
dw=DW-1
S=[[x=='#' for x in list(input())] for _ in range(H)]
q=[(0,0,CH-1,CW-1)]
heapq.heapify(q)
checked=set()
def check(h,w,c):
    if h<0 or h>=H or w<0 or w>=W:
        return
    if S[h][w]:
        return
    p=(abs(dh-h),abs(dw-w))
    heapq.heappush(q,(c,p,h,w))

def main():
    while q:
        c,_,h,w=heapq.heappop(q)
        if h==dh and w==dw:
            return c
        key=(h,w)
        if key in checked:
            continue
        checked.add(key)
        # walk
        check(h-1,w-0,c)
        check(h-0,w-1,c)
        check(h+1,w+0,c)
        check(h+0,w+1,c)
        # warp
        check(h-1,w-1,c+1)
        check(h-1,w+1,c+1)
        check(h+1,w-1,c+1)
        check(h+1,w+1,c+1)
        for i in [-2,+2]:
            for j in range(-2,3):
                check(h+i,w+j,c+1)
                check(h+j,w+i,c+1)
    return -1
print(main())


Fixed submission:
import math
N,X,T = map(int, input().split())
print(math.ceil(N/X)*T)
Buggy python submission (verdict: Runtime Error):
N,*A=map(int,input().split())
m=max(A)
s=sum([m-a for a in A])
print(s)


Fixed submission:

input()
A=list(map(int,input().split()))
m=0
s=0
for a in A:
    d=max(0, m-a)
    s+=d
    m=max(m, a)
print(s)
Buggy python submission (verdict: Runtime Error):
N = int(open(0).read())
m = N % 1000
if m == 0:
    print(0)
else:
    print(1000 - m)
|                        

Fixed submission:
N = int(open(0).read())
m = N % 1000
if m == 0:
    print(0)
else:
    print(1000 - m)
Buggy python submission (verdict: Runtime Error):
n,m,k,*ab = map(int, open(0).read().split())
aa = ab[:n]
bb = ab[m-1:]
ans = 0
i = j = 0
while True:
    if n <= i and m <= j:
        break
    elif n > i and m > j:
        a = aa[i]
        b = bb[j]
        if a < b:
            if a > k:
                break
            i += 1
            ans += 1
            k -= a
        else:
            if b > k:
                break
            j += 1
            ans += 1
            k -= b
    elif n > i:
        a = aa[i]
        if a > k:
            break
        i += 1
        ans += 1
        k -= a
    else:
        b = bb[j]
        if b > k:
            break
        j += 1
        ans += 1
        k -= b
print(ans)


Fixed submission:
N,M,K,*AB = map(int, open(0).read().split())
A = AB[:N]
B = AB[N:]
a = [0]
b = [0]
for i in range(N): a.append(a[i] + A[i])
for i in range(M): b.append(b[i] + B[i])
ans = 0
j = M
for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i+j)
print(ans)