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

Fixed submission:
N = int(input())
a = list(map(int, input().split()))
s = [0 for i in range(N+1)]
for i in range(N):
    s[i+1] = s[i] + a[i]
#s[i+1]にはa[0]からa[i]までの総和

dic = {}
for i in range(N+1):
    if dic.get(s[i]) == None:
        dic[s[i]] = 1
    else:
        dic[s[i]] += 1

ans = 0
for k in dic:
    ans += dic[k]*(dic[k]-1)/2

print(int(ans))

Buggy submission (verdict: Runtime Error):
N = int(input())
a = list(map(int, input().split()))
s = [0 for i in range(N+1)]
for i in range(N):
    s[i+1] = s[i] + a[i]
#s[i+1]にはa[0]からa[i]までの総和

nums = [0 for i in range(N+1)]
for i in range(N+1):
    nums[s[i]] += 1

ans = 0
for i in range(N+1):
    ans += nums[i]*(nums[i]-1)/2

print(int(ans))
Problem p03449 (python)

Fixed submission:
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
sum1 = 0
sum2 = 0
ans_list = []
for i in range(n):
    sum2 += a2[i]
if n != 1:    
    for i in range(n-1):
        sum1 += a1[i]
        sum2 -= a2[i]
        ans1 = sum1 + sum2 + a1[i+1]
        ans2 = sum1 + sum2 + a2[i]
        ans_list.append(ans1)
        ans_list.append(ans2)   
else:
    ans_list.append(a1[0]+a2[0])
print(max(ans_list))

Buggy submission (verdict: Runtime Error):
n = int(input())
a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
sum1 = 0
sum2 = 0
ans_list = []
for i in range(n):
    sum2 += a2[i]
for i in range(n-1):
    sum1 += a1[i]
    sum2 -= a2[i]
    ans1 = sum1 + sum2 + a1[i+1]
    ans2 = sum1 + sum2 + a2[i]
    ans_list.append(ans1)
    ans_list.append(ans2)       
print(max(ans_list))
Problem p03487 (python)

Fixed submission:
n = int(input())
a_list = list(map(int, input().split()))
dic = {}
i_list = []
for a in a_list:
    dic[a] = 0
for a in a_list:
    dic[a] += 1
    if dic[a] == 1:
        i_list.append(a)
ans = 0
for i in i_list:
    p = dic[i] - i 
    if p >= 0:
        ans += p
    else:
        ans += dic[i]
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
a_list = list(map(int, input().split()))
dic = {}
i_list = []
for a in a_list:
    dic[a] = 0
for a in a_list:
    dic[a] += 1
    if dic[a] = 1:
        i_list.append(a)
ans = 0
for i in i_list:
    p = dic[i] - i 
    if p >= 0:
        ans += p
    else:
        ans += dic[i]
print(ans)
Problem p03612 (python)

Fixed submission:
n = int(input())
p_list = list(map(int, input().split()))
cnt = 0
for i in range(n-1):
    if p_list[i] == i+1:
        p_list[i+1] = p_list[i]
        cnt += 1
if p_list[n-1] == n:
    cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
n = int(input())
p_list = list(map(int, input().split()))
cnt = 0
for i in range(n):
    if p_list[i] == i+1:
        p_list[i+1] = p_list[i]
        cnt += 1
print(cnt)
Problem p03632 (python)

Fixed submission:
a,b,c,d = map(int, input().split())
if c >= b or a >= d:
    print(0)
else:
    if a <= c:
        print(min(b-c,d-c))
    else:
        print(min(d-a,b-a))

Buggy submission (verdict: Runtime Error):
a,b,c,d = map(int, input().split())
if c >= b or a >= d:
    print(0)
