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;
int i, n, m, f[200005][26], dp[200005][26], d[26], cnt, k, l, r, ans, j;
string s[200005];
int check(string s) {
  int n = s.length(), i;
  for (i = 1; i < n; i++)
    if (s[i] != s[0]) return 0;
  return 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (i = 1; i <= n; i++) cin >> s[i];
  for (i = 1; i <= n; i++) {
    for (j = 0; j <= 25; j++) f[i][j] = f[i - 1][j];
    m = s[i].length();
    for (j = 0; j < m; j++) f[i][s[i][j] - 'a'] = 1;
  }
  for (i = 1; i <= n; i++) {
    m = s[i].length();
    cnt = 0;
    if (check(s[i])) {
      for (j = 0; j <= 25; j++)
        if (f[i][j])
          dp[i][j] = 1;
        else
          dp[i][j] = 0;
      k = s[i][0] - 'a';
      dp[i][k] = dp[i - 1][k] + m * (dp[i - 1][k] + 1);
      continue;
    }
    for (j = 0; j <= 25; j++) d[j] = 0;
    for (j = 0; j < m; j++) {
      cnt++;
      if (s[i][j] != s[i][j + 1] || j == m - 1) {
        d[s[i][j] - 'a'] = max(d[s[i][j] - 'a'], cnt);
        cnt = 0;
      }
    }
    r = m - 1;
    l = 0;
    while (s[i][r] == s[i][m - 1]) r--;
    while (s[i][l] == s[i][0]) l++;
    r = m - r - 1;
    for (j = 0; j <= 25; j++)
      if (f[i][j])
        dp[i][j] = max(1, d[j]);
      else
        dp[i][j] = 0;
    if (s[i][0] == s[i][m - 1] && f[i - 1][s[i][0] - 'a']) {
      k = s[i][0] - 'a';
      dp[i][k] = max(dp[i][k], l + r + 1);
    } else {
      k = s[i][0] - 'a';
      if (f[i - 1][k]) dp[i][k] = max(dp[i][k], l + 1);
      k = s[i][m - 1] - 'a';
      if (f[i - 1][k]) dp[i][k] = max(dp[i][k], r + 1);
    }
  }
  for (i = 0; i <= 25; i++) ans = max(ans, dp[n][i]);
  cout << ans;
}
