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 double eps = 1e-8;
const long long mod = 1e9 + 7;
const int inf = 1 << 30;
const int maxn = 1000500;
const double EPS = 1e-7;
long long cn[26], cu[26];
char st[maxn];
int sz;
inline long long getPr() {
  int i = 1;
  while (i < sz && st[i] == st[0]) i++;
  return i;
}
inline long long getSu() {
  int i = sz - 2;
  while (i >= 0 && st[i] == st[sz - 1]) i--;
  return sz - i + 1;
}
inline void upd() {
  for (int j = 0; j < (int)(26); ++j) cu[j] = 0;
  for (int i = 0; i < (int)(sz); ++i) {
    int j = i;
    while (j < sz && st[j] == st[i]) ++j;
    cu[st[i] - 'a'] = max(cu[st[i] - 'a'], j - i * 1LL);
    i = j - 1;
  }
}
void solve() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < (int)(n); ++i) {
    scanf("%s", st);
    sz = strlen(st);
    long long pr = getPr(), su = getSu();
    if (pr == sz) {
      for (int j = 0; j < (int)(26); ++j) {
        if (j == (st[0] - 'a'))
          cn[j] = (cn[j] + 1) * 1LL * pr + cn[j];
        else
          cn[j] = min(cn[j], 1LL);
      }
    } else {
      upd();
      for (int j = 0; j < (int)(26); ++j) cn[j] = min(cn[j], 1LL);
      if (st[0] == st[sz - 1]) {
        if (cn[st[0] - 'a'])
          cn[st[0] - 'a'] = max(cn[st[0] - 'a'], pr + su + 1LL);
      } else {
        if (cn[st[0] - 'a']) cn[st[0] - 'a'] = max(cn[st[0] - 'a'], pr);
        if (cn[st[sz - 1] - 'a'])
          cn[st[sz - 1] - 'a'] = max(cn[st[sz - 1] - 'a'], su + 1);
      }
      for (int j = 0; j < (int)(26); ++j)
        if (cu[j]) cn[j] = max(cn[j], cu[j]);
    }
  }
  long long ret = 0;
  for (int j = 0; j < (int)(26); ++j) ret = max(ret, cn[j]);
  printf("%lld\n", ret);
}
int main() {
  int tc = 1;
  for (int tt = 0; tt < (int)(tc); ++tt) {
    solve();
  }
}
