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

Fixed submission:
n, k = map(int, input().split())
d = list(map(int, input().split()))
digit = [str(i) for i in range(10) if not i in d]
ans = []
stack = [i for i in digit]
while stack:
  s = stack.pop()
  if int(s) >= n:
    ans.append(int(s))
  else:
    for i in digit:
      if len(i+s) <= len(str(n))+1:
        stack.append(i+s)

print(min(ans))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
d = list(map(int, input().split()))
digit = [str(i) for i in range(10) if not i in d]
ans = []
stack = [i for i in digit]
while stack:
  s = stack.pop()
  if int(s) >= n:
    ans.append(s)
  else:
    for i in digit:
      if len(i+s) <= len(str(n)+1):
        stack.append(i+s)

print(min(ans))

Buggy submission (verdict: Runtime Error):
n, k = map(int, input().split())
d = list(map(int, input().split()))
digit = [str(i) for i in range(10) if not i in d]
ans = []
stack = [i for i in digit]
while stack:
  s = stack.pop()
  if int(s) >= n:
    ans.append(s)
  else:
    for i in digit:
      if len(i+s) <= len(str(n)):
        stack.append(i+s)
print(min(ans))
Problem p02658 (python)

Fixed submission:
def sol():
    n=int(input())
    a=list(map(int,input().split()))
    if 0 in a:
        print(0)
        return
    prod=1 
    for i in a:
        prod*=i 
        if prod>1000000000000000000:
            print(-1)
            return
    print(prod)
    
sol()

Buggy submission (verdict: Runtime Error):
def main ():
	N = int(input())
	A = list(map(int,input(). split ()))
    if 0 in A:
    	print(0)
    	return
    prod = 1
      for a in A:
      prod *= a
      if prod > 1000000000000000000:
      print(-1)
      return
    print(prod)
main ()
Problem p02621 (python)

Fixed submission:
a = int(input())

ans = a+a*a+a*a*a

print(ans)

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

ans = a+a*a+a*a*a

return ans

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

ans = a+a*2+a*3

return ans

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

ans = a+a*2+a*3

print ans

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

int ans = a+a*2+a*3

print(ans)
Problem p02657 (python)

Fixed submission:
A,B = map(int,input().split())
print(A*B)

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

if 0 in A:
  print(0)
  
for a in M:
    mult *= a
    if mult> 1000000000000000000:
        print(-1)
        
print(mult)
Problem p02658 (python)

Fixed submission:
def main():
    N = input()
    M = list(map(int,input().split()))
    
    mult = 1
    
    if 0 in M:
        print(0)
        return
    
    for a in M:
        mult *= a
        if mult>10**18:
            print(-1)
            return
        
    print(mult)
    
main()

Buggy submission (verdict: Runtime Error):
N = input()
M = list(map(int,input().split()))
    
mult = 1
 
if 0 in A:
  print(0)
  return

for a in M:
    mult *= a
    if mult> 1000000000000000000:
        print(-1)
        
print(mult)
Problem p02718 (python)

Fixed submission:
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse = True)
num = 0
for i in A:
    num += i
if A[M-1] >= num/(4*M):
    print('Yes')
else:
    print('No')

Buggy submission (verdict: Runtime Error):
N,M = map(int,input().split())
A = list(map(int,input().split()))
A.sort(reverse = True)
num = 0
for i in A:
    num += i
if A[M] >= num//4*M:
    print('Yes')
else:
    print('No')
Problem p02708 (python)

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

c = 0
for i in range(k, n + 2):
  c += ((n - i + 1) * i + 1) % (10 ** 9 + 7)

print(c % (10 ** 9 + 7))

Buggy submission (verdict: Runtime Error):
N, K = map(int, input().split())
 
c = 0
for i in range(K, N + 1 + 1):
    ma = ((N + N - (i - 1)) * i) / 2
    mi = ((0 + i - 1) * i) / 2
    c += int(ma - mi + 1)
 	c %= (10 ** 9 + 7)
