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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int rnd(int l, int r) { return l + rng() % (r - l + 1); }
const int maxn = 1e5 + 10;
int f[maxn][30], n, dem[30], ma[30];
string s;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s;
    memset(dem, 0, sizeof(dem));
    memset(ma, 0, sizeof(ma));
    char pre = '*';
    for (int j = 0; j <= s.size() - 1; j++) {
      if (s[j] == pre)
        dem[s[j] - 'a']++;
      else
        pre = s[j], dem[s[j] - 'a'] = 1;
      ma[s[j] - 'a'] = max(ma[s[j] - 'a'], dem[s[j] - 'a']);
    }
    int l = s.size();
    for (int j = 0; j <= 25; j++) {
      f[i][j] = ma[j];
      int pref = 0;
      while (pref < l && s[pref] == (j + 'a')) ++pref;
      int suff = l - 1;
      while (suff > -1 && s[suff] == (j + 'a')) --suff;
      if (pref == l)
        f[i][j] = max(f[i][j], f[i - 1][j] * l + l + f[i - 1][j]);
      else if (f[i - 1][j])
        f[i][j] = max(f[i][j], pref + l - suff);
    }
  }
  int kq = 0;
  for (int i = 0; i <= 25; i++) kq = max(kq, f[n][i]);
  cout << kq;
}
