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

Fixed submission:
from collections import deque
import sys
input=sys.stdin.readline

mod=10**9+7
n,k=map(int,input().split())
A=list(map(int,input().split()))
cnt=k

B,C=[],[]
for i in range(n):
    num=A[i]
    if num>=0:B.append(num)
    else:C.append(num)

B.sort(reverse=True)
C.sort()
B,C=deque(B),deque(C)

ans,flag=1,1
while k!=0:
    num=0
    length_B,length_C=len(B),len(C)
    if k>=2:
        if length_B>=2 and length_C>=2:
            plus=B[0]*B[1]
            negative=C[0]*C[1]
            if plus>negative:
                ans *=B.popleft()
                num=1
            else:ans *=C.popleft()*C.popleft()
        elif length_C>=2:ans *=C.popleft()*C.popleft()
        elif length_B>=2:ans *=B.popleft()*B.popleft()
        else:
            ans *=B.popleft()*C.popleft()
            flag=0
        k -=2-num
    else:
        if 0<length_B:ans *=B.popleft()
        elif 0<length_C:
            ans *=C.popleft()
            flag=0
        k -=1
    ans %=mod

if flag:print(ans);exit()

ans=1
A=sorted(A,key=lambda x:abs(x))
for i in range(cnt):
    ans *=A[i]
    ans %=mod
print(ans)

Buggy submission (verdict: Runtime Error):
mod=10**9+7
n,k=map(int,input().split())
A=list(map(int,input().split()))
count=k

B,C=[],[]
for i in A:
    if i>=0:B.append(i)
    else:C.append(i)

B.sort()
C.sort(key=lambda x:abs(x))

ans,flag=1,1
while k!=0:
    if k>=2:
        point=0
        if len(B)>=2 and len(C)>=2:
            if B[-1]*B[-2]>C[-1]*C[-2]:
                ans *=B.pop()
                point=1
            else:ans *=C.pop()*C.pop()
        elif len(B)>=2:ans *=B.pop()*B.pop()
        elif len(C)>=2:ans *=C.pop()*C.pop()
        else:flag=0
        k -=2-point
    else:
        if len(B)>=1:ans *=B.pop()
        else:flag=0
        k -=1
    ans %=mod

if flag:print(ans)
else:
    ans=1
    A=sorted(reverse=True)
    for i in range(count):
        ans *=A[i]
        ans %=mod
    print(ans)
Problem p02630 (python)

Fixed submission:
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
q=int(input())
BC=[list(map(int,input().split())) for _ in range(q)]

num=sum(A)
N={}
for i in A:
   if i not in N:N[i]=0
   N[i] +=1

for b,c in BC:
    if b not in N:
        print(num)
        continue
    dig=c-b
    num +=dig*N[b]
    print(num)
    if c not in N:N[c]=0
    N[c] +=N[b]
    N[b]=0

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
q=int(input())
BC=[list(map(int,input().split())) for _ in range(q)]

num=sum(A)
N={}
for i in A:
   if i not in N:N[i]=0
   N[i] +=1

for b,c in BC:
    dig=c-b
    num +=dig*N[b]
    print(num)
    if c not in N:N[c]=0
    N[c] +=N[b]
    N[b]=0

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
A=list(map(int,input().split()))
q=int(input())
BC=[list(map(int,input().split())) for _ in range(q)]

num=sum(A)
N={i+1:0 for i in range(9)}
for i in A:
    N[i] +=1

for b,c in BC:
    dig=c-b
    num +=dig*N[b]
    print(num)
    if c not in N:N[c]=0
    N[c] +=N[b]
    N[b]=0
Problem p02646 (python)

Fixed submission:
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())

if v>w:
    if a-v*t<=b-w*t and a+v*t>=b+w*t:print("YES")
    else:print("NO")
else:print("NO")

Buggy submission (verdict: Runtime Error):
a,v=map(int,input().split())
b,w=map(int,input().split())
t=int(input())

if a+v*t>=b+w*t:
    if (b-a)%(v-w)==0:
        print("YES")
    else:print("NO")
else:print("NO")
Problem p02647 (python)

Fixed submission:
n,k=map(int,input().split())
A=list(map(int,input().split()))
C=[n for i in range(n)]

