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;
namespace mine {
const int MAX_N = 110000;
char s[MAX_N];
int f[2][30];
void chmax(int &x, int y) { x = x > y ? x : y; }
void main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    memset(f[i & 1], 0, sizeof f[i & 1]);
    scanf("%s", s + 1);
    int ln = strlen(s + 1);
    int st = s[1] - 'a', ln1 = 1;
    while (ln1 + 1 <= ln and s[ln1 + 1] - 'a' == st) ln1++;
    int lst = st, ln2 = ln1;
    for (int j = ln1 + 1; j <= ln; j++) {
      if (lst != s[j] - 'a')
        chmax(f[i & 1][lst], ln2), lst = s[j] - 'a', ln2 = 1;
      else
        ln2++;
    }
    chmax(f[i & 1][lst], ln2);
    if (ln1 == ln)
      chmax(f[i & 1][st], f[(i - 1) & 1][st] * ln1 + ln1 + f[(i - 1) & 1][st]);
    else if (st == lst and f[(i - 1) & 1][st])
      chmax(f[i & 1][st], 1 + ln1 + ln2);
    else {
      if (f[(i - 1) & 1][st]) chmax(f[i & 1][st], 1 + ln1);
      if (f[(i - 1) & 1][lst]) chmax(f[i & 1][lst], 1 + ln2);
    }
    for (int j = 0; j < 26; j++)
      if (f[(i - 1) & 1][j]) chmax(f[i & 1][j], 1);
  }
  int ans = 1;
  for (int i = 0; i <= 25; i++) chmax(ans, f[n & 1][i]);
  printf("%d", ans);
}
};  // namespace mine
int main() {
  srand(time(0));
  mine::main();
}
