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;
int main() {
  int n;
  cin >> n;
  vector<string> p(n);
  for (int i = 0; i < n; ++i) {
    cin >> p[i];
  }
  vector<int> best(26, 0);
  for (int i = 0; i < n; ++i) {
    if (p[i] == string(p[i].size(), p[i][0])) {
      int k = best[p[i][0] - 'a'];
      for (int k = 0; k < 26; ++k) {
        best[k] = min(1, best[k]);
      }
      best[p[i][0] - 'a'] = k + p[i].size() * (k + 1);
    } else {
      vector<int> new_best(26, 0);
      int nowl = 1;
      for (int j = 1; j <= p[i].size(); ++j) {
        if (j == p[i].size() || p[i][j] != p[i][j - 1]) {
          new_best[p[i][j - 1] - 'a'] = max(new_best[p[i][j - 1] - 'a'], nowl);
          nowl = 0;
        }
        ++nowl;
      }
      42;
      ;
      int pref = 0;
      while (p[i][pref] == p[i][0]) ++pref;
      int suf = 0;
      while (p[i][p[i].size() - suf - 1] == p[i].back()) ++suf;
      if (p[i][0] == p[i].back()) {
        suf += pref;
        pref = suf;
      }
      new_best[p[i][0] - 'a'] =
          max(new_best[p[i][0] - 'a'], pref + (best[p[i][0] - 'a'] > 0));
      new_best[p[i].back() - 'a'] =
          max(new_best[p[i].back() - 'a'], suf + (best[p[i].back() - 'a'] > 0));
      for (int i = 0; i < 26; ++i) {
        best[i] = max((int)(best[i] > 0), new_best[i]);
      }
      swap(best, new_best);
    }
  }
  cout << *max_element(best.begin(), best.end()) << '\n';
  return 0;
}
