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;
const int N = 1e5;
vector<int> val[N];
string s[N];
LL solve(int n) {
  LL f1 = 0, len1 = 0, len = 0;
  {
    LL curr = 0;
    for (int x : val[0]) {
      f1 += x;
      if (x == 1) {
        curr++;
        len1 = max(len1, curr);
      } else {
        curr = 0;
      }
    }
    len = val[0].size();
  }
  for (int i = 1; i < n; i++) {
    int pre = 0, suf = 0, tot = 0, best = 0;
    const int sz = val[i].size();
    for (int j = 0; j < sz; j++) {
      if (val[i][j] == 0) break;
      pre++;
    }
    for (int j = sz - 1; j >= 0; j--) {
      if (val[i][j] == 0) break;
      suf++;
    }
    for (int j = 0, curr = 0; j < sz; j++) {
      tot += val[i][j];
      if (val[i][j] == 1) {
        curr++;
        best = max(best, curr);
      } else {
        curr = 0;
      }
    }
    if (tot == sz) {
      len1 = len1 + (len1 + 1) * tot;
    } else {
      if (len1 > 0) len1 = pre + 1 + suf;
      len1 = max(len1, 1ll * best);
    }
    f1 += (len + 1) * tot;
    len += (len + 1) * sz;
  }
  return len1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
    val[i].resize(s[i].size());
  }
  LL ans = 0;
  for (char ch = 'a'; ch <= 'z'; ch++) {
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < (int)s[i].size(); j++) {
        val[i][j] = (s[i][j] == ch);
      }
    }
    ans = max(ans, solve(n));
  }
  cout << ans << endl;
  return 0;
}
