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 = 1e5 + 5;
string s[maxn];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, i;
  cin >> n;
  for (i = 0; i < n; i++) cin >> s[i];
  bool isonly = 1;
  int pre = 1, suf = 1;
  char charpre = s[n - 1][0], charsuf = s[n - 1][s[n - 1].length() - 1];
  int ans = 1;
  int temp = 1;
  for (i = 1; i < s[n - 1].length(); i++) {
    if (s[n - 1][i] == s[n - 1][i - 1]) {
      temp++;
    } else {
      ans = max(ans, temp);
      isonly = 0;
      temp = 1;
    }
  }
  ans = max(ans, temp);
  if (isonly)
    pre = suf = s[n - 1].length();
  else {
    for (i = 1; i < s[n - 1].length(); i++) {
      if (s[n - 1][i] == s[n - 1][i - 1])
        pre++;
      else
        break;
    }
    for (i = s[n - 1].length() - 2; i >= 0; i--) {
      if (s[n - 1][i] == s[n - 1][i + 1])
        suf++;
      else
        break;
    }
  }
  int j;
  int tot;
  for (i = n - 2; i >= 0; i--) {
    if (isonly) {
      int pos1, pos2;
      tot = 0;
      for (j = 0; j < s[i].length(); j++) {
        if (s[i][j] == charpre)
          tot++;
        else {
          pos1 = j;
          break;
        }
      }
      if (tot == s[i].length()) {
        pre = suf = pre * (s[i].length() + 1) + s[i].length();
        ans = max(ans, pre);
      } else {
        isonly = 0;
        pre = (tot + 1) * pre + tot;
        ans = max(ans, pre);
        tot = 0;
        for (j = s[i].length() - 1; j >= 0; j--) {
          if (s[i][j] == charsuf)
            tot++;
          else {
            pos2 = j;
            break;
          }
        }
        int last = suf;
        suf = (tot + 1) * suf + tot;
        ans = max(ans, suf);
        for (j = pos1 + 1; j < pos2; j++) {
          if (s[i][j] == charpre) {
            int len = 0, k;
            for (k = j; k < pos2; k++) {
              if (s[i][k] == charpre)
                len++;
              else {
                ans = max((len + 1) * last + len, ans);
                break;
              }
            }
            j = k;
            ans = max((len + 1) * last + len, ans);
          }
        }
      }
    } else {
      if (charpre == charsuf) {
        for (j = 0; j < s[i].length(); j++) {
          if (s[i][j] == charpre) {
            ans = max(ans, pre + suf + 1);
            break;
          }
        }
      } else {
        for (j = 0; j < s[i].length(); j++) {
          if (s[i][j] == charpre)
            ans = max(ans, pre + 1);
          else if (s[i][j] == charsuf)
            ans = max(ans, suf + 1);
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}
