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 long long inff = 0x3f3f3f3f3f3f3f3f;
int a[28], b[28];
int now[28];
char s[100008];
int g[100008];
int main() {
  int n;
  int h, t, k;
  scanf("%d", &n);
  while (n--) {
    for (int i = 0; i < 26; i++) {
      now[i] = 0;
    }
    scanf("%s", &s);
    k = strlen(s) - 1;
    h = s[0] - 'a';
    int tot = 0;
    g[tot] = 1;
    for (int i = 1; s[i]; i++) {
      if (s[i] == s[i - 1]) {
        g[tot]++;
      } else {
        now[s[i - 1] - 'a'] = max(now[s[i - 1] - 'a'], g[tot]);
        tot++;
        g[tot] = 1;
      }
    }
    now[s[k] - 'a'] = max(now[s[k] - 'a'], g[tot]);
    for (int i = 0; i < 26; i++) {
      if (a[i] == 0 && now[i] == 0) {
        b[i] = 0;
      } else if (a[i] <= now[i]) {
        b[i] = now[i];
      } else if (a[i] > now[i]) {
        b[i] = max(now[i], 1);
      }
    }
    if (tot == 0) {
      b[s[0] - 'a'] = (a[s[0] - 'a'] + 1) * (now[s[0] - 'a']) + a[s[0] - 'a'];
    } else if ((s[0] - 'a') == (s[k] - 'a')) {
      if (a[s[0] - 'a'] > 0) {
        b[s[0] - 'a'] = max(b[s[0] - 'a'], g[0] + g[tot] + 1);
      }
    } else {
      if (a[s[0] - 'a'] > 0) {
        b[s[0] - 'a'] = max(b[s[0] - 'a'], g[0] + 1);
      }
      if (a[s[k] - 'a'] > 0) {
        b[s[k] - 'a'] = max(b[s[k] - 'a'], g[tot] + 1);
      }
    }
    for (int i = 0; i < 26; i++) {
      a[i] = b[i];
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    ans = max(ans, a[i]);
  }
  cout << ans << endl;
}
