#include <bits/stdc++.h>
long long n, i, j, h, k, t, d, m;
using namespace std;
char check[3] = {'S', 'E', 'T'};
string s[1505], ss;
unordered_map<string, long long> ma[1505];
char ec(char a, char b) {
  for (int i = 0; i < 3; i++)
    if ((a != b && check[i] != a && check[i] != b) || (a == b && b == check[i]))
      return check[i];
}
int main() {
  long long res = 0;
  cin >> n >> k;
  for (i = 1; i <= n; i++) cin >> s[i];
  ss = s[1];
  for (i = 1; i <= n; i++) {
    ma[i][s[i + 1]]++;
    for (j = i + 2; j <= n; j++) {
      for (t = 0; t < k; t++) ss[t] = ec(s[i][t], s[j][t]);
      res += ma[i][ss];
      ma[i][s[j]]++;
    }
  }
  cout << res << endl;
}
