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;
vector<pair<int, int>> RLE(string s) {
  vector<pair<int, int>> v;
  for (int i = 0; i < s.size(); i++) {
    if (v.size() and v.back().first == s[i] - 'a') {
      v.back().second++;
    } else
      v.push_back({s[i] - 'a', 1});
  }
  return v;
}
int dp[2][26];
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    vector<pair<int, int>> v = RLE(s);
    for (int j = 0; j < 26; j++) {
      if (dp[(i % 2) ^ 1][j] > 0)
        dp[i % 2][j] = 1;
      else
        dp[i % 2][j] = 0;
    }
    for (auto p : v) {
      dp[i % 2][p.first] = max(dp[i % 2][p.first], p.second);
    }
    if (v.size() == 1) {
      dp[i % 2][v[0].first] =
          max(dp[i % 2][v[0].first],
              (dp[(i % 2) ^ 1][v[0].first] + 1) * v[0].second +
                  dp[(i % 2) ^ 1][v[0].first]);
    } else {
      if (v[0].first == v.back().first and dp[(i % 2) ^ 1][v[0].first]) {
        dp[i % 2][v[0].first] =
            max(dp[i % 2][v[0].first], v[0].second + v.back().second + 1);
      }
      if (dp[(i % 2) ^ 1][v[0].first]) {
        dp[i % 2][v[0].first] = max(dp[i % 2][v[0].first], 1 + v[0].second);
      }
      if (dp[(i % 2) ^ 1][v.back().first]) {
        dp[i % 2][v.back().first] =
            max(dp[i % 2][v.back().first], 1 + v.back().second);
      }
    }
    for (int j = 0; j < 26; j++) {
      dp[(i % 2) ^ 1][j] = dp[i % 2][j];
    }
  }
  int res = 0;
  for (int i = 0; i < 26; i++) {
    res = max(res, dp[n % 2][i]);
  }
  cout << res << endl;
}
