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 int N = 1e5 + 10;
char s[N];
long long dp[N][26];
int rec[26], recmax[26];
int main() {
  int n, len, l, r;
  long long ans;
  scanf("%d", &n);
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    len = strlen(s + 1);
    memset(rec, 0, sizeof(rec));
    memset(recmax, 0, sizeof(recmax));
    for (int j = 1; j <= len; j++) {
      if (j > 1 && s[j] == s[j - 1])
        rec[s[j] - 'a']++;
      else
        rec[s[j] - 'a'] = 1;
      recmax[s[j] - 'a'] = max(recmax[s[j] - 'a'], rec[s[j] - 'a']);
    }
    for (int j = 0; j < 26; j++) {
      dp[i][j] = recmax[j];
      l = 1;
      r = len;
      while (s[l] == 'a' + j && l <= r) l++;
      while (s[r] == 'a' + j && r > l) r--;
      if (l > len)
        dp[i][j] = max(dp[i][j], (dp[i - 1][j] + 1) * len + dp[i - 1][j]);
      else if (dp[i - 1][j])
        dp[i][j] = max(dp[i][j], 0LL + len - r + l);
    }
  }
  ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[n][i]);
  printf("%I64d\n", ans);
  return 0;
}
