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 maxd = 1000000007, N = 100000;
const double pi = acos(-1.0);
int n, pre[30], suf[30], len;
long long dp[100100][30];
char s[100100];
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while ((ch < '0') || (ch > '9')) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while ((ch >= '0') && (ch <= '9')) {
    x = x * 10 + (ch - '0');
    ch = getchar();
  }
  return x * f;
}
void init(int now) {
  scanf("%s", s + 1);
  len = strlen(s + 1);
  int i, j;
  memset(pre, 0, sizeof(pre));
  memset(suf, 0, sizeof(suf));
  for (j = 0; j < 26; j++) {
    int cnt = 0, maxlen = 0;
    for (i = 1; i <= len; i++)
      if (s[i] - 'a' == j) {
        cnt++;
        maxlen = max(maxlen, cnt);
      } else
        cnt = 0;
    dp[now][j] = maxlen;
    for (i = 1; i <= len; i++)
      if (s[i] - 'a' == j)
        pre[j]++;
      else
        break;
    for (i = len; i >= 1; i--)
      if (s[i] - 'a' == j)
        suf[j]++;
      else
        break;
  }
}
int main() {
  n = read();
  init(1);
  int i, j;
  for (i = 2; i <= n; i++) {
    init(i);
    for (j = 0; j < 26; j++) {
      if (dp[i - 1][j]) {
        if (pre[j] == len)
          dp[i][j] =
              max(dp[i][j], 1ll * len * (dp[i - 1][j] + 1) + dp[i - 1][j]);
        else
          dp[i][j] = max(dp[i][j], 1ll * (pre[j] + suf[j] + 1));
      }
    }
  }
  long long ans = 0;
  for (i = 0; i < n; i++) ans = max(ans, dp[n][i]);
  printf("%lld", ans);
  return 0;
}
