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;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
int const z = 'z' - 'a' + 1;
vector<int> mostlens(const string& s) {
  vector<int> res(z, 0);
  char pr = '0';
  int cnt = 0;
  for (char c : s) {
    if (pr != c) {
      pr = c;
      cnt = 0;
    }
    res[c - 'a'] = max(res[c - 'a'], ++cnt);
  }
  return res;
}
pair<char, int> getpref(string s, bool rev = false) {
  if (rev) reverse(begin(s), end(s));
  pair<char, int> res = {s[0], 1};
  for (size_t i = 1; i < s.length(); ++i)
    if (s[i] == s[0])
      ++res.second;
    else
      break;
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  int n;
  cin >> n;
  vector<string> a(n);
  for (auto& s : a) cin >> s;
  reverse(begin(a), end(a));
  vector<vector<int>> dp(z, vector<int>(4, 0));
  {
    if (count(begin(a[0]), end(a[0]), a[0][0]) == a[0].length())
      dp[a[0][0] - 'a'][3] = a[0].length();
    auto cnts = mostlens(a[0]);
    for (int i = 0; i < z; ++i) dp[i][0] = cnts[i];
    auto pa = getpref(a[0]);
    dp[pa.first - 'a'][1] = pa.second;
    pa = getpref(a[0], true);
    dp[pa.first - 'a'][2] = pa.second;
  }
  for (int i = 1; i < n; ++i) {
    vector<vector<int>> ndp(z, vector<int>(4, 0));
    auto cnts = mostlens(a[i]);
    for (int j = 0; j < z; ++j)
      ndp[j][0] = max({dp[j][0], dp[j][3] * (1 + cnts[j]) + cnts[j],
                       (cnts[j] > 0) * (dp[j][2] + 1 + dp[j][1])});
    if (count(begin(a[i]), end(a[i]), a[i][0]) == a[i].length())
      ndp[a[i][0] - 'a'][3] = a[i].length() * dp[a[i][0] - 'a'][3];
    auto pa = getpref(a[i]);
    for (int j = 0; j < z; ++j)
      ndp[j][1] =
          max(dp[j][1], dp[j][3] * (1 + (pa.first == 'a' + j) * pa.second));
    pa = getpref(a[i], true);
    for (int j = 0; j < z; ++j)
      ndp[j][2] =
          max(dp[j][2], dp[j][3] * (1 + (pa.first == 'a' + j) * pa.second));
    dp.swap(ndp);
  }
  int res = 0;
  for (int i = 0; i < z; ++i)
    res = max(res, *max_element(dp[i].begin(), dp[i].end()));
  cout << res << endl;
}
