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;
using i64 = int64_t;
using u64 = uint64_t;
using i32 = int32_t;
using u32 = uint32_t;
const int N = 100100;
int n;
string s[N];
int v[N][26], f[N][26], hcons[N], lcons[N];
void init() {
  for (int i = (0); (i) < (n); (i)++) {
    int last = -1, len = 0;
    for (int j = (0); (j) < (s[i].length()); (j)++) {
      if (s[i][j] == last) {
        len++;
      } else {
        len = 1;
      }
      v[i][s[i][j] - 'a'] = max(v[i][s[i][j] - 'a'], len);
      last = s[i][j];
    }
    int j;
    for (j = 1; j < s[i].length(); j++)
      if (s[i][j] != s[i].front()) break;
    hcons[i] = j;
    for (j = s[i].length() - 2; j >= 0; j--)
      if (s[i][j] != s[i].back()) break;
    lcons[i] = s[i].length() - 1 - j;
  }
}
void debug() {
  for (int i = (0); (i) < (n); (i)++) {
    for (int j = (0); (j) < (26); (j)++)
      printf("f %d %c = %d\n", i, j + 'a', f[i][j]);
  }
}
int main() {
  cin >> n;
  for (int i = (0); (i) < (n); (i)++) cin >> s[i];
  init();
  for (int i = (0); (i) < (26); (i)++) f[0][i] = v[0][i];
  for (int i = (1); (i) < (n); (i)++) {
    int hc = s[i].front() - 'a';
    int lc = s[i].back() - 'a';
    if (v[i][hc] >= s[i].length()) {
      for (int j = (0); (j) < (26); (j)++) f[i][j] = min(f[i - 1][j], 1);
      f[i][hc] = (f[i - 1][hc] + 1) * s[i].length() + f[i - 1][hc];
    } else {
      for (int j = (0); (j) < (26); (j)++) f[i][j] = min(f[i - 1][j], 1);
      f[i][hc] = (f[i - 1][hc] >= 1) + hcons[i];
      f[i][lc] = (f[i - 1][lc] >= 1) + lcons[i];
      if (hc == lc && f[i - 1][hc] >= 1) f[i][hc] = hcons[i] + lcons[i] + 1;
      for (int j = (0); (j) < (26); (j)++) f[i][j] = max(f[i][j], v[i][j]);
    }
  }
  int ans = 0;
  for (int i = (0); (i) < (26); (i)++) ans = max(ans, f[n - 1][i]);
  cout << ans << endl;
  return 0;
}