for m in range(k):
    B=[0 for _ in range(n)]
    for i in range(n):
        l,r=max(0,i-A[i]),min(n-1,i+A[i])
        B[l] +=1
        if r+1<n:B[r+1] -=1
    for i in range(n-1):
        B[i+1]=B[i]+B[i+1]
    A=B
    if A==C:break
print(*A)

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
A=list(map(int,input().split()))
C=[n for _ range(n)]

while k!=0:
    B=[0 for _ in range(n+1)]
    for i,j in enumerate(A):
        B[max(0,i-j)] +=1
        B[min(n,i+j+1)] -=1
    for i in range(1,n):
        B[i] +=B[i-1]
    A=B[:n]
    k -=1
    if A==C:break
print(*A)
Problem p02684 (python)

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

time=0
color=["white" for _ in range(n+1)]
D=[-1 for _ in range(n+1)]
C,s=[],A[0]
point=0
while 1:
    if color[s]=="white":
        color[s]="gray"
        C.append(s)
        D[s]=time
        time +=1
        s=A[s-1]
    else:
        point=D[s]
        break

loop=C[point:]
if k>len(C):
    k -=point+1
    print(loop[k%len(loop)])
else:print(C[k-1])

Buggy submission (verdict: Runtime Error):
def DFS(num):
    global time
    if D[num]==0:
        D[num]=time
        time +=1
    for i in M[num]:
        if color[i]=="white":
            color[num]="gray"
            color[i]="gray"
            DFS(i)
        elif color[i]=="gray":
            color[num]="black"
            color[i]="black"
            DFS(i)
        elif color[i]=="black":
            return


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

B=[]
point,cnt=0,0
while cnt<n*2:
    point=A[point]
    B.append(point)
    point -=1
    cnt +=1

M=[set() for _ in range(n+1)]
for i in range(len(B)-1):
    a,b=B[i],B[i+1]
    M[a].add(b)

time=1
color=["white" for _ in range(n+1)]
D=[0 for _ in range(n+1)]
DFS(A[0])
route=[]
for i in range(n+1):
    if color[i]=="black":
        route.append([D[i],i])

C=[]
for i in sorted(route):
    C.append(i[1])

k=k-D[C[0]]
print(C[k%len(C)])

Buggy submission (verdict: Runtime Error):
def DFS(num):
    global time
    if D[num]==0:
        D[num]=time
        time +=1
    for i in M[num]:
        if color[i]=="white":
            color[num]="gray"
            color[i]="gray"
            DFS(i)
        elif color[i]=="gray":
            color[num]="black"
            color[i]="black"
            DFS(i)
        elif color[i]=="black":
            return


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

B=[]
point,cnt=0,0
while cnt<n*2:
    point=A[point]
    B.append(point)
    point -=1
    cnt +=1

M=[set() for _ in range(n+1)]
for i in range(len(B)-1):
    a,b=B[i],B[i+1]
    M[a].add(b)

time=1
color=["white" for _ in range(n+1)]
D=[0 for _ in range(n+1)]
DFS(A[0])
route=[]
for i in range(n+1):
    if color[i]=="black":
        route.append([D[i],i])

C=[]
for i in sorted(route):
    C.append(i[1])

k=k-D[C[0]]+1
print(C[k%len(C)-1])
Problem p02768 (python)

Fixed submission:
def cmb(n,r,mod):
    if r<0 or r>n:return 0
    return g1[r]*g2[r]%mod


mod=10**9+7
n,a,b=map(int,input().split())
k=max(a,b)
g1=[1,n]
g2=[1,1]
inverse=[0,1]

for i,j in enumerate(range(n-1,((n-k+1)-1),-1)):
    i=i+2
    g1.append((g1[-1]*j)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1]%mod))

N=pow(2,n,mod)-1
print((N-cmb(n,b,mod)-cmb(n,a,mod))%mod)

Buggy submission (verdict: Runtime Error):
"""n<10**7の場合に使える。
https://drken1215.hatenablog.com/entry/2018/06/08/210000"""


def cmb(n,r,mod):
    if r<0 or r>n:return 0
    return g1[r]*g2[r]%mod


