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 = 100005;
int n;
string p[N];
bool b[N][26];
int wrk(int x, char c) {
  if (x == 0) return 0;
  int s, q, t = 0, _t = 0, l = p[x].length();
  for (int i = 0; i < l; i++)
    if (p[x][i] == c)
      ++t;
    else
      break;
  if (t == l) return (l + 1) * wrk(x - 1, c) + l;
  for (int i = l - 1; i; i--)
    if (p[x][i] == c)
      ++_t;
    else
      break;
  s = q = p[x][0] == c;
  for (int i = 1; i < l; i++)
    if (p[x][i] == c)
      ++q;
    else
      s = max(s, q), q = 0;
  s = max(s, q);
  return max((b[x - 1][c - 'a'] ? (((x != 1) ? (t + _t) : max(t, _t)) + 1) : 0),
             s);
}
int main() {
  int i, j, l, t = 1, ans = 1;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> p[i];
    l = p[i].length();
    for (j = 0; j < 26; j++) b[i][j] = b[i - 1][j];
    for (j = 0; j < l; j++) b[i][p[i][j] - 'a'] = 1;
  }
  for (i = 1; i < l; i++)
    if (p[n][i] == p[n][i - 1])
      ++t;
    else
      ans = max(ans, t), t = 1;
  cout << max(max(wrk(n, p[n][0]), wrk(n, p[n][l - 1])), max(ans, t));
  return 0;
}
