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 <typename T>
vector<T> read_n(long long n) {
  vector<T> ret(n);
  for (long long i = 0; i < n; i++) cin >> ret[i];
  return ret;
}
template <typename iter>
void dump(iter begin, iter end) {
  for (iter it = begin; it != end; it++) {
    if (it != begin) cout << " ";
    cout << *it;
  }
  cout << endl;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  long long n;
  cin >> n;
  vector<string> s(n);
  for (long long i = 0; i < n; i++) cin >> s[i];
  vector<pair<long long, long long> > a(n);
  for (long long i = 0; i < n; i++) {
    long long m = s[i].size();
    long long u = 0, v = 0;
    while (u < m && s[i][u] == s[i][0]) u++;
    while (v < m && s[i][m - v - 1] == s[i][m - 1]) v++;
    a[i] = {u, v};
  }
  auto go = [&](int j, int ch) {
    long long ret = 0;
    long long cur = 0;
    long long m = s[j].size();
    for (long long i = 0; i < m; i++) {
      if (s[j][i] == ch + 'a') {
        cur++;
      } else {
        cur = 0;
      }
      ret = max(ret, cur);
    }
    return ret;
  };
  long long dbg_target = 0;
  long long ret = 1;
  for (long long ch = 0; ch < 26; ch++) {
    long long val = go(0, ch);
    if (ch == dbg_target)
      if (0) cerr << val << endl;
    for (long long i = 1; i < n; i++) {
      long long next = val;
      if (s[i].front() == ch + 'a' && a[i].first == s[i].size()) {
        next = val + (val + 1) * s[i].size();
      } else if (val) {
        next = 1;
        if (s[i].front() == ch + 'a') next += a[i].first;
        if (s[i].back() == ch + 'a') next += a[i].second;
      }
      val = max(next, go(i, ch));
      if (ch == dbg_target)
        if (0) cerr << val << endl;
    }
    ret = max(ret, val);
  }
  cout << ret << "\n";
  return 0;
}
