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 GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
using ll = long long;
const int mxN = 100001;
vector<pair<int, int>> arr[mxN];
int curr[26];
int pre[26];
int n;
string alph = "abcdefghijklmnopqrstuvwxyz";
map<char, int> mp;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < 26; ++i) {
    mp[alph[i]] = i;
  }
  string k;
  for (int i = 0; i < n; ++i) {
    cin >> k;
    arr[i].push_back({mp[k[0]], 1});
    for (int j = 1; j < k.size(); ++j) {
      if (k[j] == k[j - 1]) {
        arr[i].back().second++;
      } else {
        arr[i].push_back({mp[k[j]], 1});
      }
    }
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < 26; ++j) {
      curr[j] = (pre[j] > 0);
    }
    if (arr[i].size() == 1) {
      int k = arr[i][0].first;
      for (int j = 0; j < 26; ++j) {
        if (j == k)
          curr[j] = pre[j] + arr[i][0].second * (pre[j] + 1);
        else
          curr[j] = (pre[j] > 0);
      }
    } else {
      for (auto p : arr[i]) {
        curr[p.first] = max(curr[p.first], p.second);
      }
      if (arr[i][0].first == arr[i].back().first) {
        int col = arr[i][0].first;
        if (pre[col] > 0) {
          curr[col] =
              max(curr[col], arr[i][0].second + arr[i].back().second + 1);
        }
      } else {
        int col = arr[i][0].first;
        if (pre[col] > 0) {
          curr[col] = max(curr[col], arr[i][0].second + 1);
        }
        col = arr[i].back().first;
        if (pre[col] > 0) {
          curr[col] = max(curr[col], arr[i].back().second + 1);
        }
      }
    }
    for (int j = 0; j < 26; ++j) {
      pre[j] = curr[j];
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) {
    ans = max(ans, curr[i]);
  }
  cout << ans << "\n";
  return 0;
}
