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;
char s[100010];
long long m[300], ans;
long long dp[100010];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    for (char j = 'a'; j <= 'z'; j++) {
      if (m[j] == 0) continue;
      int k1, k2;
      for (k1 = 0; k1 <= len; k1++) {
        if (s[k1 + 1] != j) break;
      }
      if (k1 == len) {
        m[j] = m[j] + (m[j] + 1) * len;
        if (i == n) ans = max(ans, m[j]);
        continue;
      }
      for (k2 = 0; k2 <= len; k2++) {
        if (s[len - k2] != j) break;
      }
      m[j] = 1 + k1 + k2;
      if (i == n) ans = max(ans, m[j]);
    }
    for (int j = 1; j <= strlen(s + 1); j++) {
      if (s[j] == s[j - 1])
        dp[j] = dp[j - 1] + 1;
      else
        dp[j] = 1;
      m[s[j]] = max(m[s[j]], dp[j]);
      if (i == n) ans = max(ans, m[s[j]]);
    }
  }
  cout << ans;
  return 0;
}
