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;
long long qnt[30], qnt2[30];
int main() {
  int n;
  cin >> n;
  string A;
  cin >> A;
  if (A.size() == 1)
    qnt[A[0] - 'a'] = 1;
  else {
    for (int i = 0; i < A.size() - 1; i++) {
      long long x = 1, y = A[i] - 'a';
      while (A[i] == A[i + 1] && i < A.size() - 1) x++, i++;
      qnt[y] = max(qnt[y], x);
    }
    if (A[A.size() - 1] != A[A.size() - 2])
      qnt[A[A.size() - 1] - 'a'] = max(qnt[A[A.size() - 1] - 'a'], 1ll);
  }
  for (int i = 1; i < n; i++) {
    memset(qnt2, 0, sizeof qnt2);
    cin >> A;
    long long x = 0, y = 0;
    for (int j = 0; j < A.size(); j++) {
      if (A[j] != A[0]) break;
      x++;
    }
    for (int j = A.size() - 1; j >= 0; j--) {
      if (A[j] != A[A.size() - 1]) break;
      y++;
    }
    if (A.size() == 1)
      qnt2[A[0] - 'a'] = 1;
    else {
      for (int j = 0; j < A.size() - 1; j++) {
        long long xx = 1;
        int yy = A[j] - 'a';
        while (A[j] == A[j + 1] && j < A.size() - 1) xx++, j++;
        qnt2[yy] = max(qnt2[yy], xx);
      }
      if (A[A.size() - 1] != A[A.size() - 2])
        qnt2[A[A.size() - 1] - 'a'] = max(qnt2[A[A.size() - 1] - 'a'], 1ll);
    }
    if (x == A.size()) {
      int u = A[0] - 'a';
      qnt2[u] = x;
      qnt[u] = (qnt[u] + 1) * (qnt2[u] + 1) - 1;
      for (int j = 0; j < 26; j++) {
        if (j == u) continue;
        qnt[j] = min(1ll, qnt[j]);
        qnt[j] = max(qnt2[j], qnt[j]);
      }
    } else if (A[0] == A[A.size() - 1]) {
      int u = A[0] - 'a';
      qnt2[u] = x + y;
      if (qnt[u])
        qnt[u] = qnt2[u] + 1;
      else
        qnt[u] = max(x, y);
      for (int j = 0; j < 26; j++) {
        if (j == u) continue;
        qnt[j] = min(1ll, qnt[j]);
        qnt[j] = max(qnt2[j], qnt[j]);
      }
    } else {
      int v = A[A.size() - 1] - 'a';
      int u = A[0] - 'a';
      qnt2[u] = x;
      qnt2[v] = y;
      qnt[u] = min(qnt[u], 1ll);
      qnt[u] = qnt[u] + qnt2[u];
      qnt[v] = min(qnt[v], 1ll);
      qnt[v] = qnt[v] + qnt2[v];
      for (int j = 0; j < 26; j++) {
        if (j == u || j == v) continue;
        qnt[j] = min(qnt[j], 1ll);
        qnt[j] = max(qnt[j], qnt2[j]);
      }
    }
  }
  long long maior = 0ll;
  for (int i = 0; i < 26; i++) maior = max(maior, qnt[i]);
  cout << maior << "\n";
  return 0;
}
