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 grrr {
  long long mx[26], pref[26], suf[26];
  int ch;
  grrr(string s) {
    for (int i = 0; i < 26; ++i) {
      mx[i] = pref[i] = suf[i] = 0;
    }
    int i = 1;
    ++pref[s[0] - 'a'];
    ++suf[s[s.size() - 1] - 'a'];
    while (i < s.size() && s[i] == s[i - 1]) {
      ++pref[s[i] - 'a'];
      ++i;
    }
    if (i == s.size()) {
      ch = s[0] - 'a';
    } else {
      ch = -1;
    }
    i = int(s.size()) - 2;
    while (i >= 0 && s[i] == s[i + 1]) {
      ++suf[s[i] - 'a'];
      --i;
    }
    i = 1;
    long long len = 1;
    for (; i < s.size(); ++i) {
      mx[s[i - 1] - 'a'] = max(mx[s[i - 1] - 'a'], len);
      if (s[i] == s[i - 1]) {
        len++;
      } else {
        len = 1;
      }
    }
    mx[s[s.size() - 1] - 'a'] = max(mx[s[s.size() - 1] - 'a'], len);
  }
  void operator*=(grrr& g) {
    swap(g, *this);
    if (ch != -1 && g.ch != -1) {
      if (ch == g.ch) {
        long long len = mx[ch] * (g.mx[ch] + 1) + g.mx[ch];
        mx[ch] = pref[ch] = suf[ch] = len;
      } else {
        ch = -1;
        mx[g.ch] = g.mx[g.ch];
      }
      return;
    }
    if (ch != -1) {
      pref[ch] = (g.pref[ch] + 1) * mx[ch] + g.pref[ch];
      suf[ch] = (g.suf[ch] + 1) * mx[ch] + g.suf[ch];
      mx[ch] = (g.mx[ch] + 1) * mx[ch] + g.mx[ch];
      for (int i = 0; i < 26; ++i) {
        if (g.mx[i]) mx[i] = max(mx[i], 1ll);
      }
      ch = -1;
      return;
    }
    for (int i = 0; i < 26; ++i) {
      if (g.mx[i] > 0) {
        mx[i] = max(mx[i], pref[i] + suf[i] + 1);
        mx[i] = max(mx[i], 1ll);
      }
    }
  }
  long long get_max() {
    long long res = 0;
    for (int i = 0; i < 26; ++i) {
      res = max(res, mx[i]);
    }
    return res;
  }
};
int main() {
  int n;
  cin >> n;
  vector<string> p(n + 1);
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
  }
  grrr now(p[1]);
  for (int i = 2; i <= n; ++i) {
    auto g = grrr(p[i]);
    now *= g;
  }
  cout << now.get_max();
}
