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 = 100010;
char s[maxn], t[maxn];
int n, now, st[maxn], ed[maxn];
int pre[maxn], suf[maxn];
int ans[30];
inline long long getint() {
  long long ret = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') ret = ret * 10 + c - '0', c = getchar();
  return ret * f;
}
int main() {
  n = getint();
  for (int i = 1; i <= n; i++) {
    st[i] = now;
    scanf("%s", t + 1);
    int len = strlen(t + 1);
    for (int j = 1; j <= len; j++) s[++now] = t[j];
    ed[i] = now;
  }
  for (int i = 1; i <= n; i++) {
    int len = ed[i] - st[i];
    pre[i] = 1;
    for (int j = 2; j <= len; j++) {
      if (s[j + st[i]] != s[j + st[i] - 1]) break;
      pre[i]++;
    }
    suf[i] = 1;
    for (int j = len - 1; j >= 1; j--) {
      if (s[j + st[i]] != s[j + st[i] + 1]) break;
      suf[i]++;
    }
    if (pre[i] == len) {
      for (int j = 1; j <= 26; j++) {
        if (s[ed[i]] - 'a' + 1 != j)
          ans[j] = 1;
        else
          ans[j] = ans[j] + (ans[j] + 1) * len;
      }
      continue;
    }
    for (int j = 1; j <= 26; j++) {
      if (s[st[i] + 1] - 'a' + 1 == j) ans[j] += pre[i];
      if (s[ed[i]] - 'a' + 1 == j) ans[j] += suf[i];
      if (s[st[i] + 1] - 'a' + 1 != j && s[ed[i]] - 'a' + 1 != j)
        ans[j] = ans[j] ? 1 : 0;
    }
  }
  int Ans = 0;
  for (int i = 1; i <= 26; i++) Ans = max(Ans, ans[i]);
  printf("%d\n", Ans);
  return 0;
}
