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;
const int N = 110000;
const long long mod = 1e9 + 7;
int n;
string s[110000];
int ans;
int f[N][26];
int dp[N][26];
int dfs(int id, char x) {
  if (id == 0) return 0;
  int l = 0, r = 0;
  for (int i = 0; i < s[id].size(); i++)
    if (s[id][i] == x)
      l++;
    else
      break;
  for (int i = s[id].size() - 1; i >= 0; i--)
    if (s[id][i] == x)
      r++;
    else
      break;
  if (l == r && l == s[id].size()) {
    return dfs(id - 1, x) * (l + 1) + l;
  } else if (f[id - 1][x - 'a'])
    return max(l + r + 1, dp[id][x - 'a']);
  else
    return dp[id][x - 'a'];
}
int main() {
  cin.sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> s[i];
    for (char x = 'a'; x <= 'z'; x++) {
      int mx = 0, now = 0;
      for (int j = 0; j < s[i].size(); j++)
        if (s[i][j] == x)
          now++;
        else
          mx = max(now, mx), now = 0;
      mx = max(now, mx);
      dp[i][x - 'a'] = mx;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < 26; j++) f[i][j] = f[i - 1][j];
    for (int j = 0; j < s[i].size(); j++) f[i][s[i][j] - 'a'] = 1;
  }
  for (char i = 'a'; i <= 'z'; i++) ans = max(ans, dfs(n, i));
  cout << ans << endl;
  return 0;
}
