Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Time Limit Exceeded):
n,m,l=map(int,input().split())
edge=[[]for _ in range(n)]
for _ in range(m):
  a,b,c=map(int,input().split())
  if c>l:continue
  a-=1;b-=1
  edge[a].append([b,c])
  edge[b].append([a,c])
from heapq import heappop,heappush
inf=10**10
cost=[[[inf,inf]for _ in range(n)]for _ in range(n)]
for i in range(n):
  cost[i][i]=[0,0]
  h=[[0,i]]
  while h:
    c,v=heappop(h)
    c,co=c//(10**9+7),c%(10**9+7)
    if cost[i][v][0]<c or (cost[i][v][0]==c and cost[i][v][1]<co):continue
    for u,t in edge[v]:
      if co+t>l:
        c2=c+1
        co2=t
      else:
        c2=c
        co2=co+t
      if cost[i][u][0]>c2 or (cost[i][u][0]==c2 and cost[i][u][1]>co2):
        cost[i][u]=[c2,co2]
        heappush(h,[c2*(10**9+7)+co2,u])
ans=[[j[0]for j in i]for i in cost]
q=int(input())
ab=[list(map(int,input().split()))for _ in range(q)]
for a,b in ab:
  if ans[a-1][b-1]==10**10:print(-1)
  else:print(ans[a-1][b-1])

Fixed submission:
def warshall_floyd(edge):
  e=edge
  for k in range(len(e)):
    for i in range(len(e)):
      for j in range(len(e)):e[i][j]=min(e[i][j],e[i][k]+e[k][j])
  return e
n,m,l=map(int,input().split())
edge=[n*[10**10]for _ in range(n)]
for i in range(n):edge[i][i]=0
for _ in range(m):
  a,b,c=map(int,input().split())
  a-=1;b-=1
  edge[a][b]=edge[b][a]=c
edge=warshall_floyd(edge)
edgee=[n*[10**10]for _ in range(n)]
for i in range(n):
  edgee[i][i]=0
  for j in range(n):
    if edge[i][j]<=l:edgee[i][j]=1
edgee=warshall_floyd(edgee)
q=int(input())
for _ in range(q):
  s,t=map(int,input().split())
  s-=1;t-=1
  ans=edgee[s][t]
  if ans==10**10:print(-1)
  else:print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
def warshall_floyd(edge):
  e=edge
  for k in range(len(e)):
    for i in range(len(e)):
      for j in range(len(e)):e[i][j]=min(e[i][j],e[i][k]+e[k][j])
  return e
n,m,l=map(int,input().split())
edge=[n*[10**10]for _ in range(n)]
for i in range(n):edge[i][i]=0
for _ in range(m):
  a,b,c=map(int,input().split())
  a-=1;b-=1
  edge[a][b]=edge[b][a]=c
edge=warshall_floyd(edge)
edgee=[n*[10**10]for _ in range(n)]
for i in range(n):
  edgee[i][i]=0
  for j in range(n):
    if edge[i][j]<=l:edgee[i][j]=1
edgee=warshall_floyd(edgee)
q=int(input())
for _ in range(q):
  s,t=map(int,input().split())
  s-=1;t-=1
  ans=edgee[s][t]
  if ans==10**10:print(-1)
  else:print(ans-1)

Fixed submission:
def warshall_floyd(edge):
  e=edge
  for k in range(len(e)):
    for i in range(len(e)):
      for j in range(len(e)):e[i][j]=min(e[i][j],e[i][k]+e[k][j])
  return e
n,m,l=map(int,input().split())
edge=[n*[10**10]for _ in range(n)]
for i in range(n):edge[i][i]=0
for _ in range(m):
  a,b,c=map(int,input().split())
  a-=1;b-=1
  edge[a][b]=edge[b][a]=c
edge=warshall_floyd(edge)
edgee=[n*[10**10]for _ in range(n)]
for i in range(n):
  edgee[i][i]=0
  for j in range(n):
    if edge[i][j]<=l:edgee[i][j]=1
