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;
string s[100005];
int n, len1, len2, ans, flag;
char L, R, c;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> s[i];
  int len = s[n].size();
  L = s[n][0], R = s[n][len - 1];
  for (int i = 0; i < len; i++)
    if (s[n][i] == L)
      len1++;
    else
      break;
  for (int i = len - 1; i >= 0; i--)
    if (s[n][i] == R)
      len2++;
    else
      break;
  ans = 1;
  int cnt = 1;
  for (int i = 0; i < len; i++)
    if (s[n][i] == s[n][i + 1])
      ans = max(ans, ++cnt);
    else
      cnt = 1;
  if (L == R && ans == len) flag = 1;
  for (int i = n - 1; i >= 1; i--) {
    len = s[i].size();
    int tmpl = 0, tmpr = 0, cntl = 0, cntr = 0;
    for (int j = 0; j < len; j++)
      if (s[i][j] == L)
        cntl = max(cntl, ++tmpl);
      else
        tmpl = 0;
    for (int j = 0; j < len; j++)
      if (s[i][j] == R)
        cntr = max(cntr, ++tmpr);
      else
        tmpr = 0;
    if (flag) {
      ans = max(ans, cntl * (len1 + 1) + len1);
    } else {
      if (cntl) ans = max(ans, 1 + len1);
      if (cntr) ans = max(ans, 1 + len2);
      if (L == R && cntl && cntr) ans = max(ans, 1 + len1 + len2);
    }
    if (flag) {
      for (int j = 0; j < len; j++)
        if (s[i][j] == L)
          len1 += (1 + len1);
        else {
          flag = 0;
          break;
        }
      for (int j = len - 1; j >= 0; j--)
        if (s[i][j] == R)
          len2 += (1 + len2);
        else {
          flag = 0;
          break;
        }
    }
    ans = max(ans, max(len1, len2));
  }
  cout << ans << endl;
}
