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;
string s[N];
int n;
int state, l, r;
char lc, rc;
int ans = 1;
void init() {
  int len = s[n].length();
  int t = 1;
  for (int i = 1; i < len; i++) {
    if (s[n][i] == s[n][i - 1])
      t++, ans = max(ans, t);
    else
      t = 1;
  }
  lc = s[n][0], rc = s[n][len - 1];
  int gs = 0, p = 0;
  while (p < len && s[n][p] == lc) gs++, p++;
  l = gs;
  p = len - 1, gs = 0;
  while (p >= 0 && s[n][p] == rc) gs++, p--;
  r = gs;
  if (gs == len)
    state = 1;
  else if (lc == rc)
    state = 2;
  else
    state = 3;
}
void cl1(string x) {
  int cl = 0, cr = 0, len = x.length();
  for (int i = 0; i < len; i++) {
    if (x[i] != lc) break;
    cl++;
  }
  for (int i = len - 1; i >= 0; i--) {
    if (x[i] != rc) break;
    cr++;
  }
  int mxl = 0, curl = 0;
  for (char c : x) {
    if (c == lc)
      curl++;
    else
      curl = 0;
    mxl = max(mxl, curl);
  }
  ans = max(ans, (mxl + 1) * l + mxl);
  l = (cl + 1) * l + cl;
  r = (cr + 1) * r + cr;
  if (cl < len) state = 2;
  return;
}
void cl2(string x) {
  int len = x.length();
  for (int i = 0; i < len; i++) {
    if (x[i] == lc || x[i] == rc) ans = max(ans, l + 1 + r);
  }
}
void cl3(string x) {
  int len = x.length();
  for (int i = 0; i < len; i++) {
    if (x[i] == lc) ans = max(ans, l + 1);
    if (x[i] == rc) ans = max(ans, r + 1);
  }
}
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  init();
  for (int i = n - 1; i >= 1; i--) {
    if (state == 1)
      cl1(s[i]);
    else if (state == 2)
      cl2(s[i]);
    else
      cl3(s[i]);
    ans = max(ans, max(l, r));
  }
  cout << ans << endl;
}
