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 <typename T>
inline void ckmax(T& x, T y) {
  x = (y > x ? y : x);
}
template <typename T>
inline void ckmin(T& x, T y) {
  x = (y < x ? y : x);
}
const int MAXN = 1e5, MAXLEN = 1e5;
int n;
long long f[MAXN + 5][26];
char s[MAXLEN + 5];
int main() {
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> (s + 1);
    int len = strlen(s + 1);
    int pre = 1;
    for (int j = 2; j <= len; ++j) {
      if (s[j] == s[1])
        pre++;
      else
        break;
    }
    int suf = 1;
    for (int j = len - 1; j >= 1; --j) {
      if (s[j] == s[len])
        suf++;
      else
        break;
    }
    for (int j = 0; j < 26; ++j) {
      f[i][j] = (f[i - 1][j] > 0);
    }
    for (int j = 1; j <= len; ++j) {
      int k = j;
      while (k + 1 <= len && s[k + 1] == s[j]) ++k;
      ckmax(f[i][s[j] - 'a'], (long long)k - j + 1);
      j = k;
    }
    if (pre == len) {
      f[i][s[1] - 'a'] =
          (f[i - 1][s[1] - 'a'] + 1) * len + f[i - 1][s[1] - 'a'];
    } else {
      ckmax(f[i][s[1] - 'a'], (long long)pre + (f[i - 1][s[1] - 'a'] != 0));
      ckmax(f[i][s[len] - 'a'], (long long)suf + (f[i - 1][s[len] - 'a'] != 0));
      if (s[1] == s[len] && f[i - 1][s[1] - 'a']) {
        ckmax(f[i][s[1] - 'a'], (long long)pre + suf + 1);
      }
    }
  }
  long long ans = 0;
  for (int j = 0; j < 26; ++j) ckmax(ans, f[n][j]);
  cout << ans << endl;
  return 0;
}
