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;
long long M = 100000007;
long long size[100005];
bool complete[100005][30];
long long longest[100005][30];
long long rigth[100005][30];
long long left[100005][30];
long long Wrigth[100005][30];
long long Wleft[100005][30];
long long Wlongest[100005][30];
long long Wsize[100005];
bool Wcomplete[100005][30];
int main() {
  int n;
  cin >> n;
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    Wsize[i] = s.size();
    if (i == 0) {
      size[i] = s.size();
    } else {
      size[i] = size[i - 1] + (size[i - 1] + 1LL) * s.size();
    }
    for (int j = 0; j < 28; j++) {
      long long count = 0;
      while (count < s.size() && s[count] - 'a' == j) {
        count++;
      }
      if (count == s.size()) {
        Wcomplete[i][j] = true;
      }
      Wleft[i][j] = count;
      count = 0;
      while (count < s.size() && s[s.size() - 1 - count] - 'a' == j) {
        count++;
      }
      Wrigth[i][j] = count;
      count = 0;
      long long lon = 0;
      for (int k = 0; k < s.size(); k++) {
        if (s[k] - 'a' == j) {
          count++;
          lon = max(lon, count);
        } else {
          count = 0;
        }
      }
      Wlongest[i][j] = lon;
    }
  }
  long long result = 0;
  for (int j = 0; j < 28; j++) {
    complete[0][j] = Wcomplete[0][j];
    longest[0][j] = Wlongest[0][j];
    for (int i = 1; i < n; i++) {
      if (complete[i - 1][j] && Wcomplete[i][j]) {
        longest[i][j] = size[i];
        complete[i][j] = true;
      } else if (Wcomplete[i][j]) {
        longest[i][j] =
            longest[i - 1][j] + (longest[i - 1][j] + 1LL) * Wsize[i];
      } else {
        if (longest[i - 1][j] > 0) {
          longest[i][j] = max(1LL + Wleft[i][j] + Wrigth[i][j], Wlongest[i][j]);
        } else {
          longest[i][j] = Wlongest[i][j];
        }
      }
    }
    result = max(result, longest[n - 1][j]);
  }
  cout << result << '\n';
  return 0;
}
