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

Fixed submission:
N=int(input())
A=[]
for i in range(N):
  x,y=map(int, input().split())
  A.append((x,y))

def c(P1, P2, P3):
    x1, y1 = P1; x2, y2 = P2; x3, y3 = P3
    a = 2*(x1 - x2); b = 2*(y1 - y2); p = x1**2 - x2**2 + y1**2 - y2**2
    c = 2*(x1 - x3); d = 2*(y1 - y3); q = x1**2 - x3**2 + y1**2 - y3**2
    det = a*d - b*c
    x = d*p - b*q; y = a*q - c*p
    if det < 0:
        x = -x; y = -y; det = -det
    if det!=0:
      x /= det; y /= det
    r = ((x - x1)**2 + (y - y1)**2)**0.5
    return x,y,r
  
ans=(200000)**2
for i in range(N-1):
  for j in range(i+1,N):
    f=0
    x1,y1=A[i][0],A[i][1]
    x2,y2=A[j][0],A[j][1]
    x,y=(x1+x2)/2,(y1+y2)/2
    r=((x1-x)**2+(y1-y)**2)**0.5
    for a,b in A:
      d=((a-x)**2+(b-y)**2)**0.5
      if d>r:
        f=1
        break
    if f==0:
      ans=min(ans,r)
f=0

if N>2:
  for i in range(N-2):
    for j in range(i+1,N-1):
      for k in range(j+1,N):
        f=0
        x,y,r=c(A[i],A[j],A[k])
        if r>0:
          for a,b in A:
            d=((a-x)**2+(b-y)**2)**0.5
            if d>r:
              f=1
              break
          if f==0:
            ans=min(ans,r)
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
import math
A=[]
for i in range(N):
  x,y=map(int, input().split())
  A.append((x,y))

def c(P1, P2, P3):
    x1, y1 = P1; x2, y2 = P2; x3, y3 = P3
    a = 2*(x1 - x2); b = 2*(y1 - y2); p = x1**2 - x2**2 + y1**2 - y2**2
    c = 2*(x1 - x3); d = 2*(y1 - y3); q = x1**2 - x3**2 + y1**2 - y3**2
    det = a*d - b*c
    x = d*p - b*q; y = a*q - c*p
    if det < 0:
        x = -x; y = -y; det = -det
    x /= det; y /= det
    r = ((x - x1)**2 + (y - y1)**2)
    return x,y,r
  
ans=(200000)**2
for i in range(N-1):
  for j in range(i+1,N):
    f=0
    x1,y1=A[i][0],A[i][1]
    x2,y2=A[j][0],A[j][1]
    x,y=(x1+x2)/2,(y1+y2)/2
    r=(x1-x)**2+(y1-y)**2
    for a,b in A:
      d=(a-x)**2+(b-y)**2
      if d>r:
        f=1
        break
    if f==0:
      ans=min(ans,math.sqrt(r))

if N>2:
  for i in range(N-2):
    for j in range(i,N-1):
      for k in range(j,N):
        f=0
        if c(A[i],A[j],A[k])!=-1:
          x,y,r=c(A[i],A[j],A[k])
          for a,b in A:
            d=(a-x)**2+(b-y)**2
            if d>r:
              f=1
              break
          if f==0:
            ans=min(ans,math.sqrt(r))

print(ans)
Problem p02845 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
D=[0]*3
ans=1
for i in A:
  c=0
  E=[]
  if i==D[0]:
    c+=1
    E.append(0)
  if i==D[1]:
    c+=1
    E.append(1)
  if i==D[2]:
    c+=1
    E.append(2)
  if c==0:
    print(0)
    exit()
  D[E[0]]+=1
  ans*=c
  ans%=10**9+7
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
D=[0]*3
ans=1
for i in A:
  c=0
  E=[]
  if i==D[0]:
    c+=1
    E.append(0)
  if i==D[1]:
    c+=1
    E.append(1)
  if i==D[2]:
    c+=1
    E.append(2)
  D[E[0]]+=1
  ans*=c
  ans%=10**9+7
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
D=[-1]*3
ans=1
for i in A:
  c=0
  E=[]
  if i-1==D[0]:
    c+=1
    E.append(0)
  if i-1==D[1]:
    c+=1
    E.append(1)
  if i-1==D[2]:
    c+=1
    E.append(2)
  D[E[0]]+=1
  ans*=c
  ans%=10**9+7
