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>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma comment(linker, "/STACK:1024000000,1024000000")
using namespace std;
long long x, y, z[100005][35], vis[100005], rep;
string s;
struct MyStruct {
  long long num, charater;
} a[100005], b[100005];
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  ;
  cin >> x;
  for (int i = 0; i < x; i++) {
    cin >> s;
    vis[i] = s.size();
    long long count = 1;
    char love_Ramadan = s[0];
    for (int j = 1; j < s.size(); j++) {
      if (s[j] != love_Ramadan) {
        if (j == count) a[i] = MyStruct{count, love_Ramadan - 96};
        z[i][love_Ramadan - 96] = max(z[i][love_Ramadan - 96], count);
        count = 0, love_Ramadan = s[j];
      }
      count++;
    }
    b[i] = MyStruct{count, love_Ramadan - 96};
    z[i][love_Ramadan - 96] = max(z[i][love_Ramadan - 96], count);
    if (count == vis[i]) {
      a[i] = b[i];
    }
  }
  long long ans = 0, maxi = 0;
  for (int i = 1; i <= 26; i++) {
    maxi = z[0][i];
    for (int j = 1; j < x; j++) {
      if (maxi == 0) {
        maxi = z[j][i];
        continue;
      }
      if (z[j][i] == vis[j]) {
        maxi = (maxi + 1) * vis[j] + maxi;
        continue;
      }
      rep = 1;
      if (a[j].charater == i) rep += a[j].num;
      if (b[j].charater == i) rep += b[j].num;
      maxi = max(z[j][i], rep);
    }
    ans = max(ans, maxi);
  }
  cout << ans << endl;
  return 0;
}
