9
lfpgbnlzyn
c
s
w
r
m
q
y
yinfblfcdhidphyfvgkxyuwomahiibbhnigdslsguhjkplibnhhrshtekwgefxeugyyyyy
 6
u
p
m
z
v
vv
 4
qe
nd
iqryhukieskfvaeettersinksrmazelxtgvartuz
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 6
nf
ysvchtjkfgsbyfzxjaykey
advqnf
wl
pi
ppppfvvmaebvhkoagppppp
 3
j
k
kkailgwqnxtdsttkkkkkkk
 4
o
yhnx
e
ennn
 10
j
dyfu
udzj
wwow
xtnw
f
c
q
o
gggg
 6
w
g
c
j
y
f
 4
r
o
w
wwwwwwwwww
 2
zxwp
ppppctfisvflhtjggg
 5
m
g
u
t
tttt
 2
n
nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn
 3
lt
en
eeeeeeeeee
 4
vr
hp
l
llbn

7 5 541 10 10 4 4 1 21 5 9 93 21 3
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  vector<long long> ans(26);
  for (char l = 'a'; l <= 'z'; l++) {
    long long t = 0, tmp = 1;
    for (int j = 1; j < s[0].size(); j++) {
      if (s[0][j] != s[0][j - 1]) {
        if (s[0][j - 1] == l) {
          t = max(t, tmp);
        }
        tmp = 0;
      }
      tmp++;
    }
    if (s[0][s[0].size() - 1] == l) {
      t = max(t, tmp);
    }
    for (int i = 1; i < n; i++) {
      string x = s[i];
      long long left = 0, right = 0, t1 = 0;
      tmp = 1;
      bool fl = 0;
      for (int j = 1; j < x.size(); j++) {
        if (x[j] != x[j - 1]) {
          if (fl == 0) {
            fl = 1;
            left = tmp;
          }
          if (x[j - 1] == l) {
            t1 = max(t1, tmp);
          }
          tmp = 0;
        }
        tmp++;
      }
      if (x[x.size() - 1] == l) {
        t1 = max(t1, tmp);
      }
      if (fl == 0) {
        left = tmp;
      }
      right = tmp;
      ans[l - 'a'] = t1;
      if (t > 0) {
        ans[l - 'a'] = max(1ll, t1);
      }
      if (right == x.size() && x[0] == l && t > 0) {
        ans[l - 'a'] = max(ans[l - 'a'], t + right * (t + 1));
      } else if (x[0] == l && x[x.size() - 1] == l && t > 0) {
        ans[l - 'a'] = max(ans[l - 'a'], left + right + 1);
      }
      if (x[0] == l && t > 0) {
        ans[l - 'a'] = max(ans[l - 'a'], left + 1);
      }
      if (x[x.size() - 1] == l && t > 0) {
        ans[l - 'a'] = max(ans[l - 'a'], right + 1);
      }
      t = ans[l - 'a'];
    }
  }
  long long res = 0;
  for (auto i : ans) {
    res = max(res, i);
  }
  cout << res;
  return 0;
}
