#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("-O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
const long long INF = 4e18;
const int inf = 1e9;
const int N = 2e5 + 5;
const long long mod = 998244353;
char uni(char a, char b) {
  for (char i : {'S', 'E', 'T'}) {
    if (i != a && i != b) {
      return i;
    }
  }
}
int make_h(string s) {
  long long h = 0, p = 31, q = 1;
  for (int i = 0; i < s.size(); i++) {
    h += (s[i] - 'A' + 1) * q;
    q *= p;
  }
  return h;
}
void solve() {
  int n, k;
  cin >> n >> k;
  string s[n];
  map<long long, int> mp;
  long long h[n];
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    mp[make_h(s[i])]++;
    h[i] = make_h(s[i]);
  }
  long long ans = 0;
  for (int i = 0; i < n - 1; i++) {
    mp[h[i]]--;
    for (int j = i + 1; j < n; j++) {
      string x = s[i];
      for (int p = 0; p < k; p++) {
        if (s[i][p] != s[j][p]) {
          x[p] = uni(s[i][p], s[j][p]);
        } else {
          x[p] = s[i][p];
        }
      }
      mp[h[j]]--;
      ans += mp[make_h(x)];
      mp[h[j]]++;
    }
  }
  cout << ans / 2 << '\n';
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
