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;
void maximize(int &x, int y) { x = max(x, y); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  struct character {
    int longest;
    int suffix;
    int prefix;
    character() { longest = suffix = prefix = 0; }
  };
  function<vector<character>(string)> extract = [&](string s) {
    vector<character> ans(26);
    int current = 0;
    for (int i = 0; i < s.size(); ++i) {
      if (i > 0 && s[i] == s[i - 1]) {
        ++current;
      } else {
        current = 1;
      }
      maximize(ans[s[i] - 'a'].longest, current);
      if (i - current + 1 == 0) maximize(ans[s[i] - 'a'].prefix, current);
      if (i == s.size() - 1) maximize(ans[s[i] - 'a'].suffix, current);
    }
    return ans;
  };
  vector<character> a(26);
  int n;
  cin >> n;
  long long totsize = 0;
  for (int i = 0; i < n; ++i) {
    string s;
    cin >> s;
    if (i == 0) {
      a = extract(s);
      totsize = s.size();
    } else {
      vector<character> b = extract(s), tmp(26);
      for (int c = 0; c < 26; ++c) {
        if (a[c].longest == totsize) {
          tmp[c].longest = (a[c].longest + 1) * b[c].longest + a[c].longest;
          if (b[c].longest == s.size()) {
            tmp[c].suffix = tmp[c].prefix = tmp[c].longest;
          } else {
            tmp[c].prefix = b[c].prefix;
            tmp[c].suffix = b[c].suffix;
          }
        } else {
          if (b[c].longest == s.size()) {
            tmp[c].prefix = b[c].longest * (a[c].prefix + 1) + a[c].prefix;
            tmp[c].suffix = b[c].longest * (a[c].suffix + 1) + a[c].suffix;
            tmp[c].longest = b[c].longest * (a[c].longest + 1) + a[c].longest;
          } else {
            tmp[c].prefix = b[c].prefix;
            tmp[c].suffix = b[c].suffix;
          }
          maximize(tmp[c].longest, b[c].longest);
          if (b[c].prefix) maximize(tmp[c].longest, a[c].suffix + b[c].prefix);
          if (b[c].suffix) maximize(tmp[c].longest, a[c].prefix + b[c].suffix);
        }
      }
      if (totsize + (totsize + 1) * s.size() > (long long)1e9)
        totsize = int(1e9) + 1;
      else
        totsize = totsize + (totsize + 1) * s.size();
      a = tmp;
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; ++i) ans = max(ans, a[i].longest);
  cout << ans;
  return 0;
}
