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;
  string s[n + 1];
  for (int i = 0; i < n; i++) {
    cin >> s[i + 1];
  }
  int dp[26][n + 1];
  for (int i = 0; i < 26; i++) {
    dp[i][0] = 0;
  }
  for (int i = 1; i <= n; i++) {
    int lng = s[i].size();
    char prefletter = s[i][0];
    char suffletter = s[i][lng - 1];
    int preflng = 0;
    int sufflng = 0;
    bool oneletter = true;
    for (int j = 0; j < lng; j++) {
      if (prefletter == s[i][j])
        preflng++;
      else
        break;
    }
    for (int j = lng - 1; j >= 0; j--) {
      if (suffletter == s[i][j])
        sufflng++;
      else
        break;
    }
    for (int j = 1; j < lng; j++) {
      if (s[i][j] != s[i][j - 1]) {
        oneletter = false;
        break;
      }
    }
    for (int j = 'a'; j <= 'z'; j++) {
      dp[j - 'a'][i] = (dp[j - 'a'][i - 1] > 0);
      if (oneletter && prefletter == j) {
        dp[j - 'a'][i] = dp[j - 'a'][i - 1] + lng * (dp[j - 'a'][i - 1] + 1);
      } else {
        if (dp[j - 'a'][i - 1] > 0) {
          dp[j - 'a'][i] = max(dp[j - 'a'][i], 1 + (suffletter == j) * sufflng +
                                                   (prefletter == j) * preflng);
        }
        int maxlong = 0;
        int c = 0;
        for (int k = 0; k < lng; k++) {
          if (s[i][k] == j) {
            maxlong = max(maxlong, ++c);
          } else
            c = 0;
        }
        dp[j - 'a'][i] = max(dp[j - 'a'][i], maxlong);
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) {
    ans = max(ans, dp[i][n]);
  }
  cout << ans;
}