print(c)
Problem p02714 (python)

Fixed submission:
import sys

n = int(sys.stdin.readline().rstrip())
s = sys.stdin.readline().rstrip()
r = []
b = []
g = []
for i, si in enumerate(s):
    if si == 'R':
        r.append(i + 1)
    elif si == 'G':
        g.append(i + 1)
    elif si == 'B':
        b.append(i + 1)
count = 0
for i in range(n):
    for j in range(i + 1, n):
        k = j + j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            count += 1
print(len(r) * len(g) * len(b) - count)

Buggy submission (verdict: Runtime Error):

from collections import Counter
n = int(input())
s = input()
d = Counter(s)
f = [d[i] for i in d]
c = f[0] * f[1] * f[2]
 


for i in range(n):
    for j in range(i + 1, n):
        k = j + j - i
        if k < n and s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
            c -= 1
print(c)

Buggy submission (verdict: Runtime Error):
from collections import Counter
n = int(input())
s = input()
d = Counter(s)
f = [d[i] for i in d]
c = f[0] * f[1] * f[2]

for j in range(n):
	for i in range(n):
		if(j-i < 0 or j+i >= n):
			break
		elif(s[j-i] != s[j] and s[j+i] != s[j] and s[j+i] != s[j-i]):	c -= 1
 
print(c)
Problem p02718 (python)

Fixed submission:
N, M = map(int, input().split())
vote_nums = sorted([float(i) for i in input().split()], reverse=True)
 
border_rate = 1 / (4 * M)
target = vote_nums[:M]
 
for vote_num in target:
  if vote_num < border_rate * sum(vote_nums):
    print('No')
    exit()
 
print('Yes')

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = [int(x) for x in input().split()]
s = sum(a)
l = a // (4 * m)

a = sorted(a, reverse = True)
f = 0
for i in a:
  i < l:
    f = i
    break
if(f < m):
  print('No')
else:
  print('Yes')
Problem p02765 (python)

Fixed submission:

n, k = map(int, input().split())
if(n >= 10):
	print(k)
else:
	print(k + 100 * (10 - n))

Buggy submission (verdict: Runtime Error):
import sys
sys.stdin = open('input.txt', 'r') 
sys.stdout = open('output.txt', 'w')

n, k = map(int, input().split())
if(n >= 10):
	print(k)
else:
	print(k + 100 * (10 - n))
Problem p02772 (python)

Fixed submission:
N = int(input())
A = list(map(int, input().split()))
app_fl = True
for Ai in [a for a in A if a % 2 == 0]:
    if Ai % 3 != 0 and Ai % 5 != 0:
        app_fl = False
        break
 

if app_fl is True:
    print("APPROVED")
else:
    print("DENIED")

Buggy submission (verdict: Runtime Error):
N = int(input())
num_list = list(map(int, input().split()))
 
a=0
for i in num_list:
  if i%2==0 and (i%3!=0 and i%5!=0):
  	print('DENIED')
    exit()
print('APPROVED')

Buggy submission (verdict: Runtime Error):
N = int(input())
num_list = list(map(int, input().split()))
 
a=0
for i in num_list:
  if i%2==0 and (i%3!=0 and i%5!=0):
  	print('DENIED')
    exit()
 
print('APPROVED')
Problem p02922 (python)

Fixed submission:
from math import ceil
a, b = map(int, input().split())
print(ceil((b - 1) / (a - 1)))

