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 dp[26];
void UpdateState(char c, int x) {
  int k = c - 'a';
  dp[k] = (x + (dp[k] > 0));
}
int main() {
  int t, ans = 0;
  string s;
  cin >> t;
  while (t--) {
    cin >> s;
    char startChar = s.front(), endChar = s.back();
    int n = s.size(), startCharLength = 0, endCharLength = 0;
    for (int i = 0; i < n && s[i] == startChar; ++i, ++startCharLength)
      ;
    for (int i = n - 1; i > -1 && s[i] == endChar; --i, ++endCharLength)
      ;
    for (int i = 0; i < 26; ++i) {
      char c = 'a' + i;
      if (c == startChar || c == endChar) {
        continue;
      }
      UpdateState(c, 0);
    }
    if (startCharLength == n) {
      int k = startChar - 'a';
      dp[k] += (dp[k] + 1) * n;
    } else {
      if (startChar == endChar) {
        UpdateState(startChar, startCharLength + endCharLength);
      } else {
        UpdateState(startChar, startCharLength);
        UpdateState(endChar, endCharLength);
      }
    }
    for (int i = 0; i < n;) {
      int j;
      for (j = i; j < n && s[j] == s[i]; ++j)
        ;
      int k = s[i] - 'a';
      dp[k] = max(dp[k], j - i);
      i = j;
    }
  }
  for (int i = 0, n = s.size(); i < n;) {
    int j;
    for (j = i; j < n && s[j] == s[i]; ++j)
      ;
    ans = max(ans, j - i);
    i = j;
  }
  for (int i = 0; i < 26; ++i) {
    ans = max(ans, dp[i]);
  }
  cout << ans << '\n';
  return 0;
}