print(ans)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
D=[-1,-1,-1]
ans=1
for i in A:
  c=0
  E=[]
  if i-1==D[0]:
    c+=1
    E.append(0)
  if i-1==D[1]:
    c+=1
    E.append(1)
  if i-1==D[2]:
    c+=1
    E.append(2)
  D[E[0]]+=1
  ans*=c
  ans%=10**9+7
print(ans)
Problem p02850 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

n=int(input())
A=[[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  a,b = a-1,b-1
  A[a].append([b,i])
    
ans = [0]*(n-1)

def col(now,color):
  c=1
  for (b,j) in A[now]:
    if c==color:
      c+=1
    ans[j]=c
    col(b,c)
    c+=1
col(0,0)
print(max(ans))
for a in ans:
  print(a)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=[[] for i in range(n)]
for i in range(n-1):
  a,b = map(int,input().split())
  a,b = a-1,b-1
  A[a].append([b,i])
    
ans = [0]*(n-1)

def col(now,color):
  c=1
  for (b,j) in A[now]:
    if c==color:
      c+=1
    ans[j]=c
    col(b,c)
    c+=1
col(0,0)
print(max(ans))
for a in ans:
  print(a)
Problem p02856 (python)

Fixed submission:
M=int(input())
k,g=0,0
for i in range(M):
  d,c=map(int,input().split())
  k+=c
  g+=c*d
print((g-1)//9+(k-1))

Buggy submission (verdict: Runtime Error):
M=int(input())
ans=0
A=[]
def f(x):
  e=str(x)
  n=len(e)
  l=0
  for i in e:
    l+=int(i)
  if l<10:
    return l
  else:
    f(l)
  
for i in range(M):
  d,c=map(int,input().split())
  ans+=(c-1)+d*c//10
  A.append(f(d*c))
  
ans+=len(A)-1
ans+=(sum(A)-1)//9
print(ans)

Buggy submission (verdict: Runtime Error):
M=int(input())
ans=0
A=[]
def f(x):
  e=str(x)
  n=len(e)
  l=0
  for i in e:
    l+=int(i)
  if l<10:
    return l
  else:
    f(l)
  
for i in range(M):
  d,c=map(int,input().split())
  ans+=(c-1)+d*c//10
  A.append(f(d*c))
if len(A)==1:
  print(ans)
  exit()
cnt=A[0]
for i in A[1:]:
  if cnt+i<10:
    cnt+=i
    ans+=1
  else:
    e=str(cnt+i)
    cnt=int(e[0])+int(e[1])
    ans+=2
print(ans)

Buggy submission (verdict: Runtime Error):
M=int(input())
ans=0
A=[]
def f(x):
  e=str(x)
  n=len(e)
  l=0
  for i in e:
    l+=int(i)
  if l<10:
    return l
  else:
    f(l)
  
for i in range(M):
  d,c=map(int,input().split())
  ans+=(c-1)+d*c//10
  A.append(f(d*c))
  
cnt=A[0]
for i in A[1:]:
  if cnt+i<10:
    cnt+=i
    ans+=1
  else:
    e=str(cnt+i)
    cnt=int(e[0])+int(e[1])
    ans+=2
print(ans)
Problem p02883 (python)

Fixed submission:
N,K=map(int, input().split())
A=list(map(int, input().split()))
F=list(map(int, input().split()))
A=sorted(A)
F=sorted(F)[::-1]
import numpy as np
a=np.array(A)
f=np.array(F)

low=-1
high=10**18

while high-low>1:
  d=(high+low)//2
  #0かa-d//fの大きい値を採用するnp.maximum　
  if np.maximum(0,a-d//f).sum()<=K:
    high=d
  else:
    low=d
print(high)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
F=list(map(int,input().split()))
B=sorted(A)
G=sorted(F)[::-1]
C=[]
for i in range(N):
  C.append(B[i]*G[i])

def dfs(t):
  if t==K:
    print(max(C))
  else:
    n=C.index(max(C))
    C[n]-=G[n]
    dfs(t+1)

if sum(A) <= K:
  print(0)
else:
  dfs(0)
Problem p02936 (python)

Fixed submission:
N, Q = map(int, input().split())

l = [[] for i in range(N)]

for i in range(N-1):
  a, b = map(int, input().split())
  l[a-1].append(b-1)
  l[b-1].append(a-1)

used = [False] * N
r = [0] * N

for i in range(Q):
  p, x = map(int, input().split())
  r[p-1] += x

stack = [0]
while stack:
  i = stack.pop()
  used[i] = True
  for to in l[i]:
    if not used[to]:
      stack.append(to)
      r[to] += r[i]

print(*r)

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N-1)]
B=[list(map(int,input().split())) for i in range(Q)]

#行先
C=[[]*i for i in range(N)]
#合計値
D=[0]*N
#足跡
E=[False]*N

for i in range(N-1):
  C[A[i][0]-1].append(A[i][1])
  C[A[i][1]-1].append(A[i][0])


def f(a,b):
  D[a-1]+=b
  E[a-1]=True
  x=len(C[a-1])
  if x>0:
    for k in C[a-1]:
      if a=!k:
        f(k,b)

for l in range(Q):
  f(B[l][0],B[l][1])
  
  
print(*D)

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N-1)]
B=[list(map(int,input().split())) for i in range(Q)]

