h, w = list(map(int, input().split()))

s = [list(eval(input())) for _ in range(h)]

m = [[0] * w for _ in range(h)]

ans = 0

for i in range(h):

    for j in range(w):

        if m[i][j] == 1:

            continue

        m[i][j] = 1

        qs = [[i, j]]

        white = 0

        black = 0

        while len(qs) != 0:

            q = qs.pop(0)

            if s[q[0]][q[1]] == '.':

                white += 1

            else:

                black += 1

            m[q[0]][q[1]] = 1

            for k in [[1, 0], [-1, 0], [0, 1], [0, -1]]:

                if not (0 <= q[0] + k[0] <= h - 1) or not (0 <= q[1] + k[1] <= w - 1):

                    continue

                if m[q[0] + k[0]][q[1] + k[1]] == 0 and s[q[0]][q[1]] != s[q[0] + k[0]][q[1] + k[1]]:

                    m[q[0] + k[0]][q[1] + k[1]] = 1

                    qs.append([q[0] + k[0], q[1] + k[1]])

        ans += black * white

print(ans)
h, w = list(map(int, input().split()))

s = [[''] * (w + 2)]

s += [[''] + list(eval(input())) + [''] for _ in range(h)]

s += [[''] * (w + 2)]

m = [[1] * (w + 2)]

m += [[1] + [0] * w + [1] for _ in range(h)]

m += [[1] * (w + 2) for _ in range(h + 2)]

ans = 0

for i in range(1, h + 1):

    for j in range(1, w + 1):

        if m[i][j] == 1:

            continue

        m[i][j] = 1

        qs = [[i, j]]

        white = 0

        black = 0

        while len(qs) != 0:

            q = qs.pop(0)

            if s[q[0]][q[1]] == '.':

                white += 1

            else:

                black += 1

            m[q[0]][q[1]] = 1

            for k in [[1, 0], [-1, 0], [0, 1], [0, -1]]:

                if m[q[0] + k[0]][q[1] + k[1]] == 0 and s[q[0]][q[1]] != s[q[0] + k[0]][q[1] + k[1]]:

                    m[q[0] + k[0]][q[1] + k[1]] = 1

                    qs.append([q[0] + k[0], q[1] + k[1]])

        ans += black * white

print(ans)
h, w = list(map(int, input().split()))
s = [list(eval(input())) for _ in range(h)]
m = [[0] * w for _ in range(h)]
ans = 0
for i in range(h):
    for j in range(w):
        if m[i][j] == 1:
            continue
        m[i][j] = 1
        qs = [[i, j]]
        white = 0
        black = 0
        while len(qs) != 0:
            q = qs.pop(0)
            if s[q[0]][q[1]] == ".":
                white += 1
            else:
                black += 1
            m[q[0]][q[1]] = 1
            for k in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
                if not (0 <= q[0] + k[0] <= h - 1) or not (0 <= q[1] + k[1] <= w - 1):
                    continue
                if (
                    m[q[0] + k[0]][q[1] + k[1]] == 0
                    and s[q[0]][q[1]] != s[q[0] + k[0]][q[1] + k[1]]
                ):
                    m[q[0] + k[0]][q[1] + k[1]] = 1
                    qs.append([q[0] + k[0], q[1] + k[1]])
        ans += black * white
print(ans)

h, w = list(map(int, input().split()))
s = [[""] * (w + 2)]
s += [[""] + list(eval(input())) + [""] for _ in range(h)]
s += [[""] * (w + 2)]
m = [[1] * (w + 2)]
m += [[1] + [0] * w + [1] for _ in range(h)]
m += [[1] * (w + 2) for _ in range(h + 2)]
ans = 0
for i in range(1, h + 1):
    for j in range(1, w + 1):
        if m[i][j] == 1:
            continue
        m[i][j] = 1
        qs = [[i, j]]
        white = 0
        black = 0
        while len(qs) != 0:
            q = qs.pop(0)
            if s[q[0]][q[1]] == ".":
                white += 1
            else:
                black += 1
            m[q[0]][q[1]] = 1
            for k in [[1, 0], [-1, 0], [0, 1], [0, -1]]:
                if (
                    m[q[0] + k[0]][q[1] + k[1]] == 0
                    and s[q[0]][q[1]] != s[q[0] + k[0]][q[1] + k[1]]
                ):
                    m[q[0] + k[0]][q[1] + k[1]] = 1
                    qs.append([q[0] + k[0], q[1] + k[1]])
        ans += black * white
print(ans)

-s = [list(eval(input())) for _ in range(h)] -m = [[0] * w for _ in range(h)] +s = [[""] * (w + 2)] +s += [[""] + list(eval(input())) + [""] for _ in range(h)] +s += [[""] * (w + 2)] +m = [[1] * (w + 2)] +m += [[1] + [0] * w + [1] for _ in range(h)] +m += [[1] * (w + 2) for _ in range(h + 2)] -for i in range(h): -    for j in range(w): +for i in range(1, h + 1): +    for j in range(1, w + 1): -                if not (0 <= q[0] + k[0] <= h - 1) or not (0 <= q[1] + k[1] <= w - 1): -                    continue