edgee=warshall_floyd(edgee)
q=int(input())
for _ in range(q):
  s,t=map(int,input().split())
  s-=1;t-=1
  ans=edgee[s][t]
  if ans==10**10:print(-1)
  else:print(ans-1)
Buggy python submission (verdict: Runtime Error):
n=int(input())
b=[[]for _ in range(n)]
d=[]
inf=float('inf')
for i in range(n):
  s=input()
  c=[]
  for j in range(n):
    if s[j]=="1":
      b[i]+=[(i,j)]
    c.append(1 if s[j]=="1" else inf)
  d.append(c)
from scipy.sparse.csgraph import bellman_ford
d=bellman_ford(d)
x=[-1]*n
x[0]=0
Q=b[0]
while Q:
  p=[]
  for i,j in Q:
    if x[j]<0:
      x[j]=x[i]^1
      p+=b[j]
    elif x[i]==x[j]:print(-1);exit()
  Q=p
print(int(max(map(max,*d)))+1)

Fixed submission:
n=int(input())
b=[[]for _ in range(n)]
d=[]
inf=float('inf')
inf=float('inf')
for i in range(n):
  s=input()
  c=[]
  for j in range(n):
    if s[j]=="1":
      b[i]+=[(i,j)]
    c.append(1 if s[j]=="1" else inf)
  d.append(c)
def warshall_floyd(d):
    for i in range(n):d[i][i]=0
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
d=warshall_floyd(d)
x=[-1]*n
x[0]=0
Q=b[0]
while Q:
  p=[]
  for i,j in Q:
    if x[j]<0:
      x[j]=x[i]^1
      p+=b[j]
    elif x[i]==x[j]:print(-1);exit()
  Q=p
z=0
for i in d:
  for j in i:
    if j!=float("inf"):z=max(j,z)
print(z+1)

Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
b=[[]for _ in range(n)]
d=[]
inf=float('inf')
for i in range(n):
  s=input()
  c=[]
  for j in range(n):
    if s[j]=="1":
      b[i]+=[(i,j)]
    c.append(1 if s[j]=="1" else inf)
  d.append(c)
from scipy.sparse.csgraph import bellman_ford
d=bellman_ford(d)
x=[-1]*n
x[0]=0
Q=b[0]
while Q:
  p=[]
  for i,j in Q:
    if x[j]<0:
      x[j]=x[i]^1
      p+=b[j]
    elif x[i]==x[j]:print(-1);exit()
  Q=p
print(int(max(map(max,*d)))+1)

Fixed submission:
n=int(input())
b=[[]for _ in range(n)]
d=[]
inf=float('inf')
inf=float('inf')
for i in range(n):
  s=input()
  c=[]
  for j in range(n):
    if s[j]=="1":
      b[i]+=[(i,j)]
    c.append(1 if s[j]=="1" else inf)
  d.append(c)
def warshall_floyd(d):
    for i in range(n):d[i][i]=0
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d
d=warshall_floyd(d)
x=[-1]*n
x[0]=0
Q=b[0]
while Q:
  p=[]
  for i,j in Q:
    if x[j]<0:
      x[j]=x[i]^1
      p+=b[j]
    elif x[i]==x[j]:print(-1);exit()
  Q=p
z=0
for i in d:
  for j in i:
    if j!=float("inf"):z=max(j,z)
print(z+1)
Buggy python submission (verdict: Runtime Error):
L()=lambda:list(map(int,input().split()))
I()=lambda:input()
s=I()
d=["Sunny","Cloudy","Rainy","Sunny"]
print(d[d.index(s)+1])

Fixed submission:
L=lambda:list(map(int,input().split()))
I=lambda:input()
s=I()
d=["Sunny","Cloudy","Rainy","Sunny"]
print(d[d.index(s)+1])

