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>
inline long long read() {
  long long x = 0;
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') x = (x << 3) + (x << 1) + c - 48, c = getchar();
  return x;
}
long long n, len[100005];
char S[100005];
std::string s[100005];
long long lc, rc;
long long ans, now, flag;
char lp, rp;
signed main() {
  n = read();
  for (register long long i = 1; i <= n; i++)
    scanf("%s", S), s[i] = S, len[i] = s[i].size();
  lp = s[n][0], rp = s[n][len[n] - 1];
  lc = 1;
  for (register long long i = 1; i < len[n]; i++) {
    if (s[n][i] == s[n][i - 1])
      lc++;
    else
      break;
  }
  rc = 1;
  for (register long long i = len[n] - 2; i >= 0; --i) {
    if (s[n][i] == s[n][i + 1])
      rc++;
    else
      break;
  }
  ans = 1;
  now = 1;
  for (register long long i = 1; i < len[n]; i++) {
    if (s[n][i] == s[n][i - 1])
      now++, ans = ((ans) > (now) ? (ans) : (now));
    else
      now = 1;
  }
  if (lc == rc && lc == len[n]) flag = 1;
  for (register long long i = n - 1; i >= 1; --i) {
    if (lc == rc && flag) {
      long long now = (s[i][0] == lp), t = now;
      for (register long long j = 1; j < len[i]; j++) {
        if (s[i][j] == lp && s[i][j] == s[i][j - 1])
          now++, t = ((now) > (t) ? (now) : (t));
        else
          now = 0;
      }
      if (t != len[i]) flag = 0;
      ans = ((ans) > ((long long)t + ((long long)t + 1) * (long long)lc)
                 ? (ans)
                 : ((long long)t + ((long long)t + 1) * (long long)lc));
      if (s[i][0] == lp) {
        long long L = 1;
        for (register long long j = 1; j < len[i]; j++) {
          if (s[i][j] == s[i][j - 1] && s[i][j] == rp)
            L++;
          else
            break;
        }
        lc = (L + 1) * lc + L;
      }
      if (s[i][len[i] - 1] == lp) {
        long long R = 1;
        for (register long long j = len[i] - 2; j >= 0; --j) {
          if (s[i][j] == s[i][j + 1] && s[i][j] == lp)
            R++;
          else
            break;
        }
        rc = R + (R + 1) * rc;
      }
      continue;
    }
    for (register long long j = 0; j < len[i]; j++) {
      if (lp == s[i][j]) ans = ((ans) > (lc + 1) ? (ans) : (lc + 1));
      if (rp == s[i][j]) ans = ((ans) > (rc + 1) ? (ans) : (rc + 1));
      if (lp == rp && lp == s[i][j])
        ans = ((ans) > (lc + rc + 1) ? (ans) : (lc + rc + 1));
    }
  }
  std::cout << ans;
}
