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 desperate_optimization(int precision) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.setf(ios::fixed);
  cout.setf(ios::showpoint);
  cout.precision(precision);
}
const int N = 1e5;
long long maxi[27][N + 5];
long long pref[27][N + 5];
long long suff[27][N + 5];
string s[N + 5];
long long fast(long long A, long long B) {
  long long res = 1;
  while (B) {
    if (B & 1) res = res * A;
    A = A * A;
    B /= 2;
  }
  return res;
}
void hora(int tc) {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int last = -1;
    long long tot = 0;
    cin >> s[i];
    for (int j = 0; j < s[i].size(); j++) {
      if (s[i][j] - 'a' != last) {
        last = s[i][j] - 'a';
        tot = 1;
      } else
        tot++;
      maxi[s[i][j] - 'a'][i] = max(maxi[s[i][j] - 'a'][i], tot);
    }
    last = s[i][0] - 'a';
    tot = 1;
    pref[last][i] = 1;
    for (int j = 1; j < s[i].size(); j++) {
      if (s[i][j] - 'a' != last) {
        last = s[i][j] - 'a';
        tot = 1;
        break;
      } else
        tot++;
      pref[last][i] = tot;
    }
    int len = s[i].size();
    last = s[i][len - 1] - 'a';
    tot = 1;
    suff[last][i] = 1;
    for (int j = len - 2; j >= 0; j--) {
      if (s[i][j] - 'a' != last) {
        last = s[i][j] - 'a';
        tot = 1;
        break;
      } else
        tot++;
      suff[last][i] = tot;
    }
  }
  long long res = 0;
  for (int i = n - 1; i >= n - 1; i--) {
    for (int j = 0; j < 26; j++) {
      res = max(res, maxi[j][i]);
    }
  }
  for (int i = n - 2; i >= 0; i--) {
    for (int j = 0; j < 26; j++) {
      if (maxi[j][i]) res = max(res, pref[j][n - 1] + suff[j][n - 1] + 1);
    }
  }
  int rem = -1;
  for (int i = 0; i < 26; i++)
    if (maxi[i][n - 1] == s[n - 1].size()) rem = i;
  if (rem != -1) {
    long long ans = s[n - 1].size();
    for (int i = n - 2; i >= 0; i--) {
      if (maxi[rem][i] == s[i].size()) {
        long long space = s[i].size() + 1;
        long long ntot = ans * space;
        ans = ntot + maxi[rem][i];
      } else {
        long long space = maxi[rem][i] + 1;
        long long ntot = ans * space;
        ans = ntot + maxi[rem][i];
        break;
      }
    }
    res = max(res, ans);
  }
  cout << res << '\n';
}
int main() {
  desperate_optimization(10);
  int ntc = 1;
  for (int tc = 1; tc <= ntc; tc++) hora(tc);
  return 0;
}
