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;
using ll = long long;
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (T e : v) {
    os << e << ' ';
  }
  return os;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  vector<string> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  int best = 1;
  for (char c = 'a'; c <= 'z'; ++c) {
    int longest = 0, pref = 0, suf = 0;
    for (const auto& s : p) {
      bool pure = true, contains = false;
      for (char cc : s) {
        if (cc != c) {
          pure = false;
        } else {
          contains = true;
        }
      }
      int m = s.size();
      if (pure) {
        pref = (pref + 1) * m + pref;
        suf = (suf + 1) * m + suf;
        longest = (longest + 1) * m + longest;
        continue;
      }
      int i = 0, tmp = 0, cx = 0, cur_pref = 0, cur_suf = 0;
      while (i < m && s[i] == c) {
        ++i;
        ++cur_pref;
      }
      for (i = 0; i < m; ++i) {
        if (s[i] == c) {
          ++tmp;
        } else {
          cx = max(cx, tmp);
          tmp = 0;
        }
      }
      cx = max(cx, tmp);
      i = m - 1;
      while (i >= 0 && s[i] == c) {
        --i;
        ++cur_suf;
      }
      longest = max((longest ? 1 : 0) + cur_pref + cur_suf, cx);
      suf = cur_suf;
      pref = cur_pref;
    }
    best = max(best, longest);
  }
  cout << best << '\n';
  return 0;
}
