Buggy python submission (verdict: Time Limit Exceeded):
import queue
H, W = map(int, input().split())
S = [list(map(int, input().replace(".", "0").replace("#","1"))) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
Visited = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if not Visited[h][w]:
            Visited[h][w] = True
            Color = ([1, 0] if S[h][w] == 0 else [0, 1])
            Q = queue.Queue()
            Q.put((h, w, S[h][w]))
            while not Q.empty():
                nh, nw, nc = Q.get()
                for s in Search:
                    nexth, nextw = nh + s[0], nw + s[1]
                    if 0 <= nexth < H and 0 <= nextw < W:
                        if not Visited[nexth][nextw] and S[nexth][nextw] != nc:
                            nextc = S[nexth][nextw]
                            Visited[nexth][nextw] = True
                            Q.put((nexth, nextw, nextc))
                            Color[nextc] += 1
            Total += Color[0] * Color[1]

print(Total)

Fixed submission:
import queue
H, W = map(int, input().split())
S = [list(map(int, input().replace(".", "0").replace("#","1"))) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
Visited = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if not Visited[h][w]:
            Visited[h][w] = True
            Color = ([1, 0] if S[h][w] == 0 else [0, 1])
            Q = queue.Queue()
            Q.put((h, w, S[h][w]))
            while not Q.empty():
                nh, nw, nc = Q.get()
                for s in Search:
                    nexth, nextw = nh + s[0], nw + s[1]
                    if 0 <= nexth < H and 0 <= nextw < W:
                        if not Visited[nexth][nextw] and S[nexth][nextw] != nc:
                            nextc = S[nexth][nextw]
                            Visited[nexth][nextw] = True
                            Q.put((nexth, nextw, nextc))
                            Color[nextc] += 1
            Total += Color[0] * Color[1]

print(Total)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
 
Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
Visited = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if not Visited[h][w]:
            Visited[h][w] = True
            if S[h][w] == ".": Black, White = 0, 1
            else: Black, White = 1, 0
            Q = queue.Queue()
            Q.put((h, w))
            while not Q.empty():
                now = Q.get()
                nh, nw = now[0], now[1]
                for s in Search:
                    nexth, nextw = nh + s[0], nw + s[1]
                    if 0 <= nexth < H and 0 <= nextw < W:
                        if not Visited[nexth][nextw] and S[nexth][nextw] != S[nh][nw]:
                            Visited[nexth][nextw] = True
                            Q.put((nexth, nextw))
                            if S[nexth][nextw] == ".": White += 1
                            else: Black += 1
            Total += Black * White

print(Total)

Fixed submission:
import queue
H, W = map(int, input().split())
S = [list(map(int, input().replace(".", "0").replace("#","1"))) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
Visited = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if not Visited[h][w]:
            Visited[h][w] = True
            Color = ([1, 0] if S[h][w] == 0 else [0, 1])
            Q = queue.Queue()
            Q.put((h, w, S[h][w]))
            while not Q.empty():
                nh, nw, nc = Q.get()
                for s in Search:
                    nexth, nextw = nh + s[0], nw + s[1]
                    if 0 <= nexth < H and 0 <= nextw < W:
                        if not Visited[nexth][nextw] and S[nexth][nextw] != nc:
                            nextc = S[nexth][nextw]
                            Visited[nexth][nextw] = True
                            Q.put((nexth, nextw, nextc))
                            Color[nextc] += 1
            Total += Color[0] * Color[1]

print(Total)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
 
Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
BlackVis = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            if not BlackVis[h][w]:
                Visited = [[False for w in range(W)] for h in range(H)]
                Visited[h][w] = True
                Q = queue.Queue()
                Q.put((h,w))
                Mult = 1
                Count = 0
                while not Q.empty():
                    now = Q.get()
                    for s in Search:
                        nh, nw = now[0] + s[0], now[1]+s[1]
                        if 0 <= nh < H and 0 <= nw < W:
                            if S[now[0]][now[1]] != S[nh][nw] and not Visited[nh][nw]:
                                Visited[nh][nw] = True
                                Q.put((nh, nw))
                                if S[nh][nw] == ".":
                                    Count += 1
                                else:
                                    BlackVis[nh][nw] = True
                                    Mult += 1
                Total += Count * Mult 
print(Total)

Fixed submission:
import queue
H, W = map(int, input().split())
S = [list(map(int, input().replace(".", "0").replace("#","1"))) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
Visited = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if not Visited[h][w]:
            Visited[h][w] = True
            Color = ([1, 0] if S[h][w] == 0 else [0, 1])
            Q = queue.Queue()
            Q.put((h, w, S[h][w]))
            while not Q.empty():
                nh, nw, nc = Q.get()
                for s in Search:
                    nexth, nextw = nh + s[0], nw + s[1]
                    if 0 <= nexth < H and 0 <= nextw < W:
                        if not Visited[nexth][nextw] and S[nexth][nextw] != nc:
                            nextc = S[nexth][nextw]
                            Visited[nexth][nextw] = True
                            Q.put((nexth, nextw, nextc))
                            Color[nextc] += 1
            Total += Color[0] * Color[1]

print(Total)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
 
Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
BlackVis = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w] == "#" and not BlackVis[h][w]:
            Visited = [[False for w in range(W)] for h in range(H)]
            Visited[h][w] = True
            Q = queue.Queue()
            Q.put((h,w))
            Mult = 1
            Count = 0
            while not Q.empty():
                now = Q.get()
                for s in Search:
                    nh, nw = now[0] + s[0], now[1]+s[1]
                    if 0 <= nh < H and 0 <= nw < W:
                        if S[now[0]][now[1]] != S[nh][nw] and not Visited[nh][nw]:
                            Visited[nh][nw] = True
                            Q.put((nh, nw))
                            if S[nh][nw] == ".":
                                Count += 1
                            else:
                                BlackVis[nh][nw] = True
                                Mult += 1
            Total += Count * Mult 
print(Total)

Fixed submission:
import queue
H, W = map(int, input().split())
S = [list(map(int, input().replace(".", "0").replace("#","1"))) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
Visited = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if not Visited[h][w]:
            Visited[h][w] = True
            Color = ([1, 0] if S[h][w] == 0 else [0, 1])
            Q = queue.Queue()
            Q.put((h, w, S[h][w]))
            while not Q.empty():
                nh, nw, nc = Q.get()
                for s in Search:
                    nexth, nextw = nh + s[0], nw + s[1]
                    if 0 <= nexth < H and 0 <= nextw < W:
                        if not Visited[nexth][nextw] and S[nexth][nextw] != nc:
                            nextc = S[nexth][nextw]
                            Visited[nexth][nextw] = True
                            Q.put((nexth, nextw, nextc))
                            Color[nextc] += 1
            Total += Color[0] * Color[1]

print(Total)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]
 
Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
BlackVis = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w] == "#" and not BlackVis[h][w]:
            Visited = [[False for w in range(W)] for h in range(H)]
            Visited[h][w] = True
            Q = queue.Queue()
            Q.put((h,w))
            Mult = 1
            Count = 0
            while not Q.empty():
                now = Q.get()
                for s in Search:
                    if 0 <= now[0] + s[0] < H and 0 <= now[1]+s[1] < W:
                        if S[now[0]][now[1]] == "#":
                            if S[now[0]+s[0]][now[1]+s[1]] == "." and not Visited[now[0]+s[0]][now[1]+s[1]]:
                                Visited[now[0]+s[0]][now[1]+s[1]] = True
                                Count += 1
                                Q.put((now[0]+s[0], now[1]+s[1]))
                        else:
                            if S[now[0]+s[0]][now[1]+s[1]] == "#" and not Visited[now[0]+s[0]][now[1]+s[1]]:
                                Visited[now[0]+s[0]][now[1]+s[1]] = True
                                BlackVis[now[0]+s[0]][now[1]+s[1]] = True
                                Mult += 1
                                Q.put((now[0]+s[0], now[1]+s[1]))
            Total += Count * Mult 
print(Total)

Fixed submission:
import queue
H, W = map(int, input().split())
S = [list(map(int, input().replace(".", "0").replace("#","1"))) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
Visited = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if not Visited[h][w]:
            Visited[h][w] = True
            Color = ([1, 0] if S[h][w] == 0 else [0, 1])
            Q = queue.Queue()
            Q.put((h, w, S[h][w]))
            while not Q.empty():
                nh, nw, nc = Q.get()
                for s in Search:
                    nexth, nextw = nh + s[0], nw + s[1]
                    if 0 <= nexth < H and 0 <= nextw < W:
                        if not Visited[nexth][nextw] and S[nexth][nextw] != nc:
                            nextc = S[nexth][nextw]
                            Visited[nexth][nextw] = True
                            Q.put((nexth, nextw, nextc))
                            Color[nextc] += 1
            Total += Color[0] * Color[1]

print(Total)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
BlackVis = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if S[h][w] == "#" and not BlackVis[h][w]:
            Visited = [[False for w in range(W)] for h in range(H)]
            Visited[h][w] = True
            Q = queue.Queue()
            Q.put((h,w))
            Mult = 1
            Count = 0
            while not Q.empty():
                now = Q.get()
                color = S[now[0]][now[1]]
                for s in Search:
                    if 0 <= now[0] + s[0] < H and 0 <= now[1]+s[1] < W:
                        if color == "#":
                            if S[now[0]+s[0]][now[1]+s[1]] == "." and not Visited[now[0]+s[0]][now[1]+s[1]]:
                                Visited[now[0]+s[0]][now[1]+s[1]] = True
                                Count += 1
                                Q.put((now[0]+s[0], now[1]+s[1]))
                        else:
                            if S[now[0]+s[0]][now[1]+s[1]] == "#" and not Visited[now[0]+s[0]][now[1]+s[1]]:
                                Visited[now[0]+s[0]][now[1]+s[1]] = True
                                BlackVis[now[0]+s[0]][now[1]+s[1]] = True
                                Mult += 1
                                Q.put((now[0]+s[0], now[1]+s[1]))
            Total += Count * Mult 
print(Total)

Fixed submission:
import queue
H, W = map(int, input().split())
S = [list(map(int, input().replace(".", "0").replace("#","1"))) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
Visited = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if not Visited[h][w]:
            Visited[h][w] = True
            Color = ([1, 0] if S[h][w] == 0 else [0, 1])
            Q = queue.Queue()
            Q.put((h, w, S[h][w]))
            while not Q.empty():
                nh, nw, nc = Q.get()
                for s in Search:
                    nexth, nextw = nh + s[0], nw + s[1]
                    if 0 <= nexth < H and 0 <= nextw < W:
                        if not Visited[nexth][nextw] and S[nexth][nextw] != nc:
                            nextc = S[nexth][nextw]
                            Visited[nexth][nextw] = True
                            Q.put((nexth, nextw, nextc))
                            Color[nextc] += 1
            Total += Color[0] * Color[1]

print(Total)

Buggy python submission (verdict: Time Limit Exceeded):
import queue
H, W = map(int, input().split())
S = [list(input()) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
for h in range(H):
    for w in range(W):
        if S[h][w] == "#":
            Visited = [[False for w in range(W)] for h in range(H)]
            Visited[h][w] = True
            Q = queue.Queue()
            Q.put((h,w))
            Count = 0
            while not Q.empty():
                now = Q.get()
                color = S[now[0]][now[1]]
                for s in Search:
                    if 0 <= now[0] + s[0] < H and 0 <= now[1]+s[1] < W:
                        if color == "#":
                            if S[now[0]+s[0]][now[1]+s[1]] == "." and not Visited[now[0]+s[0]][now[1]+s[1]]:
                                Visited[now[0]+s[0]][now[1]+s[1]] = True
                                Count += 1
                                Q.put((now[0]+s[0], now[1]+s[1]))
                        else:
                            if S[now[0]+s[0]][now[1]+s[1]] == "#" and not Visited[now[0]+s[0]][now[1]+s[1]]:
                                Visited[now[0]+s[0]][now[1]+s[1]] = True
                                Q.put((now[0]+s[0], now[1]+s[1]))
            Total += Count
print(Total)

Fixed submission:
import queue
H, W = map(int, input().split())
S = [list(map(int, input().replace(".", "0").replace("#","1"))) for h in range(H)]

Search = [(-1, 0), (0, -1), (1, 0), (0, 1)]
Total = 0
Visited = [[False for w in range(W)] for h in range(H)]
for h in range(H):
    for w in range(W):
        if not Visited[h][w]:
            Visited[h][w] = True
            Color = ([1, 0] if S[h][w] == 0 else [0, 1])
            Q = queue.Queue()
            Q.put((h, w, S[h][w]))
            while not Q.empty():
                nh, nw, nc = Q.get()
                for s in Search:
                    nexth, nextw = nh + s[0], nw + s[1]
                    if 0 <= nexth < H and 0 <= nextw < W:
                        if not Visited[nexth][nextw] and S[nexth][nextw] != nc:
                            nextc = S[nexth][nextw]
                            Visited[nexth][nextw] = True
                            Q.put((nexth, nextw, nextc))
                            Color[nextc] += 1
            Total += Color[0] * Color[1]

print(Total)