Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p04045 (python)

Fixed submission:
n, k = map(int, input().split())
dd = list(map(int, input().split()))
frag = 1
for i in range(n, 10*n+1):
  frag = 1
  for d in dd:
    if(str(d) in str(i)):
      frag = 0
  if(frag):
    print(i)
    break

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
d = list(map(int, input().split()))
other = [i for i in range(10)] - d
m = 0
def dfs(m, now):
  m = int(m)
  if(m >= n):
    print(int(now))
  else:
    if(m == 0):
      m = ""
    m = str(m)
    for(o in other):
      dfs(m, m + o)
Problem p03087 (python)

Fixed submission:
# -*- coding: utf-8 -*-
N,Q=map(int, input().split())
s = input();
charList=list(s);
AClist=[0]*N;

for i in range(N-1):
 if charList[i]=='A' and charList[i+1]=='C':
  AClist[i+1]=AClist[i]+1;
 else:
  AClist[i+1]=AClist[i];

result=[0]*Q;
for i in range(Q):
 l, r = map(int, input().split())
 result[i]=AClist[r-1]-AClist[l-1];
 if result[i]<0:
  result[i]=0;
for i in range(Q):
 print(result[i]);

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
N=int(input());
Q=int(input());
s = input();
charList=list(s);
AClist=[0]*N;

for i in range(N-1):
 if charList[i]=='A' and charList[i+1]=='C':
  AClist[i+1]=AClist[i]+1;
 else:
  AClist[i+1]=AClist[i];

result=[0]*Q;
for i in range(Q):
 l, r = map(int, input().split())
 result[i]=AClist[r-1]-AClist[l];
 if result[i]<0:
  result[i]=0;
for i in range(Q):
 print(result[i]);
Problem p02585 (python)

Fixed submission:
N,K=map(int,input().split())
P=[int(a)-1 for a in input().split()]
C=[int(a) for a in input().split()]
ans=-float("inf")
for si in range(N):
  x=si
  S=[]
  tot=0
  while True:
    x=P[x]
    S.append(C[x])
    tot+=C[x]
    if x==si:
      break
  L=len(S)
  t=0
  for i in range(L):
    t+=S[i]
    if i+1>K:
      break
    now=t
    if tot>0:
      e=(K-i-1)//L
      now+=tot*e
    ans=max(ans,now)
    
print(ans)

Buggy submission (verdict: Runtime Error):
 bmn,km;lghjklm

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

n,k=map(int,input().split())

p=list(map(lambda x:int(x)-1,input().split()))
c=list(map(int,input().split()))

lps=[]
vtd=[False]*n
for i in range(n):
    if vtd[i]:continue
    now=p[i]
    vtd[now]=True
    vc=set()
    vc.add(now)
    while now!=i:
        now=p[now]
        vtd[now]=True
        vc.add(now)
    point=0
    for v in vc:
        point+=c[v]
    lps.append((list(vc),point))
