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

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

T=[0,2,5,5,4,5,6,3,7,6]
B=[]
for i in A:
    B.append(T[i])
B=sorted(list(set(B)))
dp=[0 for i in range(N+1)]
AB=[[i,T[i]] for i in A]
AB=sorted(AB,reverse=True)

for i in range(1,N+1):
    for j in B:
        if i-j>=0 and dp[i-j]!=-1:
            dp[i]=max(dp[i],dp[i-j]+1)
            #print(i,j,dp[i])
    if dp[i]==0:
        dp[i]=-1
#print(dp)
#print(AB)

c=N
U=[0 for i in range(8)]
while c>0:
    for i in range(len(AB)):
        if c-AB[i][1]>=0 and dp[c]==dp[c-AB[i][1]]+1:
            U[AB[i][1]]+=1
            c-=AB[i][1]
            break
#print(U)

ans=""
if 9 in A:
    ans+='9'*U[6]
    U[6]=0
if 8 in A:
    ans+='8'*U[7]
if 7 in A:
    ans+='7'*U[3]
if 6 in A:
    ans+='6'*U[6]
if 5 in A:
    ans+='5'*U[5]
    U[5]=0
if 4 in A:
    ans+='4'*U[4]
if 3 in A:
    ans+='3'*U[5]
    U[5]=0
if 2 in A:
    ans+='2'*U[5]
if 1 in A:
    ans+='1'*U[2]

print(ans)

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

T=[0,2,5,5,4,5,6,3,7,6]
B=[]
for i in A:
    B.append(T[i])
B=sorted(list(set(B)))
dp=[0 for i in range(N+1)]
AB=[[i,T[i]] for i in A]
AB=sorted(AB,reverse=True)

for i in range(1,N+1):
    for j in B:
        if i-j>=0 and dp[i-j]!=-1:
            dp[i]=max(dp[i],dp[i-j]+1)
            #print(i,j,dp[i])
    if dp[i]==0:
        dp[i]=-1
#print(dp)
#print(AB)

c=N
U=[0 for i in range(8)]
while c>0:
    for i in range(len(AB)):
        if dp[c]==dp[c-AB[i][1]]+1:
            U[AB[i][1]]+=1
            c-=AB[i][1]
            break
#print(U)

ans=""
if 9 in A:
    ans+='9'*U[6]
    U[6]=0
if 8 in A:
    ans+='8'*U[7]
if 7 in A:
    ans+='7'*U[3]
if 6 in A:
    ans+='6'*U[6]
if 5 in A:
    ans+='5'*U[5]
    U[5]=0
if 4 in A:
    ans+='4'*U[4]
if 3 in A:
    ans+='3'*U[5]
    U[5]=0
if 2 in A:
    ans+='2'*U[5]
if 1 in A:
    ans+='1'*U[2]

print(ans)
Problem p03160 (python)

Fixed submission:
import numpy as np

N=int(input())
H=list(map(int,input().split()))

dp=np.empty(N,dtype=int)
dp[0]=0
dp[1]=abs(H[1]-H[0])

for i in range(2,N):
    a=dp[i-1]+abs(H[i]-H[i-1])
    b=dp[i-2]+abs(H[i]-H[i-2])
    dp[i]=min(a,b)

print(dp[N-1])

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

def dp(x):
    if x==0:
        return 0
    elif x==1:
        return abs(H[1]-H[0])
    else:
        a=dp(x-1)+abs(H[x]-H[x-1])
        b=dp(x-2)+abs(H[x]-H[x-2])
        return min(a,b)

print(dp(N-1))
Problem p03273 (python)

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

#'#'が入っている行および列を列挙する
Tate=[0]*H
Yoko=[0]*W
for i in range(H):
    for j in range(W):
        if A[i][j]=='#':
            Tate[i]+=1
            Yoko[j]+=1

ans=['']*H
for i in range(H):
    for j in range(W):
        if Tate[i]*Yoko[j]>0:
            ans[i]+=A[i][j]

