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 + 5;
long long dp[maxn][30], num[30], len;
int c_nt(string s) {
  int cnt = 1, j = 0, len = s.length();
  while (j + 1 < len && s[j] == s[j + 1]) cnt++, j++;
  return cnt;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    string s;
    cin >> s;
    memset(num, 0, sizeof(num));
    len = s.length();
    for (int j = 0; j < len; j++) {
      long long cnt = 1;
      while (j + 1 < len && s[j] == s[j + 1]) cnt++, j++;
      num[s[j] - 'a'] = max(num[s[j] - 'a'], cnt);
    }
    pair<int, int> l1, l2;
    l1 = {s[0] - 'a', c_nt(s)};
    reverse(s.begin(), s.end());
    l2 = {s[0] - 'a', c_nt(s)};
    for (int j = 0; j < 26; j++) {
      dp[i][j] = num[j];
      if (l1.second == len && l1.first == j) {
        if (1e10 / len > dp[i - 1][j] + 1) {
          dp[i][j] = 1;
          continue;
        }
        dp[i][j] = (dp[i - 1][j] + 1) * len + dp[i - 1][j];
        if (dp[i][j] > 1e9) dp[i][j] = 1;
      } else if (l1.first == l2.first && l1.first == j) {
        long long cmp = l1.second + l2.second + (dp[i - 1][j] >= 1);
        dp[i][j] = max(dp[i][j], cmp);
      } else if (l1.first == j) {
        long long cmp = l1.second + (dp[i - 1][j] >= 1);
        dp[i][j] = max(dp[i][j], cmp);
      } else if (l2.first == j) {
        long long cmp = l2.second + (dp[i - 1][j] >= 1);
        dp[i][j] = max(dp[i][j], cmp);
      } else if (dp[i - 1][j])
        dp[i][j] = 1;
    }
  }
  long long ans = 0;
  for (int i = 0; i <= 25; i++) ans = max(ans, dp[n][i]);
  cout << ans;
}
