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 wlen[26], pwlen[26], used[26];
char ts[100010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    scanf("%s", ts);
    int l = strlen(ts);
    for (int j = 0; j < l; j++) ts[j] -= 'a';
    int s1 = -1, s1c;
    memset(wlen, 0, sizeof wlen);
    for (int j = 0; j < l; j++) {
      if (ts[j] != s1) {
        s1 = ts[j];
        s1c = 1;
      } else
        s1c++;
      wlen[s1] = max(wlen[s1], s1c);
    }
    int il = 0, ir = l - 1;
    for (; il < l && ts[il] == ts[0]; il++)
      ;
    for (; ir >= 0 && ts[ir] == ts[l - 1]; ir--)
      ;
    if (ir == -1) {
      long long t = (long long)l * pwlen[ts[0]] + l + pwlen[ts[0]];
      wlen[ts[0]] = min(t, 1000000010ll);
    } else if (ts[0] == ts[l - 1]) {
      if (used[ts[0]]) wlen[ts[0]] = max(wlen[ts[0]], il + l - ir);
    } else {
      if (used[ts[0]]) wlen[ts[0]] = max(wlen[ts[0]], il + 1);
      if (used[ts[l - 1]]) wlen[ts[l - 1]] = max(wlen[ts[l - 1]], l - ir);
    }
    for (int j = 0; j < 26; j++) wlen[j] = max(wlen[j], used[j]);
    for (int j = 0; j < l; j++) used[ts[j]] = 1;
    memcpy(pwlen, wlen, sizeof wlen);
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, wlen[i]);
  cout << ans;
  return 0;
}