#行先
C=[[]*i for i in range(N)]
#合計値
D=[0]*N
#足跡
E=[False]*N

for i in range(N-1):
  C[A[i][0]-1].append(A[i][1])
  C[A[i][1]-1].append(A[i][0])


def f(a,b):
  D[a-1]+=b
  E[a-1]=True
  x=len(C[a-1])
  if x>0:
    for k in C[a-1]:
      if a<k:
        f(k,b)

for l in range(Q):
  f(B[l][0],B[l][1])
  
  
print(*D)

Buggy submission (verdict: Runtime Error):
r = [0] * n
for i in range(q):
    p, x = map(int, input().split())
    r[p - 1] += x
stack = [0]
used = [False] * n    
while stack:
    i = stack.pop()
    used[i] = True
    for to in l[i]:
        if not used[to]:
            stack.append(to)
            r[to] += r[i]
for t_r in r:
    print(t_r)

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
A=[list(map(int,input().split())) for i in range(N-1)]
B=[list(map(int,input().split())) for i in range(Q)]
#行先
C=[[]*i for i in range(N)]
#合計値
D=[0]*N

for i in range(N-1):
  C[A[i][0]-1].append(A[i][1])

def f(a,b):
  D[a-1]+=b
  x=len(C[a-1])
  if x>0:
    for k in range(x):
      f(C[a-1][k],b)

for l in range(Q):
  f(B[l][0],B[l][1]) 
  
print(*D)
Problem p02937 (python)

Fixed submission:
import bisect
from collections import defaultdict

S=list(input().strip())
T=list(input().strip())
L=len(S)

if not set(T)<=set(S):
  print(-1)
  exit()

d=defaultdict(list)
for i,s in enumerate(S):
  d[s].append(i)
start=-1
ans=0
for i in T:
  p=bisect.bisect_right(d[i],start)
  le=len(d[i])
  if p==le:
    ans+=(L-start-1)+(d[i][0]+1)
    start=d[i][0]    
  else:
    ans+=d[i][p]-start
    start=d[i][p]
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
from collections import defaultdict

S=list(input().strip())
T=list(input().strip())
L=len(S)

if set(T)>set(S):
  print(-1)
  exit()

d=defaultdict(list)
for i,s in enumerate(S):
  d[s].append(i)
start=-1
ans=0
for i in T:
  p=bisect.bisect_right(d[i],start)
  le=len(d[i])
  if p==le:
    ans+=(L-start-1)+(d[i][0]+1)
    start=d[i][0]    
  else:
    ans+=d[i][p]-start
    start=d[i][p]
print(ans)
Problem p02953 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))

for i in range(N-1):
  if A[N-2-i]-A[N-1-i]==1:
    A[N-2-i]-=1
  elif A[N-2-i]-A[N-1-i]>1:
    print('No')
    exit()
print('Yes')

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))

if A[0]-A[1]==1:
  A[0]-=1

for i in range(1,N-1):
  if A[i]-A[i+1]==1:
    A[i]-=1
    if A[i-1]-A[i]==1:
      print('No')
      exit()
 
  elif A[i]-A[i+1]>1:
    print('No')
    exit()
print('Yes')
print(A)
Problem p02975 (python)

Fixed submission:
N=int(input())
A=list(map(int, input().split()))

a=A[0]
for i in range(N-1):
  a=a^A[i+1]
