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 f[101001][27], g[101010][27], n;
string s[1010101];
inline long long read() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int main() {
  n = read();
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    int las = 26, lalen = 0;
    for (char x : s[i]) {
      if (las != x - 'a') {
        g[i][las] = lalen;
        las = x - 'a';
        lalen = 1;
      } else {
        lalen++;
      }
    }
    g[i][las] = lalen;
  }
  for (int i = 0; i < 26; i++) f[1][i] = g[1][i];
  for (int i = 2; i <= n; i++) {
    if (g[i][s[i][0] - 'a'] == s[i].size()) {
      for (int j = 0; j < 26; j++) f[i][j] = (f[i - 1][j] ? 1 : 0);
      f[i][s[i][0] - 'a'] = f[i - 1][s[i][0] - 'a'] +
                            (f[i - 1][s[i][0] - 'a'] + 1) * g[i][s[i][0] - 'a'];
    } else {
      for (int j = 0; j < 26; j++)
        f[i][j] = max(g[i][j] +
                          (j == s[i][s[i].size() - 1] - 'a' ? 1 : 0) *
                              (f[i - 1][j] ? 1 : 0) +
                          (j == s[i][0] - 'a' ? 1 : 0) * (f[i - 1][j] ? 1 : 0),
                      f[i - 1][j] ? 1ll : 0ll);
    }
  }
  long long ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, f[n][i]);
  cout << ans;
  return 0;
}
