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 MAXN = 100100;
const long long INF = 2000000100;
const long long MOD = 998244353;
int T, N, ans = 1;
int B[300], nB[300], l1, l2;
char c1, c2;
bool prevsame = true;
bool used[300];
string S;
bool issame() {
  char b = S[0];
  for (int i = 1; i < N; i++) {
    if (S[i] != b) return false;
  }
  return true;
}
void output() {
  cerr << c1 << " " << l1 << "   " << c2 << " " << l2 << "\n";
  cerr << prevsame << "\n";
  for (int i = 'a'; i <= 'z'; i++) {
    cerr << used[i] << " ";
  }
  cerr << "\n";
  for (int i = 'a'; i <= 'z'; i++) {
    cerr << B[i] << " ";
  }
  cerr << "\n\n";
}
void update(bool f) {
  N = S.size();
  for (int i = 'a'; i <= 'z'; i++) nB[i] = used[i];
  int prev = S[0];
  int cnt = 1;
  for (int i = 1; i <= N; i++) {
    if (i == N)
      nB[prev] = max(nB[prev], cnt);
    else if (S[i] != prev) {
      nB[prev] = max(nB[prev], cnt);
      prev = S[i];
      cnt = 0;
    }
    cnt++;
  }
  if (issame()) {
    char c = S[0];
    if (f) {
      c1 = c2 = c;
      l1 = l2 = N;
    } else {
      if (prevsame && c1 != c) prevsame = false;
      if (c1 == c)
        l1 = l1 + N * (l1 + 1);
      else
        l1 = N;
      c1 = c;
      if (c2 == c)
        l2 = l2 + N * (l2 + 1);
      else
        l2 = N;
      c2 = c;
    }
    nB[c] = max(nB[c], B[c] + N * (B[c] + 1));
  } else {
    int nl1 = 0, nl2 = 0;
    char nc1, nc2;
    nc1 = S[0];
    nc2 = S[N - 1];
    for (int i = 0; i < N; i++) {
      if (S[i] == nc1)
        nl1++;
      else
        break;
    }
    for (int i = N - 1; i >= 0; i--) {
      if (S[i] == nc2)
        nl2++;
      else
        break;
    }
    if (!f) {
      if (prevsame && c1 == nc1 && c1 == nc2) {
        nB[c1] = nl1 + l1 + nl2;
      } else {
        if (nc1 == nc2 && used[nc1]) nB[c1] = max(nB[c1], nl1 + 1 + nl2);
        if (used[nc1]) nB[c1] = max(nB[c1], nl1 + 1);
        if (used[nc2]) nB[c2] = max(nB[c1], nl2 + 1);
      }
    }
    l1 = nl1;
    l2 = nl2;
    c1 = nc1;
    c2 = nc2;
  }
  for (int i = 'a'; i <= 'z'; i++) B[i] = nB[i];
  for (int i = 0; i < N; i++) used[S[i]] = 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> T;
  for (int i = 0; i < T; i++) {
    cin >> S;
    update(i == 0);
  }
  int ans = -39;
  for (int i = 'a'; i <= 'z'; i++) {
    ans = max(ans, B[i]);
  }
  cout << ans << "\n";
}
