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;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
template <class T>
inline void umin(T &x, T y) {
  x = x < y ? x : y;
}
template <class T>
inline void umax(T &x, T y) {
  x = x > y ? x : y;
}
inline unsigned int R() {
  static unsigned int seed = 416;
  return seed ^= seed >> 5, seed ^= seed << 17, seed ^= seed >> 13;
}
const int N = 102000;
int n;
long long val[N][26];
bool cnt[N][26];
char s[N];
int main() {
  read(n);
  for (register int t = (1); t <= (n); t++) {
    scanf("%s", s + 1);
    int len = strlen(s + 1);
    for (register int i = (0); i <= (25); i++) cnt[t][i] = cnt[t - 1][i];
    for (register int i = (1); i <= (len); i++) cnt[t][s[i] - 'a'] = 1;
    bool flag = 1;
    for (register int i = (1); i <= (len - 1); i++) flag &= s[i] == s[i + 1];
    for (register int i = (0); i <= (25); i++)
      if (cnt[t - 1][i]) {
        val[t][i] = 1;
        for (int j = 1; j <= len; j++)
          if (s[j] == 'a' + i)
            val[t][i]++;
          else
            break;
        for (int j = len; j >= 1; j--)
          if (s[j] == 'a' + i)
            val[t][i]++;
          else
            break;
        if (flag && s[1] == 'a' + i)
          val[t][i] = val[t - 1][i] + 1LL * len * (val[t - 1][i] + 1);
      }
    for (register int i = (1); i <= (len); i++) {
      int j;
      for (j = i; j <= len; j++)
        if (s[j] != s[i]) break;
      umax(val[t][s[i] - 'a'], (long long)j - i);
      i = j - 1;
    }
  }
  long long res = 0;
  for (register int i = (0); i <= (25); i++) umax(res, val[n][i]);
  cout << res;
  return 0;
}
