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;
long long num[30], pre[100010], cnt;
int main() {
  int n, l, lr, ll;
  char s[100010];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s + 1;
    l = strlen(s + 1);
    for (int j = 0; j < 26; j++)
      if (num[j] && j + 'a' != s[1] && j + 'a' != s[l]) num[j] = 1;
    lr = 1;
    while (s[lr + 1] == s[lr]) lr++;
    ll = l;
    while (lr != l && s[ll] == s[ll - 1]) ll--;
    ll = l - ll + 1;
    if (s[1] == s[l])
      if (lr == l)
        num[s[1] - 'a'] = (l + 1) * num[s[1] - 'a'] + l;
      else
        num[s[1] - 'a'] = lr + ll + 1;
    else {
      num[s[1] - 'a'] = num[s[1] - 'a'] > 0 ? lr + 1 : lr;
      num[s[l] - 'a'] = num[s[l] - 'a'] > 0 ? ll + 1 : ll;
    }
    for (int j = lr + 1; j <= l - ll + 1; j++)
      if (s[j] == s[j - 1])
        pre[j] = pre[j - 1] + 1;
      else {
        pre[j] = 1;
        num[s[j - 1] - 'a'] = max(num[s[j - 1] - 'a'], pre[j - 1]);
      }
  }
  cnt = 0;
  for (int j = 0; j < 26; j++) cnt = max(cnt, num[j]);
  cout << cnt;
}
