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;
void start(vector<int> &arr, pair<char, int> &prefAns, pair<char, int> &sufAns,
           string &s) {
  int i;
  for (i = 0; i < s.size(); ++i) {
    int cnt = 0;
    while (i + 1 != s.size() && s[i] == s[i + 1]) {
      ++cnt;
      ++i;
    }
    arr[s[i]] = max(arr[s[i]], cnt + 1);
  }
  i = 0;
  while (i + 1 != s.size() && s[i] == s[i + 1]) {
    ++i;
  }
  prefAns = {s[0], i + 1};
  i = s.size() - 1;
  while (i - 1 != -1 && s[i] == s[i - 1]) {
    --i;
  }
  sufAns = {s[s.size() - 1], s.size() - i};
}
char same(string &s) {
  int res = s[0];
  for (auto c : s) {
    if (res != c) {
      return -1;
    }
  }
  return res;
}
void relax(vector<int> &ans, pair<char, int> &prefAns, pair<char, int> &sufAns,
           string &s) {
  for (auto c : s) {
    ans[c] = max(ans[c], (sufAns.first == c) * sufAns.second + 1 +
                             (prefAns.first == c) * prefAns.second);
  }
}
int max(vector<int> &arr) {
  int res = 0;
  for (auto elem : arr) {
    res = max(res, elem);
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  vector<string> arr(n);
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
  }
  vector<int> ans('z' + 1);
  pair<char, int> prefAns;
  pair<char, int> sufAns;
  start(ans, prefAns, sufAns, arr[n - 1]);
  bool flag = (same(arr[n - 1]) != -1);
  for (int i = n - 2; i >= 0; --i) {
    char c = same(arr[i]);
    if (flag && (c != arr[n - 1][0])) {
      c = arr[n - 1][0];
      vector<int> tmpAns('z' + 1);
      pair<char, int> tmpPrefAns;
      pair<char, int> tmpSufAns;
      start(tmpAns, tmpPrefAns, tmpSufAns, arr[i]);
      ans[c] = ans[c] * (tmpAns[c] + 1) + tmpAns[c];
      if (tmpPrefAns.first == c) {
        prefAns = {
            c, prefAns.second * (tmpPrefAns.second + 1) + tmpPrefAns.second};
      }
      if (tmpSufAns.first == c) {
        sufAns = {c, sufAns.second * (tmpSufAns.second + 1) + tmpSufAns.second};
      }
      flag = false;
      continue;
    }
    if (flag) {
      ans[c] = ans[c] * (arr[i].size() + 1) + arr[i].size();
      prefAns = {c, ans[c]};
      sufAns = {c, ans[c]};
    } else {
      relax(ans, prefAns, sufAns, arr[i]);
    }
  }
  cout << max(ans) << endl;
  return 0;
}
