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;
string s;
int con[27], mcon[27];
int lens[27];
int main() {
  int n;
  scanf("%d", &n);
  int pre, suf;
  int ans;
  while (n--) {
    cin >> s;
    int len = s.length();
    memset(con, 0, sizeof(con));
    memset(mcon, 0, sizeof(mcon));
    for (int i = 0; i < len; i++) {
      if (i && s[i] == s[i - 1])
        con[s[i] - 'a']++;
      else
        con[s[i] - 'a'] = 1;
      mcon[s[i] - 'a'] = max(mcon[s[i] - 'a'], con[s[i] - 'a']);
    }
    for (int i = 0; i < 26; i++) {
      pre = 0, suf = len - 1;
      while (pre < len && s[pre] == 'a' + i) pre++;
      while (suf >= 0 && s[suf] == 'a' + i) suf--;
      if (pre == len)
        lens[i] = max(mcon[i], lens[i] * (len + 1) + len);
      else if (lens[i])
        lens[i] = max(mcon[i], pre + len - suf);
      if (!n) ans = max(ans, lens[i]);
    }
  }
  cout << ans << endl;
}
