import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;
void times(alias pred)(int n) {
    foreach(i; 0..n) pred();
}
auto rep(alias pred, T = typeof(pred()))(int n) {
    T[] res = new T[n];
    foreach(ref e; res) e = pred();
    return res;
}

void main() {
    int H, W;
    readf("%d %d\n", &H, &W);

    if (W!=3)return;

    int[][] grid = H.rep!(() => readln.chomp.to!(char[])).transposed.map!(a => a.map!(b => b.to!char-'a'+1).array).array;

    long ans = 0;
    foreach (i; 0..H) {
        foreach(j; 0..H-i) {
            auto x = H-j-1;
            if (grid[1][x]==grid[0][x]) ans++;
            if (grid[1][x]==grid[2][x]) ans++;
            if (x > 0) grid[1][x] = grid[1][x-1];
        }
    }
    ans.writeln;
}
