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;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long rand(long long l, long long r) {
  uniform_int_distribution<long long> uid(l, r);
  return uid(rng);
}
const int mod = 1e9 + 7;
int pwr(int a, long long b) {
  int ans = 1;
  while (b) {
    if (b & 1) {
      ans = ((long long)ans * a) % mod;
    }
    a = ((long long)a * a) % mod;
    b >>= 1;
  }
  return ans;
}
const int N = 1e5 + 5;
int lol[N][26], pre[N][26], suf[N][26];
bool eq[N];
char z[N];
int cur[26];
int cur1[26];
string p[N];
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    for (int j = 0; j <= (int)p[i].size() - 1; j++) {
      char ch = p[i][j];
      int pt = j;
      while (pt < (int)p[i].size() && p[i][pt] == ch) pt++;
      lol[i][ch - 'a'] = max(lol[i][ch - 'a'], pt - j);
      if (j == 0) pre[i][ch - 'a'] = pt - j;
      if (pt == (int)p[i].size()) suf[i][ch - 'a'] = pt - j;
      if (j == 0 && pt == (int)p[i].size()) {
        z[i] = ch, eq[i] = 1;
      }
      j = pt - 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j <= 25; j++) {
      cur1[j] = max(cur1[j], lol[i][j]);
      if (cur[j]) cur1[j] = max(cur1[j], pre[i][j] + suf[i][j] + 1);
    }
    if (eq[i]) {
      cur1[z[i] - 'a'] =
          max(cur1[z[i] - 'a'],
              cur[z[i] - 'a'] + (cur[z[i] - 'a'] + 1) * (int)p[i].size());
    }
    for (int j = 0; j <= 25; j++) {
      cur[j] = cur1[j];
      cur1[j] = 0;
    }
  }
  int ans = 0;
  for (int j = 0; j <= 25; j++) {
    ans = max(ans, cur[j]);
  }
  cout << ans;
  return 0;
}
