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;
void File() {
  freopen("e.in", "r", stdin);
  freopen("e.out", "w", stdout);
}
template <typename T>
void read(T &_) {
  _ = 0;
  T f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -1;
  for (; isdigit(c); c = getchar()) _ = (_ << 1) + (_ << 3) + (c ^ '0');
  _ *= f;
}
const int maxn = 1e5 + 10;
int n;
vector<int> s[maxn];
char str[maxn];
bool vis[maxn][26];
long long ans;
long long calc(int k, int c) {
  if (!k) return 0;
  long long ret = 0;
  bool flag = true;
  for (int j = 0, j_end_ = s[k].size() - 1; j <= j_end_; ++j)
    if (s[k][j] != c) {
      flag = false;
      break;
    }
  if (!flag) {
    long long up = 0, down = 0, len = 0;
    for (int j = 0, j_end_ = s[k].size() - 1; j <= j_end_; ++j) {
      if (s[k][j] != c) break;
      up = j + 1;
    }
    for (int j = s[k].size() - 1, j_end_ = 0; j >= j_end_; --j) {
      if (s[k][j] != c) break;
      down = s[k].size() - j;
    }
    if (vis[k - 1][c])
      ret = max(ret, up + down + 1);
    else
      ret = max(ret, max(up, down));
    for (int j = 0, j_end_ = s[k].size() - 1; j <= j_end_; ++j) {
      if (s[k][j] != c)
        len = 0;
      else
        ++len;
      ret = max(ret, len);
    }
  } else {
    long long fuck = calc(k - 1, c);
    ret = max(ret, 1ll * (fuck + 1) * (long long)s[k].size() + fuck);
  }
  return ret;
}
int main() {
  read(n);
  for (int i = 1, i_end_ = n; i <= i_end_; ++i) {
    scanf("%s", str + 1);
    for (int j = 1, j_end_ = strlen(str + 1); j <= j_end_; ++j) {
      s[i].push_back(str[j] - 'a');
      vis[i][s[i][j - 1]] = 1;
    }
  }
  for (int i = 1, i_end_ = n; i <= i_end_; ++i)
    for (int j = 0, j_end_ = 25; j <= j_end_; ++j) vis[i][j] += vis[i - 1][j];
  for (int i = 0, i_end_ = 25; i <= i_end_; ++i) ans = max(ans, calc(n, i));
  printf("%lld\n", ans);
  return 0;
}
