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

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

ans=-10**20
for i in range(n):
    loop=1
    j=p[i]-1
    acm=[c[j]]
    while j!=i:
        j=p[j]-1
        acm.append(acm[-1]+c[j])
        loop+=1
    
    if acm[-1]>0:
        if k<=loop:
            cur=max(acm[:k])
        else:
            cur=(k//loop)*acm[-1]
            if k%loop>0:
                cur=max(cur,cur+max(acm[:k%loop]))
            else:
                cur-=acm[-1]
                cur+=max(acm)
    else:
        cur=max(acm[:min(k,loop)])
    
    ans=max(cur,ans)
    
print(ans)

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

ans=-10**20
for i in range(n):
    loop=1
    j=p[i]-1
    acm=[c[j]]
    while j!=i:
        j=p[j]-1
        acm.append(acm[-1]+c[j])
        loop+=1
    
    if acm[-1]>0:
        if k<loop:
            cur=max(acm[:k])
        else:
            cur=(k//loop)*acm[-1]
            cur=max(cur,cur+max(acm[:k%loop]))
    else:
        cur=max(acm[:min(k,loop)])
    
    ans=max(cur,ans)

print(ans)
Problem p02588 (python)

Fixed submission:
from fractions import Fraction
from decimal import Decimal

n=int(input())
a=[Fraction(Decimal(input())) for _ in range(n)]

num=[aa.numerator*10**9//aa.denominator for aa in a]

cnt=[[0]*50 for _ in range(50)]
pair=[]

for nu in num:
    c2=0
    c5=0
    while nu>0 and nu%2==0:
        nu//=2
        c2+=1
    
    while nu>0 and nu%5==0:
        nu//=5
        c5+=1
    
    cnt[c2][c5]+=1
    pair.append((c2,c5))
ans=0

for i in range(49,-1,-1):
    for j in range(49,-1,-1):
        if i+1<49:
            cnt[i][j]+=cnt[i+1][j]
        if j+1<49:
            cnt[i][j]+=cnt[i][j+1]

        if i+1<49 and j+1<49:
            cnt[i][j]-=cnt[i+1][j+1]

for c2,c5 in pair:
    ans+=cnt[max(0,18-c2)][max(0,18-c5)]
    if c2>=9 and c5>=9:
        ans-=1

print(ans//2)

Buggy submission (verdict: Runtime Error):
from fractions import Fraction
from decimal import Decimal

n=int(input())
a=[Fraction(Decimal(input())) for _ in range(n)]

num=[aa.numerator*10**9//aa.denominator for aa in a]

cnt=[[0]*20 for _ in range(20)]
pair=[]

for nu in num:
    c2=0
    c5=0
    while nu>0 and nu%2==0:
        nu//=2
        c2+=1
    
    while nu>0 and nu%5==0:
        nu//=5
        c5+=1
    
    cnt[c2][c5]+=1
    pair.append((c2,c5))
ans=0

for c2,c5 in pair:
    for cc2 in range(18-c2,20):
        for cc5 in range(18-c5,20):
            ans+=cnt[cc2][cc5]
    if c2>=9 and c5>=9:
        ans-=1

print(ans//2)

Buggy submission (verdict: Runtime Error):
from fractions import Fraction
from decimal import Decimal

n=int(input())
a=[Fraction(Decimal(input())) for _ in range(n)]

num=[aa.numerator*10**9//aa.denominator for aa in a]

cnt=[[0]*15 for _ in range(15)]
pair=[]

for nu in num:
    c2=0
    c5=0
    while nu%2==0:
        nu//=2
        c2+=1
    
    while nu%5==0:
        nu//=5
        c5+=1
    
    cnt[c2][c5]+=1
    pair.append((c2,c5))
ans=0

for c2,c5 in pair:
    for cc2 in range(18-c2,15):
        for cc5 in range(18-c5,15):
            ans+=cnt[cc2][cc5]
    if c2>=9 and c5>=9:
        ans-=1

print(ans//2)
Problem p02609 (python)

Fixed submission:
n=int(input())
s=[int(c) for c in input()]

pc=sum(s)

resm=[0]*n
resp=[0]*n

jm=1
jp=1

totm=0
totp=0
for i in range(n):
    if pc-1>0:
        resm[n-i-1]=jm%(pc-1)
        jm=(2*jm)%(pc-1)
        totm+=resm[n-i-1]*s[n-i-1]
        totm%=pc-1
    
    resp[n-i-1]=jp%(pc+1)
    jp=(2*jp)%(pc+1)
    totp+=resp[n-i-1]*s[n-i-1]
    totp%=pc+1

def popc(x):
    return sum([int(c) for c in format(x,'b')])

for i in range(n):
    if s[i]==1:
        pcc=pc-1
        if pcc==0:
            print(0)
            continue
        cres=(totm+pc-1-resm[i])%(pc-1)
    else:
        pcc=pc+1
        cres=(totp+resp[i])%(pc+1)
    
    if cres==0:
        print(1)
        continue

    cnt=1
    while cres>0:
        cres%=popc(cres)
        cnt+=1
    
    print(cnt)

Buggy submission (verdict: Runtime Error):
n=int(input())
s=[int(c) for c in input()]

pc=sum(s)

resm=[0]*n
resp=[0]*n

jm=1
jp=1

totm=0
totp=0
for i in range(n):
    resm[n-i-1]=jm%(pc-1)
    resp[n-i-1]=jp%(pc+1)

    jm=(2*jm)%(pc-1)
    jp=(2*jp)%(pc+1)

    totm+=resm[n-i-1]*s[n-i-1]
    totm%=pc-1

    totp+=resp[n-i-1]*s[n-i-1]
    totp%=pc+1

def popc(x):
    return sum([int(c) for c in format(x,'b')])

for i in range(n):
    if s[i]==1:
        pcc=pc-1
        cres=(totm+pc-1-resm[i])%(pc-1)
    else:
        pcc=pc+1
        cres=(totp+resp[i])%(pc+1)
    
    if cres==0:
        print(1)
        continue

    cnt=1
    while cres>0:
        cres%=popc(cres)
        cnt+=1
    
    print(cnt)
Problem p02616 (python)

Fixed submission:
N,K=list(map(int,input().split()))
a=list(map(int,input().split()))
a.sort(key=lambda x:abs(x),reverse=True)

mod=10**9+7

p=[]
m=[]
zero=False
cntm=0
cntp=0

for aa in a:
    if aa>=0:
        p.append(aa)
        if cntp+cntm<K:
            cntp+=1
    elif aa<0:
        m.append(-aa)
        if cntp+cntm<K:
            cntm+=1
    
    if aa==0:
        zero=True

ans=1

if cntm%2==1:
    if cntm+1<=len(m) and cntm+1<=K and cntp+1<=len(p) and cntp+1<=K:
        if p[cntp]*p[cntp-1]>m[cntm]*m[cntm-1]:
            cntp+=1
            cntm-=1
        else:
            cntm+=1
            cntp-=1
    elif cntm+1<=len(m) and cntm+1<=K:
        cntm+=1
        cntp-=1
    elif cntp+1<=len(p) and cntp+1<=K:
        cntp+=1
        cntm-=1
    else:
        if zero:
            print(0)
            exit(0)
        
        for i in range(K):
            ans*=a[N-i-1]
            ans=(ans+mod*mod)%mod
        
        print(ans)
        exit(0)

for i in range(cntm):
    ans*=m[i]
    ans%=mod
for i in range(cntp):
    ans*=p[i]
    ans%=mod

print(ans)

Buggy submission (verdict: Runtime Error):
        m.append(-aa)
        if cntp+cntm<K:
            cntm+=1
    
    if aa==0:
        zero=True

ans=1

if cntm%2==1:
    if cntm+1<=len(m) and cntm+1<=K and cntp+1<=len(p) and cntp+1<=K:
        if p[cntp]*p[cntp-1]>m[cntm]*m[cntm-1]:
            cntp+=1
            cntm-=1
        else:
            cntp+=1
            cntm-=1
    elif cntm+1<=len(m) and cntm+1<=K:
        cntm+=1
        cntp-=1
    elif cntp+1<=len(p) and cntp+1<=K:
        cntp+=1
        cntm-=1
    else:
        if zero:
            print(0)
            exit(0)
        
        for i in range(K):
            ans*=a[N-i-1]
            ans=(ans+mod*mod)%mod
        
        print(ans)
        exit(0)

for i in range(cntm):
    ans*=m[i]
    ans%=mod
for i in range(cntp):
    ans*=p[i]
    ans%=mod

print(ans)
Problem p02631 (python)

Fixed submission:
N=int(input())
a=list(map(int,input().split()))
ans=[[0]*30 for _ in range(N)]

if sum(a)==0:
    print(' '.join(['0']*N))
    exit(0)

i=29

while i>=0:
    curbit=[aa%2 for aa in a]

    s=sum(curbit)

    if s%2==0:
        for j in range(N):
            ans[j][i]=curbit[j]
    else:
        for j in range(N):
            ans[j][i]=0 if curbit[j] else 1



    a=[aa//2 for aa in a]
    
    i-=1

print(' '.join([str(int(''.join([str(aaa) for aaa in aa]),2)) for aa in ans]))

Buggy submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
ans=[['']*30 for _ in range(N)]

if sum(a)==0:
    print(' '.join(['0']*N))
    exit(0)

i=29

while True:
    curbit=[aa%2 for aa in a]

    s=sum(curbit)

    if s==0:
        break

    if s%2==0:
        for j in range(N):
            ans[j][i]=str(curbit[j])
    else:
        for j in range(N):
            ans[j][i]=str(0 if curbit[j] else 1)



    a=[aa//2 for aa in a]
    i-=1

print(' '.join([str(int(''.join(aa),2)) for aa in ans]))

Buggy submission (verdict: Runtime Error):
N=int(input())
a=list(map(int,input().split()))
ans=[['']*30 for _ in range(N)]
i=29

while True:
    curbit=[aa%2 for aa in a]

    s=sum(curbit)
    if s==0:
        break

    if s%2==0:
        for j in range(N):
            ans[j][i]=str(curbit[j])
    else:
        for j in range(N):
            ans[j][i]=str(0 if curbit[j] else 1)


    a=[aa//2 for aa in a]
    i-=1

print(' '.join([str(int(''.join(aa),2)) for aa in ans]))
Problem p02705 (python)

Fixed submission:
import numpy as np

R=int(input())

print(2*np.pi*R)

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

R=int(input())

print(2*np.pi*R)
Problem p02733 (python)

Fixed submission:
h,w,k=list(map(int,input().split()))
s=[list(map(int,[x for x in input()])) for _ in range(h)]

cnt=10001

for i in range(2**(h-1)):
    split=[0]*h
    curcnt=0
    for j in range(h):
        if (i>>j)&1:
            split[j]=1
            curcnt+=1
        
    nsplit=curcnt+1
    sumlst=[[0]*(nsplit) for _ in range(w)]

    cw=0
    memo=0
    chk=0
    flag=False
    while cw<w:
        l=0
        for ch in range(h):
            sumlst[memo][l]+=s[ch][cw]

            if sumlst[memo][l]>k:
                memo+=1
                chk+=1
                break

            if split[ch]:
                l+=1
        else:
            chk=0
            cw+=1
            continue

        if chk>1:
            break
    else:
        cnt=min(cnt,curcnt+memo)

print(cnt)

Buggy submission (verdict: Runtime Error):
h,w,k=list(map(int,input().split()))
s=[list(map(int,[x for x in input()])) for _ in range(h)]

cnt=10001

for i in range(2**(h-1)):
    split=[0]*h
    curcnt=0
    for j in range(h):
        if (i>>j)&1:
            split[j]=1
            curcnt+=1
        
    nsplit=curcnt+1
    sumlst=[[0]*(nsplit) for _ in range(w)]
    
    cw=0
    memo=0
    while cw<w:
        l=0
        for ch in range(h):
            sumlst[memo][l]+=s[ch][cw]

            if sumlst[memo][l]>k:
                memo+=1
                break

            if split[ch]:
                l+=1
        else:
            cw+=1
    
    cnt=min(cnt,curcnt+memo)

print(cnt)

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

s=[list(map(int,[x for x in input()])) for _ in range(h)]

cnt=10001

for i in range(2**(h-1)):
    split=[(i>>j)&1 for j in range(h)]

    curcnt=sum(split)
    nsplit=curcnt+1
    
    
    cw=0
    while cw<w:
        l=0
        for ch in range(h):
            sumlst[l]+=s[ch][cw]

            if sumlst[l]>k:
                sumlst=[0]*(nsplit)
                curcnt+=1
                break

            if split[ch]:
                l+=1
        else:
            cw+=1
    
    cnt=min(cnt,curcnt)

print(cnt)

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

s=[list(map(int,[x for x in input()])) for _ in range(h)]

cnt=10000

for i in range(2**(h-1)):
    split=[0]*h

    for j in range(h-1):
        split[j]=(i>>j)&1
    
    curcnt=sum(split)
    
    sumlst=[0]*(curcnt+1)

    j=0
    while j<w:
        l=0
        ch=0

        while ch<h:
            sumlst[l]+=s[ch][j]
            
            if sumlst[l]>k:
                curcnt+=1
                sumlst=[0]*(sum(split)+1)
                j-=1
                continue

            if split[ch]==1:
                l+=1
            
            ch+=1
        
        j+=1
    
    cnt=min(cnt,curcnt)

print(cnt)
Problem p02765 (python)

Fixed submission:
import sys
import heapq
import copy
import numpy as np
from collections import deque

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

ret=0
if n>=10:
    ret=r
else:
    ret=r+100*(10-n)

print(ret)

Buggy submission (verdict: Runtime Error):
import sys
import heapq
import copy
import numpy as np
from collections import deque

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

ret=0
if n>=10:
    ret=r
else:
    ret=r+100*(10-n)

print(ret)
Problem p02882 (python)

Fixed submission:
import numpy as np

a,b,x=list(map(int,input().split()))
area=x/a

if area<=a*b/2.0:
    h=2*area/b
    print(90-np.degrees(np.arctan(h/b)))
else:
    h=2*b-2*area/a
    print(np.degrees(np.arctan(h/a)))

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

a,b,x=list(map(int,input().split()))
area=x/a

if area<=a*b/2.0:
    h=2*area/b
    print(90-np.degrees(np.arctan(h/b)))
else:
    h=2*b-2*area/a
    print(np.degrees(np.arctan(h/a)))
Problem p02900 (python)

Fixed submission:
import fractions

A,B=list(map(int,input().split()))    

maxn=10**6
prime=[1]*(maxn+1)
prime[0]=0
prime[1]=0

for i in range(2,maxn+1):
    if prime[i]==0:
        continue

    for j in range(2,maxn//i+1):
        prime[i*j]=0

C=fractions.gcd(A,B)
cnt=1

for i in range(2,maxn+1):
    if prime[i]==0:
        continue

    if C%i==0:
        while C%i==0:
            C//=i
        cnt+=1

if C>1:
    cnt+=1

print(cnt)

Buggy submission (verdict: Runtime Error):
import math

A,B=list(map(int,input().split()))

maxn=10**6
prime=[1]*(maxn+1)
prime[0]=0
prime[1]=0

for i in range(2,maxn+1):
    if prime[i]==0:
        continue

    for j in range(2,maxn//i+1):
        prime[i*j]=0

C=math.gcd(A,B)
cnt=1

for i in range(2,maxn+1):
    if prime[i]==0:
        continue

    if C%i==0:
        while C%i==0:
            C//=i
        cnt+=1

if C>1:
    cnt+=1

print(cnt)
Problem p02997 (python)

Fixed submission:
from itertools import combinations

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

node=(N-1)*(N-2)//2

if K>node:
    print(-1)
    exit(0)

g=[[] for _ in range(N+1)]
M=0

for i in range(2,N+1):
    g[1].append(i)
    M+=1

cnt=node-K

for u,v in combinations(range(2,N+1),2):
    if cnt==0:
        break
    g[u].append(v)
    
    M+=1
    cnt-=1


print(M)
for i in range(1,N+1):
    for j in g[i]:
        print('{} {}'.format(i,j))

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

node=(N-1)*(N-2)//2

if K>node:
    print(-1)
    exit(0)

g=[[] for _ in range(N+1)]
M=0

for i in range(2,node+2):
    g[1].append(i)
    M+=1

for i in range(node-K):
    g[i+2].append(i+3)
    M+=1
print(M)
for i in range(1,N+1):
    for j in g[i]:
        print('{} {}'.format(i,j))
Problem p03032 (python)

Fixed submission:
from collections import deque
from copy import deepcopy
import heapq

N,K=list(map(int,input().split()))
V=list(map(int,input().split()))

minus=[[[0]*(N+1) for _ in range(N+1)] for _ in range(N+1)]

vdeque=deque(V)

for left in range(N+1):
    for right in range(N-left+1):
        v=deepcopy(vdeque)
        q=[]

        tleft=left
        while tleft>0:
            vi=deque.popleft(v)
            if vi<0:
                heapq.heappush(q,vi)
            tleft-=1
        
        tright=right

        while tright>0:
            vj=deque.pop(v)
            if vj<0:
                heapq.heappush(q,vj)
            tright-=1
        
        for k in range(1,N+1):
            if len(q)>0:
                minus[k][left][right]=minus[k-1][left][right]-heapq.heappop(q)
            else:
                minus[k][left][right]=minus[k-1][left][right]

leftacum=[0]*(N+1)
rightacum=[0]*(N+1)

for i in range(N):
    leftacum[i+1]=leftacum[i]+V[i]
    rightacum[i+1]=rightacum[i]+V[N-i-1]

ans=-10**10

for left in range(N+1):
    for right in range(N-left+1):
        k=min(N,K-left-right)
        if k<0:
            continue

        ans=max(ans,leftacum[left]+rightacum[right]+minus[k][left][right])

print(ans)

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

N,K=list(map(int,input().split()))
V=deque(list(map(int,input().split())))

minus=[[[0]*(N+1) for _ in range(N+1)] for _ in range(N+1)]

for left in range(N+1):
    for right in range(N-left+1):
        v=deepcopy(V)
        q=[]

        tleft=left
        while tleft>0:
            vi=deque.popleft(v)
            if vi<0:
                heapq.heappush(q,vi)
            tleft-=1
        
        tright=right

        while tright>0:
            vj=deque.pop(v)
            if vj<0:
                heapq.heappush(q,vj)
            tright-=1
        
        for k in range(1,N+1):
            if len(q)>0:
                minus[k][left][right]=minus[k-1][left][right]-heapq.heappop(q)
            else:
                minus[k][left][right]=minus[k-1][left][right]

leftacum=[0]*(N+1)
rightacum=[0]*(N+1)

vl=deepcopy(V)
vr=deepcopy(V)

for i in range(N):
    leftacum[i+1]=leftacum[i]+vl.popleft()
    rightacum[i+1]=rightacum[i]+vr.pop()

ans=-10**10

for left in range(N+1):
    for right in range(N-left+1):
        k=K-left-right
        if k<0:
            continue

        ans=max(ans,leftacum[left]+rightacum[right]+minus[k][left][right])

print(ans)
Problem p03050 (python)

Fixed submission:
n=int(input())

t1=2
comb=set()
while t1*t1<=n:
    if n%t1==0:
        t2=n//t1

        m=t1-1
        if t2==n%m:
            comb.add(m)
        m=t2-1
        if t1==n%m:
            comb.add(m)
    t1+=1

if n>2:
    print(sum(comb)+n-1)
else:
    print(sum(comb))

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

t1=2
comb=set()
while t1*t1<=n:
    if n%t1==0:
        t2=n//t1

        m=t1-1
        if t2==n%m:
            comb.add(m)
        m=t2-1
        if t1==n%m:
            comb.add(m)
    t1+=1

m=n-1
print(sum(comb)+n-1 if n==(m+1)*(n%m) else sum(comb))
Problem p03128 (python)

Fixed submission:
import math

n,_,*a=map(int,open(0).read().split())
match={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
a=sorted(a)

num=[0]*8

for d in a:
    num[match[d]]=d

dig=set(num)
dig.remove(0)
dig=sorted(list(dig),reverse=True)

dp=[-10**10]*(n+1)
dp[0]=0

for i in range(n+1):
    for d in dig:
        if i-match[d]<0:
            continue

        dp[i]=max(dp[i],dp[i-match[d]]+1)

ans=''

i=n
while i>0:
    for d in dig:
        if i-match[d]<0:
            continue
        if dp[i]==dp[i-match[d]]+1:
            ans=ans+str(d)
            break
    
    i-=match[d]

print(ans)

Buggy submission (verdict: Runtime Error):
import math

n,_,*a=map(int,open(0).read().split())
match={1:2,2:5,3:5,4:4,5:5,6:6,7:3,8:7,9:6}
a=sorted(a)

num=[0]*8

for d in a:
    num[match[d]]=d

dig=set(num)
dig.remove(0)
dig=sorted(list(dig),reverse=True)

dp=[-10**10]*(n+1)
dp[0]=0

for i in range(n+1):
    for d in dig:
        if i-match[d]<0:
            continue

        dp[i]=max(dp[i],dp[i-match[d]]+1)

ans=''

i=n
while i>0:
    for d in dig:
        if dp[i]==dp[i-match[d]]+1:
            ans=ans+str(d)
            break
    
    i-=match[d]

print(ans)
Problem p03157 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500*500)

h,w=list(map(int,input().split()))
s=[[1 if c=='#' else 0 for c in input()] for _ in range(h)]
g=[[] for _ in range(h*w)]

for i in range(w):
    for j in range(h):
        for di in [-1,0,1]:
            for dj in [-1,0,1]:
                if abs(di)+abs(dj)!=1:
                    continue
                if 0<=i+di<w and 0<=j+dj<h:
                    if s[j][i]!=s[j+dj][i+di]:
                        g[j*w+i].append(i+di+(j+dj)*w)

visit=[0]*(h*w)
black=[0]*(h*w)
white=[0]*(h*w)

def rec(j,i,rj,ri):
    if s[j][i]:
        black[rj*w+ri]+=1
    else:
        white[rj*w+ri]+=1
    
    for n in g[j*w+i]:
        if visit[n]:
            continue

        visit[n]=1

        rec(n//w,n%w,rj,ri)

ans=0

for i in range(w):
    for j in range(h):
        if visit[w*j+i]:
            continue
        visit[w*j+i]=1

        rec(j,i,j,i)
        
        ans+=black[w*j+i]*white[w*j+i]

print(ans)

Buggy submission (verdict: Runtime Error):
h,w=list(map(int,input().split()))
s=[input() for _ in range(h)]
g=[[] for _ in range(h*w)]

for i in range(w):
    for j in range(h):
        for di in [-1,0,1]:
            for dj in [-1,0,1]:
                if abs(di)+abs(dj)!=1:
                    continue
                if 0<=i+di<w and 0<=j+dj<h:
                    if s[j][i]!=s[j+dj][i+di]:
                        g[j*w+i].append(i+di+(j+dj)*w)

visit=[0]*(h*w)
ans=0
black=[0]*(h*w)
white=[0]*(h*w)

def rec(j,i,rj,ri):
    if s[j][i]=='#':
        black[rj*w+ri]+=1
    else:
        white[rj*w+ri]+=1
    
    for n in g[j*w+i]:
        if visit[n]==1:
            continue

        nj=n//w
        ni=n%w

        visit[n]=1

        rec(nj,ni,rj,ri)

for i in range(w):
    for j in range(h):
        if visit[w*j+i]:
            continue
        visit[w*j+i]=1

        rec(j,i,j,i)
        
        ans+=black[w*j+i]*white[w*j+i]

print(ans)

Buggy submission (verdict: Runtime Error):
h,w=list(map(int,input().split()))
s=[input() for _ in range(h)]
g=[[] for _ in range(h*w)]

for i in range(w):
    for j in range(h):
        for di in [-1,0,1]:
            for dj in [-1,0,1]:
                if abs(di)+abs(dj)!=1:
                    continue
                if 0<=i+di<w and 0<=j+dj<h:
                    if s[j][i]!=s[j+dj][i+di]:
                        g[j*w+i].append(i+di+(j+dj)*w)

visit=[0]*(h*w)
ans=0
black=[0]*(h*w)
white=[0]*(h*w)

def rec(j,i,rj,ri):
    if s[j][i]=='#':
        black[rj*w+ri]+=1
    else:
        white[rj*w+ri]+=1
    
    for n in g[j*w+i]:
        if visit[n]==1:
            continue

        nj=n//w
        ni=n%w

        visit[n]=1

        rec(nj,ni,rj,ri)

for i in range(w):
    for j in range(h):
        if visit[w*j+i]:
            continue
        visit[w*j+i]=1

        if s[j][i]=='#':
            rec(j,i,j,i)
        else:
            rec(j,i,j,i)
        
        ans+=black[w*j+i]*white[w*j+i]

print(ans)
Problem p03213 (python)

Fixed submission:
from collections import Counter
N=int(input())
p=[]
dp=[[0]*100 for _ in range(100)]
dp[0][1]=1

for i in range(2,N+1):
    ti=i
    for j in range(2,i+1):
        while ti%j==0:
            p.append(j)
            ti//=j

cnt=Counter(p)
ans=0
for i,v in enumerate(cnt.values()):
    for j in range(100):
        for k in range(1,v+2):
            dp[i+1][min(76,j*k)]+=dp[i][j]
    ans=dp[i+1][75]

print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
N=int(input())
p=[]
dp=[[0]*100 for _ in range(100)]
dp[0][1]=1

for i in range(2,N+1):
    ti=i
    for j in range(2,i+1):
        while ti%j==0:
            p.append(j)
            ti//=j

cnt=Counter(p)

for i,v in enumerate(cnt.values()):
    for j in range(100):
        for k in range(1,v+2):
            dp[i+1][min(76,j*k)]+=dp[i][j]
    ans=dp[i+1][75]

print(ans)
Problem p03230 (python)

Fixed submission:
n=int(input())

m=-1

for i in range(3,1000,2):
    if i*i==8*n+1:
        m=(1+i)//2

if m==-1:
    print('No')
    exit(0)

cnt=1
s=[[0] for _ in range(m+1)]

for i in range(1,m+1):
    for j in range(i+1,m+1):
        s[i][0]+=1
        s[j][0]+=1

        s[i].append(cnt)
        s[j].append(cnt)

        cnt+=1

print('Yes')
print(m)
for i in range(1,m+1):
    print(' '.join([str(c) for c in s[i]]))

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

m=-1

for i in range(3,1000,2):
    if i*i==8*n+1:
        m=(1+i)//2

if m==-1:
    print('No')
    exit(0)

cnt=1
s=[[0] for _ in range(n+1)]

for i in range(1,m+1):
    for j in range(i+1,m+1):
        s[i][0]+=1
        s[j][0]+=1

        s[i].append(cnt)
        s[j].append(cnt)

        cnt+=1

print('Yes')
print(m)
for i in range(1,m+1):
    print(' '.join([str(c) for c in s[i]]))

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

m=-1

for i in range(3,1000,2):
    if i*i==8*n+1:
        m=(1+i)//2

if m==-1:
    print('No')
    exit(0)

cnt=1
s=[[0] for _ in range(n+1)]

for i in range(1,m+1):
    for j in range(i+1,m+1):
        s[i][0]+=1
        s[j][0]+=1

        s[i].append(cnt)
        s[j].append(cnt)

        cnt+=1

for i in range(1,m+1):
    print(' '.join([str(c) for c in s[i]]))
Problem p03282 (python)

Fixed submission:
s=input()
k=int(input())

cntone=0
while len(s)>cntone and s[cntone]=='1':
    cntone+=1

if k>cntone:
    print(s[cntone])
else:
    print(s[0])

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

if s[0]=='1':
    print(s[1])
else:
    print(s[0])