mod=10**9+7
n,a,b=map(int,input().split())
k=max(a,b)
g1=[1,n]
g2=[1,1]
inverse=[0,1]

for i,j in enumerate(range(n-1,n-k+1,-1)):
    i=i+2
    g1.append((g1[-1]*j)%mod)
    inverse.append((-inverse[mod%i]*(mod//i))%mod)
    g2.append((g2[-1]*inverse[-1]%mod))

N=pow(2,n,mod)-1
print((N-cmb(n,b,mod)-cmb(n,a,mod))%mod)
Problem p02814 (python)

Fixed submission:
import fractions
from functools import reduce


n, m = map(int, input().split())
A = list(set(map(int, input().split())))

hA = [a//2 for a in A]
lcm = 1
for a in hA:
    lcm = (lcm * a) // fractions.gcd(lcm, a)
    if lcm > m:
        print(0)
        break
else:
    for a in A:
        if lcm % a == 0:
            print(0)
            break
    else:
        if (m//lcm) % 2 == 0:
            print(m//lcm//2)
        else:
            print(m//lcm//2 + 1)

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


n,m=map(int,input().split())
A=list(map(lambda x: int(x)//2,input().split()))

lcm=np.lcm.reduce(np.array(A))
if any([i for i in range(n) if lcm%(A[i]*2)==0]):
    print(0);exit()

ans=m//(2*lcm)
print(ans if m//lcm==0 else ans+1)

Buggy submission (verdict: Runtime Error):
import fractions
from functools import reduce


n, m = map(int, input().split())
A = list(set(map(int, input().split())))

hA = [a//2 for a in A]
lcm = 1
for a in hA:
    lcm = (lcm * a) // fractions.gcd(lcm, a)
    if lcm > m:
        print(0)
        break
else:
    else:
        if (m//lcm) % 2 == 0:
            print(m//lcm//2)
        else:
            print(m//lcm//2 + 1)
Problem p02866 (python)

Fixed submission:
from collections import Counter
mod=998244353
n=int(input())
D=list(map(int,input().split()))
Count=Counter(D)
if Count[0]!=1 or D[0]!=0:print(0);exit()
ans=1
for i in range(1,max(Count)+1):
    ans *=Count[i-1]**Count[i]
    ans %=mod
print(ans)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
D=list(map(int,input().split()))
D_count=sorted(Counter(D).items())
if D_count[0][0]!=0 or D_count[0][1]!=1:print(0);exit()
ans=1
for i in range(1,max(D)+1):
    ans *=D_count[i-1][1]**D_count[i][1]
    ans %=998244353
print(ans)
Problem p02900 (python)

Fixed submission:
from collections import Counter
def prime_fact(n):
    a=[]
    while n%2==0:
        a.append(2)
        n //=2
    f=3
    while f**2<=n:
        if n%f==0:
            a.append(f)
            n //=f
        else:f +=2
    if n!=1:a.append(n)
    return a

a,b=map(int,input().split())
a_key=Counter(prime_fact(a))
b_key=Counter(prime_fact(b))
print(len(a_key&b_key)+1)

Buggy submission (verdict: Runtime Error):
from prime_factorize import prime_factorize
a,b=map(int,input().split())
print(len(set(prime_factorize(a))&set(prime_factorize(b)))+1)

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

n=min(a,b)
is_prime=[True]*(n+1)
is_prime[0],is_prime[1]=False,False
for i in range(2,int(n**0.5)+1):
    if not is_prime[i]:continue
    for j in range(i*2,n+1,i):
        is_prime[j]=False
prime=[i for i in range(n+1) if is_prime[i]]

count=1
for i in prime:
    if i>n:break
    elif a%i==0 and b%i==0:
        count +=1

print(count)

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

def prime(n):
    is_prime=[True]*(n+1)
    is_prime[0],is_prime[1]=False,False
    for i in range(2,int(n**0.5)+1):
        if not is_prime[i]:continue
        for j in range(i*2,n+1,i):
            is_prime[j]=False
    return [i for i in range(n+1) if is_prime[i]]

prime_num=prime(min(a,b))

count=1
min_num=min(a,b)
for i in prime_num:
    if i>min_num//2:break
    elif a%i==0 and b%i==0:
        count +=1

print(count)

Buggy submission (verdict: Runtime Error):
a,b=map(int,input().split())
def cf(x1,x2):
    cf=[]
    for i in range(2,min(x1,x2)+1):
        if x1 % i == 0 and x2 % i == 0:
            cf.append(i)
    return cf

def prime(n):
    is_prime=[True]*(n+1)
    is_prime[0],is_prime[1]=False,False
    for i in range(2,int(n**0.5)+1):
        if not is_prime[i]:continue
        for j in range(i*2,n+1,i):
            is_prime[j]=False
    return [i for i in range(n+1) if is_prime[i]]

number=prime(min(a,b))
answer=cf(a,b)
flag=0
count=1
for i in answer:
    if i==number[flag]:
        count +=1
        flag +=1

print(count)
Problem p02937 (python)

Fixed submission:
from collections import defaultdict
from bisect import bisect_right

s,t=input(),input()
m=len(s)

if set(s)&set(t)!=set(t):print(-1);exit()

dict=defaultdict(list)
for i,j in enumerate(s):
    dict[j] +=[i+1]

ans,index=0,0
for i in t:
    point=bisect_right(dict[i],index)
    if point==len(dict[i]):num=dict[i][0]
    else:num=dict[i][point]

    if index>=num:
        ans +=m
    index=num

print(ans+index)

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

s,t=input(),input()
m=len(s)

if set(s)&set(t)!=set(t):print(-1);exit()

dict=defaultdict(list)
for i,j in enumerate(s):
    dict[j] +=[i+1]

ans,index=0,0
for i in t:
    point=bisect_right(dict[i],index)
    if point==len(dict[i]):num=dict[i][0]
    else:num=dict[i][point]

    if index>=num:
        ans +=m
    index=num
    
print(ans+index)

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

s,t=input(),input()
m=len(s)

if set(s)&set(t)!=set(t):print(-1);exit()

dict=defaultdict(list)
for i,j in enumerate(s):
    dict[j] +=[i+1]

ans,index=0,0
for i in t:
    point=bisect_right(dict[i],index)
    if point==len(dict[i]):num=dict[i][0]
    else:num=dict[i][point]

    if index>num:
        ans +=m
    index=num
    
print(ans+index)
Problem p02972 (python)

Fixed submission:
n=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(n+1)]
C=[]
cnt=0
for i in range(1,n+1)[::-1]:
    sum_B=sum(B[j] for j in range(i,n+1,i))
    if sum_B%2!=A[i-1]:
        B[i]=1
        C.append(i)
        cnt +=1
print(cnt)
print(*[i for i in C[::-1]])

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(n)]
flag=0
for i in range(1,int(n**0.5)+1):
    for j in range(0,n,i):
        B[i-1] +=A[j]
C=[]
for i in range(int(n**0.5)+1):
    if B[i]%2==A[i] and B[i]%2==0:
        flag=1
    if B[i]%2==A[i] and B[i]%2!=0:
        C.append(i+1)
        flag=1

if flag:
    if len(C)==0:print(0);exit()
    print(1)
    print(*C)
else:print(-1)

Buggy submission (verdict: Runtime Error):
n=int(input())
A=list(map(int,input().split()))
B=[0 for i in range(n)]
for i in range(1,int(n**0.5)+1):
    for j in range(0,n,i):
        B[i] +=A[j]

C=[]
for i in range(int(n**0.5)+1):
    if B[i]%2==A[i]:
        C.append(i+1)

if len(C)==0:print(0);exit()
print(1)
print(*C)
Problem p02981 (python)

Fixed submission:
n,a,b=map(int,input().split())
print(min(n*a,b))

Buggy submission (verdict: Runtime Error):
n,a,b=map(int,input())
print(min(n*a,b))
Problem p03006 (python)

Fixed submission:
from collections import Counter
n=int(input())
A=[list(map(int,input().split())) for i in range(n)]
Per=[(a[0]-b[0],a[1]-b[1]) for a in A for b in A if a!=b]
print(n-Counter(Per).most_common(1)[0][1] if n!=1 else 1)

Buggy submission (verdict: Runtime Error):
from collections import Counter
from itertools import permutations
n=int(input())
A=[list(map(int,input().split())) for i in range(n)]
B=[(a[0]-b[0],a[1]-b[1]) for a,b in permutations(A,2)]
most=max(Counter(B).values())
print(n-most if n!=1 else 1)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n=int(input())
A=[list(map(int,input().split())) for i in range(n)]
Per=[(a[0]-b[0],a[1]-b[1]) for a in A for b in A if a!=b]
print(n-Counter(Per).most_common(1)[0][1])
Problem p03007 (python)

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

XY=[]
left,right=A[0],A[-1]
for i in range(1,n-1):
    num=A[i]
    if num<0:
        XY.append([right,num])
        right -=num
    else:
        XY.append([left,num])
        left -=num
XY.append([right,left])
print(right-left)
for x,y in XY:print(x,y)

Buggy submission (verdict: Runtime Error):
from collections import deque
n=int(input())
A=deque(sorted(list(map(int,input().split()))))
B=[]
while len(A)!=2:
    x,y=A.popleft(),A.pop()
    A.append(x-y)
    B.append([x,y])
    A=sorted(A)

B.append([A[-1],A[0]])
print(A[-1]-A[0])
for i in B:
    print(*i)
Problem p03014 (python)

Fixed submission:
import numpy as np
h,w=map(int,input().split())
S=np.array([list(input()) for _ in range(h)])
S=np.where(S==".",1,0)

left,right,up,down=[np.zeros((h,w),dtype=np.int64) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

print(int(np.max(left+right+up+down)-3))

Buggy submission (verdict: Runtime Error):
import numpy as np
h,w=map(int,input().split())
S=np.array([list(input()) for _ in range(h)])
S=np.where(S==".",1,0)

left,right,up,down=[np.zeros((h,w)) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[:,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

print(int(np.max(left+right+up+down)-3))

Buggy submission (verdict: Runtime Error):
import numpy as np
h,w=map(int,input().split())
S=np.array([list(input()) for _ in range(h)])
S=np.where(S==".",1,0)

left,right,up,down=[np.zeros((h,w)) for _ in range(4)]
for i in range(w):
    left[:,i]=(left[:,i-1]+1)*S[:,i]
    right[:,-i-1]=(right[:,-i]+1)*S[i,-i-1]
for i in range(h):
    up[i]=(up[i-1]+1)*S[i]
    down[-i-1]=(down[-i]+1)*S[-i-1]

print(np.max(left+right+up+down)-3)
Problem p03026 (python)

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


def DFS(num,pre):
    global point
    if color[num]=="white":
        ans[num]=C.pop()
        point +=min(ans[num],pre)
        color[num]="black"
        for i in T[num]:
            DFS(i,ans[num])


n=int(input())
AB=[list(map(int,input().split())) for _ in range(n-1)]
C=sorted(list(map(int,input().split())))
color=["white" for _ in range(n)]

T=[[] for _ in range(n)]
for a,b in AB:
    T[a-1].append(b-1)
    T[b-1].append(a-1)

ans=[0 for _ in range(n)]
point=0
DFS(0,0)

print(point)
print(*ans)

Buggy submission (verdict: Runtime Error):
def DFS(num,pre):
    global point
    if color[num]=="white":
        A[num]=C.pop()
        point +=min(A[num],pre)
        color[num]="black"
        for i in tree[num]:
            DFS(i,A[num])


n=int(input())
AB=[list(map(int,input().split())) for _ in range(n-1)]
C=sorted(list(map(int,input().split())))

color=["white" for _ in range(n+1)]
tree=[[] for _ in range(n+1)]
for a,b in AB:
    tree[a].append(b)
    tree[b].append(a)

A=[0 for _ in range(n+1)]
point=0
DFS(1,0)

print(point)
print(*A[1:])

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


def DFS(num):
    if color[num]=="white":
        ans[num]=C.pop()
        color[num]="black"
        for i in T[num]:
            DFS(i)


n=int(input())
AB=[list(map(int,input().split())) for _ in range(n-1)]
C=sorted(list(map(int,input().split())))
color=["white" for _ in range(n)]

T=[[] for _ in range(n)]
for a,b in AB:
    T[a-1].append(b-1)
    T[b-1].append(a-1)

ans=[0 for _ in range(n)]
DFS(0)

point=0
color=["white" for _ in range(n)]
for i in range(1,n+1):
    if len(T[i])>0:
        color[i-1]="black"
        for j in T[i]:
            if color[j-1]=="white":
                point +=min(ans[i-1],ans[j-1])
                color[j-1]="black"

print(point)
print(*ans)
Problem p03087 (python)

Fixed submission:
n,q=map(int,input().split())
s=input()+"P"
A=[list(map(int,input().split())) for i in range(q)]
B=[0]*(n+1)
cnt=0
for i in range(1,n):
    if s[i-1]+s[i]=="AC":cnt +=1
    B[i+1]=cnt

for l,r in A:print(B[r]-B[l])

Buggy submission (verdict: Runtime Error):
n,q=map(int,input().split())
s=input()+" "
A=[0]*(n+1)
cnt=0
for i in range(1,n+1):
    if s[i-1]+s[i]=="AC":
        cnt +=1
    A[i+1]=cnt

for i in range(q):
    l,r=map(int,input().split())
    print(A[r]-A[l])
Problem p03157 (python)

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


def DFS(add,next,cnt):
    x,y=add
    for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
        X,Y=x+i,y+j
        if 0<=X<h and 0<=Y<w:
            if S[X][Y]==next and color[X][Y]=="white":
                color[X][Y]=str(cnt)
                DFS([X,Y],"." if next=="#" else "#",cnt)


h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]
cnt=0

color=[["white" for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        if S[i][j]=="#" and color[i][j]=="white":
            cnt +=1
            DFS([i,j],".",cnt)

dictionary={str(i+1):[0,0] for i in range(cnt)}
for i in range(h):
    for j in range(w):
        if color[i][j]!="white":
            if S[i][j]==".":dictionary[color[i][j]][0] +=1
            else:dictionary[color[i][j]][1] +=1

ans=0
for v,m in dictionary.values():
    ans +=v*m
print(ans)

Buggy submission (verdict: Runtime Error):
from numba import jit
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline

@jit
def DFS(add,next):
    global cnt
    x,y=add
    for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
        X,Y=x+i,y+j
        if 0<=X<h and 0<=Y<w:
            if S[X][Y]==next and color[X][Y]=="white":
                color[X][Y]="black"
                DFS([X,Y],"." if next=="#" else "#")
                if next==".":cnt +=1


h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]
cnt=0

for i in range(h):
    for j in range(w):
        if S[i][j]=="#":
            color=[["white" for _ in range(w)] for _ in range(h)]
            color[i][j]="black"
            DFS([i,j],".")

print(cnt)

Buggy submission (verdict: Runtime Error):
from numba import jit
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline

@jit
def DFS(add,next):
    global cnt
    x,y=add
    for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
        X,Y=x+i,y+j
        if 0<=X<h and 0<=Y<w:
            if S[X][Y]==next and color[X][Y]=="white":
                color[X][Y]="black"
                DFS([X,Y],"." if next=="#" else "#")
                if next==".":cnt +=1


h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]
cnt=0

for i in range(h):
    for j in range(w):
        if S[i][j]=="#":
            color=[["white" for _ in range(w)] for _ in range(h)]
            color[i][j]="black"
            DFS([i,j],".")

print(cnt)

Buggy submission (verdict: Runtime Error):
def DFS(add,next):
    global cnt
    x,y=add
    for i,j in [[1,0],[-1,0],[0,1],[0,-1]]:
        X,Y=x+i,y+j
        if 0<=X<h and 0<=Y<w:
            if S[X][Y]==next and color[X][Y]=="white":
                color[X][Y]="black"
                DFS([X,Y],"." if next=="#" else "#")
                if next==".":cnt +=1


h,w=map(int,input().split())
S=[list(input()) for _ in range(h)]
cnt=0

for i in range(h):
    for j in range(w):
        if S[i][j]=="#":
            color=[["white" for _ in range(w)] for _ in range(h)]
            color[i][j]="black"
            DFS([i,j],".")

print(cnt)