#include <bits/stdc++.h>
using namespace std;
int n, l[30][30], t, l1[110][40], z[10], r;
string s[110];
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= n; i++) {
    t = 0;
    r = 1;
    for (int j = 0; j < s[i].length(); j++) {
      if (l1[i][(s[i][j] - '0') - 48] == 0) {
        t++;
        l1[i][(s[i][j] - '0') - 48] = 1;
        z[r] = (s[i][j] - '0') - 48;
        r++;
      }
    }
    if (t == 2) {
      for (int j = 0; j < s[i].length(); j++) {
        l[z[1]][z[2]]++;
        l[z[2]][z[1]]++;
      }
    }
    if (t == 1) {
      for (int j = 1; j <= 26; j++) {
        if (z[1] != j) {
          l[z[1]][j] += s[i].length();
          l[j][z[1]] += s[i].length();
        }
      }
    }
  }
  for (int i = 1; i <= 27; i++) {
    sort(l[i] + 1, l[i] + 27);
  }
  for (int i = 1; i <= 26; i++) {
    l[i + 1][26] = max(l[i][26], l[i + 1][26]);
  }
  cout << l[27][26];
}