for i in ans:
    if i!='':
        print(i)

Buggy submission (verdict: Runtime Error):
H,W = map(int,input().split())
S=[]
for i in range(H):
    S.append(input())
T=[]
for i in range(H):
    T.append([])
    for j in range(W):
        T[-1].append(int(S[i][j]=='#'))

#横
for i in range(H):
    if T[i].count(1)==0:
        for j in range(W):
            T[i][j]=2

#縦
for i in range(W):
    tate=0
    for j in range(H):
        if T[j][i]!=1:
            tate+=1
    if tate==H:
        for j in range(H):
            T[j][i]=2

A=[]
for i in range(H):
    A.append([])
    for j in range(W):
        if T[i][j]!=2:
            A[i].append('#.'[T[i][j]==0])

for i in range(H-1):
    if len(A[i])==0:
        A.pop(i)

for i in range(len(A)):
    print(''.join(A[i]))
Problem p03274 (python)

Fixed submission:
N,K=map(int,input().split())
X=list(map(int,input().split()))
X.sort()
ans=10**10

for i in range(N-K+1):
    R=X[i+K-1]
    L=X[i]
    A=[ans, abs(L)+abs(R-L), abs(R)+abs(R-L)]
    ans=min(A)

print(ans)

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

cost=10**10

Plus=[i for i in X if i>=0]
Minus=[-i for i in X if i<=0]

if len(Plus)>=K:
    cost=Plus[K-1]
if len(Minus)>=K:
    cost=min(cost,Minus[-K])

i=0
while X[i]<0 and i<=K:
    if i+K-1<N:
        cost=min(cost,X[i+K-1]-X[i]+abs(X[i]))
    i+=1

print(cost)

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

cost=10**10
P=X.copy()
i=0
while P[i]<0:
    P.pop(0)
if len(P)>=K:
    cost=P[K-1]    

for i in range(N-K+1):
    if X[i] >= 0:
        break
    else:
        L=[j-X[i] for j in X]
        cost=min(cost,L[i+K-1]+abs(X[i]))

print(cost)
Problem p03282 (python)

Fixed submission:
S=input()
K=int(input())

i=0
while S[i]=='1' and i<len(S)-1:
    i+=1

print([1,S[i]][K>i])

Buggy submission (verdict: Runtime Error):
S=input()
K=int(input())

i=0
while S[i]=='1':
    i+=1

print([1,S[i]][K>i])
Problem p03423 (python)

