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 input() {
  int x = 0, f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') f |= ch = getchar();
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return f ? -x : x;
}
int n;
string s;
int dp[(int)(1e5 + 7)][26], cnt[26], t1, t2, Ans = 0;
int main() {
  n = input();
  for (int i = 1; i <= n; i++) {
    cin >> s;
    int len = s.length();
    memset(cnt, 0, sizeof(cnt));
    int t = 1;
    for (int j = 1; j < len; j++) {
      if (s[j] != s[j - 1])
        cnt[s[j - 1] - 'a'] = max(cnt[s[j - 1] - 'a'], t), t = 1;
      else
        t++;
    }
    cnt[s[len - 1] - 'a'] = max(cnt[s[len - 1] - 'a'], t);
    t1 = 1, t2 = 1;
    if (len > 1)
      for (int j = 1; j < len; j++)
        if (s[j] == s[j - 1])
          t1++;
        else
          break;
    if (len > 1)
      for (int j = len - 2; j >= 0; j--)
        if (s[j] == s[j + 1])
          t2++;
        else
          break;
    if (t1 == len) {
      int k = s[0] - 'a';
      dp[i][k] = t1 * (dp[i - 1][k] + 1) + dp[i - 1][k];
    }
    for (int j = 0; j < 26; j++) {
      dp[i][j] = max(cnt[j], dp[i][j]);
      if (dp[i - 1][j]) {
        dp[i][j] = max(dp[i][j], 1);
        bool b1 = 0, b2 = 0;
        if (s[0] == 'a' + j) {
          b1 = 1;
          dp[i][j] = max(dp[i][j], t1 + 1);
        }
        if (s[len - 1] == 'a' + j) {
          b2 = 1;
          dp[i][j] = max(dp[i][j], t1 + 1);
        }
        if (b1 && b2) dp[i][j] = max(dp[i][j], t1 + t2 + 1);
      }
    }
  }
  for (int i = 0; i < 26; i++) Ans = max(Ans, dp[n][i]);
  cout << Ans << endl;
}
