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 + 5;
const int A = 28;
int n;
string second;
int dp[N][A], pref[N][A], suf[N][A], sub[N][A], len[N];
int main() {
  scanf("%d", &n);
  for (int curr = 1; curr <= n; curr++) {
    cin >> second;
    len[curr] = second.length();
    int cntPref = 0;
    for (int i = 0; i <= second.length() - 1; i++) {
      if (second[i] != second[0]) {
        break;
      }
      cntPref++;
    }
    pref[curr][second[0] - 'a' + 1] = cntPref;
    int cntSuf = 0;
    for (int i = second.length() - 1; i >= 0; i--) {
      if (second[i] != second[second.length() - 1]) {
        break;
      }
      cntSuf++;
    }
    suf[curr][second[second.length() - 1] - 'a' + 1] = cntSuf;
    second = '0' + second;
    int cntCurr = 0;
    for (int i = 1; i <= second.length() - 1; i++) {
      if (second[i] == second[i - 1]) {
        cntCurr++;
      } else {
        cntCurr = 1;
      }
      sub[curr][second[i] - 'a' + 1] =
          max(sub[i][second[i] - 'a' + 1], cntCurr);
    }
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= 26; j++) {
      if (dp[i - 1][j] == 0) {
        dp[i][j] = sub[i][j];
      } else {
        if (pref[i][j] == len[i]) {
          dp[i][j] = dp[i - 1][j] * (len[i] + 1) + len[i];
        } else {
          dp[i][j] = max(sub[i][j], pref[i][j] + suf[i][j] + 1);
        }
      }
    }
  }
  int ans = INT_MIN;
  for (int j = 1; j <= 26; j++) {
    ans = max(ans, dp[n][j]);
  }
  printf("%d\n", ans);
  return 0;
}
