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 MAXN = 100005;
const int MAXC = 26;
int N, sz[MAXN], longest[MAXN][MAXC];
string s[MAXN];
pair<char, int> st[MAXN], en[MAXN];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> s[i];
    sz[i] = s[i].size();
    st[i] = make_pair(s[i][0], 0);
    en[i] = make_pair(s[i][sz[i] - 1], 0);
    for (int j = 0; j < sz[i] && s[i][j] == s[i][0]; j++) st[i].second++;
    for (int j = sz[i] - 1; j >= 0 && s[i][j] == s[i][sz[i] - 1]; j--)
      en[i].second++;
    for (int j = 0; j < sz[i]; j++) {
      int k = j;
      while (k < sz[i] && s[i][j] == s[i][k]) k++;
      longest[i][s[i][j] - 'a'] = max(k - j, longest[i][s[i][j] - 'a']);
      j = k - 1;
    }
  }
  for (int i = 1; i < N; i++) {
    if (st[i].second == sz[i]) {
      longest[i][s[i][0] - 'a'] =
          max(longest[i][s[i][0] - 'a'],
              sz[i] * (sz[i - 1] + 1) + longest[i - 1][s[i][0] - 'a']);
    } else if (st[i].first == en[i].first && longest[i - 1][s[i][0] - 'a']) {
      longest[i][s[i][0] - 'a'] =
          max(longest[i][s[i][0] - 'a'], st[i].second + en[i].second + 1);
    }
    longest[i][s[i][0] - 'a'] =
        max(longest[i][s[i][0] - 'a'],
            st[i].second + (longest[i - 1][s[i][0] - 'a'] > 0));
    longest[i][s[i][sz[i] - 1] - 'a'] =
        max(longest[i][s[i][sz[i] - 1] - 'a'],
            en[i].second + (longest[i - 1][s[i][sz[i] - 1] - 'a'] > 0));
    for (int j = 0; j < 26; j++) {
      longest[i][j] = max(longest[i][j], (int)(longest[i - 1][j] > 0));
    }
  }
  int ans = 0;
  for (int j = 0; j < 26; j++) {
    ans = max(ans, longest[N - 1][j]);
  }
  cout << ans;
}
