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>
#pragma GCC optimize(3, "Ofast", "inline")
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  Finish_read = 1;
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
}
int n;
bool ocr[100005][26];
string s[100005];
int f[100005][26];
int mx[26];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    memset(mx, 0, sizeof(mx));
    int len = s[i].size(), pre = 0, suf = 0;
    bool ff = 1;
    for (int j = 1; j < len; j++) {
      if (s[i][j] != s[i][0]) {
        ff = 0;
        break;
      }
    }
    int lst = 0;
    for (int j = 1; j < len; j++) {
      if (s[i][j] != s[i][j - 1]) {
        mx[s[i][j - 1] - 'a'] = max(mx[s[i][j - 1] - 'a'], j - lst);
        lst = j;
      }
    }
    mx[s[i][len - 1] - 'a'] = max(mx[s[i][len - 1] - 'a'], len - lst);
    for (int j = 1; j < len; j++) {
      if (s[i][j] != s[i][0]) {
        pre = j;
        break;
      }
    }
    if (!pre) pre = len;
    for (int j = len - 2; j >= 0; j--) {
      if (s[i][j] != s[i][len - 1]) {
        suf = len - j - 1;
        break;
      }
    }
    if (!suf) suf = len;
    for (int j = 0; j < 26; j++) {
      f[i][j] = mx[j];
      ocr[i][j] = ocr[i - 1][j];
      if (mx[j]) ocr[i][j] = 1;
      if (ocr[i][j]) f[i][j] = max(f[i][j], 1);
      if (ff && s[i][0] - 'a' == j) {
        f[i][j] = max(f[i][j], f[i - 1][j] + (f[i - 1][j] + 1) * mx[j]);
      }
      if (s[i][0] == s[i][len - 1] && ocr[i - 1][j] && s[i][0] - 'a' == j) {
        f[i][j] = max(f[i][j], pre + suf + 1);
      }
      if (s[i][0] - 'a' == j && ocr[i - 1][j]) f[i][j] = max(f[i][j], pre + 1);
      if (s[i][len - 1] - 'a' == j && ocr[i - 1][j])
        f[i][j] = max(f[i][j], suf + 1);
    }
  }
  int ans = 0;
  for (int j = 0; j < 26; j++) ans = max(ans, f[n][j]);
  cout << ans << endl;
  return (0);
}