if a==0:
  print("Yes")
else:
  print("No")

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int, input().split()))
A=sorted(A)
if N%3!=0:
  if A==[0]*N:
    print('Yes')
  else:
    print('No')
else:
  B=A[0]+A[1]
  for i in range(N):
    d=B[i]^B[i+1]^B[i+2]
    if d!=0:
      print('No')
      exit()
  print('Yes')
Problem p03000 (python)

Fixed submission:
N,X=map(int,input().split())
A=list(map(int,input().split()))
D=0
cnt=1
if sum(A)<= X:
  print(N+1)
  exit()
else:
  for i in range(X+1):
    D+=A[i]
    if D <= X:
      cnt+=1
    else:
      print(cnt)
      exit()

Buggy submission (verdict: Runtime Error):
N,X=map(int,input().split())
A=list(map(int,input().split()))
D=0
cnt=1
for i in range(X+1):
  D+=A[i]
  if D <= X:
    cnt+=1
  else:
    print(cnt)
    exit()
Problem p03006 (python)

Fixed submission:
N=int(input())
if N==1:
  print(1)
  exit()
  
A=[list(map(int,input().split())) for i in range(N)]
B={}
for a,b in A:
  for c,d in A:
    e=a-c
    f=b-d
    if e!=0 or f!=0:
      if (e,f) in B:
        B[(e,f)]+=1
      else:
        B[(e,f)]=1
a=max(B.values())
print(N-a)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[list(map(int,input().split())) for i in range(N)]
B={}
for a,b in A:
  for c,d in A:
    if a>c:
      e=a-c
      f=b-d
    else:
      e=c-a
      f=d-b
    if e!=0 or f!=0:
      if (e,f) in B:
        B[(e,f)]+=1
      else:
        B[(e,f)]=1
        
a=max(B.values())
print(N-a//2)
Problem p03026 (python)

Fixed submission:
import sys 
sys.setrecursionlimit(10**6)
N=int(input())
A=[[]for i in range(N)]
X=[list(map(int, input().split())) for _ in range(N-1)]
for i in range(N-1):
  a=X[i][0]
  b=X[i][1]
  a-=1
  b-=1
  A[a].append(b)
  A[b].append(a)
D=list(map(int, input().split()))
D=sorted(D)[::-1]
from collections import deque
d=deque(D)
E=[-1]*N
def f(now,pre):
  for i in A[now]:
    if i!=pre and E[i]==-1:
      E[i]=d.popleft()
      f(i,now)
E[0]=d.popleft()
f(0,0)
print(sum(D[1:]))
print(*E)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[[]for i in range(N)]
X=[list(map(int, input().split())) for _ in range(N-1)]
for i in range(N-1):
  a=X[i][0]
  b=X[i][1]
  a-=1
  b-=1
  A[a].append(b)
  A[b].append(a)
D=list(map(int, input().split()))
D=sorted(D)[::-1]
from collections import deque
d=deque(D)
E=[-1]*N
def f(now,pre):
  for i in A[now]:
    if i!=pre and E[i]==-1:
      E[i]=d.popleft()
      f(i,now)
E[0]=d.popleft()
f(0,0)
print(sum(D[1:]))
print(*E)
Problem p03032 (python)

Fixed submission:
import bisect
n,k=map(int, input().split())
V=list(map(int, input().split()))
ans=0
for i in range(k+1):
  for j in range(k+1-i):
    if i+j>n:
      break  
    #手に取りだしたもの
    A=sorted(V[:i]+V[n-j:])
    a=min(k-i-j,bisect.bisect_left(A, 0))
    ans=max(ans,sum(A[a:]))
print(ans)

Buggy submission (verdict: Runtime Error):
import bisect
n,k=map(int, input().split())
V=list(map(int, input().split()))
ans=0
for i in range(k+1):
  for j in range(k+1-i):
    if i+j>n:
      break  
    #手に取りだしたもの
    A=sorted(V[:i]+V[n-j:])
    a=min(n-i-j,bisect.bisect_left(A, 0))
    ans=max(ans,sum(S[a:]))
print(ans)
Problem p03044 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**7)

N=int(input())
A=[list(map(int,input().split())) for _ in range(N-1)]
C=[0]*N
D=[[] for i in range(N)]
for u,v,w in A:
  u-=1
  v-=1
  D[u].append((v,w))
  D[v].append((u,w))