Buggy python submission (verdict: Runtime Error):
L()=lambda:list(map(int,input().split()))
I()=lambda:input()
s=int(I())
d=["Sunny","Cloudy","Rainy","Sunny"]
print(d[d.index(s)+1])

Fixed submission:
L=lambda:list(map(int,input().split()))
I=lambda:input()
s=I()
d=["Sunny","Cloudy","Rainy","Sunny"]
print(d[d.index(s)+1])
Buggy python submission (verdict: Runtime Error):
n=int(input())print(n*(n-1)//2)

Fixed submission:
n=int(input());print(n*(n-1)//2)
Buggy python submission (verdict: Runtime Error):
m=int(input())
d=int(input())
ans=0
for i in range(1,m+1):
  for j in range(10,d+1):
    if i==(j//10)*(j%10) and j//10>1 and j%10>1:ans+=1
print(ans)

Fixed submission:
I=lambda:input()
L=lambda:list(map(int,I().split()))
m,d=L()
a=0
for i in range(1,m+1):
  for j in range(10,d+1):
    if i==(j//10)*(j%10)and j//10>1 and j%10>1:a+=1
print(a)
Buggy python submission (verdict: Runtime Error):
L=lambda:list(map(int,input().split()))
n=int(input())
a=L()
b=0
for i in a:b+=1/a
print(1/b)

Fixed submission:
L=lambda:list(map(int,input().split()))
n=int(input())
a=L()
b=0
for i in a:b+=1/i
print(1/b)
Buggy python submission (verdict: Time Limit Exceeded):
from collections import*
M=lambda:map(int,input().split())
n,q=M()
s=[[]for _ in range(n)]
for i in range(n-1):
  a,b=M()
  s[a-1].append(b-1)
  s[b-1].append(a-1)
p=[0]*n
for i in range(q):
  a,b=M()
  p[a-1]+=b
v=[1]+[0]*(n-1)
d=deque([(0,0)])
while d:
  b,c=d.popleft()
  c+=p[b]
  p[b]=c
  for i in s[b]:
    if v[i]:continue
    v[i]=1
    d.append((i,c))
print(*p)

Fixed submission:
import sys;input=sys.stdin.readline
from collections import deque
M=lambda:map(int,input().split())
n,q=M()
s=[[]for _ in range(n)]
for i in range(n-1):
  a,b=M()
  s[a-1].append(b-1)
  s[b-1].append(a-1)
p=[0]*n
for i in range(q):
  a,b=M()
  p[a-1]+=b
v=[1]+[0]*(n-1)
d=deque([(0,0)])
while d:
  b,c=d.popleft()
  c+=p[b]
  p[b]=c
  for i in s[b]:
    if v[i]:continue
    v[i]=1
    d.append((i,c))
print(*p)

Buggy python submission (verdict: Time Limit Exceeded):
import sys;sys.setrecursionlimit(10000000)
M=lambda:map(int,input().split())
n,q=M()
s=[set()for _ in range(n)]
for i in range(n-1):
  a,b=M()
  s[a-1].add(b-1)
  s[b-1].add(a-1)
p=[0]*n
for i in range(q):
  a,b=M()
  p[a-1]+=b
x=[0]*n
def bfs(I,U):
  global x,s
  u=U
  u+=p[I]
  x[I]=u
  for i in s[I]:
    s[i].discard(I)
    bfs(i,u)
bfs(0,0)
print(*x)

Fixed submission:
import sys;input=sys.stdin.readline
from collections import deque
M=lambda:map(int,input().split())
n,q=M()
s=[[]for _ in range(n)]
for i in range(n-1):
  a,b=M()
  s[a-1].append(b-1)
  s[b-1].append(a-1)
p=[0]*n
for i in range(q):
  a,b=M()
  p[a-1]+=b
v=[1]+[0]*(n-1)
d=deque([(0,0)])
while d:
  b,c=d.popleft()
  c+=p[b]
  p[b]=c
  for i in s[b]:
    if v[i]:continue
    v[i]=1
    d.append((i,c))
print(*p)

Buggy python submission (verdict: Time Limit Exceeded):
import sys;sys.setrecursionlimit(10000000)
M=lambda:map(int,input().split())
n,q=M()
s=[set()for _ in range(n)]
for i in range(n-1):
  a,b=M()
  s[a-1].add(b-1)
  s[b-1].add(a-1)
p=[0]*n
for i in range(q):
  a,b=M()
  p[a-1]+=b
x=[0]*n
def bfs(I,U):
  global x,s
  u=U
  u+=p[I]
  x[I]=u
  for i in s[I]:
    s[i].discard(I)
    bfs(i,u)
bfs(0,0)
print(*x)

Fixed submission:
import sys;input=sys.stdin.readline
from collections import deque
M=lambda:map(int,input().split())
n,q=M()
s=[[]for _ in range(n)]
for i in range(n-1):
  a,b=M()
  s[a-1].append(b-1)
  s[b-1].append(a-1)
p=[0]*n
for i in range(q):
  a,b=M()
  p[a-1]+=b
v=[1]+[0]*(n-1)
d=deque([(0,0)])
while d:
  b,c=d.popleft()
  c+=p[b]
  p[b]=c
  for i in s[b]:
    if v[i]:continue
    v[i]=1
    d.append((i,c))
print(*p)
Buggy python submission (verdict: Time Limit Exceeded):
import math
n,a=int(input()),list(map(int,input().split()))
b=[0]*n
ba=set()
for i in range(n):
  if a[n-i-1]==(b[n-i-1]+1)%2:
    b[n-i-1]+=1
    ba.add(n-i)
    for j in range(2,n-i+1):
      if (n-i)%j==0:b[(n-i)//j-1]+=1
l=len(ba)
c=[ba.pop()for i in range(l)]
print(l)
print(*c)

Fixed submission:
n,a,d,l=int(input()),list(map(int,input().split())),set(),0;b=[0]*n
for i in range(n-1,-1,-1):
  c=0
  for j in range(2*i+1,n,i+1):c=(c+b[j])%2
  if a[i]!=c:b[i]+=1;d.add(i+1);l+=1
print(l)
print(*[d.pop()for _ in range(l)])
Buggy python submission (verdict: Time Limit Exceeded):
n=int(input())
a=[-int(input())]
l=1
for i in range(1,n):
  b=-int(input())
  if a[-1]>b:
    if a[0]>b:a[0]=b;continue
    ok=l
    ng=0
    c=ok//2
    while ng+1<ok:
      if b<a[c]:ok=c
      else:ng=c
    a[ok]=b
  else:a.append(b);l+=1
print(l)

Fixed submission:
import bisect
n=int(input())
x=[int(input())for _ in range(n)]
a=[-x[0]]
l=1
for i in range(1,n):
  b=-x[i]
  if a[-1]>b:
    if a[0]>b:a[0]=b;continue
    a[bisect.bisect_right(a,b)]=b
  else:a.append(b);l+=1
print(l)
Buggy python submission (verdict: Runtime Error):
n,a=int(input()),sorted(list(map(int,input().split())));b=set(a);l=len(b)
if l!=3:print("Yes"if(l==1and a[0]==0)or(l==2and a[0]==0and n%3==0and a[n//3-1]!=a[n//3])else"No")
elif:print("Yes"if b.pop()^b.pop()==b.pop()and n%3==0and a[n//3-1]!=a[n//3]and a[n//3*2-1]!=a[n//3*2]else"No")

Fixed submission:
n,a=int(input()),sorted(list(map(int,input().split())));b=set(a);l=len(b)
if l!=3:print("Yes"if(l==1and a[0]==0)or(l==2and a[0]==0and n%3==0and a[n//3-1]!=a[n//3])else"No")
else:print("Yes"if b.pop()^b.pop()==b.pop()and n%3==0and a[n//3-1]!=a[n//3]and a[n//3*2-1]!=a[n//3*2]else"No")

Buggy python submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=set(a)
l=len(b)
if l==1:
  if a[0]==0:print("Yes")
  else:print("No")
  exit()
elif l==2 and 0 in b and n%3==0:
  if a[n//2-1]!=a[n//2]:print("Yes")
  else:print("No")
elif l!=3:print("No");exit()
if n%3!=0:print("No");exit()
def ecount(X):
  c,ans=1,[]
  for i in range(len(X)-1):
    if X[i]==X[i+1]:c+=1
    else:
      ans.append(c);c=1
  ans.append(c)
  return ans
d=sorted(ecount(a))
if b.pop()^b.pop()==b.pop() and d[0]==d[2]:print("Yes")
else:print("No")

Fixed submission:
n,a=int(input()),sorted(list(map(int,input().split())));b=set(a);l=len(b)
if l!=3:print("Yes"if(l==1and a[0]==0)or(l==2and a[0]==0and n%3==0and a[n//3-1]!=a[n//3])else"No")
else:print("Yes"if b.pop()^b.pop()==b.pop()and n%3==0and a[n//3-1]!=a[n//3]and a[n//3*2-1]!=a[n//3*2]else"No")
Buggy python submission (verdict: Runtime Error):
x,a-map(int,input().split())
print((x>=a)*10)

Fixed submission:
x,a=map(int,input().split())
print((x>=a)*10)
Buggy python submission (verdict: Runtime Error):
w,h,x,y=map(int,input().split())
a=w*h/2
s=0
if w==x*2 and h=y*2:s=1
print(a,s)

Fixed submission:
w,h,x,y=map(int,input().split())
a=w*h/2
s=0
if w==x*2 and h==y*2:s=1
print(a,s)
Buggy python submission (verdict: Runtime Error):
p,g,r=map(int,input().split())
print(min(p+q,q+r,r+p))

Fixed submission:
a,b,c=map(int,input().split())
print(min(a+b,a+c,b+c))
Buggy python submission (verdict: Runtime Error):
n,w=int(input()),list(map(int,input().split()))
a=w[0]
for i in w[1:]:a.append(a[-1]+i)
ans=a[-1]
for i in a:
  if ans>max(i,ans-i):ans=a[-1]-i
print(ans)

Fixed submission:
n,w=int(input()),list(map(int,input().split()))
a=[w[0]]
for i in w[1:]:a.append(a[-1]+i)
ans=a[-1]
for i in a:
  if ans>abs((a[-1]-i)-i):ans=abs((a[-1]-i)-i)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
mod=%10**9+7
dp=[0]*(n+7)
dp[0]=1
a=[int(input())for _ in range(m)]
a=set(a)
for i in range(n):
  if i+1 not in a:
    dp[i+2]+=dp[i]
    dp[i+1]+=dp[i]
  dp[i+2]%=mod
print(dp[n]%mod)


Fixed submission:
n,m=map(int,input().split())
dp=[0]*(n+1)
dp[0]=1
a=b=0
if b<m:a=int(input())
for i in range(1,n+1):
  if i==a:
    b+=1
    if b<m:a=int(input())
  else:
    dp[i]=dp[i-1]
    if i>1:dp[i]+=dp[i-2]
  dp[i]%=(10**9+7)
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
dp=[0]*(n+7)
dp[0]=1
a=list(map(int,input().split()))
a=set(a)
for i in range(n):
  if i+1 not in a:
    dp[i+2]+=dp[i]
    dp[i+1]+=dp[i]
print(dp[n])

Fixed submission:
n,m=map(int,input().split())
dp=[0]*(n+1)
dp[0]=1
a=b=0
if b<m:a=int(input())
for i in range(1,n+1):
  if i==a:
    b+=1
    if b<m:a=int(input())
  else:
    dp[i]=dp[i-1]
    if i>1:dp[i]+=dp[i-2]
  dp[i]%=(10**9+7)
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
dp=[0]*(n+1)
dp[0]=1
a=int(input())
b=0
for i in range(1,n+1):
  if i==a:
    b+=1
    if b<m:a=int(input())
  else:
    dp[i]=dp[i-1]
    if i>1:dp[i]+=dp[i-2]
  dp[i]%=(10**9+7)
print(dp[-1])

Fixed submission:
n,m=map(int,input().split())
dp=[0]*(n+1)
dp[0]=1
a=b=0
if b<m:a=int(input())
for i in range(1,n+1):
  if i==a:
    b+=1
    if b<m:a=int(input())
  else:
    dp[i]=dp[i-1]
    if i>1:dp[i]+=dp[i-2]
  dp[i]%=(10**9+7)
print(dp[-1])

Buggy python submission (verdict: Runtime Error):
n,m=map(int,input().split())
dp=[0]*(n+1)
dp[0]=1
a=int(input())
b=0
for i in range(1,n+1):
  if i==a:
    b+=1
    if b<m:a=int(input())
  else:dp[i]=(dp[i-1]+dp[i-2])%(10**9+7)
print(dp[-1])

Fixed submission:
n,m=map(int,input().split())
dp=[0]*(n+1)
dp[0]=1
a=b=0
if b<m:a=int(input())
for i in range(1,n+1):
  if i==a:
    b+=1
    if b<m:a=int(input())
  else:
    dp[i]=dp[i-1]
    if i>1:dp[i]+=dp[i-2]
  dp[i]%=(10**9+7)
print(dp[-1])
Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
g=["#"*(w+1)]+["#"+input()+"#"for _ in range(h)]+["#"*(w+1)]
def check(i,j):
  global g
  a=1
  k=1
  while g[i-k][j]!="#":k+=1;a+=1
  k=1
  while g[i+k][j]!="#":k+=1;a+=1
  k=1
  while g[i][j-k]!="#":k+=1;a+=1
  k=1
  while g[i][j+k]!="#":k+=1;a+=1
  return a
ans=0
for i in range(1,h+1):
  for j in range(1,w+1):
    if g[i][j]!="#":ans=max(ans,check(i,j))
print(ans)

Fixed submission:
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
g=[["#"]*(w+1)]+[["#"]+list(input())+["#"]for _ in range(h)]+[["#"]*(w+1)]
gg=[[0]*w for _ in range(h)]
for i in range(1,h+1):
  k=1
  for j in range(1,w+1):
    if g[i][j]==".":
      gg[i-1][j-1]=k;k+=1
    else:k=1
  d=gg[i-1][-1]
  for j in range(1,w+1):
    if gg[i-1][-j]!=0:gg[i-1][-j]=d
    elif j!=w:d=gg[i-1][-j-1]
ggg=[[0]*w for _ in range(h)]
for j in range(1,w+1):
  k=1
  for i in range(1,h+1):
    if g[i][j]==".":
      ggg[i-1][j-1]=k;k+=1
    else:k=1
  d=ggg[-1][j-1]
  for i in range(1,h+1):
    if ggg[-i][j-1]!=0:ggg[-i][j-1]=d
    elif i!=h:d=ggg[-i-1][j-1]
ans=0
for i in range(h):
  for j in range(w):ans=max(ans,gg[i][j]+ggg[i][j])
print(ans-1)

Buggy python submission (verdict: Time Limit Exceeded):
h,w=map(int,input().split())
g=["#"*(w+1)]+["#"+input()+"#"for _ in range(h)]+["#"*(w+1)]
def check(i,j):
  global g
  a=1
  k=1
  while g[i-k][j]!="#":k+=1;a+=1
  k=1
  while g[i+k][j]!="#":k+=1;a+=1
  k=1
  while g[i][j-k]!="#":k+=1;a+=1
  k=1
  while g[i][j+k]!="#":k+=1;a+=1
  return a
ans=0
for i in range(1,h+1):
  for j in range(1,w+1):
    if g[i][j]!="#":ans=max(ans,check(i,j))
print(ans)

Fixed submission:
import sys
input=sys.stdin.readline
h,w=map(int,input().split())
g=[["#"]*(w+1)]+[["#"]+list(input())+["#"]for _ in range(h)]+[["#"]*(w+1)]
gg=[[0]*w for _ in range(h)]
for i in range(1,h+1):
  k=1
  for j in range(1,w+1):
    if g[i][j]==".":
      gg[i-1][j-1]=k;k+=1
    else:k=1
  d=gg[i-1][-1]
  for j in range(1,w+1):
    if gg[i-1][-j]!=0:gg[i-1][-j]=d
    elif j!=w:d=gg[i-1][-j-1]
ggg=[[0]*w for _ in range(h)]
for j in range(1,w+1):
  k=1
  for i in range(1,h+1):
    if g[i][j]==".":
      ggg[i-1][j-1]=k;k+=1
    else:k=1
  d=ggg[-1][j-1]
  for i in range(1,h+1):
    if ggg[-i][j-1]!=0:ggg[-i][j-1]=d
    elif i!=h:d=ggg[-i-1][j-1]
ans=0
for i in range(h):
  for j in range(w):ans=max(ans,gg[i][j]+ggg[i][j])
print(ans-1)
Buggy python submission (verdict: Time Limit Exceeded):
s=list(input())
n=len(s)
i,a=0,0
for i in range(n-2):
  if s[i]+s[i+1]+s[i+2]=="ABC":
    s[i],s[i+1],s[i+2]="B","C","A"
    a+=1
    j=1
    while i-j>-1and s[i-j]=="A":
      s[i-j],s[i-j+1],s[i-j+2]="B","C","A"
      a+=1;j+=1
print(a)

Fixed submission:
s=list(input())
n=len(s)
a=0
b=[]
i=0
def ac(b):
  a=b[::-1]
  t,c=0,0
  for i in range(len(b)):
    if a[i]==0:c+=i-t;t+=1
  return c
while i<n:
  f=True
  if s[i]=="A":b.append(0);f=False
  if i<n-1:
    if s[i]+s[i+1]=="BC":b.append(1);f=False;i+=1
  if f:
    a+=ac(b)
    b=[]
  i+=1
print(a+ac(b))
Buggy python submission (verdict: Runtime Error):
import math
n,a=int(input()),0
for i in range(1,int(math.sqrt(n))+1):
  if n%i==0:
    m=n//i-1
    if n//m==n%m:a+=n//i-1
print(a)

Fixed submission:
import math
n,a=int(input()),0
if n<3:print(0);exit()
for i in range(1,int(math.sqrt(n))+1):
  if n%i==0:
    m=n//i-1
    if n//m==n%m:a+=n//i-1
print(a)
Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n=int(input())
a=list(map(int,input().split()))
left=[a[0]]
for i in range(1,n):left.append(gcd(left[-1],a[i]))
right=[a[n-1]]
for i in range(n-2,-1,-1):right.append(gcd(right[-1],a[i]))
right.reverse()
ans=max(right[1],left[n-2])
print(max(ans,max(gcd(left[i-1],right[i+1])for i in range(1,n-1))))

Fixed submission:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(max(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  no,mi=a[0],a[0]
  for i in range(1,n):
    s=gcd(no,a[i])
    if s!=no:
      no=max(s,mi)
      mi=gcd(s,mi)
  print(no)

Buggy python submission (verdict: Runtime Error):
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(gcd(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  for i in range(n-1):b.append(gcd(a[i],a[i+1]))
  b.append(gcd(a[0],a[-1]))
  print(max(no,on),sorted(b)[2])

Fixed submission:
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n,a,b=int(input()),list(map(int,input().split())),[]
if n==2:print(max(a[0],a[1]))
elif n==3:print(max(gcd(a[0],a[1]),gcd(a[0],a[2]),gcd(a[1],a[2])))
else:
  no,mi=a[0],a[0]
  for i in range(1,n):
    s=gcd(no,a[i])
    if s!=no:
      no=max(s,mi)
      mi=gcd(s,mi)
  print(no)
Buggy python submission (verdict: Runtime Error):
a,b=map(int,input());ans=0
if a<b:ans+=b;b-=1
else:ans+=a;a-=1
ans+=max(a,b)
print(ans)

Fixed submission:
a,b=map(int,input().split());ans=0
if a<b:ans+=b;b-=1
else:ans+=a;a-=1
ans+=max(a,b)
print(ans)
Buggy python submission (verdict: Runtime Error):
n,h=int(input());list(map(int,input().split()));m,a=0,0
for i in range(n):
  if m<=h[i]:
    a+=1
    m=h[i]
print(a)

Fixed submission:
n,h=int(input()),list(map(int,input().split()));m,a=0,0
for i in range(n):
  if m<=h[i]:
    a+=1
    m=h[i]
print(a)
Buggy python submission (verdict: Runtime Error):
a,b,c,d,e,k=map(int,input().split())
if e-a>k:print(":(")
else:print("Yey!")

Fixed submission:
a,b,c,d,e=int(input()),int(input()),int(input()),int(input()),int(input())
k=int(input())
print("Yay!"if e-a<=k else":(")

Buggy python submission (verdict: Runtime Error):
a=[int(input())for _ in range(5)]
k=int(input())
if e-a<=k:print("Yay!")
else:print(":(")

Fixed submission:
a,b,c,d,e=int(input()),int(input()),int(input()),int(input()),int(input())
k=int(input())
print("Yay!"if e-a<=k else":(")
Buggy python submission (verdict: Time Limit Exceeded):
x,y,z,k=map(int,input().split());a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
aa=[]
for i in a:
  for j in b:aa.append(i+j)
aa.sort(reverse=1)
aa=aa[:k+1]
s=[]
for i in aa:
  for j in c:s.append(i+j)
s.sort(reverse=1)
for i in range(k):print(s[i])

Fixed submission:
from heapq import heappop,heappush;import sys;input=sys.stdin.readline
x,y,z,k=map(int,input().split());a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
q,h,l=[],[],0
for i in a:
  for j in b:heappush(q,-(i+j));l+=1
for _ in range(min(l,k)):
  t=heappop(q)
  for i in c:heappush(h,t-i)
for i in range(k):print(-heappop(h))

Buggy python submission (verdict: Runtime Error):
x,y,z,k=map(int,input().split());a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()));a.sort(reverse=1);b.sort(reverse=1);c.sort(reverse=1);ma=a[0]+b[0]+c[0];d=[[0],[0],[0]]
for i in range(len(a)-1):d[0].append(d[0][-1]+a[i]-a[i+1])
for i in range(len(b)-1):d[1].append(d[1][-1]+b[i]-b[i+1])
for i in range(len(c)-1):d[2].append(d[2][-1]+c[i]-c[i+1])
e=d[0]+d[1]+d[2]
if x*y*z>3000:
  f,i=[0,0,0],0
  while f[0]*f[1]*f[2]<3000:
    for z in range(3):
      if f[z]<len(d[z]):
        while d[z][f[z]]==i:
          f[z]+=1
          if f[z]==len(d[z]):break
    i=min(d[0][f[0]],min(d[1][f[1]],d[2][f[2]]))
  for i in range(3):d[i]=d[i][:f[i]+1]
s=[]
for i in d[0]:
  for j in d[1]:
    for h in d[2]:s.append(i+h+j)
s.sort()
for i in range(k):print(ma-s[i])

Fixed submission:
from heapq import heappop,heappush;import sys;input=sys.stdin.readline
x,y,z,k=map(int,input().split());a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
q,h,l=[],[],0
for i in a:
  for j in b:heappush(q,-(i+j));l+=1
for _ in range(min(l,k)):
  t=heappop(q)
  for i in c:heappush(h,t-i)
for i in range(k):print(-heappop(h))