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>
template <typename T>
inline void read(T &x) {
  bool b = 0;
  char c;
  while (!isdigit(c = getchar()) && c != '-')
    ;
  if (c == '-') c = getchar(), b = 1;
  x = c - 48;
  while (isdigit(c = getchar())) x = x * 10 + c - 48;
  if (b) x = -x;
}
void reads(std ::string &s) {
  char c;
  while (!isalpha(c = getchar()))
    ;
  s += c;
  while (isalpha(c = getchar())) s += c;
}
using namespace std;
const int N = 1e5 + 11;
int m;
long long n, f[N], ans[50], last[50];
string s;
int main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  if (fopen("m"
            ".inp",
            "r")) {
    freopen(
        "m"
        ".inp",
        "r", stdin);
  }
  read(m);
  long long lastl = 0, lastr = 0;
  int chl, chr;
  for (int ii = 1; ii <= m; ii++) {
    s = '#';
    reads(s);
    n = s.size() - 1;
    for (int i = 0; i < 26; i++) ans[i] = 0;
    for (int i = 1; i <= n; i++) {
      if (s[i] == s[i - 1])
        f[i] = f[i - 1];
      else
        f[i] = 0;
      f[i]++;
      ans[s[i] - 'a'] = max(ans[s[i] - 'a'], f[i]);
    }
    long long l = 1, r = f[n];
    for (int i = 2; i <= n; i++) {
      if (f[i] == 1) break;
      l = f[i];
    }
    if (s[1] == chl) l = lastl + (lastl + 1) * l;
    if (s[n] == chr) r = lastr + (lastr + 1) * r;
    if (s[1] == s[n])
      ans[s[1]] = l + r + 1;
    else
      ans[s[1] - 'a'] = l + (last[s[1] - 'a'] > 0),
                 ans[s[n] - 'a'] = r + (last[s[n] - 'a'] > 0);
    if (l == n) ans[s[1] - 'a'] = last[s[1] - 'a'] + (last[s[1] - 'a'] + 1) * l;
    for (int i = 0; i < 26; i++) {
      int ooooo = 0;
      if (last[i]) ooooo = 1;
      last[i] = ans[i];
      if (!last[i]) last[i] = ooooo;
    }
    chl = s[1] - 'a';
    chr = s[n] - 'a';
    lastl = l;
    lastr = r;
  }
  long long res = max(lastl, lastr);
  for (int i = 0; i <= n; i++) res = max(res, last[i]);
  cout << res;
}
