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 MAXC = 30;
int cc[MAXC], pf[MAXC], sf[MAXC], n;
int lcc[MAXC], rcc[MAXC];
void getdet(string &a) {
  for (int i = 0; i < MAXC; i++) cc[i] = pf[i] = sf[i] = 0;
  int cnt = 0;
  for (int i = 0; i < a.size(); i++) {
    if (i == 0 || a[i] == a[i - 1])
      cnt++;
    else
      cnt = 1;
    cc[a[i] - 'a'] = max(cc[a[i] - 'a'], cnt);
  }
  for (char t = 'a'; t <= 'z'; t++) {
    cnt = 0;
    for (int i = 0; i < a.size(); i++) {
      if (a[i] != t) break;
      cnt++;
    }
    pf[t - 'a'] = cnt;
    cnt = 0;
    for (int i = (int)a.size() - 1; i >= 0; i--) {
      if (a[i] != t) break;
      cnt++;
    }
    sf[t - 'a'] = cnt;
  }
}
int main() {
  cin >> n;
  for (int q = 0; q < n; q++) {
    string tmp;
    cin >> tmp;
    getdet(tmp);
    if (q == 0) {
      swap(lcc, cc);
      continue;
    }
    for (int i = 0; i < MAXC; i++) rcc[i] = 0;
    for (char t = 'a'; t <= 'z'; t++) {
      rcc[t - 'a'] = cc[t - 'a'];
      if (lcc[t - 'a'] > 0)
        rcc[t - 'a'] = max(rcc[t - 'a'], 1 + pf[t - 'a'] + sf[t - 'a']);
      if (pf[t - 'a'] == tmp.size())
        rcc[t - 'a'] = max(rcc[t - 'a'],
                           lcc[t - 'a'] + (lcc[t - 'a'] + 1) * (int)tmp.size());
    }
    swap(rcc, lcc);
  }
  int ans = 0;
  for (int i = 0; i < MAXC; i++) ans = max(ans, lcc[i]);
  cout << ans;
}
