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;
int main() {
  unsigned long long n;
  cin >> n;
  vector<string> v(n);
  vector<vector<unsigned long long>> counter(n, vector<unsigned long long>(26));
  vector<pair<char, unsigned long long>> pref(n), suff(n);
  vector<pair<char, bool>> only(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  for (int i = 0; i < n; ++i) {
    unsigned long long sum = 0;
    for (int j = 0; j < v[i].size() && v[i][j] == v[i][0]; ++j) ++sum;
    pref[i] = make_pair(v[i][0], sum);
    if (sum == v[i].size())
      only[i] = make_pair(v[i][0], 1);
    else
      only[i] = make_pair('/', 0);
    sum = 0;
    for (int j = v[i].size() - 1; j >= 0 && v[i][j] == v[i].back(); --j) ++sum;
    suff[i] = make_pair(v[i].back(), sum);
    char last = v[i][0];
    sum = 1;
    counter[i][int(v[i][0]) - 97] = 1;
    for (int j = 1; j < v[i].size(); ++j) {
      if (v[i][j] == last)
        ++sum;
      else {
        counter[i][int(v[i][j]) - 97] = max(counter[i][int(v[i][j]) - 97], sum);
        sum = 0;
        last = v[i][j];
      }
    }
    counter[i][int(v[i].back()) - 97] =
        max(counter[i][int(v[i].back()) - 97], sum);
  }
  for (int i = 1; i < n; ++i) {
    if (only[i].second && only[i].first == only[i - 1].first) {
      only[i] = make_pair(only[i].first, 1);
      pref[i] = suff[i] = make_pair(
          pref[i].first,
          pref[i - 1].second + (pref[i - 1].second + 1) * pref[i].second);
      counter[i][int(pref[i].first) - 97] = pref[i].second;
      continue;
    } else
      only[i] = make_pair('?', 0);
    if (suff[i].first == pref[i].first) {
      for (int j = 0; j < 26; ++j)
        counter[i][j] =
            max(counter[i][j], (unsigned long long)bool(counter[i - 1][j]));
      int pos = int(pref[i].first) - 97;
      if (counter[i - 1][pos]) {
        counter[i][pos] = pref[i].second + suff[i].second + 1;
      } else
        counter[i][pos] = max(pref[i].second, suff[i].second);
    } else {
      for (int j = 0; j < 26; ++j)
        counter[i][j] =
            max(counter[i][j], (unsigned long long)bool(counter[i - 1][j]));
      int pos = int(pref[i].first) - 97;
      int pos1 = int(suff[i].first) - 97;
      counter[i][pos] = bool(counter[i - 1][pos]) + pref[i].second;
      counter[i][pos1] = bool(counter[i - 1][pos1]) + suff[i].second;
    }
  }
  unsigned long long ma = 0;
  for (int j = 0; j < 26; ++j) ma = max(ma, counter[n - 1][j]);
  cout << ma;
  return 0;
}
