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;
const int MAXN = 2E5 + 10;
char str[MAXN], *cur = str, *sp[MAXN];
long long Ans, tlen;
int L[26], R[26], n, all[26], tL[26], tR[26], tall[26], len[MAXN];
void merge(char *s, int len) {
  int tmplen = tlen;
  memcpy(tL, L, sizeof L);
  memcpy(tR, R, sizeof R);
  memcpy(tall, all, sizeof tall);
  for (int i = 1; i <= len; i++) {
    int x = s[i] - 'a';
    for (int j = 0; j < 26; j++) {
      Ans = max(Ans, (long long)R[j] + (x == j));
      all[j] &= (x == j);
      if (all[j])
        L[j] = R[j] = tlen + 1;
      else
        R[j] = x == j ? R[j] + 1 : 0;
    }
    tlen++;
    for (int j = 0; j < 26; j++) {
      Ans = max(Ans, (long long)R[j] + tL[j]);
      all[j] &= tall[j];
      if (all[j])
        L[j] = R[j] = tlen + tmplen;
      else
        R[j] = tall[j] ? R[j] + tR[j] : tR[j];
    }
    tlen += tmplen;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int tmx = 0;
    sp[i] = cur;
    scanf("%s", sp[i] + 1);
    cur += (len[i] = strlen(sp[i] + 1));
    for (int j = 1; j <= len[i]; j++) {
      tmx = sp[i][j] == sp[i][j - 1] ? tmx + 1 : 1;
      Ans = max((long long)tmx, Ans);
    }
  }
  tlen = strlen(sp[n] + 1);
  for (int i = 1; i <= tlen; i++)
    for (int j = 0; j < 26; j++)
      L[j] = (L[j] == i - 1) ? (L[j] + (sp[n][i] - 'a' == j)) : L[j];
  for (int i = tlen; i >= 1; i--)
    for (int j = 0; j < 26; j++)
      R[j] = (R[j] == tlen - i) ? (R[j] + (sp[n][i] - 'a' == j)) : R[j];
  for (int i = 0; i < 26; i++)
    all[i] = L[i] == tlen, Ans = max(Ans, (long long)max(L[i], R[i]));
  for (int i = n - 1; i; i--) merge(sp[i], len[i]);
  printf("%lld\n", Ans);
}
