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 res[26][200000];
int main() {
  int n;
  cin >> n;
  memset(res, 0, sizeof(res));
  string s;
  long long vec[26];
  for (int i = 1; i <= n; i++) {
    memset(vec, 0, sizeof(vec));
    cin >> s;
    bool bo = true;
    int ta = s.size();
    for (int j = 0; j < s.size() - 1; j++)
      if (s[j] != s[j + 1]) {
        bo = false;
        break;
      }
    if (bo) {
      for (int j = 0; j < 26; j++) res[j][i] = res[j][i - 1] > 0;
      int ax = s[0] - 'a';
      res[ax][i] = (res[ax][i - 1] + 1ll) * ((long long)ta) + res[ax][i - 1];
      if (res[ax][i] > 1e9) res[ax][i] = 1;
    } else {
      if (s[0] == s[s.size() - 1]) {
        int b, e, can = 0;
        for (int j = 0; j < ta - 1; j++) {
          can++;
          if (s[j] != s[j + 1]) {
            b = j + 1;
            break;
          }
        }
        for (int j = ta - 1; j > 0; j--) {
          can++;
          if (s[j] != s[j - 1]) {
            e = j - 1;
            break;
          }
        }
        char ch;
        bool be = false;
        long long cani;
        for (int j = b; j <= e; j++) {
          if (be) {
            if (s[j] == ch)
              cani++;
            else {
              int ax = ch - 'a';
              vec[ax] = max(vec[ax], cani);
              cani = 1;
              ch = s[j];
            }
          } else {
            ch = s[j];
            cani = 1;
            be = true;
          }
        }
        int ax = ch - 'a';
        vec[ax] = max(vec[ax], cani);
        cani = 1;
        ax = s[0] - 'a';
        if (can >= vec[ax]) vec[ax] = can + (res[ax][i - 1] > 0);
        for (int j = 0; j < 26; j++)
          res[j][i] = max((long long)(res[j][i - 1] > 0), vec[j]);
      } else {
        char ch;
        bool be = false;
        long long cani;
        for (int j = 0; j < ta; j++) {
          if (be) {
            if (s[j] == ch)
              cani++;
            else {
              int ax = ch - 'a';
              vec[ax] = max(vec[ax], cani);
              cani = 1;
              ch = s[j];
            }
          } else {
            ch = s[j];
            cani = 1;
            be = true;
          }
        }
        int ax = ch - 'a';
        vec[ax] = max(vec[ax], cani);
        cani = 0;
        for (int j = 0; j < ta - 1; j++) {
          cani++;
          if (s[j] != s[j + 1]) break;
        }
        ax = s[0] - 'a';
        if (cani >= vec[ax]) vec[ax] = cani + (res[ax][i - 1] > 0);
        cani = 0;
        for (int j = ta - 1; j > 0; j--) {
          cani++;
          if (s[j] != s[j - 1]) break;
        }
        ax = s[ta - 1] - 'a';
        if (cani >= vec[ax]) vec[ax] = cani + (res[ax][i - 1] > 0);
        for (int j = 0; j < 26; j++)
          res[j][i] = max((long long)(res[j][i - 1] > 0), vec[j]);
      }
    }
  }
  long long resi = 0;
  for (int i = 0; i < 26; i++) resi = max(resi, res[i][n]);
  cout << resi << endl;
  return 0;
}