Fixed submission:
print(int(input())//3)

Buggy submission (verdict: Runtime Error):
N=int(input())
M,A,R,C,H=0,0,0,0,0
for i in range(N):
    s=input()[0]
    if s=='M':
        M+=1
    elif s=='A':
        A+=1
    elif s=='R':
        R+=1
    elif s=='C':
        C+=1
    elif s=='H':
        H+=1

print(M*A*R + M*A*C + M*A*H + M*R*C + M*R*H + \
      M*C*H + A*R*C + A*R*H + A*C*H + R*C*H)
Problem p03436 (python)

Fixed submission:
from collections import deque

H,W=map(int,input().split())
c=[['#']*(W+2)]
ten=0
for i in range(H):
    ip=list(input())
    ten+=ip.count('.')
    c.append(['#']+ip+['#'])
c.append(['#']*(W+2))
Q=deque([[1,1,1]])

def move(yxc):
    global Q,c
    y,x,cost=yxc[0],yxc[1],yxc[2]
    if c[y+1][x]=='.':
        c[y+1][x]=cost+1
        Q.append([y+1,x,cost+1])
    if c[y-1][x]=='.':
        c[y-1][x]=cost+1
        Q.append([y-1,x,cost+1])
    if c[y][x+1]=='.':
        c[y][x+1]=cost+1
        Q.append([y,x+1,cost+1])
    if c[y][x-1]=='.':
        c[y][x-1]=cost+1
        Q.append([y,x-1,cost+1])

c[1][1]=1
while len(Q)>0:
    move(Q.popleft())

goal=c[H][W]
if goal=='.' or goal=='#':
    print(-1)
else:
    print(ten-goal)

Buggy submission (verdict: Runtime Error):
from collections import deque

H,W=map(int,input().split())
c=[['#']*(W+2)]
ten=0
for i in range(H):
    ip=list(input())
    ten+=ip.count('.')
    c.append(['#']+ip+['#'])
c.append(['#']*(W+2))
Q=deque([[1,1,1]])

def move(yxc):
    global Q,c
    y,x,cost=yxc[0],yxc[1],yxc[2]
    if c[y+1][x]=='.':
        c[y+1][x]=cost+1
        Q.append([y+1,x,cost+1])
    if c[y-1][x]=='.':
        c[y-1][x]=cost+1
        Q.append([y-1,x,cost+1])
    if c[y][x+1]=='.':
        c[y][x+1]=cost+1
        Q.append([y,x+1,cost+1])
    if c[y][x-1]=='.':
        c[y][x-1]=cost+1
        Q.append([y,x-1,cost+1])

c[1][1]=1
while len(Q)>0:
    move(Q.popleft())

goal=c[H][W]
print(ten-goal)
Problem p03575 (python)

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

def find_root(root,x):
    y = root[x]
    if x == y:
        return x
    z = find_root(root,y)
    root[x] = z
    return z
 
def merge(root,size,x,y):
    x = find_root(root,x)
    y = find_root(root,y)
    if x == y:
        return
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    size[x] += sy

def UF_make(graph,n):
    Root=list(range(n+1))
    Size=[1] * (n+1)
    for i in range(len(graph)):
        merge(Root,Size,graph[i][0],graph[i][1])
    for i in range(n+1):
        Root[i] = find_root(Root,i)
    Root.pop(0)  #
    return Root

ans=0
for i in range(M):
    if len(set((UF_make(AB[:i]+AB[i+1:],N))))!=1:
        ans+=1

print(ans)

Buggy submission (verdict: Runtime Error):
N,M=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]


def UF_make(Graph):
    ret=[-1]*(N+1)
    for i in range(len(Graph)):
        v1=[ret[Graph[i][0]],Graph[i][0]][ret[Graph[i][0]]<0]
        v2=[ret[Graph[i][1]],Graph[i][1]][ret[Graph[i][1]]<0]
        if v1!=v2:
            if ret[v1]>ret[v2]:
                v1,v2=v2,v1
            ret[v1]+=ret[v2]
            ret[v2]=v1
    return ret

def UF_check(Array,V1,V2):
    v1=[Array[V1],V1][Array[V1]<0]
    v2=[Array[V2],V2][Array[V2]<0]
    return(True if v1==v2 else False)

def UF(Graph,V1,V2):
    return(UF_check(UF_make(Graph),V1,V2))

ans=0
for i in range(M):
    if UF(AB[:i]+AB[i+1:],AB[i][0],AB[i][1])==False:
        ans+=1

print(ans)
Problem p03597 (python)

Fixed submission:
n,a=map(int,open(0));print(n**2-a)

Buggy submission (verdict: Runtime Error):
A,B,C,D,E,F=map(int,input().split())

water=[]
for i in range(31):
    for j in range(30):
        if (A*i+B*j)*100<=F:
            water.append((A*i+B*j)*100)
sugar=[]
for i in range(501):
    for j in range(500):
        if C*i+D*j<=F//2:
            sugar.append(C*i+D*j)

ans_sum=A*100
ans_sugar=0
ans_rate=0
for i in water:
    for j in sugar:
        if i==0:
            continue
        if i+j<=F and ans_rate<j/i<=E/100:
            ans_sum=i+j
            ans_sugar=j
            ans_rate=j/i

print(ans_sum,ans_sugar)
Problem p03611 (python)

