#include <bits/stdc++.h>
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
const int maxn = 1e5 + 10;
int f[maxn][30], n, dem[30], ma[30];
string s;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    memset(dem, 0, sizeof(dem));
    memset(ma, 0, sizeof(ma));
    char pre = '*';
    for (int j = 0; j <= s.size() - 1; j++) {
      if (s[j] == pre)
        dem[s[j] - 'a']++;
      else
        pre = s[j], dem[s[j] - 'a'] = 1;
      ma[s[j] - 'a'] = max(ma[s[j] - 'a'], dem[s[j] - 'a']);
    }
    int l = s.size();
    for (int j = 0; j <= 25; j++) {
      f[i][j] = ma[j];
      int pref = 0;
      while (pref < l && s[pref] == (j + 'a')) ++pref;
      int suff = l - 1;
      while (suff > -1 && s[suff] == (j + 'a')) --suff;
      if (pref == l)
        f[i][j] = max(f[i][j], f[i - 1][j] * l + l + f[i - 1][j]);
      else if (f[i - 1][j])
        f[i][j] = max(f[i][j], pref + l - suff);
    }
  }
  int kq = 0;
  for (int i = 0; i <= 25; i++) kq = max(kq, f[n][i]);
  cout << kq;
}
