Problem: There is a grid with H rows and W columns, where each square is painted black or white.

You are given H strings S_1, S_2, ..., S_H, each of length W. If the square at the i-th row from the top and the j-th column from the left is painted black, the j-th character in the string S_i is `#`; if that square is painted white, the j-th character in the string S_i is `.`.

Find the number of pairs of a black square c_1 and a white square c_2 that satisfy the following condition:

* There is a path from the square c_1 to the square c_2 where we repeatedly move to a vertically or horizontally adjacent square through an alternating sequence of black and white squares: black, white, black, white...

Constraints

* 1 \leq H, W \leq 400
* |S_i| = W (1 \leq i \leq H)
* For each i (1 \leq i \leq H), the string S_i consists of characters `#` and `.`.

Input

Input is given from Standard Input in the following format:


H W
S_1
S_2
:
S_H


Output

Print the answer.

Examples

Input

3 3
.#.
..#
#..


Output

10


Input

3 3
.#.
..#
..


Output

10


Input

2 4
....
....


Output

0


Input

4 3


...


Output

6

Solution (in JAVA):

Solution:
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int H = scan.nextInt();
        int W = scan.nextInt();
        char[][] map = new char[H][W];
        for (int i = 0; i < H; i++) {
            String s = scan.next();
            map[i] = s.toCharArray();
        }
        UnionFind union = new UnionFind(H, W, map);
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (j + 1 < W && is_connect(map, i, j, i, j+1)) {
                    union.unite(i * W + j, i * W + j + 1);
                }
                if (i + 1 < H && is_connect(map, i, j, i+1, j)) {
                    union.unite(i * W + j, (i + 1) * W + j);
                }
            }
        }
        long answer = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (map[i][j] == '#') {
                    answer += union.white(i * W + j);
                }
            }
        }
        System.out.println(answer);
    }
    private boolean is_connect(char[][] map, int x1, int y1, int x2, int y2) {
        if (map[x1][y1] == '#' && map[x2][y2] == '.') {
            return true;
        }
        return map[x1][y1] == '.' && map[x2][y2] == '#';
    }
    class UnionFind {
        private int H;
        private int W;
        private char[][] map;
        private int[] size;
        private int[] parent;
        private int[] white;
        UnionFind(int H, int W, char[][] map) {
            this.H = H;
            this.W = W;
            int N = H * W;
            this.map = map;
            this.size = new int[N];
            Arrays.fill(this.size, 0);
            this.parent = new int[N];
            for (int i = 0; i < N; i++) {
                this.parent[i] = i;
            }
            this.white = new int[N];
            Arrays.fill(this.white, 0);
            for (int i = 0; i < H; i++) {
                for (int j = 0; j < W; j++) {
                    if (map[i][j] == '.') {
                        this.white[i * W + j] = 1;
                    }
                }
            }
        }
        int white(int i) {
            int x = find(i);
            return this.white[x];
        }
        int find(int i) {
            if (this.parent[i] == i) {
                return i;
            }
            return this.parent[i] = find(this.parent[i]);
        }
        boolean same(int i, int j) {
            return find(i) == find(j);
        }
        void unite(int i, int j) {
            int x = this.find(i);
            int y = this.find(j);
            if (x == y) {
                return;
            }
            if (this.size[x] < this.size[y]) {
                this.size[y] += this.size[x];
                this.white[y] += this.white[x];
                this.size[x] = 0;
                this.white[x] = 0;
                this.parent[x] = y;
                return;
            }
            this.size[x] += this.size[y];
            this.white[x] += this.white[y];
            this.size[y] = 0;
            this.white[y] = 0;
            this.parent[y] = x;
        }
    }
}