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 = 1e5 + 7, C = 26;
int n, maxStr[C];
string str[N];
long long pref, suf, prefC, sufC, res, len;
bool oneC = 1;
void calc(string &str) {
  for (int i = 0; i < C; ++i) {
    maxStr[i] = 0;
  }
  int act;
  for (int i = 0; i < str.size(); ++i) {
    if (i && str[i] == str[i - 1]) {
      act++;
    } else {
      act = 1;
    }
    maxStr[str[i] - 'a'] = max(maxStr[str[i] - 'a'], act);
  }
}
int getPref(string &str) {
  int pref = 1;
  while (pref < str.size() && str[pref] == str[0]) {
    pref++;
  }
  return pref;
}
int getSuf(string &str) {
  int suf = 1;
  while (suf < str.size() && str[n - suf - 1] == str.back()) {
    suf++;
  }
  return suf;
}
bool one(string &str) {
  bool res = 1;
  for (auto i : str) {
    res &= i == str[0];
  }
  return res;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> str[i];
  }
  reverse(str, str + n);
  pref = getPref(str[0]);
  suf = getSuf(str[0]);
  prefC = str[0][0] - 'a';
  sufC = str[0].back() - 'a';
  oneC = one(str[0]);
  len = str[0].size();
  calc(str[0]);
  for (int i = 0; i < n; ++i) {
    res = max(res, 1ll * maxStr[i]);
  }
  for (int i = 1; i < n; ++i) {
    calc(str[i]);
    for (int i = 0; i < n; ++i) {
      res = max(res, 1ll * maxStr[i]);
    }
    for (int i = 0; i < C; ++i) {
      if (!maxStr[i]) {
        continue;
      }
      res = max(res, pref * (i == prefC) + suf * (i == sufC) + 1);
      if (oneC && prefC == i) {
        res = max(res, (maxStr[i] + 1) * len);
      }
    }
    if (oneC) {
      if (str[i][0] - 'a' == prefC) {
        pref = len * (getPref(str[i]) + 1);
      }
      if (str[i].back() - 'a' == sufC) {
        suf = len * (getSuf(str[i]) + 1);
      }
    }
    oneC &= getPref(str[i]) == str[i].size() && str[i][0] - 'a' == prefC;
    len = len * str[i].size() + len + str[i].size();
  }
  cout << res << "\n";
  return 0;
}
