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 N = 1e5 + 5;
int n, len;
long long mx[26], nmx[26], nst, nen, ans;
char s[N];
bool check() {
  for (int i = 2; i <= len; i++) {
    if (s[i] != s[1]) {
      return 0;
    }
  }
  return 1;
}
void pre() {
  memset(nmx, 0, sizeof nmx);
  nst = 1;
  nen = 1;
  for (int i = 2;; i++) {
    if (s[i] == s[1]) {
      ++nst;
    } else {
      break;
    }
  }
  for (int i = len - 1;; i--) {
    if (s[i] == s[len]) {
      ++nen;
    } else {
      break;
    }
  }
  for (int i = 1, lst = 0, lpos = 1; i <= len + 1; i++) {
    if (s[i] != lst) {
      nmx[lst - 'a'] = max(nmx[lst - 'a'], (long long)i - lpos);
      lst = s[i];
      lpos = i;
    }
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%s", s + 1);
    len = (int)strlen(s + 1);
    if (check()) {
      mx[s[1] - 'a'] = (1LL * len * (mx[s[1] - 'a'] + 1)) + mx[s[1] - 'a'];
      for (int j = 0; j < 26; j++) {
        if (j + 'a' == s[1]) {
          continue;
        }
        mx[j] = min(mx[j], 1LL);
      }
    } else {
      pre();
      for (int j = 0; j < 26; j++) {
        mx[j] = min(mx[j], 1LL);
      }
      if (s[1] == s[len]) {
        if (mx[s[1] - 'a']) {
          mx[s[1] - 'a'] = max(mx[s[1] - 'a'], nst + nen + 1);
        }
      } else {
        if (mx[s[1] - 'a']) {
          mx[s[1] - 'a'] = max(mx[s[1] - 'a'], nst + 1);
        }
        if (mx[s[len] - 'a']) {
          mx[s[len] - 'a'] = max(mx[s[len] - 'a'], nen + 1);
        }
      }
      for (int j = 0; j < 26; j++) {
        mx[j] = max(mx[j], nmx[j]);
      }
    }
  }
  for (int i = 0; i < 26; i++) {
    ans = max(ans, mx[i]);
  }
  printf("%lld\n", ans);
  return 0;
}
