import java.io.*; import java.util.*; public class Matrice { static int[] dX = new int[]{1,1,-1,-1}; static int[] dY = new int[]{1,-1,-1,1}; public static boolean inside(int X, int Y, char c, char[][] map) { if (X < 0) return false; if (Y < 0) return false; if (map.length <= Y) return false; if (map[0].length <= X) return false; return map[Y][X] == c; } public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String s = br.readLine(); String[] parts = s.split(" "); int H = Integer.parseInt(parts[0]); int W = Integer.parseInt(parts[1]); char[][] map = new char[H][]; for (int i = 0; i < H; i++) { map[i] = br.readLine().toCharArray(); } int maxSize = 1000; int count = 0; int sizecount = 0; for (int size = 2; size <= maxSize; size++) { sizecount = 0; for (int Y = 0; Y < H; Y++) { for (int X = 0; X < W; X++) { char origin = map[Y][X]; for (int i = 0; i < 4; i++) { int dx = dX[i]; int dy = dY[i]; boolean ok = true; for (int yy = 0; yy < size; yy++) { if (!ok) break; for (int xx = 0; xx < size-yy; xx++) { int x = X + xx*dx; int y = Y + yy*dy; //System.out.printf("[%d, %d] [%d, %d]\n", X, Y, x, y); if (!inside(x,y,origin, map)) { ok = false; break; } } } if (ok) { sizecount++; } } } } count += sizecount; if (sizecount == 0) break; } System.out.println(count); } }