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;
int n, f[2][30], a[100005], b[100005];
string s;
int main() {
  scanf("%d", &n);
  int now = 1, pre = 0;
  for (int i = 1; i <= n; i++, swap(now, pre)) {
    cin >> s;
    int len = s.length();
    memset(f[now], 0, sizeof f[now]);
    for (int j = 0; j < len; j++)
      a[j] = (j == 0             ? 1
              : s[j - 1] == s[j] ? a[j - 1] + 1
                                 : 1),
      b[len - j - 1] =
          (len - j - 1 == len - 1                 ? 1
           : s[len - j - 1 + 1] == s[len - j - 1] ? b[len - j - 1 + 1] + 1
                                                  : 1),
      f[now][s[j] - 'a'] = max(f[now][s[j] - 'a'], a[j]);
    for (int j = 0; j < 26; j++) {
      f[now][j] = max(f[now][j], (f[pre][j] > 0) + (s[0] - 'a' == j) * b[0]),
      f[now][j] = max(f[now][j],
                      (f[pre][j] > 0) + (s[len - 1] - 'a' == j) * a[len - 1]);
      if (a[len - 1] == len && s[0] - 'a' == j)
        f[now][j] = max(f[now][j], f[pre][j] + len * (f[pre][j] + 1));
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, f[pre][i]);
  printf("%d\n", ans);
}
