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 tong[30], dd[30], ans, n;
char s[150009];
inline long long rd() {
  long long x = 0;
  char c = getchar();
  bool f = 0;
  while (!isdigit(c)) {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = (x << 1) + (x << 3) + (c ^ 48);
    c = getchar();
  }
  return f ? -x : x;
}
int main() {
  n = rd();
  for (int i = 1; i <= n; ++i) {
    scanf("%s", s);
    int len = strlen(s);
    int l = 1, r = 1, now = 1, nowans = 1;
    memset(dd, 0, sizeof(dd));
    for (int j = 1; j < len; ++j)
      if (s[j] == s[j - 1])
        l++;
      else
        break;
    for (int j = len - 2; j >= 0; --j)
      if (s[j] == s[j + 1])
        r++;
      else
        break;
    for (int j = 1; j < len; ++j) {
      if (s[j] == s[j - 1])
        now++;
      else {
        nowans = max(nowans, now);
        dd[s[j - 1] - 'a'] = max(dd[s[j - 1] - 'a'], now);
        now = 1;
      }
    }
    dd[s[len - 1] - 'a'] = max(dd[s[len - 1] - 'a'], now);
    nowans = max(nowans, now);
    if (nowans == len) {
      int x = s[0] - 'a';
      dd[x] = max(dd[x], (tong[x] + 1) * len + tong[x]);
    } else if (s[0] == s[len - 1]) {
      if (tong[s[0] - 'a']) dd[s[0] - 'a'] = max(dd[s[0] - 'a'], l + r + 1);
    } else {
      if (tong[s[0] - 'a']) dd[s[0] - 'a'] = max(dd[s[0] - 'a'], l + 1);
      if (tong[s[len - 1] - 'a'])
        dd[s[len - 1] - 'a'] = max(dd[s[len - 1] - 'a'], r + 1);
    }
    for (int j = 0; j < 26; ++j) tong[j] = (tong[j] != 0);
    for (int j = 0; j < 26; ++j) tong[j] = max(tong[j], dd[j]);
    for (int j = 0; j < len; ++j) s[j] = 0;
  }
  for (int i = 0; i < 26; ++i) ans = max(ans, tong[i]);
  cout << ans;
  return 0;
}