# print(lps)
anslist=[]
for lp in lps:
    loop=lp[0]
    ls=len(loop)
    point=lp[1]
    if point<=0:
        ans=max(c)
        for first in loop:
            tmp=0
            now=first
            for j in range(min(k,ls)):
                now=p[now]
                tmp+=c[now]
                ans=max(ans,tmp)
        anslist.append(ans)

    if point>0:
        s=vc[100000]
        ans=max(c)
        for first in loop:
            tmp=0
            now=first
            for j in range(k%ls+1):
                now=p[now]
                tmp+=c[now]
                ans=max(ans,tmp)
        anslist.append(ans+point*(k//ls-1))
print(max(anslist))

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

n,k=map(int,input().split())

p=list(map(lambda x:int(x)-1,input().split()))
c=list(map(int,input().split()))

lps=[]
vtd=[False]*n
for i in range(n):
    if vtd[i]:continue
    now=p[i]
    vtd[now]=True
    vc=set()
    vc.add(now)
    while now!=i:
        now=p[now]
        vtd[now]=True
        vc.add(now)
    point=0
    for v in vc:
        point+=c[v]
    lps.append((list(vc),point))
# print(lps)
anslist=[]
for lp in lps:
    loop=lp[0]
    ls=len(loop)
    point=lp[1]
    if point<=0:
        ans=max(c)
        for first in loop:
            tmp=0
            now=first
            for j in range(min(k,ls)):
                now=p[now]
                tmp+=c[now]
                ans=max(ans,tmp)
        anslist.append(ans)
        s=vc[100000]
    if point>0:
        ans=max(c)
        for first in loop:
            tmp=0
            now=first
            for j in range(k%ls+1):
                now=p[now]
                tmp+=c[now]
                ans=max(ans,tmp)
        anslist.append(ans+point*(k//ls-1))
print(max(anslist))
Problem p02642 (python)

Fixed submission:
n,*a=map(int,open(0).read().split())

ma=1001001
nums=[0]*ma

for i in a:
    nums[i]+=1
    if nums[i]==1: # 一回だけ出てきた場合
        for j in range(i+i,ma,i):
            nums[j]+=2
            
ans=nums.count(1)
print(ans)

Buggy submission (verdict: Runtime Error):
n,*a=map(int,open(0).read().split())
a.sort(reverse=True)
cnt=0
for q in a:
  flg=True
  for j in range(0,int(q**0.5)+1):
    if q%j==0:
      if q//j in a or j in a:
        flg=False
  if flg:
    cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
# O(N*sqrt(A))
n,*a=map(int,open(0).read().split())
from collections import defaultdict, deque
import sympy

dd=defaultdict(set)

for q in a:
    dd[q]=set(sympy.divisors(q))
cnt=0
a.sort()
b=deque(a)
while b:
    p=b.pop()
    if len(dd[p]&set(b))==0:
        cnt+=1
print(cnt)

Buggy submission (verdict: Runtime Error):
# O(N*sqrt(A))
n,*a=map(int,open(0).read().split())
from collections import defaultdict, deque
import sympy

dd=defaultdict(set)

for q in a:
    dd[q]=set(sympy.divisors(q))
cnt=0
a.sort()
b=deque(a)
while b:
    p=b.pop()
    if len(dd[p]&set(b))==0:
        cnt+=1
print(cnt)
Problem p02647 (python)

Fixed submission:
# coding: utf-8
# Your code here!
import time
t1=time.time()
def LI():return list(map(int,input().split()))
n,k=LI()
a=LI()

for _ in range(k):
    tab=[0]*(n)
    for i in range(n):
        q=a[i]
        if 0<=i-q:
            tab[i-q]+=1
        else:
            tab[0]+=1
        if i+q+1<=n-1:
            tab[i+q+1]-=1
        else:
            pass
    b=[tab[0]]
    for i in range(n-1):
        b.append(tab[i+1]+b[-1])
    a=b[:]
    if time.time()-t1>1.5:
        print(*a)
        exit()
print(*a)

Buggy submission (verdict: Runtime Error):
n,k=LI()
a=LI()

print(*[n]*n)
Problem p02678 (python)

Fixed submission:
def LI():return list(map(int,input().split()))
def yes():print("Yes")
def no():print("No")
from collections import deque

def main():
    n,m=LI()
    edge=[[] for i in range(n)]
    for i in range(m):
        a,b=LI()
        a-=1;b-=1
        edge[a].append(b)
        edge[b].append(a)    
    ans=[-1]*(n)
    goal=deque([0])
    while goal:
        g=goal.popleft()
        for i in edge[g]:
            if ans[i]==-1:
                ans[i]=g+1
                goal.append(i)
    yes()
    print(*ans[1:])
main()

Buggy submission (verdict: Runtime Error):
from collections import deque
def main():
  n,m=map(int,input().split())
  e=[[]for _ in range(n)]
  for _ in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    e[a].appned(b)
    e[b].append(a)
  ans=[-1]*n
  ans[0]="Yes"
  dq=deque([0])
  while dq:
    g=dq.popleft()
    for v in e[g]:
      if ans[v]==-1:
        ans[v]=g+1
        dq.append(v)
  print(*ans)
main()

Buggy submission (verdict: Runtime Error):
from collections import deque
def main():
  n,m=map(int,input().split())
  e=[[]for _ in range(n)]
  for _ in range(m):
    a,b=map(int,input().split())
    a-=1
    b-=1
    e[a].appned(b)
    e[b].append(a)
  ans=[-1]*n
  dq=deque([0])
  while dq:
    g=dq.popleft()
    for v in e[g]:
      if ans[v]==-1:
        ans[v]=g+1
        dq.append(v)
  print(*ans[1:])
main()

Buggy submission (verdict: Runtime Error):
def LI():return list(map(int,input().split()))
def yes():print("Yes")
def no():print("No")
from collections import deque

def main():
    n,m=LI()
    edge=[[]*n for i in range(n)]
    for i in range(m):
        a,b=LI()
        a-=1;b-=1
        edge[a].append(b)
        edge[b].append(a)
    
    ans=[-1]*(n-1)
    goal=deque([0])
    while (-1 in ans):
        g=goal.popleft()
        for i in edge[g]:
            if ans[i-1]==-1:
                ans[i-1]=g+1
                goal.append(i)
    yes()
    for i in ans:print(i)
main()
Problem p02694 (python)

Fixed submission:
def LI():return list(map(int,input().split()))

# for i in range(10):
#     print(i&1^0)

x=int(input())
m=100
for i in range(5000):
    m=int(m*1.01)
    if m>=x:
        print(i+1)
        exit()

Buggy submission (verdict: Runtime Error):
x,m=int(input()),100
for d in range(4000):m+=m//100
 if x<=m:print(d+1);exit()
Problem p02713 (python)

Fixed submission:
# coding: utf-8
# Your code here!

def MI():return map(int,input().split())
def LI():return list(MI())

n=int(input())

import math
from collections import Counter

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

ans=0
t=[]
for i in range(1,n+1):
    for j in range(1,n+1):
        t.append(math.gcd(i,j))
        
c=Counter(t).items()

for (i,j) in c:
    for k in range(1,n+1):
        ans+=math.gcd(i,k)*j
        # p\rint(c)
print(ans)

Buggy submission (verdict: Runtime Error):
from math import gcd
k=map(int,input())
r=range(1,k+1)
ans=0
for i in r:
  for j in r:
    for k in r:
      ans+=gcd(k,gcd(i,j))
print(ans)
# 間に合うはずなくない？？

Buggy submission (verdict: Runtime Error):
from math import gcd
k=map(int,input())
r=range(1,k+1)
ans=0
for i in r:
  for j in r:
    for k in r:
      ans+=gcd(k,gcd(i,j))
print(ans)
# 間に合うはずなくない？？
Problem p02714 (python)

Fixed submission:
# coding: utf-8
# Your code here!
from collections import Counter
def MI():return map(int,input().split())
def LI():return list(MI())

n=int(input())
s=input()
ans=s.count("R")*s.count("G")*s.count("B")


for j in range(n):
    jj=s[j]
    for i in range(j):
        k=2*j-i
        if not j<=k<=n-1:
            continue
        ii=s[i]
        kk=s[k]
        if jj!=ii and jj!=kk and ii!=kk:
            ans-=1

print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
ans=s.count("R")*s.count("G")*s.count("B")
for j in range(n):
  for i in range(j):
    if (k:=2*j-i)<n:
      if s[i]!=s[k]!=s[j]!=s[i]:
        ans-=1   
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
ans=s.count("R")*s.count("G")*s.count("B")
for j in range(n):
  for i in range(j):
    if (k:=2*j-i)<n:
      if s[i]!=s[k]!=s[j]!=s[i]:
        ans-=1   
print(ans)
Problem p02747 (python)

Fixed submission:
def mi():return map(int,input().split())

# n=int(input())
# a,b=mi()
s=input()
# l=list(mi())

ans=["hi","hihi","hihihi","hihihihi","hihihihihi"]
if s in ans:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
def mi():return map(int,input().split())
n,m=mi()
n=pow(2,n)-1
m=pow(2,m)-1

for i in range(n):
    if i==0 or i==n-1:
        print("1"*m)
    else:
        if i%2==1:
            print("1"*m)
        else:
            print("1"+"0"*(m-2)+"1")
Problem p02782 (python)

Fixed submission:
r1,c1,r2,c2=map(int,input().split())

mod = 10**9+7
MAX_N = 3*10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod

def comb(n,k,mod):
    if n<k:return 0
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans=0
ans+=comb(c1+r1,r1,mod)
ans%=mod
ans-=comb(c1+r2+1,r2+1,mod)
ans%=mod
ans-=comb(c2+r1+1,r1,mod)
ans%=mod
ans+=comb(c2+r2+2,r2+1,mod)
ans%=mod

print(ans)

Buggy submission (verdict: Runtime Error):
r1,c1,r2,c2=map(int,input().split())

mod = 10**9+7
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod

def comb(n,k,mod):
    if n<k:return 0
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans=0
ans+=comb(c1+r1,r1,mod)
ans%=mod
ans-=comb(c1+r2+1,r2+1,mod)
ans%=mod
ans-=comb(c2+r1+1,r1,mod)
ans%=mod
ans+=comb(c2+r2+2,r2+1,mod)
ans%=mod

print(ans)

Buggy submission (verdict: Runtime Error):
r1,c1,r2,c2=map(int,input().split())

mod = 10**9+7
MAX_N = 10**6

fact = [1]
fact_inv = [0]*(MAX_N+4)
for i in range(MAX_N+3):
    fact.append(fact[-1]*(i+1)%mod)

fact_inv[-1] = pow(fact[-1],mod-2,mod)
for i in range(MAX_N+2,-1,-1):
    fact_inv[i] = fact_inv[i+1]*(i+1)%mod

def comb(n,k,mod):
    return fact[n] * fact_inv[k] % mod * fact_inv[n-k] %mod

ans=0
ans+=comb(c1+r1,r1,mod)
ans%=mod
ans-=comb(c1+r2+1,r2+1,mod)
ans%=mod
ans-=comb(c2+r1+1,r1,mod)
ans%=mod
ans+=comb(c2+r2+2,r2+1,mod)
ans%=mod

print(ans)

Buggy submission (verdict: Runtime Error):
r1,c1,r2,c2=map(int,input().split())

#O(10**12) orz

from scipy.misc import comb
mod=10**9+7
tret=0
for i in range(r1,r2+1):
    for j in range(c1,c2+1):
        # print(i,j)
        tret+=comb(i+j,i,exact=True)
        tret%=mod
        
print(tret)
Problem p02787 (python)

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

a=[]
b=[]
for _ in range(n):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)
    
# print(a)
# print(b)

INF=float("inf")

dp=[INF]*(h+1)
dp[h]=0

for aa,bb in zip(a,b):
    for hh in range(h,0,-1):
        if hh-aa>=0:
            dp[hh-aa]=min(dp[hh-aa],dp[hh]+bb)
        else:
            dp[0]=min(dp[0],dp[hh]+bb)
            
print(dp[0])
# print(dp)

Buggy submission (verdict: Runtime Error):
import numpy as np

h,n=map(int,input().split())
a=[]
b=[]
for i in range(n):
    x,y=map(int,input().split())
    a.append(x)
    b.append(y)

INF=float("inf")
    
dp=np.array([[INF]*(1+h) for i in range(1+n)])


dp[0][0]=0

for i in range(n):
    # print(dp)
    for j in range(h+1):
        # print("i+1=",i+1,"j=",j)
        dp[i+1][j]=min(dp[i+1][j],dp[i][j])
        dp[i+1][min(h,j+a[i])]=min(dp[i+1][min(h,j+a[i])],dp[i+1][j]+b[i])
        # print(i+1,j,min(h,j+a[i]),"\n",dp)
    # print("==================")

# print(dp)
print(dp[n][h])
Problem p02803 (python)

Fixed submission:
from collections import deque

h,w=map(int,input().split())

maze=[list("#"*(w+2))]+[list("#"+input()+"#") for i in range(h)]+[list("#"*(w+2))]
INF=10800 #>50*50
visited=[[-INF]*(w+2) for i in range(h+2)]

ss=[]

for i in range(1,h+1):
  for j in range(1,w+1):
    if maze[i][j]==".":
      ss.append((i,j))



def bfs(maze,visited,sy,sx):#,gy,gx):
  queue=deque([[sy,sx]])
  visited[sy][sx]=0
  while queue:
    [y,x]=queue.popleft()
    for i,j in ((-1,0),(1,0),(0,1),(0,-1)):
      y_new,x_new=y+i,x+j
      if maze[y_new][x_new]=="." and visited[y_new][x_new]==-INF:
        visited[y_new][x_new]=visited[y][x]+1
        queue.append([y_new,x_new])

        
        
ans=0
for i,j in ss:
  visited=[[-INF]*(w+2) for i in range(h+2)]
  bfs(maze,visited,i,j)
  for i in range(1,h+1):
    for j in range(1,w+1):
      ans=max(ans,visited[i][j])

    
    
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import deque
#import numpy as np

h,w=map(int,input().split())
#sy,sx=map(int,input().split())
#sy=sy-1
#sx=sx-1
#gy,gx=map(int,input().split())
#gy=gy-1
#gx=gx-1
maze=[list("#"*(w+2))]+[list("#"+input()+"#") for i in range(h)]+[list("#"*(w+2))]
INF=10800 #>50*50
visited=[[-INF]*(w+2) for i in range(h+2)]

ss=[]

for i in range(1,h+1):
  for j in range(1,w+1):
    if maze[i][j]==".":
      ss.append((i,j))



def bfs(maze,visited,sy,sx):#,gy,gx):
  queue=deque([[sy,sx]])
  visited[sy][sx]=0
  while queue:
    [y,x]=queue.popleft()
    #if (y,x)==(gy,gx):
    #  return visited[gy][gx]
    for i,j in ((-1,0),(1,0),(0,1),(0,-1)):
      #もともと壁があって、はみ出す心配はない。
      y_new,x_new=y+i,x+j
      if maze[y_new][x_new]=="." and visited[y_new][x_new]==-INF:
        visited[y_new][x_new]=visited[y][x]+1
        queue.append([y_new,x_new])

        
        
ans=0
for i,j in ss:
  bfs(maze,visited,3,1)
  for i in range(1,h+1):
    for j in range(1,w+1):
      ans=max(ans,visited[i][j])

    
    
print(ans)
Problem p02812 (python)

Fixed submission:
n=input()
s=input()

print(s.count("ABC"))

Buggy submission (verdict: Runtime Error):
n=int(input())
s=input()
ans=s.cpount("ABC")
print(ans)
Problem p02817 (python)

Fixed submission:
左,右=map(str,input().split())
print(右+左)

Buggy submission (verdict: Runtime Error):
s,t=map(int,input().split())
print(t+s)

Buggy submission (verdict: Runtime Error):
s,t=map(int,input().split())
print(s+t)
Problem p02883 (python)

Fixed submission:
n,k=map(int,input().split())
abilities=sorted(list(map(int,input().split())))
foods=sorted(list(map(int,input().split())),reverse=True)

if sum(abilities)<=k:
  print(0)
  exit()
  
def check(score):
  ret=0
  for a,f in zip(abilities,foods):
    ret+=max(0,(a*f-score+f-1)//f)
  return ret<=k

ok=10**12+1
ng=0
for _ in range(50):
  mid=(ok+ng)//2
  if check(mid):
    ok=mid
  else:
    ng=mid
print(ok)

Buggy submission (verdict: Runtime Error):
from heapq import *
def abc144c():
  n,k=map(int,input().split())
  a=sorted(list(map(int,input().split())))
  f=sorted(list(map(int,input().split())))[::-1]
  q=[] 
  for i,j in zip(a,f):
    heappush(q,(-i*j,j))
  for i in range(k):
    tmp,key=heappop(q)
    heappush(q,(tmp+key,key))
  ans,key=-heappop(q)
  print(ans)
abc144c()

Buggy submission (verdict: Runtime Error):
from heapq import *
def abc144c():
  n,k=map(int,input().split())
  a=sorted(list(map(int,input().split())))
  f=sorted(list(map(int,input().split())))[::-1]
  q=[] 
  for i,j in zip(a,f):
    heappush(q,(-i*j,j))
  for i in range(k):
    tmp,key=heappop(q)
    heappush(q,(tmp+key,key))
  ans,key=-heappop(q)
  return ans
print(abc144c())

Buggy submission (verdict: Runtime Error):
def abc144c():
  n,k=map(int,input().split())
  a=list(map(int,input().split()))
  f=list(map(int,input().split()))
  a.sort(reverse=True);f.sort()

  from heapq import *
  q=[]
  for i,j in zip(a,f):
    heappush(q,(-i*j,str(j)))
  for i in range(k):
    temp,key=heappop(q)
    heappush(q,(temp+int(key),key))
  ans,key=heappop(q)
  print(-ans)

abc144c()
Problem p02909 (python)

Fixed submission:
s=input()
if s =="Sunny":
  ans="Cloudy"
elif s == "Cloudy":
  ans="Rainy"
else:
  ans="Sunny"

print(ans)

Buggy submission (verdict: Runtime Error):
def main():

  n,m=map(int,input().split())
  a=list(map(int,input().split()))
  for i in range(m):
    a.sort(reverse=True)
    a[0]=a[0]//2
  print(sum(a))
  
main()
Problem p02910 (python)

Fixed submission:
s=input()
even=["L","U","D"] #mondaide
odd=["R","U","D"]
l=len(s)
fumiyasui=False
for i in range(l):
  if i%2==0:
    if s[i] in odd:
      fumiyasui=True      
    else:
      print("No")
      exit()
  else:
    if s[i] in even:
      fumiyasui=True      
    else:
      print("No")
      exit()
print("Yes")

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

n=len(s)
for i in range(0,n,2):

  if s[i] == "R" or s[i] =="U" or s[i] =="D":
    flag1=True
  else:
    flag1=False
for i in range(1,n,2):
  if s[i] == "L" or s[i] =="U" or s[i] =="D":
    flag2=True
  else:
    flag2=False

if flag1 == True and flag2 == True:
  print("Yes")
else:
  print("No")
Problem p02918 (python)

Fixed submission:
n,k=map(int,input().split())
s=input()

happiness=0
for c,d in zip(s,s[1:]):
  if c == d:
    happiness +=1
    
ans=min(n-1,happiness+2*k)
print(ans)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
msg=input()



left=(msg[0]!="R")
right=(msg[-1]!="L")
msg2=msg[1:-1]
cntrl=msg.count("RL")


first=n-cntrl*2-left-right
print("f",first)
ans=first+2*min(k,msg2(count("RL")))
if ans==n:
  ans=n-1
print(ans)
Problem p02936 (python)

Fixed submission:
n,q=map(int,input().split())
edge=[[] for _ in range(n)] #木
cnt=[0]*n #出力用
for i in range(n-1): #辺の本数は頂点数-1
  a,b=map(int,input().split())
  a-=1
  b-=1
  edge[a].append(b)
  edge[b].append(a)
for _ in range(q):
  p,x=map(int,input().split())
  p-=1
  cnt[p]+=x
done=[False]*n #到達
par=0 #0からスタート
done[par]=True
stack=[par]
while stack:
  par=stack.pop()
  for chi in edge[par]:
    if done[chi]:
      None
    else:
      done[chi]=True
      cnt[chi]+=cnt[par]
      stack.append(chi)
    
print(*cnt)

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
egde=[[] for _ in range(N)]
cnt=[0]*N
for _ in range(N-1):
  a,b=map(int,input().split())
  edge[a-1]+=(b-1),
  edge[b-1]+=(a-1),
for _ in range(Q):
  p,x=map(int,input().split())
  cnt[p-1]+=x
done=[False]*N
done[0]=True
stack=[0]
while stack:
  par=stack.pop()
  for child in edge[par]:
    if not done[child]:
      done[child]=True
      cnt[child]+=cnt[par]
      stack.append(child)
print(*cnt)
Problem p02952 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(1, n + 1):
  if len(str(i)) % 2 == 1:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
ans=0
for i in range(1,n+1):
  if len(i)%2==1:
    ans+=1
print(ans)
Problem p02958 (python)

Fixed submission:
n=int(input())
model=[]
for i in range(n):
  model.append(i+1)
#print(model)
p=list(map(int,input().split()))
cnt=0
for j in range(n):
  if p[j] != model[j]:
    cnt+=1
if cnt<=2:
  print("YES")
else:
  print("NO")

Buggy submission (verdict: Runtime Error):
n=int(input())
model=[]
for i in range(n):
  model.append(i+1)
p=list(map(int,input().split()))
cnt=0
for j in p:
  if j != model[j]:
    cnt+=1
if cnt=<2:
  print("YES")
else:
  print("NO")
Problem p02971 (python)

Fixed submission:
n=int(input())
a=[int(input()) for i in range(n)]
b=sorted(a)
f=b[-1]
s=b[-2]
for ans in a:
  if ans < f:
    print(f)
  else:
    print(s)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for i in range(n)]
for _ in range(n):
  #b=a[0:_]+a[_+1:n]
  #print(max(b))
  print(max(max(a[0:_]),max(a[_+1:n])))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=[int(input()) for i in range(n)]
for _ in range(n):
  #b=a[0:_]+a[_+1:n]
  #print(max(b))
  print(max(a[0:_]),max(a[_+1:n]))
Problem p03000 (python)

Fixed submission:
n,x=map(int,input().split())
l=list(map(int,input().split()))+[0]
#i=1
d=0
cnt=0
for i in range(n+1):
  if d<=x:
    cnt+=1
    d+=l[i]

  
print(cnt)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
l=list(map(int,input().split()))+[0,0,0]
d=0
i=1
cnt=0
while d<=x:
  cnt+=1
  d+=l[i-1]
  i+=1
  
print(cnt)

Buggy submission (verdict: Runtime Error):
n,x=map(int,input().split())
l=list(map(int,input().split()))
d=0
i=1
cnt=0
while d<=x:
  cnt+=1
  d+=l[i-1]
  i+=1
  
print(cnt)
Problem p03086 (python)

Fixed submission:
s=input()
n=len(s)
ans=0
for i in range(n):
  for j in range(i,n):
    if all(["ACGT".count(c) == 1 for c in s[i:j+1]]):
      ans=max(ans,j+1-i)
print(ans)

Buggy submission (verdict: Runtime Error):
s=input()+"O"
tmp=""
ans=[]
for i in s:
  if i in ["A","T","G","C"]:
    tmp=tmp+i
  else:
    ans.append(tmp)
    tmp=""
res=0
for i in ans:
  if len(i)>len(res):
    res=len(i)
print(res)

Buggy submission (verdict: Runtime Error):
s=input()
n=len(s)
ans=0
for i in range(n):
  for j in range(i,n):
    if all(["ACGT",count(c) == 1 for c in s[i:j+1]]):
      ans=max(ans,j+1-i)
print(ans)
Problem p03101 (python)

Fixed submission:
H,W=map(int,input().split())
h,w=map(int,input().split())
print((H-h)*(W-w))

Buggy submission (verdict: Runtime Error):
H,W=map(int,input())
h,w=map(int,input())
print((H-h)*(W-w))
Problem p03110 (python)

Fixed submission:
rate=380000.0 #yen/btc

n=int(input())
otoshidama=0
for i in range(n):
  x,u=map(str,input().split())
  if u == "JPY":
    otoshidama+=float(x)
  else:
    otoshidama+=float(x)*rate
print(otoshidama)

Buggy submission (verdict: Runtime Error):
rate=380000.0 #yen/btc

n=int(input())
otoshidama=0
for i in range(n):
  x,u=map(input().split())
  if u == "JPY":
    otoshidama+=float(x)
  else:
    otoshidama+=float(x)*rate
print(otoshidama)