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;
using ll = long long;
constexpr int NMAX = 100000;
char str[NMAX];
int main() {
  int n;
  scanf("%d", &n);
  vector<int> lrun(26, 0);
  vector<bool> isInString(26, false);
  for (int pi = 0; pi < n; ++pi) {
    scanf("%s", str);
    int clen = strlen(str);
    int prefBreak = 0, suffBreak = clen - 1;
    while (prefBreak < clen && str[0] == str[prefBreak]) ++prefBreak;
    while (suffBreak >= 0 && str[0] == str[suffBreak]) --suffBreak;
    for (int i = 0; i < clen; ++i) isInString[str[i] - 'a'] = true;
    if (prefBreak == clen) {
      for (int i = 0; i < 26; ++i) {
        if (i + 'a' == str[0]) {
          lrun[i] += (lrun[i] + 1) * clen;
        } else {
          lrun[i] = 1;
        }
      }
    } else {
      int crlen = 0;
      vector<int> intruns(26, 0);
      for (int i = 0; i < clen; ++i) {
        if (i == 0 || str[i] != str[i - 1]) {
          crlen = 1;
        } else {
          ++crlen;
        }
        intruns[str[i] - 'a'] = max(intruns[str[i] - 'a'], crlen);
      }
      vector<int> spruns(26, 0);
      if (isInString[str[0] - 'a']) spruns[str[0] - 'a'] += prefBreak + 1;
      if (isInString[str[clen - 1] - 'a'])
        spruns[str[clen - 1] - 'a'] += (clen - suffBreak);
      if (str[0] == str[clen - 1] && isInString[str[0] - 'a'])
        --spruns[str[0] - 'a'];
      for (int i = 0; i < 26; ++i) {
        if (isInString[i]) lrun[i] = 1;
        lrun[i] = max(lrun[i], max(spruns[i], intruns[i]));
      }
    }
  }
  printf("%d\n", *max_element(begin(lrun), end(lrun)));
  return 0;
}
