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 int maxn = 1e5 + 10, mod = 1e9 + 7;
const long long inf = 1e18;
int dp[maxn];
string s[maxn];
pair<pair<int, int>, int> solve(string &s, char ch) {
  int a = 0, b = 0, c = 0;
  while (a < int((s).size()) && s[a] == ch) a++;
  while (b < int((s).size()) && s[int((s).size()) - 1 - b] == ch) b++;
  int num = 0;
  for (int i = 0; i < int((s).size()); i++) {
    if (s[i] == ch)
      c = max(c, ++num);
    else
      num = 0;
  }
  return {{a, b}, c};
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s[i];
  }
  int ANS = 0;
  for (char CH = 'a'; CH <= 'z'; CH++) {
    auto P = solve(s[0], CH);
    dp[0] = P.second;
    for (int i = 1; i < n; i++) {
      P = solve(s[i], CH);
      if (P.second == int((s[i]).size()))
        dp[i] = (dp[i - 1] + 1) * (int((s[i]).size()) + 1) - 1;
      else
        dp[i] = max(P.second,
                    dp[i - 1] > 0 ? 1 + P.first.first + P.first.second : 0);
    }
    ANS = max(ANS, dp[n - 1]);
  }
  return cout << ANS << endl, 0;
}