Buggy submission (verdict: Runtime Error):
a, b = map(int(input().split())
print(b // a + (((b % a) // a) + 1))
Problem p02900 (python)

Fixed submission:
#!/usr/bin/env python3

import sys

input = sys.stdin.buffer.readline

def gcd(a,b):
    return a if b == 0 else gcd(b,a%b)

def lcm(a,b):
    return a*b // gcd(a,b)

def prime_factorize(n):
    pf={}
    for i in range(2, int(n**0.5)+1):
        while n % i == 0:
            pf[i] = pf.get(i, 0) + 1
            n //= i
    if n > 1: pf[n] = 1
    return pf

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

pf = prime_factorize(gcd(A,B))
print(len(pf) + 1)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3

import sys

input = sys.stdin.buffer.readline

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

divA,divB = set(),set()
for i in range(1,int(A**.5+1)):
    if A%i == 0:
        divA.add(i)
        divA.add(A//i)
for i in range(1,int(B**.5+1)):
    if B%i == 0:
        divB.add(i)
        divB.add(B//i)

C = list(divA & divB)
C.sort()

N = 10**6+1
primes = []
is_prime = [True]*N
for i in range(2,N):
    if is_prime[i]:
        primes.append(i)
        j = 2
        while i*j < N:
            is_prime[i*j] = False
            j += 1

ans = 0
for c in C:
    if is_prime[c]:
        ans += 1

print(ans)
Problem p02937 (python)

Fixed submission:
#!/usr/bin/env python3
#ABC138 E

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)
f = [False]*26
f2 = [False]*26
alpha = 'abcdefghijklmnopqrstuvwxyz'
for i in range(n):
    f[alpha.index(s[i])] = True
for i in range(m):
    f2[alpha.index(t[i])] = True
for i in range(26):
    if not f[i] and f2[i]:
        print(-1)
        quit()
ans = 0
inde = s.index(t[0])
ans += inde+1
for i in range(1,m):
    s = s[inde+1:] + s[:inde+1]
    inde = s.index(t[i])
    ans += inde+1
print(ans)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python3
import sys

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input()
T = input()


idx = S.index(T[0])
ans = idx+1
lenT = len(T)
for i in range(1,lenT):
    S = S[idx+1:] + S[:idx+1]
    idx = S.index(T[i])
    ans += idx+1

print(ans)

Buggy submission (verdict: Runtime Error):
# Python3 (3.4.3)
import sys

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input()
T = input()


idx = S.index(T[0])
ans = idx+1
lenT = len(T)
for i in range(1,lenT):
    S = S[idx+1:] + S[:idx+1]
    idx = S.index(T[i])
    ans += idx+1

print(ans)

Buggy submission (verdict: Runtime Error):
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
T = input().rstrip()


idx = S.index(T[0])
ans = idx+1
lenT = len(T)
for i in range(1,lenT):
    S = S[idx+1:] + S[:idx+1]
    idx = S.index(T[i])
    ans += idx+1

print(ans)

Buggy submission (verdict: Runtime Error):
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
S = input().rstrip()
T = input().rstrip()


idx = S.index(T[0])
ans = idx+1
for i in range(1,len(T)):
    S = S[idx+1:] + S[:idx+1]
    idx = S.index(T[i])
    ans += idx+1

print(ans)
Problem p02973 (python)

Fixed submission:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
A = [int(input()) for _ in range(N)]

from collections import deque
from bisect import bisect_left

D = deque([])

for a in A:
    i = bisect_left(D,a)
    if i==0:
        D.appendleft(a)
    else:
        D[i-1] = a

print(len(D))

Buggy submission (verdict: Runtime Error):
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
A = [int(input()) for _ in range(N)]

from collections import deque
from bisect import bisect_left

D = deque([])

for a in A:
    i = bisect_left(D,a)
    if i==0:
        D.appendleft(a)
    else:
        D[i-1] = a
    print(i,D)

print(len(D))
Problem p03032 (python)

Fixed submission:
# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# library
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------
from collections import deque
import heapq

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

ans = 0

maxPop = min(N,K)
# 左popする回数
for li in range(maxPop+1):
    # 右popする回数
    for ri in range(maxPop+1-li):
        # 初期化
        D = deque(V)
        jew = [] # 手持ちの宝石

        # pushの最大値
        maxPush = K - (ri+li)
        # 左popする
        for i in range(li):
            jew.append(D.popleft())
        # 右popする
        for i in range(ri):
            jew.append(D.pop())
        # 価値順にソート
        jew.sort()
        # push最大値の回数まで、負の価値の宝石をpushする（手持ちの価値を0にする）
        for i in range(min(maxPush, len(jew))):
            if jew[i] < 0:
                jew[i] = 0
        # 合計
        ans = max(ans,sum(jew))

print(ans)

Buggy submission (verdict: Runtime Error):
# python 3.4.3
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# library
# -------------------------------------------------------------



# -------------------------------------------------------------
# main
# -------------------------------------------------------------
from collections import deque
import heapq

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

ans = 0

maxPop = min(N,K)
# 左popする回数
for li in range(maxPop+1):
    # 右popする回数
    for ri in range(maxPop+1-li):
        # 初期化
        D = deque(V)
        jew = [] # 手持ちの宝石

        # pushの最大値
        maxPush = maxPop - (ri+li)
        # 左popする
        for i in range(li):
            jew.append(D.popleft())
        # 右popする
        for i in range(li):
            jew.append(D.popright())
        # 価値順にソート
        jew.sort()
        # push最大値の回数まで、負の価値の宝石をpushする（手持ちの価値を0にする）
        for i in range(min(maxPush, len(jew))):
            if jew[i] < 0:
                jew[i] = 0
        # 合計
        ans = max(ans,sum(jew))

print(ans)
Problem p03087 (python)

Fixed submission:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,Q = map(int,input().split())
S = input().rstrip() + "Z"
LR = [map(int,input().split()) for _ in range(Q)]

A = [0]*(N+1)
for i in range(N):
    if S[i]=="A" and S[i+1]=="C":
        A[i+1] = 1
for i in range(i):
    A[i+1] += A[i]

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

Buggy submission (verdict: Runtime Error):
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N,Q = map(int,input().split())
S = input().rstrip()
LR = [map(int,input().split()) for _ in range(Q)]

A = [0]*(N+1)
for i in range(N):
    if S[i]=="A" and S[i+1]=="C":
        A[i+1] = 1
for i in range(i):
    A[i+1] += A[i]

for l,r in LR:
    print(A[r-1]-A[l-1])
Problem p03128 (python)

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

A.sort(reverse=True)

# 各数字に必要なマッチの本数
num  = [0,2,5,5,4,5,6,3,7,6]
# dp : i本のマッチで実現できる最大の桁数
dp = [-1*float("inf")]*(N+1000)
# dp初期化 (0本では0桁, 各数字を1つ作る場合は1桁)
dp[0] = 0
for a in A:
    dp[num[a]] = 1

for i in range(1,N+1):
    for a in A:
        if i - num[a] >= 0:
            dp[i] = max(dp[i], dp[i-num[a]] + 1)

ans = ""
for i in range(dp[N]):
    for a in A:
        if dp[N-num[a]] == dp[N]-1  and  N-num[a] >= 0:
            ans += str(a)
            N -= num[a]
            break

print(ans)

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

A.sort(reverse=True)

# 各数字に必要なマッチの本数
num  = [0,2,5,5,4,5,6,3,7,6]
# dp : i本のマッチで実現できる最大の桁数
dp = [-1*float("inf")]*(N+1)
# dp初期化 (0本では0桁, 各数字を1つ作る場合は1桁)
dp[0] = 0
for a in A:
    if num[a] <= N:
        dp[num[a]] = 1

for i in range(1,N+1):
    for a in A:
        if i - num[a] >= 0:
            dp[i] = max(dp[i], dp[i-num[a]] + 1)

ans = ""
for i in range(dp[N]):
    for a in A:
        if dp[N-num[a]] == dp[N]-1  and  N-num[a] >= 0:
            ans += str(a)
            N -= num[a]
            break

print(ans)

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

A.sort(reverse=True)

# 各数字に必要なマッチの本数
num  = [0,2,5,5,4,5,6,3,7,6]
# dp : i本のマッチで実現できる最大の桁数
dp = [-1*float("inf")]*(N+1)
# dp初期化 (0本では0桁, 各数字を1つ作る場合は1桁)
dp[0] = 0
for a in A:
    dp[num[a]] = 1

for i in range(1,N+1):
    for a in A:
        if i - num[a] >= 0:
            dp[i] = max(dp[i], dp[i-num[a]] + 1)

ans = ""
for i in range(dp[N]):
    for a in A:
        if dp[N-num[a]] == dp[N]-1  and  N-num[a] >= 0:
            ans += str(a)
            N -= num[a]
            break

print(ans)
Problem p03147 (python)

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

ans = 0
st = "0"
while H!=[0]*N:
    for i in range(N):
        if H[i]>0:
            st = "+"
            H[i] -= 1
        elif st=="+" and H[i]==0:
            st = "0"
            ans += 1
    if st=="+":
        ans += 1
    st = "0"

print(ans)

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(1000000)

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

def f(A):
    p = 0
    if min(A)==0 and max(A)==0:
        return 0
    if min(A)>0:
        minA = min(A)
        for i in range(len(A)):
            A[i] -= minA
        p += f(A) + minA
    else:
        for i in range(len(A)):
            if A[i]>0:
                A = A[i:]
                break
        for i in range(len(A)):
            if A[len(A)-1-i]>0:
                A = A[:len(A)-i]
                break
        x = [-1]
        for i in range(len(A)):
            if A[i]==0:
                x.append(i)
        x.append(len(A))
        for i in range(len(x)-1):
            p += f(A[x[i]+1:x[i+1]:])
    return p

print(f(H))

Buggy submission (verdict: Runtime Error):
import sys
sys.setrecursionlimit(100000)

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

def f(A):
    p = 0
    if min(A)==0 and max(A)==0:
        return 0
    if min(A)>0:
        minA = min(A)
        for i in range(len(A)):
            A[i] -= minA
        p += f(A) + minA
    else:
        for i in range(len(A)):
            if A[i]>0:
                A = A[i:]
                break
        for i in range(len(A)):
            if A[len(A)-1-i]>0:
                A = A[:len(A)-i]
                break
        x = [-1]
        for i in range(len(A)):
            if A[i]==0:
                x.append(i)
        x.append(len(A))
        for i in range(len(x)-1):
            p += f(A[x[i]+1:x[i+1]:])
    return p

print(f(H))
Problem p03148 (python)

Fixed submission:
N,K = map(int,input().split())
X = []
for i in range(N):
    t,d = map(int,input().split())
    X.append((d,t))

X.sort(reverse=True)

p,v = 0,set([])
pp = []
for i in range(K):
    p += X[i][0]
    if X[i][1] not in v:
        v.add(X[i][1])
    else:
        pp.append((X[i][0],X[i][1]))

Ans = p + len(v)**2
ans = Ans
for i in range(K,N):
    if X[i][1] not in v and len(pp)>0:
        temp = pp[-1]
        pp = pp[:len(pp)-1]
        ans = ans - temp[0] + X[i][0] - len(v)**2 + (len(v)+1)**2
        v.add(X[i][1])
        Ans = max(Ans,ans)

print(Ans)

Buggy submission (verdict: Runtime Error):
N,K = map(int,input().split())
X = []
for i in range(N):
    t,d = map(int,input().split())
    X.append((d,t))

X.sort(reverse=True)

p,v = 0,set([])
pp = []
for i in range(K):
    p += X[i][0]
    if X[i][1] not in v:
        v.add(X[i][1])
    else:
        pp.append((X[i][0],X[i][1]))

Ans = p + len(v)**2
ans = Ans
for i in range(K,N):
    if X[i][1] not in v:
        ans = ans - pp[0][0] + X[i][0] - len(v)**2 + (len(v)+1)**2
        v.add(X[i][1])
        Ans = max(Ans,ans)
        pp = pp[1:]
    

print(Ans)
Problem p03157 (python)

Fixed submission:
import sys
sys.setrecursionlimit(500000)
H,W = map(int,input().split())
S = []
for i in range(H):
    S.append(input())

def dfs(h,w,i,c):
    # グループ分け
    V[h][w] = i
    # 上
    if h>0 and V[h-1][w]==0:
        if c=="#" and S[h-1][w]==".":
            dfs(h-1,w,i,".")
        elif c=="." and S[h-1][w]=="#":
            dfs(h-1,w,i,"#")
    # 左
    if w>0 and V[h][w-1]==0:
        if c=="#" and S[h][w-1]==".":
            dfs(h,w-1,i,".")
        elif c=="." and S[h][w-1]=="#":
            dfs(h,w-1,i,"#")
    # 下
    if h<H-1 and V[h+1][w]==0:
        if c=="#" and S[h+1][w]==".":
            dfs(h+1,w,i,".")
        elif c=="." and S[h+1][w]=="#":
            dfs(h+1,w,i,"#")
    # 右
    if w<W-1 and V[h][w+1]==0:
        if c=="#" and S[h][w+1]==".":
            dfs(h,w+1,i,".")
        elif c=="." and S[h][w+1]=="#":
            dfs(h,w+1,i,"#")

V = [[0 for _ in range(W)] for _ in range(H)]
ans = 0
i = 0
for h in range(H):
    for w in range(W):
        if S[h][w]=="#" and V[h][w]==0:
            i += 1
            dfs(h,w,i,"#")

# iグループに分割完了
cnt_b = [0]*i
cnt_w = [0]*i

for h in range(H):
    for w in range(W):
        group = V[h][w]
        if group != 0:
            if S[h][w]=="#":
                cnt_b[group-1] += 1
            else:
                cnt_w[group-1] += 1

ans = 0
for i in range(len(cnt_b)):
    ans += cnt_b[i]*cnt_w[i]

print(ans)

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

def dfs(h,w,i,c):
    # グループ分け
    V[h][w] = i
    # 上
    if h>0 and V[h-1][w]==0:
        if c=="#" and S[h-1][w]==".":
            dfs(h-1,w,i,".")
        elif c=="." and S[h-1][w]=="#":
            dfs(h-1,w,i,"#")
    # 左
    if w>0 and V[h][w-1]==0:
        if c=="#" and S[h][w-1]==".":
            dfs(h,w-1,i,".")
        elif c=="." and S[h][w-1]=="#":
            dfs(h,w-1,i,"#")
    # 下
    if h<H-1 and V[h+1][w]==0:
        if c=="#" and S[h+1][w]==".":
            dfs(h+1,w,i,".")
        elif c=="." and S[h+1][w]=="#":
            dfs(h+1,w,i,"#")
    # 右
    if w<W-1 and V[h][w+1]==0:
        if c=="#" and S[h][w+1]==".":
            dfs(h,w+1,i,".")
        elif c=="." and S[h][w+1]=="#":
            dfs(h,w+1,i,"#")

V = [[0 for _ in range(W)] for _ in range(H)]
ans = 0
i = 0
for h in range(H):
    for w in range(W):
        if S[h][w]=="#" and V[h][w]==0:
            i += 1
            dfs(h,w,i,"#")

# iグループに分割完了
cnt_b = [0]*i
cnt_w = [0]*i

for h in range(H):
    for w in range(W):
        group = V[h][w]
        if group != 0:
            if S[h][w]=="#":
                cnt_b[group-1] += 1
            else:
                cnt_w[group-1] += 1

ans = 0
for i in range(len(cnt_b)):
    ans += cnt_b[i]*cnt_w[i]

print(ans)