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 = 3e5 + 5, mod = 998244353;
template <class o>
inline void qr(o &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + (c ^ 48);
    c = getchar();
  }
  x *= f;
}
template <class o>
void qw(o x) {
  if (x / 10) qw(x / 10);
  putchar(x % 10 + 48);
}
template <class o>
void pr1(o x) {
  if (x < 0) putchar('-'), x = -x;
  qw(x);
  putchar(' ');
}
template <class o>
void pr2(o x) {
  if (x < 0) putchar('-'), x = -x;
  qw(x);
  puts("");
}
inline int ksm(int a, int b = mod - 2) {
  int ans = 1;
  for (; b; b >>= 1, a = 1ll * a * a % mod)
    if (b & 1) ans = 1ll * ans * a % mod;
  return ans;
}
inline int add(int a, int b) { return a += b, a >= mod ? a - mod : a; }
inline int sub(int a, int b) { return a -= b, a < 0 ? a + mod : a; }
string s[N];
int lc[N], rc[N];
long long f[N][26], ans[26], l[N], r[N];
void solve() {
  int n;
  qr(n);
  for (int i = 1; i <= n; ++i) {
    cin >> s[i];
    int m = s[i].size();
    l[i] = r[i] = 1;
    lc[i] = s[i][0] - 'a', rc[i] = s[i][m - 1] - 'a';
    for (int j = 1; j <= m - 1; ++j)
      if (s[i][j] - 'a' == lc[i]) ++l[i];
    for (int j = m - 2; j >= 0; --j)
      if (s[i][j] - 'a' == rc[i]) ++r[i];
    int c = s[i][0] - 'a';
    long long sum = 1;
    for (int j = 1; j <= m - 1; ++j)
      if (s[i][j] - 'a' == c)
        ++sum;
      else
        f[i][c] = max(sum, f[i][c]), c = s[i][j] - 'a', sum = 1;
    f[i][c] = max(sum, f[i][c]);
    if (i == 3000) {
      for (int j = m - 50; j < m; ++j) pr2(s[i][j] - 'a');
    }
  }
  for (int i = 0; i <= 25; ++i) ans[i] = f[1][i] ? f[1][i] : -1;
  for (int i = 2; i <= n; ++i) {
    if (l[i] == s[i].size()) {
      if (ans[lc[i]] != -1) ans[lc[i]] = ans[lc[i]] + l[i] * (ans[lc[i]] + 1);
    } else {
      if (lc[i] == rc[i]) {
        if (ans[lc[i]] != -1) ans[lc[i]] = 1 + l[i] + r[i];
      } else {
        if (ans[lc[i]] != -1) ans[lc[i]] = 1 + l[i];
        if (ans[rc[i]] != -1) ans[rc[i]] = 1 + r[i];
      }
    }
    for (int j = 0; j <= 25; ++j)
      if (j != lc[i] && j != rc[i]) {
        ans[j] = (ans[j] != -1) ? 1 : -1;
      }
    for (int j = 0; j <= 25; ++j) {
      if (i == 2999 && j == 12) pr2(f[i][j]);
      ans[j] = max((f[i][j] ? f[i][j] : -1), ans[j]),
      ans[j] = min(ans[j], (long long)1e9 + 1);
    }
  }
  long long mx = 0;
  for (int i = 0; i <= 25; ++i) mx = max(mx, ans[i]);
  pr2(mx);
}
int main() {
  solve();
  return 0;
}