Fixed submission:
N=int(input())
A=sorted(list(map(int,input().split())))
C=[0]*(max(A)+1)

for i in A:
    C[i]+=1

if len(C)==1:
    print(C[0])
else:
    T=max(C[0]+C[1],C[-1]+C[-2])
    for i in range(1,max(A)):
        T=max(T,C[i-1]+C[i]+C[i+1])
    print(T)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=sorted(list(map(int,input().split())))
C=[0]*(max(A)+1)

for i in A:
    C[i]+=1

if len(C)==0:
    print(C[0])
else:
    T=max(C[0]+C[1],C[-1]+C[-2])
    for i in range(1,max(A)):
        T=max(T,C[i-1]+C[i]+C[i+1])
    print(T)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=sorted(list(map(int,input().split())))
C=[0]*(max(A)+1)

for i in A:
    C[i]+=1

T=max(C[0]+C[1],C[-1]+C[-2])
for i in range(1,max(A)):
    T=max(T,C[i-1]+C[i]+C[i+1])

print(T)
Problem p03612 (python)

Fixed submission:
N=int(input())
P=list(map(int,input().split()))
Q=P[::-1]
c=0
for i in range(N-1):
    if P[i]==i+1:
        P[i],P[i+1]=P[i+1],P[i]
        c+=1
if P[N-1]==N:
    c+=1
print(c)

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

c=[]
for i in range(N):
    if P[i]==i+1:
        c.append(i+1)

import sys
if c==[]:
    print(0)
    sys.exit()

d=[]
for i in range(1,len(c)):
    d.append(c[i]-c[i-1])

if len(c)==2:
    print(c[1]-c[0])
elif len(c)%2==0:
    print(sum(d)-max(d))
else:
    print(sum(d)-max(d)+1)
Problem p03635 (python)

Fixed submission:
n,m=map(int,input().split());print((n-1)*(m-1))

Buggy submission (verdict: Runtime Error):
n,m=map(int,open(0));print((n-1)*(m-1))
Problem p03695 (python)

