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 main() {
  int n;
  cin >> n;
  vector<string> s(n);
  for (int i = 0; i < n; i++) cin >> s[i];
  long long l = 0, r = 0;
  char lc = s[n - 1][0], rc = s[n - 1][s[n - 1].length() - 1];
  for (int i = 0; i < n; i++) {
    if (s[n - 1][i] == lc)
      l++;
    else
      break;
  }
  for (int i = s[n - 1].length() - 1; i >= 0; i--) {
    if (s[n - 1][i] == rc)
      r++;
    else
      break;
  }
  bool all = (l == s[n - 1].length());
  long long ans = 0;
  long long nl, nr;
  for (int i = n - 2; i >= 0; i--) {
    if (lc == rc) {
      for (int j = 0; j < s[i].length(); j++) {
        if (s[i][j] == lc) {
          ans = max(ans, l + r + 1);
        }
      }
    } else {
      for (int j = 0; j < s[i].length(); j++) {
        if (s[i][j] == lc) {
          ans = max(ans, l + 1);
        }
        if (s[i][j] == rc) {
          ans = max(ans, r + 1);
        }
      }
    }
    if (all) {
      nl = l;
      for (int j = 0; j < s[i].length(); j++) {
        if (s[i][j] == lc)
          nl += l + 1;
        else {
          all = false;
          break;
        }
      }
      nr = r;
      for (int j = s[i].length() - 1; j >= 0; j--) {
        if (s[i][j] == rc)
          nr += r + 1;
        else {
          all = false;
          break;
        }
      }
      if (!all) {
        int count = 0;
        for (int j = 0; j < s[i].length(); j++) {
          if (s[i][j] == nl) {
            count++;
          } else {
            ans = max(ans, l + count * (l + 1));
            count = 0;
          }
        }
        ans = max(ans, l + count * (l + 1));
      }
      l = nl;
      r = nr;
    }
  }
  ans = max(ans, max(l, r));
  cout << ans << endl;
  return 0;
}