def dfs(n,v,k):
  for i in D[n]:
    if k%2!=0:
      C[n]=1
    if v!=i[0]:
      dfs(i[0],n,k+i[1])       
        
dfs(0,0,0)

for i in C:
  print(i)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[list(map(int,input().split())) for _ in range(N-1)]
C=[0]*N
D=[[] for i in range(N)]
for u,v,w in A:
  u-=1
  v-=1
  D[u].append((v,w))
  D[v].append((u,w))

def dfs(n,v,k):
  for i in D[n]:
    if k%2!=0:
      C[n]=1
    if v==i[0]:
      continue
    dfs(i[0],n,k+i[1])       
        
dfs(0,0,0)

for i in C:
  print(i)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[list(map(int,input().split())) for _ in range(N-1)]
C=[0]*N
D=[[] for i in range(N)]
for u,v,w in A:
  u-=1
  v-=1
  D[u].append((v,w))
  D[v].append((u,w))

def dfs(n,v,k):
  for i in D[n]:
    if k%2!=0:
      C[n]=1
    if v!=i[0]:
      dfs(i[0],n,k+i[1])       
        
dfs(0,0,0)

for i in C:
  print(i)
Problem p03087 (python)

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

X=[0]*(N)
cnt=0
for i in range(N-1): 
  if S[i]=='A' and S[i+1]=='C':
    cnt+=1
    X[i+1]=cnt
  else:
    X[i+1]=cnt
    
for i in range(Q):
  a=A[i][0]-1
  b=A[i][1]-1
  print(X[b]-X[a])

Buggy submission (verdict: Runtime Error):
N,Q=map(int,input().split())
S=input()
A=[list(map(int,input().split())) for i in range(Q)]
X=[0]*(N+1)
cnt=1
for i in range(N): 
  if S[i]=='A' and S[i+1]=='C':
    X[i+1]=cnt
    cnt+=1
  else:
    X[i+1]=cnt
    
for i in range(Q):
  a=A[i][0]
  b=A[i][1]
  print(X[b]-X[a])
Problem p03096 (python)

Fixed submission:
N=int(input())
A=[int(input()) for _ in range(N)]
mod=10**9+7
B=[A[0]-1]
for i in range(1,N):
  if A[i]!=A[i-1]:
    B.append(A[i]-1)
n=len(B)
used=[-1]*(max(A)+1)
used[B[0]]=0
dp=[0]*n
dp[0]=1
for i in range(1,n):
  if used[B[i]]==-1:
    dp[i]=dp[i-1]
  else:
    a=used[B[i]]
    dp[i]=(dp[i-1]+dp[a])%mod
  used[B[i]]=i
print(dp[-1])

Buggy submission (verdict: Runtime Error):
N=int(input())
A=[int(input()) for _ in range(N)]
mod=10**9+7
B=[A[0]-1]
for i in range(1,N):
  if A[i]!=A[i-1]:
    B.append(A[i]-1)
n=len(B)
used=[-1]*N
used[B[0]]=0
dp=[0]*n
dp[0]=1
for i in range(1,n):
  if used[B[i]]==-1:
    dp[i]=dp[i-1]
  else:
    a=used[B[i]]
    dp[i]=(dp[i-1]+dp[a])%mod
  used[B[i]]=i
print(dp[-1])
Problem p03138 (python)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int, input().split()))
dp=[[0,0]for _ in range(42)]
#2の41乗が10**12とちょっと

for i in range(1,42):
  if dp[i-1][1]==1:
    dp[i][1]=1
  
  cnt=0
  #リストA内のiケタ目の1の数をカウント
  for j in range(N):
    if (A[j]>>(41-i))&1==1:
      cnt+=1
      
  #1の方が多いときは、0を当てはめる
  if cnt>=N-cnt:
    dp[i][0]=dp[i-1][0]+(2**(41-i))*cnt
    if (K>>(41-i))&1==1:
      dp[i][1]=1
  else:
    if dp[i][1]==1:
      dp[i][0]=dp[i-1][0]+(2**(41-i))*(N-cnt)
    else:
      if (K>>(41-i))&1==1:
        #そのケタが1ならば問題なし
        dp[i][0]=dp[i-1][0]+(2**(41-i))*(N-cnt)
      else:
        #桁が0ならば0にするしかない
        dp[i][0]=dp[i-1][0]+(2**(41-i))*cnt
