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