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 int maxn = 1e5 + 10;
string s[maxn];
int len[maxn];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    len[i] = s[i].length();
  }
  long long ans = 0;
  for (int i = 0; i < 26; i++) {
    char txt = i + 'a';
    long long cnt = 0;
    for (int j = 1; j <= n; j++) {
      int mx1 = 0, mx2 = 0, tmp = 0, L = 0;
      for (int k = 0; k < len[j]; k++) {
        if (s[j][k] == txt)
          tmp++;
        else
          tmp = 0;
        L = max(L, tmp);
      }
      for (int k = 0; k < len[j]; k++) {
        if (s[j][k] == txt)
          mx1++;
        else
          break;
      }
      for (int k = len[j] - 1; k >= 0; k--) {
        if (s[j][k] == txt)
          mx2++;
        else
          break;
      }
      if (mx1 == len[j]) {
        cnt = cnt + 1LL * (cnt + 1) * mx1;
      } else {
        if (cnt)
          cnt = 1 + mx1 + mx2;
        else
          cnt = max(mx1, mx2);
      }
      cnt = max(cnt, 1LL * L);
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
}
