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;
string p[100010];
long long n, ans, maxn;
int main() {
  cin >> n;
  for (register int i = 1; i <= n; i++) cin >> p[i];
  for (register int c = 0; c <= 25; c++) {
    maxn = 0;
    int judge, l, r, mid;
    for (register int i = 1; i <= n; i++) {
      judge = 1;
      mid = 0;
      for (register int j = 0; j <= (int)p[i].size() - 1; j++)
        if (p[i][j] != c + 'a') judge = 0;
      int cnt = 0, bo = 1;
      for (register int j = 0; j <= (int)p[i].size() - 1; j++)
        cnt += bo, bo = (bo && p[i][j] == c + 'a');
      l = cnt - 1;
      cnt = 0;
      bo = 1;
      for (register int j = p[i].size() - 1; j >= 0; j--)
        cnt += bo, bo = (bo && p[i][j] == c + 'a');
      r = cnt - 1;
      cnt = 0;
      bo = 1;
      for (register int j = 0; j <= (int)p[i].size() - 1; j++) {
        cnt = (p[i][j] == c + 'a') ? cnt + 1 : 0;
        mid = max(mid, cnt);
      }
      if (judge)
        maxn = maxn + (maxn + 1) * p[i].size();
      else if (maxn == 0)
        maxn = mid;
      else
        maxn = max(mid, l + r + 1);
    }
    ans = max(ans, maxn);
  }
  cout << ans;
}