else:
    if a <= c:
        print(min(b-c,d-c))
    else:
        print(min(d-a,b-a)
Problem p03694 (python)

Fixed submission:
n = int(input())
home_list = list(map(int, input().split()))
home_list.sort()
print(home_list[n-1] - home_list[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
home_list = input().split()
home_list.sort()
print(home_list[n-1] - home_list[0])

Buggy submission (verdict: Runtime Error):
n = int(input())
home_list = input().split()
home_list.sort()
print(hpme_list[n-1] - home_list[0])
Problem p03730 (python)

Fixed submission:
a, b, c = map(int, input().split())
def gcd(x,y):
    p = max(x,y)
    q = min(x,y)
    while p % q != 0:
        r = p % q
        p = q
        q = r
    c = q
    return q
if c % gcd(a,b) == 0:
    print("YES")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
#A*n = B*m + C
#Ax-By = Cを満たすx,yを求めよ
import fraction
a, b, c = map(int, input().split())
gcd = fraction.gcd(a, b)
if c % gcd == 0:
    print("YES")
else:
    print("NO")
Problem p03761 (python)

Fixed submission:
n = int(input())
#文字列を一列ごとにリストに入れる
S = [input() for _ in range(n)]
alphabet_str = "abcdefghijklmnopqrstuvwxyz"
#alphbetの文字列をリスト化
alphabets = list(alphabet_str)

s_maps = []
for s in S:
#sはSの文字列の一つ一つ
#文字列sをリスト化    
    strs = list(s)
#辞書を作る
    m = {}
#各alphbetの初期値を0にする
    for alphabet in alphabets:
        m[alphabet] = 0
#文字列の中にあるalphabetがあれば、辞書のvalueに1を追加
    for _str in strs:
        m[_str] += 1
#辞書をリストに突っ込む      
    s_maps.append(m) 
#print(s_maps)
ans = ""
#alphabetリストからalphabetを取り出す
for alphabet in alphabets:
    min_num = 51
#リストから辞書を一つずつ取り出す    
    for s_map in s_maps:
#n個の辞書の中から最小のvalueを取り出す
        min_num = min(s_map[alphabet], min_num)
    for i in range(min_num):
        ans += alphabet
print(ans)
#taku689さんのコードを大いに参考

Buggy submission (verdict: Runtime Error):
count = int(input())
ent_list = []
for i in range(count):
    org_list = [j for j in input()]
    new_list = sorted(org_list)
    ent_list.append(new_list)
if count == 1:
    result = "".join(ent_list[0])
    print(result)
else:    
    for i in range(count-1):
        for j in range(len(ent_list[i+1])):
            if ent_list[i+1][j] in ent_list[i] == True:           
                ent_list[i].remove(ent_list[i+1][j])
            else:
                ent_list[i+1].remove(ent_list[i+1][j])
result = "".join(ent_list[count-1])
print(result)
#3
#cbaa
#daacc
#acacac
Problem p03777 (python)

Fixed submission:
line = input().split()
if line[0] == "H" and line[1] == "H":
    print("H")
elif line[0] == "H" and line[1] == "D":
    print("D")
elif line[0] == "D" and line[1] == "H":
    print("D")
else:
    print("H")

Buggy submission (verdict: Runtime Error):
line = input().split()
if line[0] = "H" and line[1] = "H":
    print("H")
elif line[0] = "H" and line[1] = "D":
    print("D")
elif line[0] = "D" and line[1] = "H":
    print("D")
else:
    print("H")
Problem p03797 (python)

Fixed submission:
n, m = map(int, input().split())
if m >= n*2:
    leave_c = m - n*2
    available = leave_c // 4
    print(n + available)
else:
    available_c = m // 2
    print(available_c)

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
if m >= n*2:
    leave_c = m - n*2
    available = leave_c // 4
    print(n + available)
else:
    availabe_c = m // 2
    print(available_c)
Problem p02678 (python)

Fixed submission:
from collections import deque
N,M=map(int,input().split())
ab=[[] for i in range(N+1)]
for i in range(M):
  a,b=map(int,input().split())
  ab[a].append(b)
  ab[b].append(a)
ans=[-1]*(N+1)
que=deque([1])
while que:
  q=que.popleft()
  for i in ab[q]:
    if ans[i]==-1:
      que.append(i)
      ans[i]=q
print('Yes')
for i in range(2,N+1):
  print(ans[i])

Buggy submission (verdict: Runtime Error):
from collections import deque
q=deque()
def MI(): return map(int, input().split())
N,M=MI()
g=[[] for _ in range(M+1)]
for _ in range(M):
  a,b=MI()
  g[a].append(b)
  g[b].append(a)
check=[0]*(N+1)
check[1]=1
ans=[0]*(N+1)
q.append(1)
while len(q)>0:
  v=q.popleft()
  for u in g[v]:
    if check[u]==0:
      check[u]=1
      ans[u]=v
      q.append(u)
print('Yes')
for i in range(2,N+1):
  print(ans[i])
Problem p02756 (python)

Fixed submission:
import collections

s = collections.deque(list(input()))
q = int(input())
rev = 0
for i in range(q):
    tfc = list(input().split())
    if tfc[0]=='1':
        rev = abs(rev-1)
    else:
        t,f,c = tfc
        if rev:
            if f=='1':
                s.append(c)
            else:
                s.appendleft(c)
        else:
            if f=='1':
                s.appendleft(c)
            else:
                s.append(c)
if rev:
    t = []
    for i in range(len(s)):
        t.append(s.pop())
    print(''.join(t))
else:
    print(''.join(s))
'''
初期文字列 s が与えられ q 個のクエリを処理した後の文字列を求めます。
10^100回繰り返す根気があるなら自分でやってくれと思わなくもないです。
さて、各クエリではまず t が与えられます。t=1の時文字列を反転させます。
t=2の時はさらに f,c が与えられ、f=1の時文字列の先頭にcを加えます。
f=2の時文字列の末尾にcを加えます。
愚直に行おうとすると文字列の反転で O(len(s))、先頭への追加で 
O(len(s)) かかってしまい間に合いません。
そこでcollections.dequeを利用します。先頭、末尾への追加をO(1) で行えます。
注意する点は反転させると追加する位置が逆になることです。
なので現在の状態を管理しておく必要があります。
同様に出力する時も最終的な向きによって出力する順番が逆になります。
'''

Buggy submission (verdict: Runtime Error):
#たのん
s=input()
q=int(input())
head=[]
tail=[]
rev=False
for _ in range(q):
  tmp=list(input().split())
  if tmp[0]=='1': #文字列を反転させる操作のとき
    if rev==False: #反転していない状態であれば反転した状態にする
      rev=True
    else:
      rev=False #反転した状態であれば反転していない状態にする
  if tmp[0]=='2': #文字を追加する操作のとき
    if rev==False: 
     #反転していない状態であれば、先頭への追加はそのまま先頭に、末尾への追加もそのまま末尾に追加する
      if tmp[1]=='1':
        head.append(tmp[2])
      if tmp[1]=='2':#単純にelseとしてもOKだが、略さない方が間違えない
        tail.append(tmp[2])#↓Trueの場合、if revでOKだが、略さないがベター
  if rev==True:#反転した状態であれば、先頭への追加は末尾への追加に、末尾への追加は先頭への追加に置き換える
    if tmp[1]=='1':
      tail.append(tmp[2])
    if tmp[1]=='2':
      head.append(tmp[2])
head=''.join(map(str,head))#文字列として結合しておく
tail=''.join(map(str,tail))
ans=head[::-1]+s+tail #答えは(先頭に追加した文字列の逆順)+(元の文字列)+(末尾に追加した文字列)となる
if rev==True: #もし最終的に文字列が反転した状態なら答えの文字列を反転させる
  ans=ans[::-1]
print(ans)

Buggy submission (verdict: Runtime Error):
#たのん
s=input()
q=int(input())
head=[]
tail=[]
rev=False
for _ in range(q):
  tmp=list(input().split())
  if tmp[0]=='1': #文字列を反転させる操作のとき
    if rev==False: #反転していない状態であれば反転した状態にする
      rev=True
    else:
      rev=False #反転した状態であれば反転していない状態にする
  if tmp[0]=='2': #文字を追加する操作のとき
    if rev==False: 
     #反転していない状態であれば、先頭への追加はそのまま先頭に、末尾への追加もそのまま末尾に追加する
     if tmp[1]=='1':
        head.append(tmp[2])
      if tmp[1]=='2':#単純にelseとしてもOKだが、略さない方が間違えない
        tail.append(tmp[2])#↓Trueの場合、if revでOKだが、略さないがベター
  if rev==True: 
    #反転した状態であれば、先頭への追加は末尾への追加に、末尾への追加は先頭への追加に置き換える
     if tmp[1]=='1':
        tail.append(tmp[2])
      if tmp[1]=='2':
        head.append(tmp[2])
head=''.join(map(str,head))#文字列として結合しておく
tail=''.join(map(str,tail))
ans=head[::-1]+s+tail #答えは(先頭に追加した文字列の逆順)+(元の文字列)+(末尾に追加した文字列)となる
if rev==True: #もし最終的に文字列が反転した状態なら答えの文字列を反転させる
  ans=ans[::-1]
print(ans)
Problem p02761 (python)

Fixed submission:
N,M=map(int,input().split())
SC=[list(map(int,input().split())) for i in range(M)]

def check(x):
  x=str(x)#文字に変換
  if len(x)!=N:
    return False
  for s,c in SC:
    if x[s-1]!=str(c):
      return False
  return True

for i in range(1000):
  if check(i):
    print(i)
    exit()
print(-1)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
d={}
for i in range(M):
  s,t=map(int,input().split())
  if s in d:
    if d[s]!=t:
      print('-1')
      exit()
  if s==1:
    if t==0:
      if N==1:
        print('0')
        exit()     
      else:
        print('-1')
        exit()  
  d[s]=t
if N==1:
    if s==1:
      if t==0:
        print('0')
        exit()
if 1 not in d:
  d[1]=1
for i in range(2,N):
  if i not in d:
    d[i]=0
L=[]
for i in d.values():
  L.append(str(i))
print(''.join(L))

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
d={}
for i in range(M):
  s,t=map(int,input().split())
  if s in d:
    if d[s]!=t:
      print('-1')
      exit()
  if s==1:
    if t==0:
      print('-1')
      exit()
  
  d[s]=t
if N==1:
    if s==1:
      if t==0:
        print('0')
        exit()
if 1 not in d:
  d[1]=1
for i in range(2,N):
  if i not in d:
    d[i]=0
L=[]
for i in d.values():
  L.append(str(i))
print(''.join(L))
Problem p02780 (python)

Fixed submission:
import numpy as np
N,K=map(int,input().split())
P=list(map(int,input().split()))
Q=[0]
def ex(A):
  return (1+A)/2.0
for i in range(N):
  Q.append(ex(P[i]))
Q=np.array(Q)
R=Q.cumsum()
ans=0
for i in range(K,N+1):
  S=R[i]-R[i-K]
  if ans<S:
    ans=S
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
P=list(map(int,input().split()))
Q=[]
def ex(A):
  return (1+A)/2.0
for i in range(N):
  Q.append(ex(P[i]))
Q=np.array(Q)
R=Q.cumsum()
ans=0.0
for i in range(K,N+1):
  S=R[i]-R[i-K]
  if ans<S:
    ans=S
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np
N,K=map(int,input().split())
P=list(map(int,input().split()))
Q=[]
def ex(A):
  return (1+A)/2.0
for i in range(N):
  Q.append(ex(P[i]))
Q=np.array(Q)
R=Q.cumsum()
ans=0
for i in range(K,N):
  S=R[i]-R[i-K]
  if ans<S:
    ans=S
print(ans)
Problem p02801 (python)

Fixed submission:
C=input()
print(chr(ord(C[0])+1))

Buggy submission (verdict: Runtime Error):
print(chr(ord(input()+1)))

Buggy submission (verdict: Runtime Error):
C=input()
print(chr(ord(c[0])+1))
Problem p02802 (python)

Fixed submission:
N,M=map(int,input().split())
ac=[False]*N
wa=[0]*N
for _ in range(M):
  p,S=input().split()
  p=int(p)-1
  if S=='AC':
    ac[p]=True
  else:
    if not ac[p]:
      wa[p]+=1
a=0
b=0
for i in range(N):
  if ac[i]:
    a+=1
    b+=wa[i]
print(*[a,b])

Buggy submission (verdict: Runtime Error):
def II(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
ans,pena=0,0
N,M=MI()
P=[0]*N
PENA=[0]*N
for i in range(M):
  p,s=input().split()
  p=int(p)
  p-=1
  if s=='AC':
    if P[p]==0:
      ans+=1
      P[p]=1
  if s=='WA':
    if P[p]==0:
      PENA[p]+=1
for i in range(N):
  if P[p]!=1:
    PENA[p]=0
pena=sum(PENA)  
print(ans,pena)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
ACL=[0]*N
PL=[0]*N
AC=0
P=0
for i in range(M):
  p,S=input().split()
  p=int(p)
  if S =='AC':
    if ACL[p]==0:
      AC+=1
      P+=PL[p]
      ACL[p]=1
    else:
      PL[p]+=1
print(AC,P)
Problem p02803 (python)

Fixed submission:
H, W = map(int, input().split())
S = [input() for _ in range(H)]


def f(i, j):
    t = [[-1] * W for _ in range(H)]
    t[i][j] = 0
    q = [(i, j)]
    while q:
        y, x = q.pop(0)
        if y - 1 >= 0 and S[y - 1][x] != '#' and t[y - 1][x] == -1:
            t[y - 1][x] = t[y][x] + 1
            q.append((y - 1, x))
        if y + 1 < H and S[y + 1][x] != '#' and t[y + 1][x] == -1:
            t[y + 1][x] = t[y][x] + 1
            q.append((y + 1, x))
        if x - 1 >= 0 and S[y][x - 1] != '#' and t[y][x - 1] == -1:
            t[y][x - 1] = t[y][x] + 1
            q.append((y, x - 1))
        if x + 1 < W and S[y][x + 1] != '#' and t[y][x + 1] == -1:
            t[y][x + 1] = t[y][x] + 1
            q.append((y, x + 1))
    return max(max(tt) for tt in t)


result = 0
for i in range(H):
    for j in range(W):
        if S[i][j] != '#':
            result = max(result, f(i, j))
print(result)

Buggy submission (verdict: Runtime Error):
def MI(): return map(int, input().split())
from collections import deque
def bfs(field,s):
  q=deque([(0,s)])
  MOVE=[(-1,0),(0,-1),(1,0),(0,1)]
  dist=[[-1]*W for i in range(H)]
  d,i,j=-1,-1,-1  
  while q:
    d,(i,j)=q.popleft()
    if dist[i][j]!=-1:
      continue
    dist[i][j]=d
    for di,dj in MOVE:
      ni=i+di
      nj=j+dj
      if not 0<=ni<H or not 0<=nj<W:
        continue
      if field[ni][nj]=='#':
        continue
      if dist[ni][nj]!=-1:
        continue
      q.append((d+1,(ni,nj)))
  return d,i,j
H,W=MI()
field=[input() for _ in range(H)]
ans=0
for i in range(H):
  for j in range(W):
    if field[i][j]=='.':
      d,i,j=bfs(field,(i,j))
    ans=max(ans,d)
print(ans)
Problem p02812 (python)

Fixed submission:
N=int(input())
S=input()
print(S.count('ABC'))

Buggy submission (verdict: Runtime Error):
N=int(input())
S=input()
ans=0
for in range(N-1):
  if S[i:i+3]=='ABC':
    ans+=1
print(ans)
Problem p02911 (python)

Fixed submission:
N,K,Q=map(int,input().split())
QL=[0]*Q
NL=[K-Q]*N
for i in range(Q):
  QL[i]=int(input())-1
  NL[QL[i]]+=1
for i in range(N):
  print('Yes' if NL[i]>0 else 'No')

Buggy submission (verdict: Runtime Error):
N,K,Q=map(int,input().split())
QL=[0]*Q
NL=[K-Q]*N
for i in range(Q):
  L[i]=int(input())
  NL[L[i]]+=1
for i in range(N):
  print('Yes' if NL[i]>0 else 'No')
Problem p02917 (python)

Fixed submission:
N=int(input())
B=list(map(int,input().split()))
ans=0
ans+=B[0]+B[-1]
for i in range(N-2):
  ans+=min(B[i],B[i+1])
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
B=list(map(int,input().split()))
ans=0
ans+=B[0]+B[-1]
for i in range(N-1):
  ans+=min(B[i],B[i+1])
print(ans)
Problem p02923 (python)

Fixed submission:
N=int(input())
H=list(map(int,input().split()))
tmp=0
ans=0
for i in range(N-1):
  if H[i]>=H[i+1]:
    tmp+=1
    ans=max(ans,tmp)
  else:
    tmp=0
    continue
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input)
H=list(map(int,input().split()))
tmp=0
ans=0
for i in range(N-1):
  if H[i]>=H[i+1]:
    tmp+=1
    ans=max(ans,tmp)
  else:
    tmp=0
    break
print(ans)
Problem p02936 (python)

Fixed submission:
#ika tako
import sys
n, q = map(int, input().split())
lines = sys.stdin.readlines()
links = [set() for _ in range(n)]
for line in lines[:n - 1]:
    a, b = map(int, line.split())
    a -= 1
    b -= 1
    links[a].add(b)
    links[b].add(a)
adds = [0] * n
for line in lines[n - 1:]:
    p, x = map(int, line.split())
    p -= 1
    adds[p] += x
ans = [-1] * n
q = [(0, 0)]
while q:
    v, a = q.pop()
    a += adds[v]
    ans[v] = a
    for u in links[v]:
        if ans[u] == -1:
            q.append((u, a))
print(*ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10*10)
def MI(): return map(int, input().split())
from collections import deque
N,Q=MI()
Edge=[[] for _ in range(N)]
for i in range(N-1):
  a,b=MI()
  Edge[a-1].append(b-1)
  Edge[b-1].append(a-1)
Point=[0]*N
for i in range(Q):
  p,x=MI()
  Point[p-1]+=x
def dfs(now,pre=-1):
  for nxt in Edge[now]:
    if nxt==pre:
      continue
    Point[nxt]+=Point[now]
    dfs(nxt,now)
dfs(0)
print(*Point)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(10*6)

def MI(): return map(int, input().split())
from collections import deque
N,Q=MI()
N1=N
#Edge1=[[] for _ in range(N)]
#print(Edge1)
Edge=[[] for _ in range(N1)]
#print(Edge)
for i in range(N-1):
  a,b=MI()
  Edge[a-1].append(b-1)
  Edge[b-1].append(a-1)
Point=[0]*N
for i in range(Q):
  p,x=MI()
  Point[p-1]+=x
def dfs(now,pre=-1):
  for nxt in Edge[now]:
    if nxt==pre:
      continue
    Point[nxt]+=Point[now]
    dfs(nxt,now)
dfs(0)
print(*Point)

Buggy submission (verdict: Runtime Error):
def MI():  return map(int, input().split())
N,Q=MI()
graph=[[] for i in range(N)]
for i in range(1,N):
  a,b=MI()
  graph[a-1].append(b-1)
  graph[b-1].append(a-1)
point=[0]*N  
for i in range(Q):
  p,x=MI()
  point[p-1]+=x
def dfs(now,pre=-1):  
  for next in graph[now]:
    if next==pre:
      continue
    point[next]+=point[now]
    dfs(next,now)
dfs(0)
print(*point)

Buggy submission (verdict: Runtime Error):
#@hoshikawa1309  Qiita
#dfsを用いて累積和を計算する
import sys
sys.setrecursionlimit(10 ** 6)
def input():#これをしないとTLE
    return sys.stdin.readline()[:-1]#このスライスは1行ずつ入力？
N , Q = map(int,input().split())
graph = [[] for _ in range(N)]
point = [0] * N
for _ in range(N - 1):
    a , b = map(int,input().split())
    graph[a - 1].append(b - 1)#0-index
    graph[b - 1].append(a - 1)#0-index
for _ in range(Q):
    a , b = map(int,input().split())
    a = a - 1#0-index
    point[a] += b#問題で与えられる、その頂点についての得点をプラス
# 初期状態だと前の値がないためデフォルト引数に-1を代入
def dfs(now , prev = -1):#いま見ている頂点と、どの頂点から来たかが引数
    #for文で、いま見ている頂点に繋がっている、次に頂点について以下ABC
    for next in graph[now]:
        # 次のノードが前に参照した値の時はcontinue何もしない
        if next == prev:       continue　　#A.逆走防止
        # 現在の値を次のポイントに加算することで累積和をとる
        point[next] += point[now]#B.実際の処理は、この累積和だけ
        # 次のノードと現在のノードを引数にdfsを継続する
        dfs(next , now)#C.深く探索するイメージ
dfs(0)
print(*point)
Problem p02947 (python)

Fixed submission:
import collections
N=int(input())
S=[''.join(sorted(input())) for _ in range(N)]
C=collections.Counter(S)
ans=0
for si in set(S):
  n=C[si]
  ans+=n*(n-1)//2
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())  #数値入力 「N」だけの入力のとき

S = []
for _ in range(n):
    S.append(set(input()).sort())
print(n-len(set(S)))

Buggy submission (verdict: Runtime Error):
n=int(input())  #数値入力 「N」だけの入力のとき

S = []
for _ in range(n):
    S.append(set(input()).sort())
print(n-len(set(S))+1)

Buggy submission (verdict: Runtime Error):
n=int(input())  #数値入力 「N」だけの入力のとき

S = []
for _ in range(n):
    S.append(set(input()).sort)
print(n-len(set(S))+1)

Buggy submission (verdict: Runtime Error):
n=int(input())  #数値入力 「N」だけの入力のとき

S = []
for _ in range(H):
    S.append(set(input()).sort)
print(n-len(set(S))+1)
Problem p02952 (python)

Fixed submission:
n=int(input())

if n<10:
  print(n)
elif n<100:
  print(9)
elif n<1000:
  print(n-90)
elif n<10000:
  print(909)
elif n<100000:
  print(n-9090)
else:
  print(90909)

Buggy submission (verdict: Runtime Error):
n=int(input())

if n<10:
  print(n)
elif n<100:
  print(9)
elif n<1000:
  print(n-90)
elif n<10000:
  print(909)
else n<100000:
  print(n-9090)
else:
  print(90909)
Problem p02953 (python)

Fixed submission:
N=int(input())
H=list(map(int,input().split()))
pre=-999
for i in range(N):
  if pre<=H[i]-1:
    pre=H[i]-1
  elif pre<=H[i]:
    pre=H[i]
  else:
    print('No')
    break
else:
  print('Yes')

Buggy submission (verdict: Runtime Error):
N=int(input())
H=list(map(int,input().split()))
pre=-999
for i in range(N):
  if pre<=H[i]-1:
    pre=H[i]-1
  else if pre<=H[i]:
    pre=H[i]
  else:
    print('No')
else:print('Yes')
Problem p02971 (python)

Fixed submission:
N=int(input())
A = []
for _ in range(N):
    A.append(int(input()))
A2=sorted(A,reverse=True)
M=A2[0]
M2=A2[1]
for i in range(N):
  #print(A[i])
  
  if A[i]==M:
    print(M2)
  else:
    print(M)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=sorted(list(map(int,input().split())))
M=A[0]
for i in range(N):
  if i==M:
    print(A[1])
  else:
    print(M)