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;
template <class T>
using VV = vector<vector<T>>;
template <class T>
inline T SMIN(T& a, const T b) {
  return a = (a > b) ? b : a;
}
template <class T>
inline T SMAX(T& a, const T b) {
  return a = (a < b) ? b : a;
}
template <class Iter>
void __kumaerrc(Iter begin, Iter end) {
  for (; begin != end; ++begin) {
    cerr << *begin << ',';
  }
  cerr << endl;
}
void __kumaerr(istream_iterator<string> it) {
  (void)it;
  cerr << endl;
}
template <typename T, typename... Args>
void __kumaerr(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << "=" << a << ", ", __kumaerr(++it, args...);
}
template <typename S, typename T>
std::ostream& operator<<(std::ostream& _os, const std::pair<S, T>& _p) {
  return _os << "{" << _p.first << ',' << _p.second << "}";
}
const int MAX_N = 1e5 + 1;
string P[MAX_N];
int N;
bool cum[MAX_N][26];
long long f(int i, int c) {
  string p = P[i];
  long long res = 0;
  long long cnt = 0;
  int M = int((p).size());
  for (int j = 0; j < (M); ++j) {
    if (p[j] == 'a' + c)
      ++cnt;
    else
      cnt = 0;
    SMAX(res, cnt);
  }
  long long pcnt = 0, scnt = 0;
  for (int j = 0; j < M && p[j] == 'a' + c; ++j) ++pcnt;
  for (int j = M - 1; j >= 0 && p[j] == 'a' + c; --j) ++scnt;
  if (cum[i][c]) SMAX(res, pcnt + scnt + 1);
  if (i > 0 && pcnt == M && scnt == M) {
    long long x = f(i - 1, c);
    SMAX(res, x + (x + 1) * M);
  }
  return res;
}
void solve() {
  for (int i = 0; i < (N); ++i)
    for (int c = 0; c < (26); ++c) {
      cum[i + 1][c] = cum[i][c];
      for (int j = 0; j < (int((P[i]).size())); ++j)
        cum[i + 1][c] |= (P[i][j] == ('a' + c));
    }
  long long res = 0;
  for (int c = 0; c < (26); ++c) SMAX(res, f(N - 1, c));
  cout << res << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(12) << fixed;
  cin >> N;
  for (int i = 0; i < (N); ++i) cin >> P[i];
  solve();
  return 0;
}