print(dp[41][0])

Buggy submission (verdict: Runtime Error):
,K=map(int,input().split())
A=list(map(int, input().split()))
dp=[[0,0]for _ in range(42)]
#2の41乗が10**12とちょっと

for i in range(1,42):
  if dp[i-1][1]==1:
    dp[i][1]=1
  
  cnt=0
  #リストA内のiケタ目の1の数をカウント
  for j in range(N):
    if (A[j]>>(41-i))&1==1:
      cnt+=1
      
  #1の方が多いときは、0を当てはめる
  if cnt>=N-cnt:
    dp[i][0]=dp[i-1][0]+(2**(41-i))*cnt
    if (K>>(41-i))&1==1:
      dp[i][1]=1
  else:
    if dp[i][1]==1:
      dp[i][0]=dp[i-1][0]+(2**(41-i))*(N-cnt)
    else:
      if (K>>(41-i))&1==1:
        #そのケタが1ならば問題なし
        dp[i][0]=dp[i-1][0]+(2**(41-i))*(N-cnt)
      else:
        #桁が0ならば0にするしかない
        dp[i][0]=dp[i-1][0]+(2**(41-i))*cnt
print(dp[41][0])
Problem p03166 (python)

Fixed submission:
import sys
sys.setrecursionlimit(10**5+10)
input=sys.stdin.readline

N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)
def chmax(a,b):
  if a>=b:
    return a
  else:
    return b
dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=chmax(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=chmax(ans,rec(i))
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)
def chmax(a,b):
  if a>=b:
    return a
  else:
    return b
dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=chmax(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=chmax(ans,rec(i))
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)

dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=max(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=max(ans,rec(i))
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=[list(map(int, input().split())) for i in range(M)]
G=[[]for i in range(N)]
for a,b in A:
  G[a-1].append(b-1)
print(G)

dp=[-1]*N
def rec(v):
  if dp[v]!=-1:
    return dp[v]
  ans=0
  for i in G[v]:
    ans=max(ans,rec(i)+1)
  dp[v]=ans
  return dp[v]
    
ans=0
for i in range(N):
  ans=max(ans,rec(i))
print(ans)
Problem p03220 (python)

Fixed submission:
N=int(input())
T,A=map(int,input().split())
H=(list(map(int,input().split())))

height=[abs(A-(T-h*0.006)) for h in H]
print(int(height.index(min(height)) )+1)

Buggy submission (verdict: Runtime Error):
N=int(input())
T,A=map(int,input().split())
H=(list(map(int,input().split())))
z = abs(T-H*0.006)
while z
Problem p03266 (python)

Fixed submission:
N,K=map(int,input().split())
a=N//K
if K%2==1:
  print(a**3)
else:
  if N>=(a+0.5)*K:
    print(a**3+(a+1)**3)
  else:
    print((a**3)*2)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
import math
def d(n,r):
  return math.factorial(n)//math.factorial(r)//math.factorial(n-r)

if N<K:
  print(0)
else:  
  a=N//K
  ans=a
  if K%2==1:
    if a>=2:
      ans+=d(a,2)*6
    if a>=3:
      ans+=a*(a-1)*(a-2)
    print(ans)
  else:    
    if K*a+K//2<=N:
      b=a+1
    if a>=2:
      ans+=d(a,2)*6
      print(ans)
    if a>=3:
      ans+=a*(a-1)*(a-2)
    if b>=2:
      ans+=b+d(b,2)*6
    if b>=3:
      ans+=b*(b-1)*(b-2)

    print(ans)

Buggy submission (verdict: Runtime Error):
def d(n,r):
  return factorial(n)//factorial(r)//factorial(n-r)

if N<K:
  print(0)
else:  
  a=N//K
  ans=a
  if K%2==1:
    if a>=2:
      ans+=d(a,2)*6
    if a>=3:
      ans+=a*(a-1)*(a-2)
    print(ans)
  else:    
    if K*a+K//2<=N:
      b=a+1
    if a>=2:
      ans+=d(a,2)*6
      print(ans)
    if a>=3:
      ans+=a*(a-1)*(a-2)
    if b>=2:
      ans+=b+d(b,2)*6
    if b>=3:
      ans+=b*(b-1)*(b-2)

    print(ans)
Problem p03274 (python)

Fixed submission:
N,K=map(int,input().split())
A=list(map(int,input().split()))
a=N-K+1
long=10**9
for i in range(a):
  l=A[i+K-1]-A[i]+min(abs(A[i+K-1]),abs(A[i]))
  long=min(long,l)
print(long)

Buggy submission (verdict: Runtime Error):
N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[]
C=[]
for i in A:
  if i<=0:    
    B.append(i)
  else:
    C.append(i)

b=len(B)
c=len(C)
a=min(b,c,K)

l=10**9
for i in range(a):
  la=C[i]+B[i+1-K]*(-2)
  lb=C[i]*2-B[i+1-K]
  l=min(l,la,lb)

BB=10**9
CC=10**9
if b>=K:
  BB=(B[-K])*(-1)
if c>=K:
  CC=(C[K-1])
print(min(BB,CC,l))
Problem p03287 (python)

Fixed submission:
N,M=map(int, input().split())
A=list(map(int, input().split()))
import numpy
D=list(numpy.cumsum(A))
C={}
for i in D:
  d=i%M
  if d not in C:
    C[d]=1
  else:
    C[d]+=1
#print(C)

ans=0
for i in C.values():
  ans+=i*(i-1)//2
#余り0はそれ単独でok
if 0 in C:
  ans+=C[0]
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split())
A=list(map(int, input().split()))
import numpy
D=list(numpy.cumsum(A))
C={}
for i in D:
  d=i%M
  if d not in C:
    C[d]=1
  else:
    C[d]+=1
