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;
struct str {
  long long cnt[26], len = 0;
  pair<long long, long long> pref = {0, 0}, suf = {0, 0};
  str() { memset(cnt, 0, sizeof(cnt)); }
  str(string s) {
    memset(cnt, 0, sizeof(cnt));
    len = ((int)s.size());
    pair<long long, long long> mx = {0, 0};
    for (int i = 0; i < ((int)s.size()); ++i) {
      if (s[i] - 'a' != mx.first)
        mx = {s[i] - 'a', 1};
      else
        mx.second++;
      cnt[mx.first] = max(cnt[mx.first], mx.second);
    }
    mx = {s[0] - 'a', 0};
    for (int i = 0; i < ((int)s.size()); ++i) {
      if (s[i] - 'a' == mx.first)
        mx.second++;
      else
        break;
    }
    pref = mx;
    mx = {s[((int)s.size()) - 1] - 'a', 0};
    for (int i = ((int)s.size()) - 1; i >= 0; --i) {
      if (s[i] - 'a' == mx.first)
        mx.second++;
      else
        break;
    }
    suf = mx;
  }
};
int n;
void debug(str x) {
  cerr << "x.len"
       << " = " << x.len << endl;
  cerr << "x.pref.first"
       << " = " << x.pref.first << endl;
  cerr << "x.pref.second"
       << " = " << x.pref.second << endl;
  cerr << "x.suf.first"
       << " = " << x.suf.first << endl;
  cerr << "x.suf.second"
       << " = " << x.suf.second << endl;
  for (int i = 0; i < 26; ++i) cout << x.cnt[i] << " ";
  cout << "\n\n";
}
str merge(str A, str B) {
  str ret = str();
  ret.pref = B.pref;
  ret.suf = B.suf;
  ret.len = A.len + B.len;
  if (A.pref.second == A.len && B.pref.second == B.len) {
    if (A.pref.first == B.pref.first) {
      ret.pref = ret.suf = {A.pref.first, ret.len};
      ret.cnt[A.pref.first] = ret.len;
    } else {
      ret.cnt[A.pref.first] = A.pref.second;
      ret.cnt[B.pref.first] = B.pref.second;
    }
  } else {
    for (int i = 0; i < 26; ++i) {
      ret.cnt[i] = B.cnt[i];
      if (B.pref.first == B.suf.first && A.pref.second == A.len &&
          i == B.pref.first) {
        if (A.pref.first == B.pref.first)
          ret.cnt[i] = max(ret.cnt[i], B.pref.second + B.suf.second + 1);
        else
          ret.cnt[i] = A.cnt[i];
      } else if (B.pref.second == B.len && i == B.pref.first) {
        ret.cnt[i] = max(ret.cnt[i], B.len * (A.cnt[i] + 1) + A.cnt[i]);
        if (A.pref.first == B.pref.first)
          ret.pref = {A.pref.first,
                      B.len * (A.pref.second + 1) + A.pref.second};
        if (A.suf.first == B.pref.first)
          ret.suf = {A.suf.first, B.len * (A.suf.second + 1) * A.suf.second};
      } else {
        if (i == B.pref.first)
          ret.cnt[i] = max(ret.cnt[i], B.pref.second + (A.cnt[i] > 0));
        if (i == B.suf.first)
          ret.cnt[i] = max(ret.cnt[i], B.suf.second + (A.cnt[i] > 0));
      }
    }
  }
  return ret;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  str sol = str();
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    str x = str(s);
    sol = merge(sol, x);
  }
  long long pr = 0;
  for (int i = 0; i < 26; ++i) pr = max(pr, sol.cnt[i]);
  cout << pr;
}
