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[100005][26] = {{0}};
int precalc[100005][26] = {{0}};
int frontlongest[100005][26] = {{0}};
int backlongest[100005][26] = {{0}};
string arr[100005];
int n;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> arr[i];
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      int cur = 0;
      for (auto c : arr[i]) {
        if (c - 'a' == j)
          precalc[i][j] = max(precalc[i][j], ++cur);
        else
          cur = 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      int cur = 0;
      for (int x = 0; x < arr[i].length(); x++) {
        if (arr[i][x] - 'a' == j)
          cur++;
        else
          break;
      }
      frontlongest[i][j] = cur;
      cur = 0;
      for (int x = arr[i].length() - 1; x >= 0; x--) {
        if (arr[i][x] - 'a' == j)
          cur++;
        else
          break;
      }
      backlongest[i][j] = cur;
    }
  }
  for (int i = 0; i < 26; i++) dp[0][i] = precalc[0][i];
  for (int i = 1; i < n; i++) {
    for (int j = 0; j < 26; j++) {
      if (!dp[i - 1][j]) {
        dp[i][j] = precalc[i][j];
        continue;
      }
      if (precalc[i][j] != arr[i].length()) {
        dp[i][j] =
            max(precalc[i][j], frontlongest[i][j] + backlongest[i][j] + 1);
        continue;
      }
      dp[i][j] = arr[i].length() * (dp[i - 1][j] + 1) + dp[i - 1][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[n - 1][i]);
  cout << ans << endl;
}