#print(C)

ans=0
for i in C.values():
  ans+=i*(i-1)//2
#余り0はそれ単独でok
ans+=C[0]
print(ans)
Problem p03356 (python)

Fixed submission:
N,M=map(int, input().split()) 
P=list(map(int,input().split()))
par=[i for i in range(N+1)]
rank=[0]*(N+1)
#根
def find(x):
  if x==par[x]:
    return x
  else:
    par[x]=find(par[x])
    return par[x]
  
def find(x):
    if x == par[x]:
        return x
    par[x] = find(par[x])
    return par[x]
  
#同じ集合か判定
def same(x,y):
  return find(x)==find(y)

def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 0
  if rank[x]<rank[y]:
    par[x]=y
  else:
    par[y]=x
    if rank[x]==rank[y]:
      rank[x]+=1

for i in range(M):
  a,b=map(int,input().split())
  union(a,b)

ans=0
for i in range(1,N+1):
  if same(P[i-1],i):
    ans+=1
print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int, input().split()) 
P=list(map(int,input().split()))
par=[i for i in range(N+1)]
rank=[0]*(N+1)

#根を探す
def find(x):
  if par[x]==x:
    return x
  else:
    par[x]==find(par[x])
    return par[x]

#同じ集合か判定
def same(x,y):
  return find(x)==find(y)

def union(x,y):
  x=find(x)
  y=find(y)
  if x==y:
    return 0
  if rank[x]<rank[y]:
    par[x]=y
  else:
    par[y]=x
    if rank[x]==rank[y]:
      rank[x]+=1

for i in range(M):
  a,b=map(int,input().split())
  union(a,b)


print(par)
print(rank)     
  
ans=0
for i in range(1,N+1):
  print(i,P[i-1])
  if same(P[i-1],i):
    ans+=1
print(ans)
Problem p03361 (python)

Fixed submission:
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans='Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='#':
      if S[max(0,i-1)][j]!='#' and S[min(i+1,H-1)][j]!='#' and S[i][max(0,j-1)]!='#' and S[i][min(j+1,W-1)]!='#':
        ans='No'
        break
print(ans)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[input() for _ in range(H)]
ans='Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='#':
      if S[max(0,i-1)][j]!='#' and S[min(i+1,W-1)][j]!='#' and S[i][max(0,j-1)]!='#' and S[i-1][min(j+1,H-1)]!='#':
        ans='No'
        break
print(ans)

Buggy submission (verdict: Runtime Error):
H,W=map(int,input().split())
S=[input() for _ in range(H)]
Ans = 'Yes'
for i in range (H):
  for j in range (W):
    if S[i][j]=='#':
      if S[max(0,i-1)][j]=='#'or [min(i+1,W)][j]=='#'or[i][max(0,j-1)]=='#'or[i-1][min(j+1,H)]=='#':
        continue
      else:
        Ans = 'No'
  print(Ans)