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 f[200010][30];
string s;
int main() {
  int n, i, j, ans = 0;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> s;
    int l = s.length(), t[30] = {}, r[30] = {};
    for (j = 0; j < l; j++) {
      if (j && s[j - 1] == s[j])
        t[s[j] - 'a']++;
      else
        t[s[j] - 'a'] = 1;
      r[s[j] - 'a'] = max(r[s[j] - 'a'], t[s[j] - 'a']);
    }
    for (j = 0; j < 2; j++) {
      f[i][j] = max(f[i - 1][j], r[j]);
      int t1 = 0, t2 = l - 1;
      while (s[t1] == 'a' + j && t1 < l) t1++;
      while (s[t2] == 'a' + j && t2 > t1) t2--;
      if (t1 == l)
        f[i][j] = max(f[i][j], f[i - 1][j] * l);
      else if (f[i - 1][j])
        f[i][j] = max(f[i][j], t1 + l - t2 + 1 + 1);
      ans = max(ans, f[i][j]);
    }
  }
  cout << ans;
}
