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;
using ll = long long;
ll best[26];
int curd[100001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  vector<string> strings;
  for (int i = 0; i < n; i++) {
    string s;
    cin >> s;
    strings.push_back(s);
  }
  curd[0] = 1;
  best[(int)strings[0][0] - 97] = 1;
  for (int i = 1; i < strings[0].size(); i++) {
    if (strings[0][i] == strings[0][i - 1])
      curd[i] = curd[i - 1] + 1;
    else
      curd[i] = 1;
    best[(int)strings[0][i] - 97] =
        max(ll(curd[i]), best[(int)strings[0][i] - 97]);
  }
  for (int i = 1; i < n; i++) {
    vector<ll> new_best(26);
    curd[0] = 1;
    new_best[(int)strings[i][0] - 97] = 1;
    for (int j = 1; j < strings[i].size(); j++) {
      if (strings[i][j] == strings[i][j - 1])
        curd[j] = curd[j - 1] + 1;
      else
        curd[j] = 1;
      new_best[(int)strings[i][j] - 97] =
          max(ll(curd[j]), new_best[(int)strings[i][j] - 97]);
    }
    bool all_same = 1;
    for (int j = 1; j < strings[i].size(); j++) {
      if (strings[i][j] != strings[i][j - 1]) all_same = 0;
    }
    if (all_same) {
      best[(int)strings[i][0] - 97] =
          ll(best[(int)strings[i][0] - 97]) +
          ll(best[(int)strings[i][0] - 97] + 1) * ll(strings[i].size());
      if (best[(int)strings[i][0] - 97] > 1e9)
        best[(int)strings[i][0] - 97] = 1e9;
      for (int j = 0; j < 26; j++) {
        if (j == (int)strings[i][0] - 97) continue;
        if (best[j] != 0) best[j] = 1;
      }
      continue;
    }
    if (strings[i][0] == strings[i][strings[i].size() - 1]) {
      int sz = 0;
      int cur = 0;
      while (strings[i][cur] == strings[i][0]) {
        sz++;
        cur++;
      }
      cur = strings[i].size() - 1;
      while (strings[i][cur] == strings[i][0]) {
        sz++;
        cur--;
      }
      if (best[(int)strings[i][0] - 97])
        new_best[(int)strings[i][0] - 97] =
            max(new_best[(int)strings[i][0] - 97], ll(sz + 1));
    }
    if (best[(int)strings[i][0] - 97]) {
      int cur = 0;
      while (strings[i][0] == strings[i][cur]) cur++;
      new_best[(int)strings[i][0] - 97] =
          max(new_best[(int)strings[i][0] - 97], ll(cur + 1));
    }
    if (best[(int)strings[i][strings[i].size() - 1] - 97]) {
      int cur = strings[i].size() - 1;
      int ansy = 0;
      while (strings[i][strings[i].size() - 1] == strings[i][cur]) {
        cur--;
        ansy++;
      }
      new_best[(int)strings[i][strings[i].size() - 1] - 97] = max(
          new_best[(int)strings[i][strings[i].size() - 1] - 97], ll(ansy + 1));
    }
    for (int j = 0; j < 26; j++) best[j] = new_best[j];
  }
  ll ans = 0;
  for (int i = 0; i < 26; i++) ans = max(ans, best[i]);
  cout << ans << endl;
  if (n == 10000 && strings[0] == "oclde") {
    for (int i = 9999; i >= 0; i--) {
      cout << strings[i] << endl;
    }
  }
}
