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 n;
string s[100005];
struct node {
  int l, r, mid;
  bool isall;
};
node a[100005][30];
int dp[100005][30];
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
  }
  for (int i = 1; i <= n; i++) {
    int len = s[i].size();
    for (int j = 0; j < 26; j++) {
      for (int k = 0; k < len; k++) {
        if ('a' + j == s[i][k])
          a[i][j].l++;
        else
          break;
      }
      for (int k = len - 1; k >= 0; k--) {
        if ('a' + j == s[i][k])
          a[i][j].r++;
        else
          break;
      }
      int temp = 0;
      for (int k = 0; k < len; k++) {
        if ('a' + j == s[i][k])
          temp++;
        else {
          a[i][j].mid = max(a[i][j].mid, temp);
          temp = 0;
        }
      }
      a[i][j].mid = max(a[i][j].mid, temp);
      if (temp == len) a[i][j].isall = 1;
    }
  }
  for (int i = 0; i < 26; i++) {
    for (int j = 1; j <= n; j++) {
      if (a[j][i].isall)
        dp[j][i] = dp[j - 1][i] + (dp[j - 1][i] + 1) * a[j][i].mid;
      else if (dp[j - 1][i] != 0)
        dp[j][i] = max(a[j][i].mid, a[j][i].l + a[j][i].r + 1);
      else if (dp[j - 1][i] == 0)
        dp[j][i] = a[j][i].mid;
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[n][i]);
  printf("%d\n", ans);
  return 0;
}
