/* -*- coding: utf-8 -*- * * 1166.cc: No.1166 NADA DNA - yukicoder */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; /* constant */ const int MAX_N = 1000; const int MAX_M = MAX_N * (MAX_N - 1) / 2; const int MAX_L = 50; /* typedef */ /* global variables */ char gs[MAX_N][MAX_L + 4]; int ds[MAX_M]; /* subroutines */ inline int hdist(char s[], char t[], int l) { int d = 0; for (int i = 0; i < l; i++) if (s[i] != t[i]) d++; return d; } /* main */ int main() { int n, l; scanf("%d%d", &n, &l); for (int i = 0; i < n; i++) scanf("%s", gs[i]); int m = 0; for (int i = 0; i < n; i++) for (int j = i + 1; j < n; j++) ds[m++] = hdist(gs[i], gs[j], l); sort(ds, ds + m); int sum = 0; for (int i = 0; i < n - 1; i++) sum += ds[i]; printf("%d\n", sum); return 0; }