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;
long long isgood(string s, int v) {
  for (int i = 0; i < s.size(); i++) {
    if (s[i] != 'a' + v) return false;
  }
  return true;
}
long long getans(string s, int v) {
  long long ans = 0;
  long long cnt = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a' + v) {
      cnt++;
      ans = max(cnt, ans);
    } else
      cnt = 0;
  }
  return ans;
}
long long getprefans(string s, int v) {
  long long ans = 0;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'a' + v) {
      ans++;
    } else
      break;
  }
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == 'a' + v) {
      ans++;
    } else
      break;
  }
  return ans;
}
long long anslast[26];
bool last[26];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < 26; i++) {
    anslast[i] = getans(s, i);
    last[i] = isgood(s, i);
  }
  long long strsize = 0;
  long long one = 1;
  for (int i = 2; i <= n; i++) {
    string s1;
    cin >> s1;
    for (int j = 0; j < 26; j++) {
      bool now = isgood(s1, j);
      if (last[j] && now) {
        strsize = (strsize + 1) * s1.size() + strsize;
        anslast[j] = (strsize + 1) * s1.size() + strsize;
      } else if (now) {
        strsize = (strsize + 1) * s1.size() + strsize;
        anslast[j] = (anslast[j] + 1) * s1.size() + anslast[j];
        last[j] = 0;
      } else if (last[j]) {
        strsize = (strsize + 1) * s1.size() + strsize;
        anslast[j] = max(getans(s1, j), max(one, getprefans(s1, j) + 1));
        last[j] = 0;
      } else {
        strsize = (strsize + 1) * s1.size() + strsize;
        anslast[j] = max(getans(s1, j),
                         max(min(one, anslast[j]),
                             (getprefans(s1, j) + 1) * min(one, anslast[j])));
      }
    }
  }
  long long ansn = 0;
  for (int i = 0; i < 26; i++) {
    ansn = max(ansn, anslast[i]);
  }
  cout << ansn << "\n";
  return 0;
}
