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;
int main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];
  vector<long long> ans(26);
  for (char letter = 'a'; letter <= 'z'; letter++) {
    int ind = letter - 'a';
    long long prev = 0, tmp = 1;
    for (int j = 1; j < s[0].size(); j++) {
      if (s[0][j] != s[0][j - 1]) {
        if (s[0][j - 1] == letter) prev = max(prev, tmp);
        tmp = 0;
      }
      tmp++;
    }
    if (s[0][s[0].size() - 1] == letter) prev = max(prev, tmp);
    for (int i = 1; i < n; i++) {
      string now = s[i];
      long long left = 0, right = 0, now_beauty = 0;
      tmp = 1;
      bool flag = 0;
      for (int j = 1; j < now.size(); j++) {
        if (now[j] != now[j - 1]) {
          if (flag == 0) {
            flag = 1;
            left = tmp;
          }
          if (now[j - 1] == letter) now_beauty = max(now_beauty, tmp);
          tmp = 0;
        }
        tmp++;
      }
      if (now[now.size() - 1] == letter) now_beauty = max(now_beauty, tmp);
      if (flag == 0) left = tmp;
      right = tmp;
      ans[ind] = now_beauty;
      if (prev > 0) {
        ans[ind] = max(1ll, now_beauty);
        if (right == now.size() && now[0] == letter && prev > 0)
          ans[ind] = max(ans[ind], prev + right * (prev + 1));
        else if (now[0] == letter && now[now.size() - 1] == letter && prev > 0)
          ans[ind] = max(ans[ind], left + right + 1);
        else {
          if (now[0] == letter && prev > 0) ans[ind] = max(ans[ind], left + 1);
          if (now[now.size() - 1] == letter && prev > 0)
            ans[ind] = max(ans[ind], right + 1);
        }
      }
      prev = ans[ind];
    }
  }
  long long res = 0;
  for (auto i : ans) res = max(res, i);
  cout << res;
  return 0;
}
