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 = 1e5 + 10;
int dp[N][26];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    int m = s.length();
    vector<pair<int, int> > vp;
    int z[26] = {0};
    for (int j = 0; j < m; j++) {
      if (j == 0 || vp.back().first != s[j]) {
        vp.emplace_back(s[j] - 'a', 1);
      } else
        vp.back().second++;
      z[vp.back().first] = max(z[vp.back().first], vp.back().second);
    }
    if (vp.back().second == m) {
      pair<int, int> pa = vp.back();
      dp[i + 1][pa.first] = dp[i][pa.first] + (dp[i][pa.first] + 1) * m;
      for (int j = 0; j < 26; j++) {
        if (j != pa.first) {
          dp[i + 1][j] = (dp[i][j] > 0);
        }
      }
    } else {
      for (int j = 0; j < 26; j++) {
        if (j == vp.front().first) {
          dp[i + 1][j] = max(z[j], (dp[i][j] > 0) + vp.front().second);
        } else if (j == vp.back().first) {
          dp[i + 1][j] = max(z[j], (dp[i][j] > 0) + vp.back().second);
        } else {
          dp[i + 1][j] = z[j];
        }
      }
    }
  }
  int ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, dp[n][i]);
  cout << ans << endl;
  return 0;
}
