Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
C = [input() for i in range(H)]

import sys
sys.setrecursionlimit(500000)

def search(x, y, z):
    if y >= H or x >= W or x < 0 or y <  0:
        return
    elif C[y][x] == z:
        return
    elif itta[y][x] != 0:
        return
    else:
        itta[y][x] = 0.00000001 # appendすると遅くなる
        prez = C[y][x]
        if C[y][x] == '.':
            itta[y][x] = 1
    
    search(x+1, y, prez)
    search(x-1, y, prez)
    search(x, y+1, prez)
    search(x, y-1, prez) 

ans = 0
# #を探しに行く
for y in range(H):
    for x in range(W):
        if C[y][x] != '#':
            pass
        else:
            itta = [[0] * W for i in range(H)]
            search(x, y, '.')
            ans += int(sum(map(sum, itta))) 
            # 入れ子リスト（２次元配列）の合計値
            # https://maku77.github.io/python/numstr/sum.html

print(ans)


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

import sys
sys.setrecursionlimit(500000)

itta = [[0] * W for i in range(H)]

def search(x, y, z):
    if y >= H or x >= W or x < 0 or y <  0:
        return
    elif C[y][x] == z:
        return
    elif itta[y][x] == 1:
        return
    elif C[y][x] == z:
        return
    else:
        itta[y][x] = 1
        
        if C[y][x] == '.':
            bw_count[0] += 1
        else:
            bw_count[1] += 1
        
        prez = C[y][x]
        
    search(x+1, y, prez)
    search(x-1, y, prez)
    search(x, y+1, prez)
    search(x, y-1, prez) 

ans = 0

for y in range(H):
    for x in range(W):
        if itta[y][x] ==1:
            pass
        else:
            bw_count = [0, 0]
            search(x, y, '-')
            
            ans += bw_count[0] * bw_count[1]  

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
C = [input() for i in range(H)]

import sys
sys.setrecursionlimit(500000)

def search(x, y, z):
    if y >= H or x >= W or x < 0 or y <  0:
        return
    elif C[y][x] == z:
        return
    elif itta[y][x] != 0:
        return
    else:
        itta[y][x] = 0.00000001 # appendすると遅くなる
        prez = C[y][x]
        if C[y][x] == '.':
            itta[y][x] = 1
    
    search(x+1, y, prez)
    search(x-1, y, prez)
    search(x, y+1, prez)
    search(x, y-1, prez) 

ans = 0
# #を探しに行く
for y in range(H):
    for x in range(W):
        if C[y][x] != '#':
            pass
        else:
            itta = [[0] * W for i in range(H)]
            search(x, y, '.')
            ans += int(sum(map(sum, itta))) 
            # 入れ子リスト（２次元配列）の合計値
            # https://maku77.github.io/python/numstr/sum.html

print(ans)

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

import sys
sys.setrecursionlimit(500000)

itta = [[0] * W for i in range(H)]

def search(x, y, z):
    if y >= H or x >= W or x < 0 or y <  0:
        return
    elif C[y][x] == z:
        return
    elif itta[y][x] == 1:
        return
    elif C[y][x] == z:
        return
    else:
        itta[y][x] = 1
        
        if C[y][x] == '.':
            bw_count[0] += 1
        else:
            bw_count[1] += 1
        
        prez = C[y][x]
        
    search(x+1, y, prez)
    search(x-1, y, prez)
    search(x, y+1, prez)
    search(x, y-1, prez) 

ans = 0

for y in range(H):
    for x in range(W):
        if itta[y][x] ==1:
            pass
        else:
            bw_count = [0, 0]
            search(x, y, '-')
            
            ans += bw_count[0] * bw_count[1]  

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
C = [input() for i in range(H)]

import sys
sys.setrecursionlimit(500000)

def search(x, y, z):
    if y >= H or x >= W or x < 0 or y <  0:
        return
    elif C[y][x] == z:
        return
    elif itta[y][x] != 0:
        return
    else:
        itta[y][x] = 0.0000000000000000001 # appendすると遅くなる
        prez = C[y][x]
        if C[y][x] == '.':
            itta[y][x] = 1
    
    search(x+1, y, prez)
    search(x-1, y, prez)
    search(x, y+1, prez)
    search(x, y-1, prez) 

ans = 0
# #を探しに行く
for y in range(H):
    for x in range(W):
        if C[y][x] != '#':
            pass
        else:
            itta = [[0] * W for i in range(H)]
            search(x, y, '.')
            ans += int(sum(map(sum, itta))) 
            # 入れ子リスト（２次元配列）の合計値
            # https://maku77.github.io/python/numstr/sum.html

print(ans)

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

import sys
sys.setrecursionlimit(500000)

