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 stress();
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  stress();
}
void stress() {
  long long n;
  cin >> n;
  vector<long long> ans(26);
  for (long long i = 0; i < n; i++) {
    string s;
    cin >> s;
    set<char> ss;
    for (auto it : s) ss.insert(it);
    if (ss.size() == 1) {
      long long x = s[0] - 'a';
      if (ans[x] == 0)
        ans[x] = s.size();
      else
        ans[x] = s.size() * ans[x] + 2 * s.size();
      for (long long i = 0; i < 26; i++)
        if (x != i)
          if (ans[i]) ans[i] = 1;
    } else {
      if (s[0] == s.back()) {
        long long preflen = 0;
        while (s[preflen] == s[0]) preflen++;
        long long suflen = 0;
        while (s[s.size() - suflen - 1] == s.back()) suflen++;
        long long x = s.back() - 'a';
        for (long long i = 0; i < 26; i++) {
          if (ans[i]) ans[i] = 1;
        }
        ans[x] += preflen + suflen;
        for (long long i = 0; i < s.size(); i++) {
          long long k = i;
          while (k < s.size() && s[k] == s[i]) k++;
          long long x = s[i] - 'a';
          ans[x] = max(ans[x], k - i);
        }
      } else {
        long long preflen = 0;
        while (s[preflen] == s[0]) preflen++;
        long long suflen = 0;
        while (s[s.size() - suflen - 1] == s.back()) suflen++;
        for (long long i = 0; i < 26; i++)
          if (ans[i]) ans[i] = 1;
        long long a = s[0] - 'a';
        long long b = s.back() - 'a';
        ans[a] += preflen;
        ans[b] += suflen;
        for (long long i = 0; i < s.size(); i++) {
          long long k = i;
          while (k < s.size() && s[k] == s[i]) k++;
          long long x = s[i] - 'a';
          ans[x] = max(ans[x], k - i);
        }
      }
    }
    for (long long i = 0; i < 26; i++) ans[i] = min(ans[i], (long long)1e9);
  }
  cout << *max_element(ans.begin(), ans.end()) << endl;
}
