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 maxn = 100000 + 1;
char s[maxn];
int cnt[128];
int main() {
  int n, len, ans, l, r;
  bool same;
  cin >> n >> s, len = strlen(s);
  for (int i = 0; i < len;) {
    int j = i, k = 0;
    while (j < len && s[j] == s[i]) ++j;
    cnt[s[i]] = max(cnt[s[i]], j - i), i = j;
  }
  while (--n) {
    cin >> s, len = strlen(s), ans = 0, same = true;
    for (int i = 1; i < len && same; ++i) same = s[i] == s[0];
    if (same) {
      for (int i = 'a'; i <= 'z'; ++i)
        if (cnt[i] && i != s[0]) cnt[i] = 1;
      ans = cnt[s[0]] = (cnt[s[0]] + 1) * len + cnt[s[0]];
    } else {
      l = 0, r = 0;
      while (l < len && s[l] == s[0]) ++l;
      while (r < len && s[len - 1 - r] == s[len - 1]) ++r;
      for (int i = 'a'; i <= 'z'; ++i)
        if (cnt[i])
          cnt[i] = 1,
          ans = max(ans, 1 + (i == s[0] ? l : 0) + (i == s[len - 1] ? r : 0));
      if (s[0] == s[len - 1])
        cnt[s[0]] = cnt[s[0]] ? 1 + l + r : max(l, r);
      else
        cnt[s[0]] = (cnt[s[0]] ? 1 : 0) + l,
        cnt[s[len - 1]] = (cnt[s[len - 1]] ? 1 : 0) + r;
      for (int i = 0; i < len;) {
        int j = i, k = 0;
        while (j < len && s[j] == s[i]) ++j;
        cnt[s[i]] = max(cnt[s[i]], j - i), ans = max(ans, j - i), i = j;
      }
    }
  }
  cout << ans;
  return 0;
}
