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() {
  string str;
  vector<string> vs;
  long long len, pnum, snum, n;
  char f_c, l_c;
  bool one;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> str;
    vs.push_back(str);
  }
  reverse(vs.begin(), vs.end());
  len = 1, pnum = 1, snum = 1;
  f_c = vs[0][0], l_c = vs[0][vs[0].size() - 1];
  long long temp = 1;
  for (int i = 1; i < vs[0].size(); i++) {
    if (vs[0][i] == vs[0][i - 1]) {
      temp++;
      len = max(len, temp);
    } else {
      temp = 1;
    }
  }
  for (int i = 1; i < vs[0].size(); i++) {
    if (vs[0][i] == vs[0][i - 1]) {
      pnum++;
    } else
      break;
  }
  for (int i = vs[0].size() - 2; i >= 0; i--) {
    if (vs[0][i] == vs[0][i + 1]) {
      snum++;
    } else
      break;
  }
  if (len == vs[0].size())
    one = true;
  else
    one = false;
  for (int i = 1; i < vs.size(); i++) {
    str = vs[i];
    bool one2 = true;
    for (int j = 1; j < str.size(); j++) {
      if (str[j] != str[j - 1]) {
        one2 = false;
        break;
      }
    }
    if (f_c != str[0]) one2 = false;
    temp = 0;
    if (one) {
      temp = 0;
      int j;
      bool ok = true;
      for (j = 0; j < str.size(); j++) {
        if (str[j] == l_c) {
          temp += (len + 1);
          pnum = max(pnum, temp);
        } else {
          ok = false;
          break;
        }
      }
      if (ok) pnum += len;
      ok = true;
      temp = 0;
      for (j = str.size() - 1; j >= 0; j--) {
        if (str[j] == f_c) {
          temp += (len + 1);
          snum = max(snum, temp);
        } else {
          ok = false;
          break;
        }
      }
      if (ok) snum += len;
      temp = 0;
      long long len2 = len;
      for (int j = 0; j < str.size(); j++) {
        if (f_c == str[j]) {
          temp += len2 + 1;
        }
        if (j == str.size() - 1) {
          len = max(len, temp + len2);
        }
        if (f_c != str[j]) {
          len = max(len, temp + len2);
          temp = 0;
        }
      }
    } else {
      temp = 0;
      for (int j = 0; j < str.size(); j++) {
        if (str[j] == f_c && str[j] == l_c) {
          temp = pnum + snum + 1;
        } else if (str[j] == f_c) {
          temp = pnum + 1;
        } else if (str[j] == l_c) {
          temp = snum + 1;
        }
        len = max(len, temp);
      }
    }
    one &= one2;
  }
  cout << len;
}
