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 dp[100004][30];
int main() {
  int n;
  scanf("%d", &n);
  string s;
  for (int i = 1; i <= n; ++i) {
    cin >> s;
    int tlen[30] = {0}, maxlen[30] = {0};
    for (int j = 0; j < s.size(); ++j) {
      if (j && s[i] == s[i - 1])
        tlen[s[i] - 'a']++;
      else
        tlen[s[i] - 'a'] = 1;
      maxlen[s[i] - 'a'] = max(maxlen[s[i] - 'a'], tlen[s[i] - 'a']);
    }
    for (int j = 0; j < 26; ++j) {
      dp[i][j] = maxlen[j];
      int l = 0, r = s.size() - 1;
      while (s[l] == j + 'a' && l <= r) l++;
      while (s[r] == j + 'a' && l < r) r--;
      int len = s.size();
      if (l == s.size()) {
        dp[i][j] = max(dp[i][j], len * (dp[i - 1][j] + 1) + dp[i - 1][j]);
      } else if (dp[i - 1][j] != 0) {
        dp[i][j] = max(dp[i][j], l + len - r);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) {
    ans = max(ans, dp[n][i]);
  }
  printf("%d\n", ans);
}
