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;
struct str {
  int preLen[30], sufLen[30], b[30], len;
  void init(string s) {
    for (int i = 0; i < 30; ++i) {
      preLen[i] = sufLen[i] = b[i] = 0;
    }
    len = s.length();
    int tmp = 0;
    for (int i = 0; i < len; ++i) {
      if (i and s[i] == s[i - 1]) {
        ++tmp;
      } else {
        tmp = 1;
      }
      b[s[i] - 'a'] = max(b[s[i] - 'a'], tmp);
    }
    for (int c = 0; c < 26; ++c) {
      for (int i = 0; i < len and s[i] == c + 'a'; ++i) {
        ++preLen[c];
      }
      for (int i = len - 1; i >= 0 and s[i] == c + 'a'; --i) {
        ++sufLen[c];
      }
    }
  }
};
str operator*(str a, str b) {
  str res;
  res.len = b.len * (a.len + 1) + a.len;
  for (int c = 0; c < 26; ++c) {
    if (b.len == b.preLen[c]) {
      if (a.len == a.preLen[c]) {
        res.preLen[c] = res.len;
      } else {
        res.preLen[c] = b.len * (a.preLen[c] + 1) + a.preLen[c];
      }
      if (a.len == a.sufLen[c]) {
        res.sufLen[c] = res.len;
      } else {
        res.sufLen[c] = b.len * (a.sufLen[c] + 1) + a.sufLen[c];
      }
      res.b[c] = b.len * (a.b[c] + 1) + a.b[c];
    } else {
      res.preLen[c] = b.preLen[c];
      res.sufLen[c] = b.sufLen[c];
      if (a.b[c]) {
        res.b[c] = max(b.preLen[c] + 1 + b.sufLen[c], b.b[c]);
      } else {
        res.b[c] = b.b[c];
      }
    }
  }
  return res;
}
int n, ans;
str ansS;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    if (i) {
      str tmp;
      tmp.init(s);
      ansS = ansS * tmp;
    } else {
      ansS.init(s);
    }
  }
  for (int c = 0; c < 26; ++c) {
    ans = max(ans, ansS.b[c]);
  }
  cout << ans;
}
