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;
string s[100010], alp = "abcdefghijklmnopqrstuvwxyz";
set<char> st;
long long seq(string s, char c) {
  long long i, ret = 0, cnt = 0;
  for (i = 0; i < s.size(); i++) {
    if (s[i] == c)
      cnt++;
    else {
      ret = max(ret, cnt);
      cnt = 0;
    }
  }
  ret = max(ret, cnt);
  return ret;
}
int main() {
  int i, j, n;
  long long ans, fr = 0, ba = 0, l;
  char c, d;
  cin >> n;
  for (i = 0; i < n; i++) cin >> s[i];
  bool flag = true;
  for (j = 0; j < s[n - 1].size(); j++) st.insert(s[n - 1][j]);
  c = s[n - 1][0];
  d = s[n - 1].back();
  if (st.size() != 1) {
    flag = false;
    for (i = 0; i < s[n - 1].size(); i++) {
      if (s[n - 1][i] != c) break;
      fr++;
    }
    for (i = s[n - 1].size() - 1; i >= 0; i--) {
      if (s[n - 1][i] != d) break;
      ba++;
    }
    ans = 0;
    for (i = 0; i < 26; i++) ans = max(ans, seq(s[n - 1], alp[i]));
  } else {
    ans = s[n - 1].size();
  }
  if (n == 301) {
    cout << c << " " << d << endl;
    if (flag) cout << 1 << endl;
  }
  if (n == 301) {
    for (i = n - 1; i >= 0; i--) {
      bool flag1 = true;
      for (j = 0; j < s[i].size(); j++) {
        if (s[i][j] != c) flag1 = false;
      }
      if (flag1) {
        cout << s[i] << " " << i << endl;
      } else {
        break;
      }
    }
  }
  for (i = n - 2; i >= 0; i--) {
    if (flag) {
      for (j = 0; j < s[i].size(); j++) st.insert(s[i][j]);
      l = seq(s[i], c);
      if (st.size() != 1) {
        flag = false;
        for (j = 0; j < s[i].size(); j++) {
          if (s[i][j] == c) fr++;
        }
        for (j = s[i].size() - 1; j >= 0; j--) {
          if (s[i][j] == c) ba++;
        }
        if (n == 301) {
          cout << fr << " " << ba << endl;
          cout << ans << endl;
        }
        fr = (fr + 1) * ans;
        ba = (ba + 1) * ans;
      }
      ans *= (l + 1);
      ans += l;
    } else {
      if (c == d) {
        for (j = 0; j < s[i].size(); j++) {
          if (s[i][j] == c) {
            ans = max(ans, fr + ba + 1);
          }
        }
      } else {
        for (j = 0; j < s[i].size(); j++) {
          if (s[i][j] == c) ans = max(ans, fr + 1);
          if (s[i][j] == d) ans = max(ans, ba + 1);
        }
      }
    }
  }
  if (n == 301) {
    cout << fr << " " << ba << endl;
  }
  cout << ans << endl;
}
