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;
const int maxx = 1e5 + 7;
int dp[maxx][30], m[30], t[30];
char s[maxx];
int main() {
  int n, ans = 0;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> (s + 1);
    memset(t, 0, sizeof t);
    memset(m, 0, sizeof m);
    int len = strlen(s + 1);
    for (int j = 1; j <= len; j++) {
      if (j != 1 && s[j] == s[j - 1])
        t[s[j] - 'a']++;
      else
        t[s[j] - 'a'] = 1;
      m[s[j] - 'a'] = max(m[s[j] - 'a'], t[s[j] - 'a']);
    }
    for (int j = 0; j < 26; j++) {
      int l = 0, r = 0;
      dp[i][j] = m[j];
      while (l <= len && s[l + 1] == j + 'a') l++;
      while (len - r && s[len - r] == j + 'a') r++;
      if (l == len)
        dp[i][j] = max(dp[i][j], dp[i - 1][j] * (len + 1) + len);
      else if (dp[i - 1][j])
        dp[i][j] = max(dp[i][j], l + r + 1);
      if (i == n) ans = max(dp[i][j], ans);
    }
  }
  cout << ans << endl;
}