itta = [[0] * W for i in range(H)]

def search(x, y, z):
    if y >= H or x >= W or x < 0 or y <  0:
        return
    elif C[y][x] == z:
        return
    elif itta[y][x] == 1:
        return
    elif C[y][x] == z:
        return
    else:
        itta[y][x] = 1
        
        if C[y][x] == '.':
            bw_count[0] += 1
        else:
            bw_count[1] += 1
        
        prez = C[y][x]
        
    search(x+1, y, prez)
    search(x-1, y, prez)
    search(x, y+1, prez)
    search(x, y-1, prez) 

ans = 0

for y in range(H):
    for x in range(W):
        if itta[y][x] ==1:
            pass
        else:
            bw_count = [0, 0]
            search(x, y, '-')
            
            ans += bw_count[0] * bw_count[1]  

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
C = [input() for i in range(H)]

import sys
sys.setrecursionlimit(500000)


def search(x, y, z):
    if y >= H or x >= W or x < 0 or y <  0:
        return
    elif C[y][x] == z:
        return
    elif itta[y][x] == 1:
        return
    else:
        itta[y][x] = 1 # appendすると遅くなる
        prez = C[y][x]
        if C[y][x] == '.':
            itta_white[y][x] = 1
    
    search(x+1, y, prez)
    search(x-1, y, prez)
    search(x, y+1, prez)
    search(x, y-1, prez) 

ans = 0
# #を探しに行く
for y in range(H):
    for x in range(W):
        if C[y][x] != '#':
            pass
        else:
            itta = [[0] * W for i in range(H)]
            itta_white = [[0] * W for i in range(H)]
            search(x, y, '.')
            ans += sum(map(sum, itta_white)) 
            # 入れ子リスト（２次元配列）の合計値
            # https://maku77.github.io/python/numstr/sum.html

print(ans)


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

import sys
sys.setrecursionlimit(500000)

itta = [[0] * W for i in range(H)]

def search(x, y, z):
    if y >= H or x >= W or x < 0 or y <  0:
        return
    elif C[y][x] == z:
        return
    elif itta[y][x] == 1:
        return
    elif C[y][x] == z:
        return
    else:
        itta[y][x] = 1
        
        if C[y][x] == '.':
            bw_count[0] += 1
        else:
            bw_count[1] += 1
        
        prez = C[y][x]
        
    search(x+1, y, prez)
    search(x-1, y, prez)
    search(x, y+1, prez)
    search(x, y-1, prez) 

ans = 0

for y in range(H):
    for x in range(W):
        if itta[y][x] ==1:
            pass
        else:
            bw_count = [0, 0]
            search(x, y, '-')
            
            ans += bw_count[0] * bw_count[1]  

print(ans)

Buggy python submission (verdict: Time Limit Exceeded):
H, W = map(int, input().split())
C = [input() for i in range(H)]

import sys
sys.setrecursionlimit(500000)


def search(x, y, z):
    if y >= H or x >= W or x < 0 or y <  0:
        return
    elif C[y][x] == z:
        return
    elif itta[y][x] == 1:
        return
    else:
        itta[y][x] = 1 # appendすると遅くなる
        prez = C[y][x]
        if C[y][x] == '.':
            itta_white[y][x] = 1
    
    search(x+1, y, prez)
    search(x-1, y, prez)
    search(x, y+1, prez)
    search(x, y-1, prez) 
ans = 0
# #を探しに行く
for y in range(H):
    for x in range(W):
        if C[y][x] != '#':
            pass
        else:
            itta = [[0] * W for i in range(H)]
            itta_white = [[0] * W for i in range(H)]
            search(x, y, '.')
            ans += sum(map(sum, itta_white)) 
            # 入れ子リスト（２次元配列）の合計値
            # https://maku77.github.io/python/numstr/sum.html

print(ans)

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

import sys
sys.setrecursionlimit(500000)

itta = [[0] * W for i in range(H)]

def search(x, y, z):
    if y >= H or x >= W or x < 0 or y <  0:
        return
    elif C[y][x] == z:
        return
    elif itta[y][x] == 1:
        return
    elif C[y][x] == z:
        return
    else:
        itta[y][x] = 1
        
        if C[y][x] == '.':
            bw_count[0] += 1
        else:
            bw_count[1] += 1
        
        prez = C[y][x]
        
    search(x+1, y, prez)
    search(x-1, y, prez)
    search(x, y+1, prez)
    search(x, y-1, prez) 

ans = 0

for y in range(H):
    for x in range(W):
        if itta[y][x] ==1:
            pass
        else:
            bw_count = [0, 0]
            search(x, y, '-')
            
            ans += bw_count[0] * bw_count[1]  

print(ans)