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>
const double eps = (1e-9);
using namespace std;
int dcmp(long double a, long double b) {
  return fabsl(a - b) <= eps ? 0 : (a > b) ? 1 : -1;
}
int getBit(int num, int idx) { return ((num >> idx) & 1) == 1; }
int setBit1(int num, int idx) { return num | (1 << idx); }
long long setBit0(long long num, int idx) { return num & ~(1ll << idx); }
long long flipBit(int num, int idx) { return num ^ (1 << idx); }
void FS() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int countNumBit1(int mask) {
  int ret = 0;
  while (mask) {
    mask &= (mask - 1);
    ++ret;
  }
  return ret;
}
int n;
vector<string> s;
int getmax(string st) {
  int mx = 0, cnt = 0;
  for (int i = 0; i < ((int)(st).size()); i++) {
    if (i + 1 < ((int)(st).size()) && st[i] == st[i + 1]) {
      cnt++;
    } else {
      cnt++;
      mx = max(mx, cnt);
      cnt = 0;
    }
  }
  mx = max(cnt, mx);
  return mx;
}
int getcharmax(string st, char ch) {
  int mx = 0, cnt = 0;
  for (int i = 0; i < ((int)(st).size()) - 1; i++) {
    if (st[i] == ch) {
      cnt++;
    } else {
      mx = max(mx, cnt);
      cnt = 0;
    }
  }
  mx = max(cnt, mx);
  return mx;
}
pair<int, char> getprefix(string st) {
  int cnt = 0;
  for (int i = 0; i < ((int)(st).size()); i++) {
    if (i + 1 < ((int)(st).size()) && st[i] != st[i + 1]) {
      cnt++;
      break;
    } else {
      cnt++;
    }
  }
  return make_pair(cnt, st[0]);
}
pair<bool, char> isonechar(string st) {
  char ch = st[0];
  int n = ((int)(st).size());
  for (int i = 0; i < n; i++) {
    if (st[i] != ch) return make_pair(0, 'a');
  }
  return make_pair(1, ch);
}
pair<int, char> getsuffix(string st) {
  int cnt = 0;
  int n = ((int)(st).size());
  for (int i = n - 1; i >= 0; i--) {
    if (i - 1 >= 0 && st[i] != st[i - 1]) {
      cnt++;
      break;
    } else {
      cnt++;
    }
  }
  return make_pair(cnt, st[n - 1]);
}
bool isfind(int l, int r, char ch) {
  for (int i = l; i <= r; i++) {
    for (int j = 0; j < ((int)(s[i]).size()); j++) {
      if (s[i][j] == ch) return 1;
    }
  }
  return 0;
}
int solve(int n, char ch) {
  if (n == 1) {
    return getcharmax(s[n], ch);
  }
  int mx = 0;
  pair<bool, char> p1 = isonechar(s[n]);
  long long m1 = getcharmax(s[n], ch);
  pair<int, char> p2 = getprefix(s[n]);
  pair<int, char> p3 = getsuffix(s[n]);
  bool p4 = isfind(1, n - 1, ch);
  long long m2 = 0, m3 = 0;
  if (p2.second == p3.second && p2.second == ch && p4) {
    m2 = p2.first + p3.first + 1;
  }
  mx = max(m1, max(m2, m3));
  if (p1.first == 1 && p1.second == ch) {
    mx = max(mx, (solve(n - 1, ch) + 1));
  }
  return mx * ((int)(s[n]).size());
}
int main() {
  cin >> n;
  s.push_back("");
  for (int i = 1; i <= n; i++) {
    string str;
    cin >> str;
    s.push_back(str);
  }
  pair<bool, char> p = isonechar(s[n]);
  int m1 = getmax(s[n]);
  pair<int, char> p1 = getprefix(s[n]);
  pair<int, char> p2 = getsuffix(s[n]);
  bool p3 = isfind(1, n - 1, p1.second);
  int m2 = 0;
  if (p1.second == p2.second && p3) {
    m2 = p1.first + p2.first + 1;
  }
  if (p.first == 0) {
    cout << max(m1, m2) << endl;
    return 0;
  }
  int cnt = solve(n - 1, p.second);
  long long ans = max(m1, max(m2, (cnt + 1) * ((int)(s[n]).size())));
  cout << ans << endl;
}
