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;
bool is_easy(string t, char m) {
  bool yes = true;
  for (auto u : t) {
    if (u != m) return false;
  }
  return true;
}
long long best_string(string t) {
  long long m = 0;
  long long res = 0;
  char t1 = '-1';
  for (auto u : t) {
    if (u == t1)
      m++;
    else
      m = 1;
    t1 = u;
    res = max(res, m);
  }
  return res;
}
long long best_string(string t, char t1) {
  long long m = 0;
  long long res = 0;
  for (auto u : t) {
    if (u == t1)
      m++;
    else
      m = 0;
    res = max(res, m);
  }
  return res;
}
set<char> all_chars;
void add_string(string t) {
  for (auto u : t) all_chars.insert(u);
}
int main() {
  int n;
  cin >> n;
  vector<string> ar(n);
  for (int i = 0; i < n; i++) cin >> ar[i];
  long long additive = 0;
  reverse(ar.begin(), ar.end());
  int i = 0;
  for (; i < n; i++) {
    if (is_easy(ar[i], ar[0][0])) {
      if (additive == 0) {
        additive = ar[i].size();
      } else {
        additive = additive * (ar[i].size() + 1) + ar[i].size();
      }
    } else
      break;
  }
  if (i >= n) {
    cout << additive;
    return 0;
  }
  if (i > 0) {
    for (int j = i + 1; j < n; j++) {
      add_string(ar[j]);
    }
    int m1 = (best_string(ar[i], ar[0][0]));
    if (all_chars.find(ar[0][0]) != all_chars.end())
      m1 = best_string(ar[i] + ar[0][0] + ar[i], ar[0][0]);
    cout << additive * (m1 + 1) + m1;
  } else {
    long long answer = best_string(ar[i]);
    for (int j = 1; j < n; j++) add_string(ar[j]);
    for (auto u : all_chars) {
      answer = max(answer, best_string(ar[i] + u + ar[i]));
    }
    cout << answer;
  }
  return 0;
}
