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 long long MOD = 1e9 + 7;
vector<char> s[100005];
long long pre[100005][30], su[100005][30];
long long f[100005][30], dp[100005][30];
int n;
inline void getString(int x) {
  char c;
  while ((c = getchar()) == '\n' || c == '\r' || c == ' ')
    ;
  s[x].push_back(c);
  while ((c = getchar()) != '\n' && c != '\r' && c != ' ') s[x].push_back(c);
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    getString(i);
  }
  for (int i = 1; i <= n; i++) {
    long long sum = 1;
    char ch = s[i][0];
    for (int j = 1; j < s[i].size(); j++) {
      if (ch != s[i][j]) break;
      sum++;
    }
    pre[i][ch - 'a'] = sum;
    sum = 1;
    ch = s[i][s[i].size() - 1];
    for (int j = s[i].size() - 1; j >= 0; j++) {
      if (s[i][j] != ch) break;
      sum++;
    }
    su[i][ch - 'a'] = sum;
  }
  for (int i = 1; i <= n; i++) {
    long long sum = 1;
    char ch = s[i][0];
    for (int j = 1; j < s[i].size(); j++) {
      if (s[i][j] != ch) {
        f[i][ch - 'a'] = max(f[i][ch - 'a'], sum);
        sum = 1;
        ch = s[i][j];
      } else
        sum++;
    }
    f[i][ch - 'a'] = max(f[i][ch - 'a'], sum);
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 26; j++) {
      if (f[i][j] == s[i].size()) {
        dp[i][j] = max(dp[i][j], dp[i - 1][j] + (dp[i - 1][j] + 1) * f[i][j]);
      } else {
        dp[i][j] = max(pre[i][j] + su[i][j] + (dp[i - 1][j] ? 1 : 0), f[i][j]);
      }
    }
  }
  long long ans = 0;
  for (int j = 0; j < 26; j++) {
    ans = max(ans, dp[n][j]);
  }
  printf("%I64d", ans);
  return 0;
}
