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;
int n;
string s[100010];
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];
  for (int i = 0; i < n / 2; ++i) swap(s[i], s[n - 1 - i]);
  int s1 = s[0].size();
  int cnt_max = 0;
  int temp = 1;
  for (int i = 1; i <= s1 - 1; ++i) {
    if (s[0][i] == s[0][i - 1])
      temp++;
    else
      temp = 1;
    cnt_max = max(cnt_max, temp);
  }
  if (s[0][0] == s[0].back()) {
    char par = s[0][0];
    bool pass = true;
    int t = 0;
    int siz = 0;
    while (pass) {
      for (int i = 0; i < s[t].size(); ++i)
        if (s[t][i] != par) pass = false;
      ;
      if (pass == false) break;
      siz = (s[t].size() + 1) * siz + s[t].size();
      t++;
      if (t == n) break;
    }
    if (t == n) {
      cout << siz << endl;
      return 0;
    }
    int cnt_begin = 0, cnt_end = 0, cnt_final = 0;
    while (s[t][cnt_begin] == par) cnt_begin++;
    int st = s[t].size();
    while (s[t][st - 1 - cnt_end] == par) cnt_end++;
    int temp = 0;
    for (int i = 0; i < st; ++i) {
      if (s[t][i] == par)
        temp++;
      else
        temp = 0;
      cnt_final = max(cnt_final, temp);
    }
    cnt_final = (cnt_final + 1) * siz + cnt_final;
    cnt_final = max(cnt_final, cnt_max);
    cnt_begin = (cnt_begin + 1) * siz + cnt_begin;
    cnt_end = (cnt_end + 1) * siz + cnt_end;
    bool pos = false;
    for (int i = t + 1; i < n; i++) {
      for (int j = 0; j < s[i].size(); ++j) {
        if (s[i][j] == par) pos = true;
      }
    }
    if (pos) cnt_begin += cnt_end + 1;
    cout << max(cnt_begin, max(cnt_end, cnt_final));
    return 0;
  } else {
    int cnt_begin = 1, cnt_end = 1;
    char star = s[0][0], end = s[0].back();
    while (s[0][cnt_begin] == s[0][cnt_begin - 1]) cnt_begin++;
    while (s[0][s1 - cnt_end] == s[0][s1 - 1 - cnt_end]) cnt_end++;
    bool star_true = false, end_true = false;
    for (int i = 1; i <= n - 1; ++i) {
      for (int j = 0; j < s[i].size(); ++j) {
        if (s[i][j] == star) star_true = true;
        if (s[i][j] == end) end_true = true;
      }
    }
    if (star_true) cnt_begin++;
    if (end_true) cnt_end++;
    cout << max(cnt_begin, max(cnt_end, cnt_max)) << endl;
    return 0;
  }
  return 0;
}
