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 N;
string S[100000];
int ans;
int f(string s, char t) {
  int n = s.size();
  int i = 0;
  int res = 0;
  while (i < n) {
    if (s[i] != t) {
      i++;
      continue;
    }
    int j = i;
    while (i < n && s[i] == s[j]) i++;
    res = max(res, i - j);
  }
  return res;
}
int prefix(string s, char t) {
  int i = 0;
  while (i < s.size() && s[i] == t) i++;
  return i;
}
int suffix(string s, char t) {
  int i = 0;
  while (i < s.size() && s[s.size() - 1 - i] == t) i++;
  return i;
}
int main() {
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S[i];
  }
  reverse(S, S + N);
  int l = S[0].size();
  char fst = S[0].front();
  char lst = S[0].back();
  int pre = prefix(S[0], fst);
  int suf = prefix(S[0], lst);
  for (char i = 'a'; i <= 'z'; i++) {
    ans = max(ans, f(S[0], i));
  }
  bool same = pre == l;
  for (int i = 1; i < N; i++) {
    if (same && count(S[i].begin(), S[i].end(), fst) == S[i].size()) {
      l = l * (S[i].size() + 1) + S[i].size();
      suf = l;
      pre = l;
      ans = max(ans, l);
      continue;
    }
    if (same) {
      int k = f(S[i], fst);
      ans = max(ans, k * (l + 1) + k);
      pre = pre * (prefix(S[i], fst) + 1) + prefix(S[i], fst);
      suf = suf * (suffix(S[i], lst) + 1) + suffix(S[i], lst);
    } else {
      if (fst == lst) {
        ans = max(ans, suf + pre + f(S[i], fst));
      } else {
        ans = max(ans, pre + f(S[i], fst));
        ans = max(ans, suf + f(S[i], lst));
      }
    }
    same = false;
  }
  printf("%d\n", ans);
  return 0;
}