Fixed submission:
N=int(input())
A=sorted(list(map(int,input().split())))
A=[i//400 for i in A]

Colors=[0,0,0,0,0,0,0,0,0]
for i in A:
    if i>=8:
        Colors[8]+=1
    else:
        Colors[i]+=1

Count=0
for i in range(8):
    if Colors[i]>0:
        Count+=1

print(max(Count,1),Count+Colors[-1])

Buggy submission (verdict: Runtime Error):
N=int(input())
A=sorted(list(map(int,input().split())))
A=[i//400 for i in A]

Colors=[0,0,0,0,0,0,0,0,0]
for i in A:
    Colors[i]+=1

Count=0
for i in range(8):
    if Colors[i]>0:
        Count+=1
if Count==0:
    Count=1

print(Count,Count+Colors[-1])
Problem p03816 (python)

Fixed submission:
N=int(input());A=list(map(int,input().split()));S=len(set(A));print(S-1+S%2)

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
A.sort()
S=[]
D=[]

for i in A:
    if i in S:
        D.append(i)
    else:
        S.append(i)
#print(D)
M=N-len(D)

if len(D)%2==1:
    print(M-1)
else:
    MaxD,MinD=max(D),min(D)
    Med=-1
    for i in S:
        if MinD<=i<=MaxD:
            Med=i
            print(M)
            break
    if Med==-1:
        print(M-2)
Problem p03855 (python)

Fixed submission:
N,K,L=map(int,input().split())
PQ=[list(map(int,input().split())) for i in range(K)]
RS=[list(map(int,input().split())) for i in range(L)]

def find_root(root,x):
    y = root[x]
    if x == y:
        return x
    z = find_root(root,y)
    root[x] = z
    return z
 
def merge(root,size,x,y):
    x = find_root(root,x)
    y = find_root(root,y)
    if x == y:
        return
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    size[x] += sy
    
def UF_make(graph,n):
    Root=list(range(n+1))
    Size=[1] * (n+1)
    for i in range(len(graph)):
        merge(Root,Size,graph[i][0],graph[i][1])
    for i in range(n+1):
        Root[i] = find_root(Root,i)
    Root.pop(0)  #
    return Root

PQN=UF_make(PQ,N)
RSN=UF_make(RS,N)
PQRS=[PQN[i]*10**6+RSN[i] for i in range(N)]
D=len(set(PQRS))
PQRS=[[PQRS[i],i,0] for i in range(N)]
PQRS.sort()

p=0
while p<N:
    i=1
    c=0
    if p+i>N-1:
        break
    while PQRS[p][0]==PQRS[p+i][0]:
        c+=1
        i+=1
        if p+i>N-1:
            break
    for j in range(p,p+i):
        PQRS[j][2]=c
    p+=i
PQRS.sort(key=lambda x:x[1])
for i in range(N):
    print(PQRS[i][2]+1,end=' ')

Buggy submission (verdict: Runtime Error):
N,K,L=map(int,input().split())
PQ=[list(map(int,input().split())) for i in range(K)]
RS=[list(map(int,input().split())) for i in range(L)]

def find_root(root,x):
    y = root[x]
    if x == y:
        return x
    z = find_root(root,y)
    root[x] = z
    return z
 
def merge(root,size,x,y):
    x = find_root(root,x)
    y = find_root(root,y)
    if x == y:
        return
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    size[x] += sy
    
def UF_make(graph,n):
    Root=list(range(n+1))
    Size=[1] * (n+1)
    for i in range(len(graph)):
        merge(Root,Size,graph[i][0],graph[i][1])
    for i in range(n+1):
        Root[i] = find_root(Root,i)
    Root.pop(0)  #
    return Root

PQN=UF_make(PQ,N)
RSN=UF_make(RS,N)
PQRS=[[PQN[i]*10**6+RSN[i],i,0] for i in range(N)]
PQRS.sort()

p=0
while p<N:
    i=1
    c=0
    if p+i>=N-1:
        break
    while PQRS[p][0]==PQRS[p+i][0]:
        c+=1
        i+=1
    for j in range(p,p+i):
        PQRS[j][2]=c
    p+=i

PQRS.sort(key=lambda x:x[1])
for i in range(N):
    print(PQRS[i][2]+1,end=' ')
Problem p02555 (python)

Fixed submission:
s=int(input())
mod=10**9+7

if s<3:
    print(0)
    exit()

dp=[1]*(s+1)

dp[0]=0
dp[1]=0
dp[2]=0

#print(dp)
for i in range(3,s+1):
    for j in range(3,s-i+1):
        dp[i+j]+=dp[i]%mod
    #print(i,dp)
print(dp[s]%mod)

Buggy submission (verdict: Runtime Error):
s=int(input())
mod=10**9+7


dp=[1]*(s+1)

dp[0]=0
dp[1]=0
dp[2]=0


#print(dp)
for i in range(3,s+1):
    for j in range(3,s-i+1):
        dp[i+j]+=dp[i]%mod
    #print(i,dp)
print(dp[s]%mod)
Problem p02574 (python)

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

import math 

ans = a[0]
for i in range(1, n):
    ans = math .gcd(ans, a[i])

if ans!=1:
    #print(ans)
    print("not coprime")
    exit()
else:
    checked=[0]*(int(max(a))+1)
    #print(checked)
    for item in a:
        for j in range(1,int(item**0.5)+1):
            if item%j==0 and j*j<=item:
                if checked[j]==0:
                    if j!=1:
                        checked[j]+=1
                    
                    if j*j!=item:
                        if checked[item//j]==0:
                            checked[item//j]+=1
                        else:
                            #print(item,j,checked)
                            print("setwise coprime")
                            exit() 
                else:
                    #print(item,j,checked)
                    print("setwise coprime")
                    exit()
print("pairwise coprime")

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

g = 0
for a in A:
    g = gcd(g,a)
if g > 1:
    print('not coprime')
    exit()

sa = set(A)
if len(sa) < N:
    print('setwise coprime')
    exit()

MAXN = 10**10+10
sieve = [0,0] + [1]*MAXN
p = 2
small_primes = []
while p*p <= MAXN:
    if sieve[p]:
        small_primes.append(p)
        for q in range(2*p,MAXN+1,p):
            sieve[q] = 0
    p += 1

st = set()
for a in A:
    for p in small_primes:
        found = False
        while a%p==0:
            a //= p
            found = True
        if found:
            if p in st:
                print('setwise coprime')
                exit()
            st.add(p)
        if a==1: break
    else:
        if a in st:
            print('setwise coprime')
            exit()
        st.add(a)

print('pairwise coprime')

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

import math 

ans = a[0]
for i in range(1, n):
    ans = math .gcd(ans, a[i])

if ans!=1:
    #print(ans)
    print("not coprime")
    exit()
else:
    checked=[0]*(int(max(a)))
    #print(checked)
    for item in a:
        for j in range(1,int(item**0.5)+1):
            if item%j==0 and j*j<=item:
                if checked[j]==0:
                    if j!=1:
                        checked[j]+=1
                        if checked[item//j]==0:
                            checked[item//j]+=1
                        else:
                            #print(item,j,checked)
                            print("setwise coprime")
                            exit() 
                else:
                    #print(item,j,checked)
                    print("setwise coprime")
                    exit()
print("pairwise coprime")
Problem p02585 (python)

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

p=list(map(int,input().split()))
score=list(map(int,input().split()))

group_score=[]
checked=[0]*n

for i in range(n):
    if checked[i]==0:
        tmp_group=[]
        tmp=i
        while checked[tmp]==0:
            checked[tmp]=1
            tmp_group.append(score[tmp])
            tmp=p[tmp]-1
        group_score.append(tmp_group)



#aryの中から連続するk個選択するときの最大
def calc(k):
    if k==0:
        return 0
    global group
    ans="INF"
    for i in range(len(group)):
        tmp=0
        for j in range(k):
            tmp+=group[(i+j)%len(group)]
            if ans=="INF":
                ans=tmp
            else:
                if ans<tmp:
                    ans=tmp
    return ans

ans=score[0]
for group in group_score:
    #一周以上する場合
    if len(group)<k:
        cycle=sum(group)
        if cycle>0:
            cycle_sum=cycle*(k//len(group))
            tmp=calc(k%len(group))
            ans=max(ans,cycle_sum+tmp)

            if k//len(group)>=2:
                cycle_sum=cycle*(k//len(group)-1)
                tmp=calc(len(group))
                ans=max(ans,cycle_sum+tmp)
          

        tmp=calc(len(group))
        ans=max(ans,tmp)



    #一周しない場合k)
    else:
        tmp=calc(k)
        ans=max(ans,tmp)

print(ans)

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

p=list(map(int,input().split()))
c=list(map(int,input().split()))

check=[0]*n
group=[]

for i in range(n):
    tmp=i
    if check[tmp]==0:
        tmp_group=[]
        while check[tmp]==0:
            tmp_group.append(tmp)
            check[tmp]=1
            tmp=p[tmp]-1

        group.append(tmp_group)

ans="start"

#startの最低とgoalの最高の和
for item in group:
    
    #一周すると何になるか。これはどこスタートでも同じ
    circle=0
    cnt=k
    if len(item)<k:
        for v in item:
            circle+=c[v]
        circle=circle*(k//len(item))
        circle=max(circle,0)    
        cnt=k%len(item)
    
    #一周した後のあまりで最強を探す


    goal="INF"
    
    #startは各groupのindexが入ってる
    for start in range(len(item)):
        tmp=0
        #print("start",item,start,cnt)
        for i in range(start,start+cnt):
            #print(">>",i)
            tmp+=c[item[i%len(item)]]
            #print(item[i%len(item)],c[item[i%len(item)]])
            if goal=="INF":
                goal=tmp
            else:
                goal=max(goal,tmp)

    #print(item,circle,goal)
    if ans=="start":
        ans=goal+max(0,circle)
    else:
        ans=max(ans,goal+max(0,circle))

print(ans)
Problem p02646 (python)

Fixed submission:
#鬼
a,v=map(int,input().split())

#逃げている
b,w=map(int,input().split())

#t秒以内
t=int(input())

if v>w:
    if abs(a-b)<=(v-w)*t:
        print("YES")
        exit()

print("NO")

Buggy submission (verdict: Runtime Error):
#鬼
a,v=map(int,input().split())

#逃げている
b,w=map(int,input().split())

#t秒以内
t=int(input())

if v>w:
    abs(a-b)>=v*w*t:
    print("YES")
    exit()
else:
    print("NO")
Problem p02665 (python)

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


if n==0:
    if a[0]==1:
        print(1)
    else:
        print(-1)
    exit()

if a[0]==1 and n!=0:
    print(-1)
    exit()

suma=sum(a)

cnt=1
bk=1

for i,aa in enumerate(a[1:]):
    node=min(suma,bk*2)
    cnt+=node
    #print(i,aa,node)
    bk=node-aa
    suma-=aa

if bk==0:
    print(cnt)
else:
    print(-1)

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


if n==0:
    if a[0]==1:
        print(1)
    else:
        print(-1)
    exit()

if a[0]==1 and n!=0:
    print(-1)
    exit()

suma=sum(a)
node=1
cnt=0
for i,aa in enumerate(a[::-1]):
    cnt+=min(cnt+aa,2**(i-1))

print(cnt)
    
        


                    
        


    
print(cnt)
Problem p02698 (python)

Fixed submission:
import sys
sys.setrecursionlimit(2147483647)

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

tree=[[] for _ in range(n)]
for _ in range(n-1):
    aa,bb=map(int,input().split())
    tree[aa-1].append(bb-1)
    tree[bb-1].append(aa-1)

ans=[0]*n
import bisect

#bisect.bisect_left(a, 4) #被ったら左側のindexを返す
#bisect.bisect_right(a, 4)#被ったら右側のindexを返す

def lisOnTree(x,lis):
    global ans,tree,a,n
    i=bisect.bisect_left(lis, a[x])
    if i==len(lis):
        lis.append(a[x])
        flag="append"
    else:
        flag=(i,lis[i])
        lis[i]=a[x]
    #print(x,lis)
    ans[x]=len(lis)
    for item in tree[x]:
        if ans[item]==0:
            lisOnTree(item,lis)
    if flag=="append":
        lis.pop()
    else:
        lis[flag[0]]=flag[1]

lisOnTree(0,[])

for item in ans:
    print(item)

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

tree=[[] for _ in range(n)]
for _ in range(n-1):
    aa,bb=map(int,input().split())
    tree[aa-1].append(bb-1)
    tree[bb-1].append(aa-1)

ans=[0]*n
import bisect

#bisect.bisect_left(a, 4) #被ったら左側のindexを返す
#bisect.bisect_right(a, 4)#被ったら右側のindexを返す

def lisOnTree(x,lis):
    global ans,tree,a,n
    i=bisect.bisect_left(lis, a[x])
    if i==len(lis):
        lis.append(a[x])
        flag="append"
    else:
        flag=(i,lis[i])
        lis[i]=a[x]
    #print(x,lis)
    ans[x]=len(lis)
    for item in tree[x]:
        if ans[item]==0:
            lisOnTree(item,lis)
    if flag=="append":
        lis.pop()
    else:
        lis[flag[0]]=flag[1]

lisOnTree(0,[])

for item in ans:
    print(item)