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 N = 1e9 + 7;
long long i, j, x, y, z, m, n, k, l, r, f,
    mi = 1e9, ans, x2, y2, nV, t, ma = 0, sq, p[111010], po[111010], a[111010],
    d[111010], dp[111010], x3, y3, x4, y4;
string s[210000];
char c[210000];
int main() {
  scanf("%d", &n);
  for (i = 1; i <= n; i++) {
    scanf(" %s", c);
    s[i] = c;
  }
  for (i = 0; i < 26; i++) {
    for (j = 1; j <= n; j++) dp[j] = 0;
    for (j = 1; j <= n; j++) {
      f = 0;
      for (k = 0; k < s[j].size(); k++) {
        if (s[j][k] - 'a' != i) f = 1;
      }
      if (!f) {
        dp[j] = dp[j - 1] * (s[j].size() + 1) + s[j].size();
      } else {
        l = 0;
        r = 0;
        t = 0;
        long long t2 = 0;
        for (k = 0; k < s[j].size(); k++) {
          if (s[j][k] - 'a' == i)
            t2++;
          else
            t2 = 0;
          if (t2 > k) l = t2;
          t = max(t, t2);
        }
        r = t2;
        if (dp[j - 1])
          dp[j] = max(t, l + r + 1);
        else
          dp[j] = t;
      }
      if (dp[j] > 1e9) dp[j] = 1e9;
    }
    ma = max(ma, dp[n]);
  }
  printf("%d", ma);
}
