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> a(n);
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> dp(26);
  vector<int> b(26);
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < 26; j++) b[j] = 0;
    int tmp = 1;
    for (int j = 1; j < a[i].length(); j++) {
      if (a[i][j] == a[i][j - 1])
        tmp++;
      else
        b[a[i][j - 1] - 'a'] = max(b[a[i][j - 1] - 'a'], tmp), tmp = 1;
    }
    b[a[i].back() - 'a'] = max(b[a[i].back() - 'a'], tmp);
    int l = 1, r = 1;
    for (int j = 1; j < a[i].length() && a[i][j] == a[i].front(); j++) l++;
    for (int j = a[i].length() - 2; j >= 0 && a[i][j] == a[i].back(); j++) r++;
    for (int j = 0; j < 26; j++) {
      if (l == r) {
        if (dp[j])
          if (j + 97 == int(a[i][0]))
            dp[j] = (dp[j] + 1) * b[j] + dp[j];
          else
            dp[j] = max(1, b[j]);
        else
          dp[j] = b[j];
      } else {
        if (dp[j])
          if (a[i].front() == a[i].back()) {
            if (j + 97 == int(a[i].front()))
              dp[j] = max(b[j], l + r + 1);
            else
              dp[j] = max(1, b[j]);
          } else {
            if (j + 97 == int(a[i].front()))
              dp[j] = max(b[j], l + 1);
            else if (j + 97 == int(a[i].back()))
              dp[j] = max(b[j], r + 1);
            else
              dp[j] = max(1, b[j]);
          }
        else
          dp[j] = b[j];
      }
    }
  }
  int maxs = 0;
  for (int i = 0; i < 26; i++) maxs = max(maxs, dp[i]);
  cout << maxs;
  return 0;
}
