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>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
using namespace std;
const double pi =
    3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int MR = 1e5 + 10;
const int MS = 30;
const int inf = 1e9;
int dp[MR][MS];
char s[MR];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = (1); i <= (n); ++i) {
    scanf("%s", s);
    map<char, int> M;
    pair<int, int> pref, suf;
    int m = strlen(s);
    {
      for (int i = 0; i < m;) {
        int j = i + 1;
        while (j < m && s[j] == s[i]) j++;
        if (!i) pref = make_pair(s[i] - 'a', j - i);
        if (j == m) suf = make_pair(s[i] - 'a', j - i);
        auto it = M.find(s[i] - 'a');
        if (it == M.end())
          M[s[i] - 'a'] = j - i;
        else if (it->second < j - i)
          it->second = j - i;
        i = j;
      }
    }
    if (M.size() == 1) {
      int k = M.begin()->first;
      dp[i][k] =
          min((dp[i - 1][k] + 1) * (long long)m + dp[i - 1][k], (long long)inf);
    } else {
      if (pref.first == suf.first && dp[i - 1][pref.first])
        dp[i][pref.first] = pref.second + suf.second + 1;
      dp[i][pref.first] =
          max(dp[i][pref.first], pref.second + (dp[i - 1][pref.first] ? 1 : 0));
      dp[i][suf.first] =
          max(dp[i][suf.first], suf.second + (dp[i - 1][suf.first] ? 1 : 0));
      for (const auto &p : M) dp[i][p.first] = max(dp[i][p.first], p.second);
    }
    for (int j = ('a'); j < ('z'); ++j)
      if (!dp[i][j - 'a'] && dp[i - 1][j - 'a']) dp[i][j - 'a'] = 1;
  }
  int res = 0;
  for (int i = ('a'); i <= ('z'); ++i) res = max(res, dp[n][i - 'a']);
  printf("%d\n", res);
  return 0;
}
